<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi,<div>there are a couple of problems with doing it that way I think. </div><div><br></div><div>1. Table will not like column names with the same name. For fits headers these are the HISTORY and COMMENT fields which will have multiple entries in the output list you get from h0.keys().</div><div>2. While not 100% certain I think also the empty keys (which are used to split the HST fist headers into different sections) will cause problems.</div><div>3. Finally, there is also a small syntax error in your call to Table. Instead of writing rows=h0.values() you should write rows = [h0.values()] (making it a list of lists)</div><div><br></div><div>If you don’t need the HISTORY and COMMENT fields a simple fix maybe something like this:</div><div>keys_cl=[]</div><div>vals_cl=[]</div><div>for ii in range(len(h0.keys())):</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>if (h0.keys()[ii] != ’’)&(h0.keys()[ii] != ’HISTORY’)&(h0.keys()[ii] != ’COMMENT’):</div><div><span class="Apple-tab-span" style="white-space:pre">          </span>keys_cl.append(h0.keys()[ii])</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>vals_cl.append(h0.values()[ii])</div><div><br></div><div>tab = Table(rows=[vals_cl],names=keys_cl)</div><div><br></div><div>Good luck,</div><div>Jens </div><div><br><div><div>19 aug 2015 kl. 16:00 skrev Jason Tumlinson <<a href="mailto:tumlinson@stsci.edu">tumlinson@stsci.edu</a>>:</div><br class="Apple-interchange-newline"><blockquote type="cite">

<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">

<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
Hi,
<div><span class="Apple-tab-span" style="white-space:pre"></span>I am trying to harvest the information from a large number of FITS headers, parse them and do statistics on values, in an efficient manner. I read in each header in the usual fashion: </div>
<div><br>
</div>
<div>
<div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">
h = fits.open('lbiy83i0q_x1d.fits’)</div>
</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0); position: static; z-index: auto;">
<div style="margin: 0px;">h0 = h[0].header</div>
</div>
</div>
<div><br>
</div>
<div>My goal then is to get all the header info into an astropy Table such that the table columns are given by the header keys and the values in the rows are given by the values in each of 100+ headers. I tried this: </div>
<div><br>
</div>
<div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">
<span style="color: #5330e1">In [38]: </span>t = Table(rows=h0.values(), names=h0.keys())</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(195, 55, 32); background-color: rgb(0, 0, 0);">
---------------------------------------------------------------------------</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">
<span style="color: #c33720">TypeError</span>                                 Traceback (most recent call last)</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(52, 189, 38); background-color: rgb(0, 0, 0);">
<ipython-input-38-8a0ece2925d5><span style="color: #f5f5f5"> in </span><span style="color: #34bbc7"><module></span><span style="color: #5330e1">()</span></div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">
<span style="color: #34bd26">----> 1</span><span style="color: #c33720"> </span>t
<span style="color: #5330e1">=</span> Table<span style="color: #5330e1">(</span>rows<span style="color: #5330e1">=</span>h0<span style="color: #5330e1">.</span>values<span style="color: #5330e1">(),</span> names<span style="color: #5330e1">=</span>h0<span style="color: #5330e1">.</span>keys<span style="color: #5330e1">())</span></div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0); min-height: 14px;">
<br>
</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(52, 189, 38); background-color: rgb(0, 0, 0);">
/Users/tumlinson/Ureka/python/lib/python2.7/site-packages/astropy/table/table.pyc<span style="color: #f5f5f5"> in
</span><span style="color: #34bbc7">__init__</span><span style="color: #5330e1">(self, data, masked, names, dtype, meta, copy, rows)</span></div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">
<span style="color: #34bd26">    240</span>                 data <span style="color: #5330e1">
=</span> rows</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">
<span style="color: #34bd26">    241</span>             <span style="color: #34bd26">
else</span><span style="color: #5330e1">:</span></div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">
<span style="color: #34bd26">--> 242</span><span style="color: #c33720">                
</span>rec_data <span style="color: #5330e1">=</span> recarray_fromrecords<span style="color: #5330e1">(</span>rows<span style="color: #5330e1">)</span></div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">
<span style="color: #34bd26">    243</span>                 data <span style="color: #5330e1">
=</span> <span style="color: #5330e1">[</span>rec_data<span style="color: #5330e1">[</span>name<span style="color: #5330e1">]</span>
<span style="color: #34bd26">for</span> name <span style="color: #34bd26">in</span> rec_data<span style="color: #5330e1">.</span>dtype<span style="color: #5330e1">.</span>names<span style="color: #5330e1">]</span></div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(52, 189, 38); background-color: rgb(0, 0, 0);">
    244<span style="color: #f5f5f5"> </span></div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0); min-height: 14px;">
<br>
</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(52, 189, 38); background-color: rgb(0, 0, 0);">
/Users/tumlinson/Ureka/python/lib/python2.7/site-packages/astropy/table/np_utils.pyc<span style="color: #f5f5f5"> in
</span><span style="color: #34bbc7">recarray_fromrecords</span><span style="color: #5330e1">(rec_list)</span></div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(195, 55, 32); background-color: rgb(0, 0, 0);">
<span style="color: #34bd26">    604</span><span style="color: #f5f5f5">     </span>
# to column arrays in the recarray module; it could be there is a better</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(52, 189, 38); background-color: rgb(0, 0, 0);">
    605<span style="color: #f5f5f5">     </span><span style="color: #c33720"># way</span></div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">
<span style="color: #34bd26">--> 606</span><span style="color: #c33720">     </span>
nfields <span style="color: #5330e1">=</span> len<span style="color: #5330e1">(</span>rec_list<span style="color: #5330e1">[</span><span style="color: #34bbc7">0</span><span style="color: #5330e1">])</span></div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">
<span style="color: #34bd26">    607</span>     obj <span style="color: #5330e1">
=</span> np<span style="color: #5330e1">.</span>array<span style="color: #5330e1">(</span>rec_list<span style="color: #5330e1">,</span> dtype<span style="color: #5330e1">=</span>object<span style="color: #5330e1">)</span></div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">
<span style="color: #34bd26">    608</span>     array_list <span style="color: #5330e1">
=</span> <span style="color: #5330e1">[</span>np<span style="color: #5330e1">.</span>array<span style="color: #5330e1">(</span>obj<span style="color: #5330e1">[...,</span> i<span style="color: #5330e1">].</span>tolist<span style="color: #5330e1">())</span>
<span style="color: #34bd26">for</span> i <span style="color: #34bd26">in</span> range<span style="color: #5330e1">(</span>nfields<span style="color: #5330e1">)]</span></div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0); min-height: 14px;">
<br>
</div>
<div style="margin: 0px; font-size: 10px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">
<span style="color: #c33720">TypeError</span>: object of type 'bool' has no len()</div>
</div>
<div><br>
</div>
<div>to no avail. Is this possible, easy, or wrongheaded? Advise appreciated. </div>
<div><br>
</div>
<div>Thanks, </div>
<div>JT</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>

_______________________________________________<br>AstroPy mailing list<br><a href="mailto:AstroPy@scipy.org">AstroPy@scipy.org</a><br>http://mail.scipy.org/mailman/listinfo/astropy<br></blockquote></div><br><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px;"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;  "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>-----------------------------------</div><div>Jens Melinder</div><div>Department of Astronomy</div><div>Stockholm University</div><div><a href="mailto:jens@astro.su.se">jens@astro.su.se</a></div><div>+46 706471856</div><div><br></div></div></span><br class="Apple-interchange-newline"></span><br class="Apple-interchange-newline">
</div>
<br></div></body></html>