<div dir="ltr">astropy.io.fits.open(filename)[0]['NAXIS1'] will give you the value of the NAXSI1 keyword in the primary header.<div><br></div><div>In the Python FITS library, a FITS file is a list of headers and each header is a list of rows.  The value of a keyword can be obtained by specifying the header name or index, and the keyword name as show above.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Feb 14, 2016 at 7:47 AM, Roberts, Michael <span dir="ltr"><<a href="mailto:michael.roberts.15@ucl.ac.uk" target="_blank">michael.roberts.15@ucl.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">
<div style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif">
<p>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)</p>
<p><br>
</p>
<p>I'm looking to find an equivalent to SXPAR (<span style="font-size:12pt">whose function is to o</span><span style="font-size:12pt;white-space:pre-wrap">btain the value of a parameter in a FITS header</span><span style="font-size:12pt">)</span><span style="font-size:12pt">
 from IDL into python</span><span style="font-size:12pt">...</span></p>
<p><span style="font-size:12pt"><br>
</span></p>
<p><a href="http://idlastro.gsfc.nasa.gov/ftp/pro/fits/sxpar.pro" target="_blank">http://idlastro.gsfc.nasa.gov/ftp/pro/fits/sxpar.pro</a><span style="font-size:12pt"><br>
</span></p>
<div style="margin-bottom:20px;overflow:auto;width:100%;text-indent:0px">
<table cellspacing="0" style="width:90%;background-color:rgb(255,255,255);overflow:auto;padding-top:20px;padding-bottom:20px;margin-top:20px;border-top-width:1px;border-top-style:dotted;border-top-color:rgb(200,200,200);border-bottom-width:1px;border-bottom-style:dotted;border-bottom-color:rgb(200,200,200)">
<tbody>
<tr valign="top" style="border-spacing:0px">
<td colspan="2" style="vertical-align:top;padding:0px;display:table-cell">
<div></div>
<div style="color:rgb(0,120,215);font-weight:normal;font-size:21px;font-family:wf_segoe-ui_light,'Segoe UI Light','Segoe WP Light','Segoe UI','Segoe WP',Tahoma,Arial,sans-serif;line-height:21px">
<a href="http://idlastro.gsfc.nasa.gov/ftp/pro/fits/sxpar.pro" style="text-decoration:none" title="http://idlastro.gsfc.nasa.gov/ftp/pro/fits/sxpar.pro
Cmd+Click or tap to follow the link" target="_blank">"sxpar.pro"
 - idlastro.gsfc.nasa.gov</a></div>
<div style="margin:10px 0px 16px;color:rgb(102,102,102);font-weight:normal;font-family:wf_segoe-ui_normal,'Segoe UI','Segoe WP',Tahoma,Arial,sans-serif;font-size:14px;line-height:14px">
<a href="http://idlastro.gsfc.nasa.gov" target="_blank">idlastro.gsfc.nasa.gov</a></div>
<div style="display:block;color:rgb(102,102,102);font-weight:normal;font-family:wf_segoe-ui_normal,'Segoe UI','Segoe WP',Tahoma,Arial,sans-serif;font-size:14px;line-height:20px;max-height:100px;overflow:hidden">
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 ...</div>
</td>
</tr>
</tbody>
</table>
</div>
<p><span style="font-size:12pt;white-space:pre-wrap">This is the original code in IDL:</span><br>
</p>
<p><span style="white-space:pre-wrap;font-size:12pt"></span></p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo">
nxpix_uw1_ext1 = sxpar(hima_sk_uw1_ext1,<span style="color:#272ad8">'NAXIS1'</span>)</p>
<p></p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo">
nypix_uw1_ext1 = sxpar(hima_sk_uw1_ext1,<span style="color:#272ad8">'NAXIS2'</span>)</p>
<p><span style="white-space:pre-wrap;font-size:12pt"></span></p>
<p><span style="white-space:pre-wrap;font-size:12pt">This is my conversion attempt into python using astropy.fits:</span></p>
<p><span style="white-space:pre-wrap;font-size:12pt"></span></p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo">
<span style="color:#bb2ca2">from</span> <a href="http://astropy.io" target="_blank">astropy.io</a> <span style="color:#bb2ca2">import</span> fits</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">
<br>
</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo">
hima_sk_um2 = fits.open(<span style="color:#272ad8">''</span>) #Will contain the directory extension to the fits/img file I wish to open</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">
<br>
</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)">
# Compute the size of the images (you can also do this manually rather than calling these keywords from the header):</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo">
nxpix_um2_ext1 = hima_sk_um2[<span style="color:#272ad8">1</span>].header[<span style="color:#272ad8">'NAXIS1'</span>]</p>
<p></p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;line-height:normal;font-family:Menlo">
nypix_um2_ext1 = hima_sk_um2[<span style="color:#272ad8">1</span>].header[<span style="color:#272ad8">'NAXIS2'</span>]</p>
<p><span style="white-space:pre-wrap;font-size:12pt"></span></p>
<p><span style="white-space:pre-wrap;font-size:12pt">Firstly, is this correct? And secondly, is this the best way to handle an extension value?</span></p>
<p><span style="white-space:pre-wrap;font-size:12pt"></span></p>
<p><span style="white-space:pre-wrap;font-size:12pt">Any advise would be warmly received.</span></p>
<p><span style="white-space:pre-wrap;font-size:12pt"></span></p>
<p><span style="white-space:pre-wrap;font-size:12pt">Many thanks,</span></p>
<p><span style="white-space:pre-wrap;font-size:12pt"></span></p>
<p><span style="white-space:pre-wrap;font-size:12pt">Michael</span></p>
</div>
</div>

<br>_______________________________________________<br>
AstroPy mailing list<br>
<a href="mailto:AstroPy@scipy.org">AstroPy@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/astropy" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/astropy</a><br>
<br></blockquote></div><br></div>