<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" 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" id="LPlnk253682">http://idlastro.gsfc.nasa.gov/ftp/pro/fits/sxpar.pro</a><span style="font-size: 12pt;"><br>
</span></p>
<div id="LPBorder_GT_14554540429860.5339702949859202" style="margin-bottom: 20px; overflow: auto; width: 100%; text-indent: 0px;">
<table id="LPContainer_14554540429840.7866164406295866" cellspacing="0" style="width: 90%; background-color: rgb(255, 255, 255); position: relative; 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 id="TextCell_14554540429850.9633624730631709" colspan="2" style="vertical-align: top; position: relative; padding: 0px; display: table-cell;">
<div id="LPRemovePreviewContainer_14554540429860.15470921038649976"></div>
<div id="LPTitle_14554540429860.4091833035927266" style="top: 0px; 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 id="LPUrlAnchor_14554540429860.03254285338334739" href="http://idlastro.gsfc.nasa.gov/ftp/pro/fits/sxpar.pro" target="_blank" style="text-decoration: none;" title="http://idlastro.gsfc.nasa.gov/ftp/pro/fits/sxpar.pro
Cmd+Click or tap to follow the link">"sxpar.pro"
 - idlastro.gsfc.nasa.gov</a></div>
<div id="LPMetadata_14554540429860.5565350377000868" 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;">
idlastro.gsfc.nasa.gov</div>
<div id="LPDescription_14554540429860.4648694528732449" 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> astropy.io <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>
</body>
</html>