write reg

这段代码展示了如何利用Astropy库读取FITS文件,并进行后续处理。它首先通过os.system执行命令来筛选特定格式的文件,然后打开这些文件获取数据。接着,它创建一个.reg文件,用于标记数据中的星体位置,用circle函数写入每个星体的坐标。此过程涉及天文学数据的管理和可视化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

from astropy.io import fits
import os


# cmd1 = 'ls ./tmp/*589*.2acat >2acat.dat'
# cmd2 = 'ls ./tmp/*589*.xy >xy.dat'
#
# os.system(cmd1)
# os.system(cmd2)

blist = [line.rstrip()for line in open('in_gaborstar.log')]
path = './tmp/'
for j in blist:
    # xyfile = path+j[-65:-5]+'.xy'
    xyfile = path + j[23:83] + '.xy'
    # xyfile = j[0:66]+'.xy11'
    print(xyfile)


# alist = [line.rstrip()for line in open('2acat.dat')]
# for i in alist:
    filesatreg = xyfile[0:-3]+'.reg'
    if os.path.exists(filesatreg):
        cmd3 = 'rm '+filesatreg
        os.system(cmd3)

    f3 = open(filesatreg, 'a')
    hdul2 = fits.open(xyfile)
    stardata = hdul2[1].data

    f3.write('global color=red dashlist=8 3 width=1 font="helvetica 10 normal roman" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include =1 source=1'+'\n')
    f3.write('physical'+'\n')
    # for kk in range(len(objdata ))  :
    #      f3.write('circle('+str( objdata['X'][kk]   ) +','+str( objdata['Y'][kk]     )+','+  str(  4  )   +  ')'+'\n')
    for b in range(len(stardata ))  :
         f3.write('circle('+str( stardata['X'][b]   ) +','+str( stardata['Y'][b]     )+','+  str(  4  )   +  ')'+'\n')
    hdul2.close()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值