A First Brush With Jupyter

This notebook will show you some things I find useful to do in these notebooks.


In [1]:
# you only need to do this once. Shamelessly stolen from Johannsen.
!pip2 install --upgrade version_information


Requirement already up-to-date: version_information in /usr/local/lib/python2.7/site-packages

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]:
SoftwareVersion
Python2.7.11 64bit [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
IPython5.1.0
OSDarwin 14.5.0 x86_64 i386 64bit
numpy1.11.1
scipy0.18.0
matplotlib1.5.3
sympyThe 'sympy' distribution was not found and is required by the application
version_information1.0.3
Thu Sep 15 09:56:10 2016 CLST

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]:
<Table masked=True length=218453>
solution_idsource_idrandom_indexref_epochrara_errordecdec_errorparallaxparallax_errorpmrapmra_errorpmdecpmdec_errorra_dec_corrra_parallax_corrra_pmra_corrra_pmdec_corrdec_parallax_corrdec_pmra_corrdec_pmdec_corrparallax_pmra_corrparallax_pmdec_corrpmra_pmdec_corrastrometric_n_obs_alastrometric_n_obs_acastrometric_n_good_obs_alastrometric_n_good_obs_acastrometric_n_bad_obs_alastrometric_n_bad_obs_acastrometric_delta_qastrometric_excess_noiseastrometric_excess_noise_sigastrometric_primary_flagastrometric_relegation_factorastrometric_weight_alastrometric_weight_acastrometric_priors_usedmatched_observationsduplicated_sourcescan_direction_strength_k1scan_direction_strength_k2scan_direction_strength_k3scan_direction_strength_k4scan_direction_mean_k1scan_direction_mean_k2scan_direction_mean_k3scan_direction_mean_k4phot_g_n_obsphot_g_mean_fluxphot_g_mean_flux_errorphot_g_mean_magphot_variable_flaglbecl_lonecl_lat
int64int64int64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64int64int64int64int64int64int64float64float64float64str5float64float64float64int64int64str5float64float64float64float64float64float64float64float64int64float64float64float64str13float64float64float64float64
163537841078193356845076540421462374403718579092015.0284.0184564290.32343196268415.36440946950.352478685499------------0.6411------------------88087010--0.6551702800842.31521922399false1.20037340.6197851--210false0.32387480.3498420.333111880.5430713-104.0412-60.889313-24.12391342.22047871267.2066327711.392774661717.7676514703NOT_AVAILABLE47.17417735915.93834065265287.23474790637.968684138
163537841078193356845076540421462375689477279772015.0284.0213009010.37413719141415.35509560060.383357641937------------0.70395------------------1070107000--0.9435136871374.31267493943false2.19329930.40037948--212false0.242946880.415652450.2926160.535654-106.101234-51.403423-22.373487-44.30477106979.5172644392.402993472918.0472398262NOT_AVAILABLE47.16703256315.93172482449287.23675689337.9591048471
163537841078193356845076540464509136644877633852015.0284.0198325180.814658183715.34732858360.755669146696------------0.8254------------------96096000--0.00.0false1.00.14105824--212false0.255867180.377775670.25566570.53755957-130.51743-55.6821-18.02285644.1364793282.515435442.2262388965819.3971646118NOT_AVAILABLE47.15941066625.92952063043287.23377059937.9515691227
163537841078193356845076540464509141769674123782015.0284.0217447742.1982367098115.34888282861.91262081119------------0.80555------------------88088000--3.808358621913.31092998552false14.694740.022539811--211false0.265790670.32425450.321885820.5515567-144.66031-54.042034-14.503501-43.80985687148.9276294111.7322611517420.0923318724NOT_AVAILABLE47.16163707255.92856552565287.23633258537.9528863409
163537841078193356845076540464509143048565708682015.0284.0188326850.83557444543315.34673762670.741885055357------------0.8027------------------88088000--0.5930268839060.321201843973false2.49233220.15122868--211false0.262769040.322681730.341075150.54305035-149.5235-54.402363-13.907869-43.83423687338.1342409592.0980683170119.2020471849NOT_AVAILABLE47.15844596325.93011909003287.23246542937.9511004207
163537841078193356845076540464509335047540864202015.0284.0226408456.3085578125815.35309415934.25506455776------------0.9511------------------44044000--1.763787888411.31085372753false6.863130.024552291--25false0.40221070.497977940.401356670.6408555159.65735-47.1712724.323387-37.4952774372.68242904541.166469886420.8711964814NOT_AVAILABLE47.1658129845.92967449643287.23807310237.9569604701
1635378410781933568450765404645093926410652151262015.0284.0216258452.6482111535515.35340222451.94454049365------------0.8814------------------79079000--1.751269039610.806243224352false6.81545540.03746972--210false0.296613720.273669360.453041640.56557447-169.59645-52.335514-10.772607-41.21950578144.3561445971.8179503547920.1261818774NOT_AVAILABLE47.16565030715.93068777186287.23688880937.9573858676
163537841078193356845076540464509464322439120192015.0284.0214267890.82721058324615.35444859040.735046448107------------0.808------------------97096010--0.01.05337863468e-15false1.00.1358803--212false0.255867330.377775640.255665180.53755903-130.517-55.68169-18.02243244.1368995273.648871082.0309964135219.4317859118NOT_AVAILABLE47.16650517635.93132709075287.23680939937.9584478501
163537841078193356845076540464509466885413188632015.0284.0177884653.2291871659815.35182668332.96872495696------------0.8511------------------53053000--0.00.0false1.00.017818443--26false0.297742960.302492050.28994350.54870325-132.39615-56.010464-20.78271542.2307665289.58483335262.1430225851120.6441838385NOT_AVAILABLE47.16257070575.9332941003287.23198661237.9562743888
163537841078193356845076540464509475845626761912015.0284.024598050.66908759699615.35697072510.669975870005------------0.7614------------------98098000--1.188807043252.02345060355false4.68441870.15295707--211false0.258244250.390231040.238837640.5378416-126.249626-55.917603-19.3325143.67946697415.1246390562.2868464510918.9793237864NOT_AVAILABLE47.17014754255.92971848219287.24104994337.9605772267
...........................................................................................................................................................................
1635378410781933568450793009258784857611209522682015.0283.5004855756.9226955191415.857466131212.0954384159-------------0.24405------------------52052000--0.9387007082160.133455294105false3.74943950.030022962--28false0.559294640.51919620.811087370.24162114147.31532-80.74882-4.22044835.6564652120.1080609642.385293904720.3258396745NOT_AVAILABLE47.39461468256.60464051137286.67981157138.5182438159
163537841078193356845079300925890501124169151022015.0283.5074809948.8896895929215.852390873110.841619359-------------0.31455------------------50050000--0.00.0false1.00.0140516935--27false0.63112290.410640930.74721170.46490502144.24426-77.872765-9.13956228.2067075087.37716675581.9247273739120.6712751678NOT_AVAILABLE47.39304745896.59635692292286.68758109938.5124055913
16353784107819335684507930122641272320394252842015.0283.4795407671.5598439695415.84050898131.67117332859------------0.6811------------------71070010--4.4800486895238.2124046476false4.78483530.04258895--28false0.142006490.60709370.423547830.41521555-43.795586-51.091255-21.27455-42.1666370746.7255385786.0110777113418.3418675519NOT_AVAILABLE47.37030983436.61515773594286.65167404238.5037956515
163537841078193356845079301226412928005411969522015.0283.4815019110.42975700481215.84248885340.390735029013------------0.70395------------------1040104000--0.4991367331790.804782579033false1.06630580.43596637--212false0.198539350.424603670.42092460.53697795-92.48376-47.20726-21.054987-40.773857102836.2100385592.0203520669218.2189816216NOT_AVAILABLE47.37293926626.61434704772286.65436773638.5055380184
163537841078193356845079301226412929288837231142015.0283.4829977280.6473637789715.84275335510.578085054206------------0.7379------------------95094010--0.5179811310730.423164318503false1.04924920.21056758--212false0.190570460.404277030.358038430.5332808-117.604805-50.26653-18.30239-41.8081494460.0334106662.1648879814618.8677966284NOT_AVAILABLE47.37382139376.61317535975286.65623369938.5056301209
163537841078193356845079301226412994569490670782015.0283.4789983920.556778276515.8432165290.494710402324------------0.73235------------------1020101010--0.0-1.0255800994e-15false1.00.28595832--212false0.189979260.410364450.41248530.5261333-100.017296-48.035713-20.132118-41.064266100545.6180816763.7304595142818.682548178NOT_AVAILABLE47.37251844096.61682802692286.65142191838.506545949
163537841078193356845079301226413196801776129562015.0283.4816657270.94357698802815.84589046850.88536157682------------0.6954------------------96096000--1.348450030681.66708138357false1.52532980.1010142--213false0.233038510.335229220.50151950.43440664-142.44589-70.79233-14.85559642.88944295330.3917045672.2105209901719.2271972274NOT_AVAILABLE47.37607767826.61571704789286.65508284738.5088969875
163537841078193356845079301226413280007799831332015.0283.4781676930.51524992208515.84650542980.480103546782------------0.6038------------------1170117000--0.00.0false1.00.23775215--214false0.179348750.339270380.467596050.45869747-132.42831-56.545246-14.959238-41.68142117501.8353039892.0543380505918.7733670374NOT_AVAILABLE47.37512735816.61900505303286.65090585238.5099063669
163537841078193356845079301226413329929826774362015.0283.4730951940.44857105614415.84702030290.42847179069------------0.5396------------------1030103000--0.00.0false1.00.30521557--212false0.134226890.418809440.462008630.44826943-124.52854-58.49793-12.680218-39.789837103597.4279374372.3401725170118.5840562449NOT_AVAILABLE47.37340945896.62360557759286.64479160138.5109956693
163537841078193356845079301226413451529671924602015.0283.4867381820.46656732634515.84774689340.415764602656------------0.7388------------------1040102020--0.4071651784360.473050907855false1.05594930.385309--212false0.1368040.415470720.43410290.4518974-147.00894-54.326973-17.083355-44.437717102723.2957814294.6170574426818.3764802336NOT_AVAILABLE47.37993436026.61217009364286.66155606638.5101619219

In [7]:
data['ra'].mean()


Out[7]:
284.1834678025001

In [8]:
data['dec'].mean()


Out[8]:
15.657042760840445

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]:
<matplotlib.text.Text at 0x177320dd0>