[AstroPy] Instantiating empty tables
Joshua Schroeder
jps at astro.columbia.edu
Fri Apr 12 12:15:32 EDT 2013
I learned yesterday at the CfA code coffee about astropy.table. For my work, I want to instantiate a table that I then populate with data taken from the headers of many different fits observations. The problem is that it looks like I cannot add rows to an empty table. E.g., while this will work:
>> usefulstuff = Table([['a'],['b'],['c'],['d'],[123.1],['as'],['R'],[213.2],[2.24],['12.25151'],['33.2511']],
names=('PATH','FILE','TELESCOPE','INSTRUMENT', 'JD', 'OBJECT', 'FILTER',
'EXPTIME', 'AIRMASS', 'RA', 'DEC'),
dtypes=('a64','a25','a25','a25','f8','a25','a2', 'f8','f8','a25','a25'),
masked=True)
>> usefulstuff.add_row(['a','b','c','d',123.1,'as','R',213.2,2.24,'12.25151','33.2511'])
>> print usefulstuff
PATH FILE TELESCOPE INSTRUMENT JD OBJECT FILTER EXPTIME AIRMASS RA DEC
---- ---- --------- ---------- ----- ------ ------ ------- ------- -------- -------
a b c d 123.1 as R 213.2 2.24 12.25151 33.2511
a b c d 123.1 as R 213.2 2.24 12.25151 33.2511
What does not work is:
>> usefulstuff = Table(names=('PATH','FILE','TELESCOPE','INSTRUMENT',
'JD', 'OBJECT', 'FILTER', 'EXPTIME',
'AIRMASS', 'RA', 'DEC'),
dtypes=('a64','a25','a25','a25','f8','a25','a2',
'f8','f8','a25','a25'), masked=True)
>> usefulstuff.add_row(['a','b','c','d',123.1,'as','R',213.2,2.24,'12.25151','33.2511'])
ERROR: TypeError: Empty data-type [numpy.core.fromnumeric]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/data/<ipython-input-227-985123887cc4> in <module>()
----> 1 usefulstuff.add_row(['a','b','c','d',123.1,'as','R',213.2,2.24,'12.25151','33.2511'])
/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/astropy/table/table.pyc in add_row(self, vals, mask)
1584
1585 if self.masked:
-> 1586 self._data = ma.resize(self._data, (newlen,))
1587 else:
1588 self._data.resize((newlen,), refcheck=False)
/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/numpy/ma/core.pyc in resize(x, new_shape)
6460 m = getmask(x)
6461 if m is not nomask:
-> 6462 m = np.resize(m, new_shape)
6463 result = np.resize(x, new_shape).view(get_masked_subclass(x))
6464 if result.ndim:
/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/numpy/core/fromnumeric.pyc in resize(a, new_shape)
850 a = ravel(a)
851 Na = len(a)
--> 852 if not Na: return mu.zeros(new_shape, a.dtype.char)
853 total_size = um.multiply.reduce(new_shape)
854 n_copies = int(total_size / Na)
TypeError: Empty data-type
Do I really need to instantiate a table with a dummy row that I then delete after populating the table or, for example, do I need to read the data into arrays and only make the table after looping over files?
More information about the AstroPy
mailing list