In [2]:
import numpy as np
import pandas as pd
from astropy.io import fits
import glob
import matplotlib.pyplot as plt
%matplotlib notebook
The following query was used to select obvious stars from the Gaia-PS1 crossmatch table:
select ps1.*,
sqrt(power(pmra,2) + power(pmdec,2)) as pm,
sqrt( power(pmra,2)*power(pmra_error, 2)/(power(pmra,2) + power(pmdec,2))
+ power(pmdec,2)*power(pmdec_error, 2)/(power(pmra,2) + power(pmdec,2))
+ 2*pmra*pmdec/(power(pmra,2) + power(pmdec,2))*pmra_pmdec_corr*pmra_error*pmdec_error) as pm_unc,
gaia.parallax_over_error, gaia.phot_g_mean_mag, gaia.b
from gaiadr2.panstarrs1_best_neighbour as ps1
inner join gaiadr2.gaia_source as gaia
on ps1.source_id = gaia.source_id
where gaia.astrometric_params_solved > 3
and gaia.dec between -10 and -5
and phot_bp_rp_excess_factor < 1.3+0.06*power(phot_bp_mean_mag-phot_rp_mean_mag,2)
AND phot_bp_rp_excess_factor > 1.0+0.015*power(phot_bp_mean_mag-phot_rp_mean_mag,2)
AND astrometric_chi2_al/(astrometric_n_good_obs_al-5) < 1.44*greatest(1,exp(-0.4*(phot_g_mean_mag-19.5)))
order by ps1.original_ext_source_id
where the above query produced the file dec_neg10-result.fits
and the declination range was adjusted to create all the other files.
In [5]:
gaia_dir = "/Users/adamamiller/Desktop/PS1_fits/gaia_stars/"
gaia_files = glob.glob(gaia_dir + "tmp_dec*fits")
for file_num, gf in enumerate(gaia_files):
gdat = fits.getdata(gf)
parallax_stars = np.where( (gdat['parallax_over_error'] >= 8) &
(gdat['number_of_neighbours'] == 1) &
(gdat['number_of_mates'] == 0))
pm_stars = np.where((gdat['pm']/gdat['pm_unc'] >= 7.5) &
(gdat['number_of_neighbours'] == 1) &
(gdat['number_of_mates'] == 0))
tmp_df = pd.DataFrame(gdat['original_ext_source_id'][parallax_stars], columns=['objid'])
big_df = tmp_df.copy()
big_df['pm_over_error'] = gdat['pm'][parallax_stars]/gdat['pm_unc'][parallax_stars]
big_df['parallax_over_error'] = gdat['parallax_over_error'][parallax_stars]
big_df['g_mag'] = gdat['phot_g_mean_mag'][parallax_stars]
print(file_num, gf.split("/")[-1], len(gdat[parallax_stars]),
len(parallax_stars[0])/len(gdat))
if file_num == 0:
master_df = tmp_df.copy()
master_big = big_df.copy()
else:
master_df = master_df.append(tmp_df, ignore_index=True)
master_big = master_big.append(big_df, ignore_index=True)
In [6]:
master_df.to_hdf(gaia_dir + "parallax_objid_stars.h5", "d1")
len(master_df)
Out[6]:
In [7]:
master_big.to_hdf(gaia_dir + "parallax_ps1_gaia_mag_pm_plx.h5", "d1")
len(master_big)
Out[7]:
In [11]:
for file_num, gf in enumerate(gaia_files):
gdat = fits.getdata(gf)
parallax_stars = np.where( (gdat['parallax_over_error'] >= 8) &
(gdat['number_of_neighbours'] == 1) &
(gdat['number_of_mates'] == 0))
pm_stars = np.where((gdat['pm']/gdat['pm_unc'] >= 7.5) &
(gdat['number_of_neighbours'] == 1) &
(gdat['number_of_mates'] == 0))
tmp_df = pd.DataFrame(gdat['original_ext_source_id'][pm_stars], columns=['objid'])
big_df = tmp_df.copy()
big_df['pm_over_error'] = gdat['pm'][pm_stars]/gdat['pm_unc'][pm_stars]
big_df['parallax_over_error'] = gdat['parallax_over_error'][pm_stars]
big_df['g_mag'] = gdat['phot_g_mean_mag'][pm_stars]
print(file_num, gf.split("/")[-1], len(gdat[pm_stars]),
len(pm_stars[0])/len(gdat))
if file_num == 0:
master_df = tmp_df.copy()
master_big = big_df.copy()
else:
master_df = master_df.append(tmp_df, ignore_index=True)
master_big = master_big.append(big_df, ignore_index=True)
In [12]:
master_df.to_hdf(gaia_dir + "pm_objid_stars.h5", "d1")
len(master_df)
Out[12]:
In [13]:
master_big.to_hdf(gaia_dir + "pm_ps1_gaia_mag_pm_plx.h5", "d1")
len(master_big)
Out[13]: