forked from SIMPLE-AstroDB/SIMPLE-db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgaia.py
139 lines (114 loc) · 3.67 KB
/
gaia.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import numpy as np
from astroquery.gaia import Gaia
import logging
from simple.utils.astrometry import ingest_parallaxes, ingest_proper_motions
# from scripts.utils.photometry import ingest_photometry
# used by broken ingest_gaia_photometry
__all__ = [
"get_gaiadr3",
"ingest_gaia_photometry",
"ingest_gaia_parallaxes",
"ingest_gaia_pms",
]
logger = logging.getLogger("SIMPLE")
def get_gaiadr3(gaia_id, verbose=True):
"""
Currently setup just to query one source
TODO: add some debug and info messages
Parameters
----------
gaia_id: str or int
verbose
Returns
-------
Table of Gaia data
"""
gaia_query_string = (
f"SELECT "
f"parallax, parallax_error, "
f"pmra, pmra_error, pmdec, pmdec_error, "
f"phot_g_mean_flux, phot_g_mean_flux_error, phot_g_mean_mag, "
f"phot_rp_mean_flux, phot_rp_mean_flux_error, phot_rp_mean_mag "
f"FROM gaiadr3.gaia_source WHERE "
f"gaiadr3.gaia_source.source_id = '{gaia_id}'"
)
job_gaia_query = Gaia.launch_job(gaia_query_string, verbose=verbose)
gaia_data = job_gaia_query.get_results()
return gaia_data
def ingest_gaia_photometry(db, sources, gaia_data, ref):
# TODO write some tests
unmasked_gphot = np.logical_not(gaia_data["phot_g_mean_mag"].mask).nonzero()
gaia_g_phot = gaia_data[unmasked_gphot][
"phot_g_mean_flux", "phot_g_mean_flux_error", "phot_g_mean_mag"
]
unmased_rpphot = np.logical_not(gaia_data["phot_rp_mean_mag"].mask).nonzero()
gaia_rp_phot = gaia_data[unmased_rpphot][
"phot_rp_mean_flux", "phot_rp_mean_flux_error", "phot_rp_mean_mag"
]
# e_Gmag=abs(-2.5/ln(10)*e_FG/FG) from Vizier Note 37 on Gaia DR2 (I/345/gaia2)
gaia_g_phot["g_unc"] = np.abs(
-2.5
/ np.log(10)
* gaia_g_phot["phot_g_mean_flux_error"]
/ gaia_g_phot["phot_g_mean_flux"]
)
gaia_rp_phot["rp_unc"] = np.abs(
-2.5
/ np.log(10)
* gaia_rp_phot["phot_rp_mean_flux_error"]
/ gaia_rp_phot["phot_rp_mean_flux"]
)
if ref == "GaiaDR2":
g_band_name = "GAIA2.G"
rp_band_name = "GAIA2.Grp"
elif ref == "GaiaEDR3" or ref == "GaiaDR3":
g_band_name = "GAIA3.G"
rp_band_name = "GAIA3.Grp"
else:
raise Exception
print(g_band_name, rp_band_name)
# TODO: Turn into a loop and ingest one at a time
# ingest_photometry(
# db,
# sources,
# g_band_name,
# gaia_g_phot["phot_g_mean_mag"],
# gaia_g_phot["g_unc"],
# ref,
# ucds="em.opt",
# telescope="Gaia",
# instrument="Gaia",
# )
# ingest_photometry(
# db,
# sources,
# rp_band_name,
# gaia_rp_phot["phot_rp_mean_mag"],
# gaia_rp_phot["rp_unc"],
# ref,
# ucds="em.opt.R",
# telescope="Gaia",
# instrument="Gaia",
# )
return
def ingest_gaia_parallaxes(db, sources, gaia_data, ref):
# TODO write some tests
unmasked_pi = np.logical_not(gaia_data["parallax"].mask).nonzero()
gaia_parallaxes = gaia_data[unmasked_pi]["parallax", "parallax_error"]
ingest_parallaxes(
db, sources, gaia_parallaxes["parallax"], gaia_parallaxes["parallax_error"], ref
)
def ingest_gaia_pms(db, sources, gaia_data, ref):
# TODO write some tests
unmasked_pms = np.logical_not(gaia_data["pmra"].mask).nonzero()
pms = gaia_data[unmasked_pms]["pmra", "pmra_error", "pmdec", "pmdec_error"]
refs = [ref] * len(pms)
ingest_proper_motions(
db,
sources,
pms["pmra"],
pms["pmra_error"],
pms["pmdec"],
pms["pmdec_error"],
refs,
)