[AstroPy] Parse DETSEC etc..

Petr Kubánek petr at kubanek.net
Wed Jul 4 21:21:56 EDT 2018


Hi Astropy,

I might be stupid, but I don't see any way how to parse DETSEC and
similar FITS header you can encounter in (multiframe) FITS files. I of
course know how to parse that with e.g. re and mapping result to float
array, but is there a better way? See for the code (yes, that will
become a function..unless I know about better way):

from astropy.io import fits
import re

ff=fits.open('file.fits')
r = re.compile('\[(\d+):(\d+),(\d+):(\d+)\]')
g = r.match(ff[1].header['DETSEC'])  # DETSEC is '[20:30,40:50]'
b=map(float, g.groups())
print(b)
[20,30,40,50]


Thanks

Petr Kubánek
http://rts2.org


More information about the AstroPy mailing list