Python in Astronomy

Pandas

何勃亮
中国科学院国家天文台 国家天文科学数据中心
In [1]:
%matplotlib inline

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
In [4]:
data = pd.read_csv('data/dr1.sample', delimiter='|')
In [5]:
data.head()
Out[5]:
obsid designation obsdate lmjd planid spid fiberid ra dec snru ... mag5 mag6 mag7 tsource fibertype tfrom t_info rv z z_err
0 101001 J220848.54-020324.3 2011-10-24 55859 F5902 1 1 332.202274 -2.056767 2.23 ... 15.97 99.0 99.0 JF_LEGAS_S Obj SDSS_S NaN -23.069030 NaN 0.000003
1 101002 J220953.17-020506.0 2011-10-24 55859 F5902 1 2 332.471576 -2.085015 2.00 ... 15.67 99.0 99.0 JF_LEGAS_S Obj SDSS_S NaN 27.100000 NaN 0.000178
2 101008 J220928.49-015720.7 2011-10-24 55859 F5902 1 8 332.368745 -1.955771 1.84 ... 15.64 99.0 99.0 JF_LEGAS_S Obj SDSS_S NaN 25.038666 NaN 0.000003
3 101009 J220849.59-015207.1 2011-10-24 55859 F5902 1 9 332.206665 -1.868653 1.86 ... 16.25 99.0 99.0 JF_LEGAS_S Obj SDSS_S NaN -22.169652 NaN 0.000005
4 101016 J220923.69-020809.9 2011-10-24 55859 F5902 1 16 332.348725 -2.136096 2.17 ... 14.62 99.0 99.0 JF_LEGAS_S Obj SDSS_S NaN -6.631409 NaN 0.000001

5 rows × 32 columns

In [7]:
data[['ra','dec']]
Out[7]:
ra dec
0 332.202274 -2.056767
1 332.471576 -2.085015
2 332.368745 -1.955771
3 332.206665 -1.868653
4 332.348725 -2.136096
... ... ...
994 332.904375 0.369077
995 332.857210 0.272130
996 332.891050 0.215370
997 333.020110 0.150630
998 333.113113 0.108325

999 rows × 2 columns

In [5]:
from astropy import units as u

from astropy.coordinates import Angle

fig = plt.figure()

axes = fig.add_axes([0.1, 0.1, 0.8, 0.8]) # left, bottom, width, height (range 0 to 1)

axes.scatter(data['ra'], data['dec'], s = data['mag2'])

xticks = axes.get_xticks()
yticks = axes.get_yticks()

xt = ["$%.1f^{\circ}$"%n for n in xticks.tolist()]
yt = ["$%.1f^{\circ}$"%n for n in yticks.tolist()]

xt,yt
axes.set_xticklabels(xt)
axes.set_yticklabels(yt)
Out[5]:
[<matplotlib.text.Text at 0x10d447198>,
 <matplotlib.text.Text at 0x10d44bc50>,
 <matplotlib.text.Text at 0x10d472a20>,
 <matplotlib.text.Text at 0x10d455048>,
 <matplotlib.text.Text at 0x10d4474a8>,
 <matplotlib.text.Text at 0x10d43dcc0>,
 <matplotlib.text.Text at 0x10d4ac748>,
 <matplotlib.text.Text at 0x10d4b20f0>,
 <matplotlib.text.Text at 0x10d4b2b00>]
In [ ]: