[英]astropy.fits: Manipulating image data from a fits Table? (e.g., 3072R x 2C)
I'm currently having a little issue with a fits file. 我目前在Fits文件上有一个小问题。 The data is in table format, a format I haven't previously used.
数据采用表格格式,这是我以前从未使用过的格式。 I'm a python user, and rely heavily on astropy.fits to manipulate fits images.
我是python用户,在很大程度上依赖astropy.fits来处理拟合图像。 A quick output of the info gives:
信息的快速输出给出:
No. Name Type Cards Dimensions Format
0 PRIMARY PrimaryHDU 60 ()
1 BinTableHDU 29 3072R x 2C [1024E, 1024E]
The header for the BinTableHDU is as follows: BinTableHDU的标头如下:
XTENSION= 'BINTABLE' /Written by IDL: Mon Jun 22 23:28:21 2015
BITPIX = 8 /
NAXIS = 2 /Binary table
NAXIS1 = 8192 /Number of bytes per row
NAXIS2 = 3072 /Number of rows
PCOUNT = 0 /Random parameter count
GCOUNT = 1 /Group count
TFIELDS = 2 /Number of columns
TFORM1 = '1024E ' /Real*4 (floating point)
TFORM2 = '1024E ' /Real*4 (floating point)
TTYPE1 = 'COUNT_RATE' /
TUNIT1 = '1e-6cts/s/arcmin^2' /
TTYPE2 = 'UNCERTAINTY' /
TUNIT2 = '1e-6cts/s/arcmin^2' /
HISTORY g000m90r1b120pm.fits created on 10/08/97. PI channel range: 8: 19
PIXTYPE = 'HEALPIX ' / HEALPIX pixelisation
ORDERING= 'NESTED ' / Pixel ordering scheme, either RING or NESTED
NSIDE = 512 / Healpix resolution parameter
NPIX = 3145728 / Total number of pixels
OBJECT = 'FULLSKY ' / Sky coverage, either FULLSKY or PARTIAL
FIRSTPIX= 0 / First pixel # (0 based)
LASTPIX = 3145727 / Last pixel # (zero based)
INDXSCHM= 'IMPLICIT' / indexing : IMPLICIT or EXPLICIT
GRAIN = 0 / GRAIN = 0: No index,
COMMENT GRAIN =1: 1 pixel index for each pixel,
COMMENT GRAIN >1: 1 pixel index for Grain consecutive pixels
BAD_DATA= -1.63750E+30 / Sentinel value given to bad pixels
COORDSYS= 'G ' / Pixelization coordinate system
COMMENT G = Galactic, E = ecliptic, C = celestial = equatorial
END
I'd like to access the fits image which is stored within the TTYPE labeled 'COUNT-RATE', and then have this in a format with which I can then add to other count-rate arrays with the same dimensions. 我想访问存储在标记为“ COUNT-RATE”的TTYPE中的拟合图像,然后以一种格式使用该图像,然后可以将其添加到具有相同尺寸的其他计数率数组中。
I started with my usual prodcedure for opening a fits file: 我从打开装配文件的常规程序开始:
hdulist_RASS_SXRB_R1 = fits.open('/Users/.../RASS_SXRB_R1.fits')
hdulist_RASS_SXRB_R1.info()
image_XRAY_SKYVIEW_R1 = hdulist_RASS_SXRB_R1[1].data
image_XRAY_SKYVIEW_R1 = numpy.array(image_XRAY_SKYVIEW_R1)
image_XRAY_SKYVIEW_header_R1 = hdulist_RASS_SXRB_R1[1].header
But this is coming back with IndexError: too many indices for array
. 但这又返回了
IndexError: too many indices for array
。 I've had a look at accessing table data in the astropy documentation here ( Accessing data stored as a table in a multi-extension FITS (MEF) file ) 我在这里的astropy文档中已经看过访问表数据( 访问以表形式存储在多扩展FITS(MEF)文件中的数据 )
If anyone has a tried and tested method for accessing such images from a fits table I'd be very grateful! 如果有人有经过验证的方法可以从拟合表访问此类图像,我将不胜感激! Many thanks.
非常感谢。
I can't be sure without seeing the full traceback but I think the exception you're getting is from this: 我不能确定没有完整的追溯,但是我认为您从这里得到的异常是:
image_XRAY_SKYVIEW_R1 = numpy.array(image_XRAY_SKYVIEW_R1)
There's no reason to manually wrap numpy.array()
around the array. 没有理由手动将
numpy.array()
包裹在数组周围。 It's already a Numpy array. 它已经是一个Numpy数组。 But in this case it's a structured array (see http://docs.scipy.org/doc/numpy/user/basics.rec.html ).
但在这种情况下,它是一个结构化数组(请参阅http://docs.scipy.org/doc/numpy/user/basics.rec.html )。
@Andromedae93's answer is right one. @ Andromedae93的答案是正确的。 But also for general documentation on this see: http://docs.astropy.org/en/stable/io/fits/index.html#working-with-table-data
但有关此方面的常规文档,请参见: http : //docs.astropy.org/en/stable/io/fits/index.html#working-with-table-data
However, the way you're working (which is fine for images) of manually calling fits.open
, accessing the .data
attribute of the HDU, etc. is fairly low level, and Numpy structured arrays are good at representing tables, but not great for manipulating them. 但是,您手动调用
fits.open
,访问HDU的.data
属性等的工作方式(对图像而言是很好的)是相当低级的,并且Numpy结构化数组擅长表示表,但不能非常适合操纵它们。
You're better off generally using Astropy's higher-level Table
interface. 通常情况下,最好使用Astropy的高级
Table
接口。 A FITS table can be read directly into an Astropy Table
object with Table.read()
: http://docs.astropy.org/en/stable/io/unified.html#fits FITS表可以通过
Table.read()
直接读取到Astropy Table
对象中: http : Table.read()
The only reason the same thing doesn't exist for FITS images is there's no a generic "Image" class yet. FITS图像不存在相同事物的唯一原因是还没有通用的“ Image”类。
I used astropy.io.fits during my internship in Astrophysics and this is my process to open file .fits and make some operations : 我在天体物理学实习期间使用了astropy.io.fits,这是打开文件.fits并进行一些操作的过程:
# Opening the .fits file which is named SMASH.fits
field = fits.open(SMASH.fits)
# Data fits reading
tbdata = field[1].data
Now, with this kind of method, tbdata is a numpy.array and you can make lots of things. 现在,使用这种方法,tbdata是一个numpy.array,您可以做很多事情。
For example, if you have data like : 例如,如果您有以下数据:
ID, Name, Object
1, HD 1527, Star
2, HD 7836, Star
3, NGC 6739, Galaxy
If you want to print data along one condition : 如果要在一种情况下打印数据:
Data_name = tbdata['Name']
You will get : 你会得到 :
HD 1527
HD 7836
NGC 6739
I don't know what do you want exactly with your data, but I can help you ;) 我不知道您到底想要什么与您的数据,但我可以为您提供帮助;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.