andresgur / muse_project

Scripts to deal with some subtleties regarding MUSE data
0 stars 1 forks source link

Optimize writting of the annulus region #1

Closed andresgur closed 3 years ago

andresgur commented 3 years ago

``f_reg = open('annuli.reg', 'w+') The current writting of the region file is not optimal f_reg.write( '# Region file format: DS9 version 4.1\n'\ +'#global color=green 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\nfk5\n')

for i in range(nbins):

if i == 0:
    curr_tuple = ra_tuple + dec_init_tuple
    f_reg.write('circle(%i:%i:%s,%i:%i:%s,%s")\n' % curr_tuple)
else:
    curr_tuple = ra_tuple + dec_tuple + (str(round(radii[i].value, 4)), str(round(radii[i + 1].value, 4)))
    f_reg.write('annulus(%i:%i:%s,%i:%i:%s,%s",%s")\n' % curr_tuple)

`f_reg.close()```

it can be written much easily using something like radii_string = "" for radius in radii[1:]: radii_string += ",%.4f" radius.value 'annulus(%i:%i:%s,%i:%i:%s' %(center, radii_string) plus the final region will be stored as a real annulus instead of a composite of regions

andresgur commented 3 years ago

fixed

andresgur commented 3 years ago

def write_annuli(ctr_coord, radii):

out_reg = '# Region file format: DS9 version 4.1\n'\
    + '#global color=green 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\nfk5\n'

out_reg += 'annulus(%d:%d:%.4f,%d:%d:%.4f,' % (ctr_coord.ra.hms[0], ctr_coord.ra.hms[1],
                  ctr_coord.ra.hms[2], ctr_coord.dec.dms[0], np.abs(ctr_coord.dec.dms[1]), np.abs(ctr_coord.dec.dms[2]))

for radius in radii[1:-1]:
    out_reg += '%.3f",' % radius
out_reg += '%.3f")' % radii[-1]
f_reg = open('annuli.reg', 'w+')
f_reg.write(out_reg)
f_reg.close()