In [1]:
# you only need to do this once. Shamelessly stolen from Johannsen.
!pip2 install --upgrade version_information
In [2]:
#Preamble. These are some standard things I like to include in IPython Notebooks.
import astropy
from astropy.table import Table, Column, MaskedColumn
import numpy as np
import matplotlib.pyplot as plt
%load_ext version_information
%version_information numpy, scipy, matplotlib, sympy, version_information
Out[2]:
You will more than likely want to plot some things. In the notebook environment, this can be done in different ways. I typically choose an inline plot. However, you can also have images from matplotlib run as separate windows or as interactive objects within the notebook.
In [3]:
# special IPython command to prepare the notebook for matplotlib
#interactive plotting in separate window
#%matplotlib qt
#interactive charts inside notebooks, matplotlib 1.4+
#%matplotlib notebook
#normal charts inside notebooks
%matplotlib inline
So what to do first? Lets download some Gaia file.
In [4]:
#This cell will download some gaia data file to your pwd
import urllib2
import gzip
some_zipped_gaia_file = urllib2.urlopen('http://cdn.gea.esac.esa.int/Gaia/gaia_source/csv/GaiaSource_000-010-207.csv.gz')
some_gaia_file_saved = open('GaiaSource_000-010-207.csv.gz','wb')
some_gaia_file_saved.write(some_zipped_gaia_file.read())
some_zipped_gaia_file.close()
some_gaia_file_saved.close()
some_gaia_zipfile = gzip.GzipFile('GaiaSource_000-010-207.csv.gz', 'r')
In [5]:
from astropy.io import ascii
data = ascii.read(some_gaia_zipfile)
In [6]:
data
Out[6]:
In [7]:
data['ra'].mean()
Out[7]:
In [8]:
data['dec'].mean()
Out[8]:
In [9]:
from numpy import random
random_subsample = data[random.choice(len(data), 10000)]
In [10]:
plt.scatter(random_subsample['ra'],random_subsample['dec'], s=0.1, color='black')
plt.xlabel('R.A.', fontsize=16)
plt.ylabel('Dec', fontsize=16)
Out[10]: