In [1]:
import astropy.units as u
from astropy.coordinates.sky_coordinate import SkyCoord
from astropy.units import Quantity
from astroquery.gaia import Gaia
Created TAP+ (v1.0.1) - Connection:
	Host: gea.esac.esa.int
	Use HTTPS: False
	Port: 80
	SSL Port: 443
In [2]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

# Suppress warnings. Comment this out if you wish to see the warning messages
import warnings
warnings.filterwarnings('ignore')
In [3]:
from astroquery.gaia import Gaia
tables = Gaia.load_tables(only_names=True)
for table in (tables):
    print (table.get_qualified_name())
Retrieving tables...
Parsing tables...
Done.
public.public.dual
public.public.hipparcos
public.public.hipparcos_newreduction
public.public.hubble_sc
public.public.igsl_source
public.public.igsl_source_catalog_ids
public.public.tycho2
tap_schema.tap_schema.columns
tap_schema.tap_schema.key_columns
tap_schema.tap_schema.keys
tap_schema.tap_schema.schemas
tap_schema.tap_schema.tables
gaiadr1.gaiadr1.aux_qso_icrf2_match
gaiadr1.gaiadr1.ext_phot_zero_point
gaiadr1.gaiadr1.allwise_best_neighbour
gaiadr1.gaiadr1.allwise_neighbourhood
gaiadr1.gaiadr1.gsc23_best_neighbour
gaiadr1.gaiadr1.gsc23_neighbourhood
gaiadr1.gaiadr1.ppmxl_best_neighbour
gaiadr1.gaiadr1.ppmxl_neighbourhood
gaiadr1.gaiadr1.sdss_dr9_best_neighbour
gaiadr1.gaiadr1.sdss_dr9_neighbourhood
gaiadr1.gaiadr1.tmass_best_neighbour
gaiadr1.gaiadr1.tmass_neighbourhood
gaiadr1.gaiadr1.ucac4_best_neighbour
gaiadr1.gaiadr1.ucac4_neighbourhood
gaiadr1.gaiadr1.urat1_best_neighbour
gaiadr1.gaiadr1.urat1_neighbourhood
gaiadr1.gaiadr1.cepheid
gaiadr1.gaiadr1.phot_variable_time_series_gfov
gaiadr1.gaiadr1.phot_variable_time_series_gfov_statistical_parameters
gaiadr1.gaiadr1.rrlyrae
gaiadr1.gaiadr1.variable_summary
gaiadr1.gaiadr1.allwise_original_valid
gaiadr1.gaiadr1.gsc23_original_valid
gaiadr1.gaiadr1.ppmxl_original_valid
gaiadr1.gaiadr1.sdssdr9_original_valid
gaiadr1.gaiadr1.tmass_original_valid
gaiadr1.gaiadr1.ucac4_original_valid
gaiadr1.gaiadr1.urat1_original_valid
gaiadr1.gaiadr1.gaia_source
gaiadr1.gaiadr1.tgas_source
gaiadr2.gaiadr2.aux_allwise_agn_gdr2_cross_id
gaiadr2.gaiadr2.aux_iers_gdr2_cross_id
gaiadr2.gaiadr2.aux_sso_orbit_residuals
gaiadr2.gaiadr2.aux_sso_orbits
gaiadr2.gaiadr2.dr1_neighbourhood
gaiadr2.gaiadr2.allwise_best_neighbour
gaiadr2.gaiadr2.allwise_neighbourhood
gaiadr2.gaiadr2.apassdr9_best_neighbour
gaiadr2.gaiadr2.apassdr9_neighbourhood
gaiadr2.gaiadr2.gsc23_best_neighbour
gaiadr2.gaiadr2.gsc23_neighbourhood
gaiadr2.gaiadr2.hipparcos2_best_neighbour
gaiadr2.gaiadr2.hipparcos2_neighbourhood
gaiadr2.gaiadr2.panstarrs1_best_neighbour
gaiadr2.gaiadr2.panstarrs1_neighbourhood
gaiadr2.gaiadr2.ppmxl_best_neighbour
gaiadr2.gaiadr2.ppmxl_neighbourhood
gaiadr2.gaiadr2.ravedr5_best_neighbour
gaiadr2.gaiadr2.ravedr5_neighbourhood
gaiadr2.gaiadr2.sdssdr9_best_neighbour
gaiadr2.gaiadr2.sdssdr9_neighbourhood
gaiadr2.gaiadr2.tmass_best_neighbour
gaiadr2.gaiadr2.tmass_neighbourhood
gaiadr2.gaiadr2.tycho2_best_neighbour
gaiadr2.gaiadr2.tycho2_neighbourhood
gaiadr2.gaiadr2.urat1_best_neighbour
gaiadr2.gaiadr2.urat1_neighbourhood
gaiadr2.gaiadr2.sso_observation
gaiadr2.gaiadr2.sso_source
gaiadr2.gaiadr2.vari_cepheid
gaiadr2.gaiadr2.vari_classifier_class_definition
gaiadr2.gaiadr2.vari_classifier_definition
gaiadr2.gaiadr2.vari_classifier_result
gaiadr2.gaiadr2.vari_long_period_variable
gaiadr2.gaiadr2.vari_rotation_modulation
gaiadr2.gaiadr2.vari_rrlyrae
gaiadr2.gaiadr2.vari_short_timescale
gaiadr2.gaiadr2.vari_time_series_statistics
gaiadr2.gaiadr2.panstarrs1_original_valid
gaiadr2.gaiadr2.gaia_source
In [4]:
import math
au = 4.84813681 * 10 ** (-6) # [pc]
M = 1.9884 * 10 ** 30 * 10 ** 3 # [g]
radius = 150 # [pc]

parallax = math.atan2( au , radius) / math.pi * 180 * 10 ** 3 * 60 ** 2
query = "SELECT source_id,parallax FROM gaiadr2.gaia_source WHERE (parallax>=" + str(parallax) +")"
job = Gaia.launch_job_async(query, dump_to_file=True)
r = job.get_results()
rows = len(r)

n = []
X = []
Y = []
R = radius + 1

for j in range (10, R, 10):
    number = 0
    for i in range(1,rows):
         if r['parallax'][i] >= math.atan2( au , j) / math.pi * 180 * 10 ** 3 * 60 ** 2:
                number = number + 1
    n = n + [number]
    X = X + [j]

for k in range(0,len(X)):
    y = n[k] * M / (4 / 3 * math.pi * (X[k] * 3.08567758 * 10 ** 18) **3)
    Y = Y + [y]
In [6]:
plt.title("The density of the amount of matter in the visible stars\n")
plt.plot(X,Y,'o')
plt.xlabel("distance [pc]")
plt.ylabel("density of matter [g / cm ^ 3]")
plt.xscale('log')
plt.yscale('log')
plt.show()
In [7]:
import pandas as pd
table = pd.DataFrame({
    "                distance [pc]             ":X,
    "density of matter [g / cm ^ 3]":Y,
})
print(table)
                    distance [pc]               density of matter [g / cm ^ 3]
0                                           10                    2.782253e-23
1                                           20                    1.090604e-23
2                                           30                    9.038403e-24
3                                           40                    9.033083e-24
4                                           50                    9.467546e-24
5                                           60                    9.895104e-24
6                                           70                    1.033343e-23
7                                           80                    1.069982e-23
8                                           90                    1.102859e-23
9                                          100                    1.131086e-23
10                                         110                    1.154223e-23
11                                         120                    1.173018e-23
12                                         130                    1.186946e-23
13                                         140                    1.197797e-23
14                                         150                    1.205508e-23
In [9]:
plt.title("The number of the visible stars\n")
plt.plot(X,n,'o')
plt.xlabel("distance [pc]")
plt.ylabel("number")
plt.xscale('log')
plt.yscale('log')
plt.show()
In [10]:
N = []
for l in range(0,len(X)):
    nn = n[l] / (4 / 3 * math.pi * X[l] ** 3)
    N = N + [nn]
    
plt.title("The number density of the visible stars\n")
plt.plot(X,N,'o')
plt.xlabel("distance [pc]")
plt.ylabel("number density [/ pc^3]")
plt.xscale('log')
plt.yscale('log')
plt.show()
In [ ]: