“Astropy”的版本间差异
		
		
		
		
		
		跳到导航
		跳到搜索
		
				
		
		
	
无编辑摘要  | 
				无编辑摘要  | 
				||
| (未显示同一用户的23个中间版本) | |||
| 第1行: | 第1行: | ||
*很好的教程网站 [https://learn.astropy.org/]  | 
|||
| ⚫ | |||
[  | 
  :比如星际红化的 [https://learn.astropy.org/tutorials/color-excess.html]  | 
||
==io==  | 
|||
 >>> hdulist = fits.open('input.fits')  | 
  |||
| ⚫ | |||
 >>> hdulist.info()  | 
  |||
* ascii文件:Table格式,支持ecsv文件直接读入table  | 
|||
==  | 
  ==astrometry==  | 
||
*match 两个星表  | 
|||
*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']  | 
  |||
 >>> from astropy import units as u  | 
|||
 >>> c = SkyCoord(ra=ra1*u.degree, dec=dec1*u.degree)    | 
|||
*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)):  | 
  |||
 >>> catalog = SkyCoord(ra=ra2*u.degree, dec=dec2*u.degree)    | 
|||
*It’s also possible to view a slice of the header:  | 
  |||
 >>> idx, d2d, d3d = c.match_to_catalog_sky(catalog) #d3d是假设距离为1的地方的3维距离,因此是以弧度为单位  | 
|||
 >>> header[:2]  | 
  |||
 >>> sel=np.where(d2d.degree < 0.00002)  | 
|||
*Another way to either update an existing card or append a new one is to use the Header.set() method:  | 
  |||
 >>> Nsel=len(sel[0])  | 
|||
 >>> prihdr.set('observer', 'Edwin Hubble')  | 
  |||
 >>> print(ra1[sel][0],ra2[idx[sel][0])  | 
|||
*算出任意两点之间距离向量的PA角,还有中点坐标[https://docs.astropy.org/en/stable/coordinates/matchsep.html]  | 
|||
===fits 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')  | 
  |||
==宇宙学==  | 
  ==宇宙学==  | 
||
| 第32行: | 第23行: | ||
 >>>from astropy.cosmology import FlatLambdaCDM   | 
   >>>from astropy.cosmology import FlatLambdaCDM   | 
||
 >>>cosmo = FlatLambdaCDM(H0=70, Om0=0.3)  | 
   >>>cosmo = FlatLambdaCDM(H0=70, Om0=0.3)  | 
||
>>> lum_dis=cosmo.luminosity_distance(redshift) #计算光度距离  | 
|||
*从年龄到红移  | 
  *从年龄到红移  | 
||
| 第37行: | 第29行: | ||
 >>> from astropy.cosmology import  z_at_value  | 
   >>> from astropy.cosmology import  z_at_value  | 
||
 >>> z_at_value(cosmos.age, 2 * u.Gyr)  | 
   >>> z_at_value(cosmos.age, 2 * u.Gyr)  | 
||
==单位转换==  | 
|||
 dL=lum_dis.to(u.cm)  | 
|||
==bug==  | 
|||
*在anaconda3.8.3升级 astropy 和liberfc之后,astropy.fits出错,解决方法是降级  | 
|||
*安装pytorch之后,自动降级到4.3,但是还是又小问题  | 
|||
*进一步[[conda]]指定降级到4.2才行  | 
|||
*可以看出[[conda]]的版本管理并不好,  | 
|||
2024年7月12日 (五) 14:24的最新版本
- 很好的教程网站 [1]
 
- 比如星际红化的 [2]
 
io
- astropy.io.fits
 - ascii文件:Table格式,支持ecsv文件直接读入table
 
astrometry
- match 两个星表
 
>>> from astropy.coordinates import SkyCoord >>> from astropy import units as u >>> c = SkyCoord(ra=ra1*u.degree, dec=dec1*u.degree) >>> catalog = SkyCoord(ra=ra2*u.degree, dec=dec2*u.degree) >>> idx, d2d, d3d = c.match_to_catalog_sky(catalog) #d3d是假设距离为1的地方的3维距离,因此是以弧度为单位 >>> sel=np.where(d2d.degree < 0.00002) >>> Nsel=len(sel[0]) >>> print(ra1[sel][0],ra2[idx[sel][0])
- 算出任意两点之间距离向量的PA角,还有中点坐标[3]
 
宇宙学
http://docs.astropy.org/en/stable/cosmology/
- 从红移到年龄
 
>>>from astropy.cosmology import FlatLambdaCDM >>>cosmo = FlatLambdaCDM(H0=70, Om0=0.3)
>>> lum_dis=cosmo.luminosity_distance(redshift) #计算光度距离
- 从年龄到红移
 
>>> import astropy.units as u >>> from astropy.cosmology import z_at_value >>> z_at_value(cosmos.age, 2 * u.Gyr)
单位转换
dL=lum_dis.to(u.cm)