Writing files with astropy.io.fits files

I am trying to add data to the fits file using astropy.io.

Here is an example of my code:

import numpy as np from astropy.io import fits a1 = np.array([1,2,4,8]) a2 = np.array([0,1,2,3]) hdulist = fits.BinTableHDU.from_columns( [fits.Column(name='FIRST', format='E', array=a1), fits.Column(name='SECOND', format='E', array=a2)]) hdulist.writeto('file.fits') 

The error I get is

 type object 'BinTableHDU' has no attribute 'from_columns' 
  • Could this be the problem with the version of astropy.io that I am using?
  • Is there an easier way to add extensions or columns to an astropy.io-enabled file?

Any help would be appreciated.

+5
source share
1 answer

You will need to update astropia.
I can execute your example in order; what's with the latest version of astrophysics.

Looking at the change log at 0.4, it definitely looks like your version for astrology is too old. The magazine says :

The astropy.io.fits.new_table function is now completely deprecated (although it will not be removed for a long time, given how widely it is used).

Instead, use the more explicit BinTableHDU.from_columns to create a new binary HDU table and similar HDU.from_columns tables to create a new ASCII table. Otherwise, they accept the same arguments as new_table, which is now just a wrapper for them.

implying from_columns was reintroduced in 0.4


In general, if you are really using astropy version 0.3, you may need to upgrade to version 1.0 or (current) 1.1:

  • while 0.3 is only about 1.5 years old (and a little younger if you have version 0.3.x), the fast pace of astrophysics makes it pretty outdated. The interface has changed a lot, and the examples you find on the Internet these days will rarely work with your version.

  • Since astropy now belongs to the 1.x series (.y), this should mean that the API is relatively stable: only a minor change has you encountered backward compatibility issues.

  • Version 1.0 (.x) is a long-term support version with two years of bug fixes. Astropy 1.0 was released on February 18, 2015, so if you are looking for a more stable job, it will last until February 18, 2017. (Other versions support six months of bug fixes. But with the previous point, if you are doing minor updates the way you should be fine too.)

+7
source

Source: https://habr.com/ru/post/1238596/


All Articles