[AstroPy] Equivalent expression for SXPAR from IDL in python

Howard Bushouse bushouse at stsci.edu
Mon Feb 15 10:14:46 EST 2016


getval is a convenient shortcut for not having to separately open the FITS file or load the entire header and then search for a particular keyword. The default example below will retrieve a keyword from the primary header only. To get a value from a particular extension header use options like:

 fits.getval(“my filename.fits”, ‘NAXIS’, 2)    or
 fits.getval(“my filename.fits”, ‘NAXIS’, ext=2)  or
 fits.getval(“my filename.fits”, ‘NAXIS’, extname=‘sci’, extver=2)   or
 fits.getval(“my filename.fits”, ‘NAXIS’, (‘sci’, 2))

-Howard

On Feb 15, 2016, at 10:00 AM, Martin Beroiz <martinberoiz at gmail.com<mailto:martinberoiz at gmail.com>> wrote:

Hello,
This is how I get a single value of the header

from astropy.io<http://astropy.io/> import fits
naxis1 = fits.getval(“my filename.fits”, ’NAXIS1’)


M.

On Feb 14, 2016, at 6:47 AM, Roberts, Michael <michael.roberts.15 at ucl.ac.uk<mailto:michael.roberts.15 at ucl.ac.uk>> wrote:

I'm hoping this question is relatively straightforward for those proficient with IDL and python and fits file handling (I'm using the astropy.fits module)

I'm looking to find an equivalent to SXPAR (whose function is to obtain the value of a parameter in a FITS header) from IDL into python...

http://idlastro.gsfc.nasa.gov/ftp/pro/fits/sxpar.pro
"sxpar.pro" - idlastro.gsfc.nasa.gov<http://idlastro.gsfc.nasa.gov/ftp/pro/fits/sxpar.pro>
idlastro.gsfc.nasa.gov<http://idlastro.gsfc.nasa.gov/>
Apostrophes are stripped ; from strings. If the parameter is logical, 1b is ; returned for T, and 0b is returned for F. ; If Name was of ...

This is the original code in IDL:

nxpix_uw1_ext1 = sxpar(hima_sk_uw1_ext1,'NAXIS1')

nypix_uw1_ext1 = sxpar(hima_sk_uw1_ext1,'NAXIS2')

This is my conversion attempt into python using astropy.fits:

from astropy.io<http://astropy.io/> import fits

hima_sk_um2 = fits.open('') #Will contain the directory extension to the fits/img file I wish to open

# Compute the size of the images (you can also do this manually rather than calling these keywords from the header):
nxpix_um2_ext1 = hima_sk_um2[1].header['NAXIS1']

nypix_um2_ext1 = hima_sk_um2[1].header['NAXIS2']

Firstly, is this correct? And secondly, is this the best way to handle an extension value?

Any advise would be warmly received.

Many thanks,

Michael
_______________________________________________
AstroPy mailing list
AstroPy at scipy.org<mailto:AstroPy at scipy.org>
https://mail.scipy.org/mailman/listinfo/astropy

_______________________________________________
AstroPy mailing list
AstroPy at scipy.org<mailto:AstroPy at scipy.org>
https://mail.scipy.org/mailman/listinfo/astropy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20160215/99a13f5f/attachment.html>


More information about the AstroPy mailing list