from astropy import units as u u.m u.Angstrom print(u.m.__doc__) print(u.m.physical_type) print(u.Angstrom.physical_type) 1.0 * u.m [1.0, 2.0, 3.0] * u.m q = [1.0, 2.0, 3.0] * u.m q.to(u.Angstrom) q1 = 3. * u.m q1 q2 = 5. * u.cm / u.s / u.g**2 q2 q1 * q2 (q1 * q2).to(u.m**2 / u.kg**2 / u.s) from astropy.constants import G print repr(G) F = (G * 1. * u.M_sun * 100. * u.kg) / (3.2 * u.au)**2 F.unit.find_equivalent_units() F.to(u.N) (450. * u.nm).to(u.GHz) (450. * u.nm).to(u.GHz, equivalencies=u.spectral()) (450. * u.eV).to(u.nm, equivalencies=u.spectral()) import numpy as np np.sin(90) np.sin(90 * u.degree) from astropy.table import Table import numpy as np t = Table() t['name'] = ['source 1', 'source 2', 'source 3', 'source 4'] t['flux'] = [1.2, 2.2, 3.1, 4.3] t.colnames t.dtype t t.show_in_browser() t['flux'] t[1] t[1:3] t2 = Table([['x', 'y', 'z'], [1.1, 2.2, 3.3]], names=['name', 'value'], masked=True) t2 t2['value'].mask = [False, True, False] t2 t2['value'].mean() t2['value'].fill_value t2['value'].fill_value = -99 t2.filled() t t2 = Table() t2['name'] = ['source 1', 'source 3', 'source 8'] t2['flux2'] = [1.4, 3.5, 8.6] from astropy.table import join t3 = join(t, t2, keys=['name'], join_type='outer') t3 t3 = join(t, t2, keys=['name'], join_type='inner') t3 t3.write('example.fits', overwrite=True) t4 = Table.read('example.fits') t4 t4.write('example.vot', format='votable', overwrite=True) !cat example.vot t = Table() t['name'] = ['source 1', 'source 2', 'source 3', 'source 4'] t['flux'] = [1.2, 2.2, 3.1, 4.3] t t.write('mytable.tex', format='latex') t.write(sys.stdout, format='latex') text = """ \begin{table} \begin{tabular}{cc} name & flux \\ source 1 & 1.2 \\ source 2 & 2.2 \\ source 3 & 3.1 \\ source 4 & 4.3 \\ \end{tabular} \end{table} """ Table.read('mytable.tex', format='latex') import sys sys.stdout from astropy.io import fits # The following FITS file lives in the lesson repository, relative # to this file. However, if you get a "file not found" error you can download and open the file # by uncommenting these lines (and commenting the last line) # from astropy.utils import download_file # filename = download_file('https://github.com/abostroem/2015-01-03-aas/raw/gh-pages/intermediate/astropy/data/gll_iem_v02_P6_V11_DIFFUSE.fit') # hdulist = fits.open(filename) hdulist = fits.open('data/gll_iem_v02_P6_V11_DIFFUSE.fit') hdulist.info() primary_hdu = hdulist[0] primary_hdu = hdulist['PRIMARY'] primary_hdu.header primary_hdu.header['OBSERVER'] primary_hdu.header['DATE'] %matplotlib inline from matplotlib.pyplot import imshow imshow(primary_hdu.data[0], origin='lower') from aplpy import FITSFigure fig = FITSFigure('data/gll_iem_v02_P6_V11_DIFFUSE.fit', slices=[0]) fig.show_colorscale() new_hdu = fits.PrimaryHDU(data=primary_hdu.data[0], header=primary_hdu.header) del new_hdu.header['FILENAME'] del new_hdu.header['C*3'] new_hdu.header new_hdu.writeto('lat_background_model_slice.fits', checksum=True, clobber=True) from astropy.coordinates import SkyCoord from astropy import units as u SkyCoord(ra=10.68458 * u.deg, dec=41.26917 * u.deg, frame='icrs') c = SkyCoord('00h42m44.3s +41d16m9s', frame='icrs') c c.ra c.ra.hour c.galactic c.transform_to('galactic') from astropy.coordinates import FK5 FK5? frame = FK5(equinox='J2010') c.transform_to(frame)