“Astropy”的版本间差异
		
		
		
		
		
		跳到导航
		跳到搜索
		
				
		
		
	
|  (→宇宙学) | 无编辑摘要 | ||
| 第5行: | 第5行: | ||
|  >>> hdulist.info() |  >>> hdulist.info() | ||
| ===header=== | |||
| *each element of an HDUList is an HDU object with .header and .data attributes, which can be used to access the header and data portions of the HDU. | *each element of an HDUList is an HDU object with .header and .data attributes, which can be used to access the header and data portions of the HDU. | ||
|  >>> hdulist[0].header['targname'] |  >>> hdulist[0].header['targname'] | ||
| 第13行: | 第14行: | ||
| *Another way to either update an existing card or append a new one is to use the Header.set() method: | *Another way to either update an existing card or append a new one is to use the Header.set() method: | ||
|  >>> prihdr.set('observer', 'Edwin Hubble') |  >>> prihdr.set('observer', 'Edwin Hubble') | ||
| ===fits table 的读与写=== | |||
| *写  | |||
|  from astropy.table import Table | |||
|  t=Table([Bage,fzbin,Age_weight2],names=('Age','z','weights')) | |||
|  t.write('SFH_LMC3_out.fits',format='fits') | |||
| *读 | |||
|  hdu = fits.open('SFH_LMC3_out.fits') | |||
|  data=hdu[1].data | |||
|  data.columns #看看有那些列 | |||
|  Bage=data.field('Age') | |||
| ==宇宙学== | ==宇宙学== | ||
2017年10月9日 (一) 06:35的版本
astropy.io.fits
>>> hdulist = fits.open('input.fits')
>>> hdulist.info()
header
- each element of an HDUList is an HDU object with .header and .data attributes, which can be used to access the header and data portions of the HDU.
>>> hdulist[0].header['targname']
- To see the entire header as it appears in the FITS file (with the END card and padding stripped), simply enter the header object by itself, or print(repr(header)):
- It’s also possible to view a slice of the header:
>>> header[:2]
- Another way to either update an existing card or append a new one is to use the Header.set() method:
>>> prihdr.set('observer', 'Edwin Hubble')
fits table 的读与写
- 写
from astropy.table import Table
t=Table([Bage,fzbin,Age_weight2],names=('Age','z','weights'))
t.write('SFH_LMC3_out.fits',format='fits')
- 读
hdu = fits.open('SFH_LMC3_out.fits')
data=hdu[1].data
data.columns #看看有那些列
Bage=data.field('Age')
宇宙学
http://docs.astropy.org/en/stable/cosmology/
- 从红移到年龄
>>>from astropy.cosmology import FlatLambdaCDM >>>cosmo = FlatLambdaCDM(H0=70, Om0=0.3)
- 从年龄到红移
>>> import astropy.units as u >>> from astropy.cosmology import z_at_value >>> z_at_value(cosmos.age, 2 * u.Gyr)