Bo Zhang (NAOC, mailto:bozhang@nao.cas.cn) will have a few lessons on python.
python
to process astronomical data.These lectures are organized as below:
In [1]:
%pylab inline
from astropy.io import fits
# read hdu list
hl = fits.open('./data/lamost_dr2_spectra/spec-55892-F9205_sp09-174.fits')
In [2]:
# show fits info
print hl.info()
In [3]:
# read HDU header
hl[0].header
Out[3]:
In [4]:
# read HDU data
hl[0].data
Out[4]:
In [5]:
# transform data to WVS coordinates
naxis1 = hl[0].header['NAXIS1']
crval1 = hl[0].header['CRVAL1']
crpix1 = hl[0].header['CRPIX1']
cdelt1 = hl[0].header['CD1_1']
wave = 10**( crval1 + (np.arange(naxis1)+1-crpix1)*cdelt1)
print wave
flux = hl[0].data[0, :]
print flux
In [6]:
fig = plt.figure(figsize=(15,8 ))
plt.plot(wave, flux)
Out[6]:
In [7]:
from astropy.table import Table, Column
spec_table = Table([Column(wave, 'wave'),
Column(flux, 'flux')])
# Table.write('./data/lamost_dr2_spectra/test_spec_table.fits')
spec_table.pprint
Out[7]:
In [ ]:
In [8]:
%pylab
from astropy.coordinates import SkyCoord, Longitude, Latitude
import astropy.units as u
In [9]:
ra = Longitude([1, 2, 3], unit=u.deg) # Could also use Angle
dec = np.array([4.5, 5.2, 6.3]) * u.deg # Astropy Quantity
c = SkyCoord(ra, dec, frame='icrs')
c
Out[9]:
In [10]:
c.info()
In [11]:
c.galactic
Out[11]:
In [12]:
c.galactic.l, c.galactic.b
Out[12]:
In [ ]:
download a LAMOST spectra, and write a function to read data in the fits file.
requirements:
spec = read_spectrum_lamost('filepath')
spec
should be a 5-column table, including these data:
wavelength, flux, inverse variance, and-mask, or-mask
hint: the data structure of LAMOST DR2 spectra fits files can be found here
In [ ]: