“Astropy”的版本间差异

来自Shiyin's note
跳到导航 跳到搜索
第36行: 第36行:
ulimit -n 100000
ulimit -n 100000
vim /etc/security/limits.conf
vim /etc/security/limits.conf
* 把python的软限制编程硬限制
import resource
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
resource.setrlimit(resource.RLIMIT_NOFILE, (hard, hard))


==fits image读写==
==fits image读写==

2021年2月23日 (二) 07:35的版本

astropy.io.fits

[1]

>>> 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')
hdu.info() #看看哪些hdu
data=hdu[1].data
data.columns #看看有那些列
Bage=data.field('Age')

fits文件打开过多错误

  • [2]
  • fits.close()
  • del hdu.data
  • hdu = fits.open(fits_name,memmap=False) #打开fits文件数目比较多的情况下
  • 可能还根系统设置有关
ulimit -a
ulimit -n 100000
vim /etc/security/limits.conf
  • 把python的软限制编程硬限制
import resource
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
resource.setrlimit(resource.RLIMIT_NOFILE, (hard, hard))

fits image读写

n = np.arange(100.0) 
hdu = fits.PrimaryHDU(n)
hdu.writeto('new2.fits')
hdu.writeto('new2.fits')
  • 如果超过一个hud
>>> hdul = fits.HDUList([hdu])
>>> hdul.writeto('new1.fits')

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)
>>> sel=np.where(d2d.degree < 0.00002)

宇宙学

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)