from functools import wraps
from ..Configuration.epochs import EpochStruct
from ..StructureMethods.method_definitions import (exportplot, plot, savedata,
saveplot, showdata,
showplot)
break_str = "|"
epochs = EpochStruct().epoch_list
[docs]
class HrdStruct(object):
"""HrdStruct()
This structure is returned from hrd queries, when read from a hrd file that was originally created by an image query, or through the Models module (in which case all attributes are set to None).
.. rubric:: Attributes
:heading-level: 1
kind : *str*
"hrd"
survey: *str*
"gaia"
sources : *int*
Gaia source IDs of target systems
identifiers : *str*
Positions of target systems in JHHMMSS.SS±DDMMSS.SS format
dataname : *str*
Default file for the :func:`savedata` method
plotname : *str*
Default file name for the :func:`showplot` and :func:`saveplot` methods
figure : *Bokeh figure*
Stores figures generated by the :func:`plot` method
data: *dict*
Returned data in the form:
.. code-block:: python
"bp-rp": [bp-rp colour of sources]
"absg": [absolute g magnitude of sources]
|
"""
def __init__(self, sources, data, identifiers=None, survey="gaia", positions=None, traces=None):
self.kind = "hrd"
self.survey = survey
self.sources = sources
self.identifiers = identifiers
self.data = data
self.figure = None
self.dataname = None
self.positions = positions
self.traces = traces
def __str__(self):
return "<ATK HRD Structure>"
@wraps(plot)
def plot(self, **kwargs):
return plot(self, **kwargs)
@wraps(showdata)
def showdata(self, pprint=True, print_methods=True):
showdata(self, pprint, print_methods)
return self
@wraps(savedata)
def savedata(self, fname=None):
fname = savedata(self, fname)
return fname
@wraps(showplot)
def showplot(self, fname=None):
fname = showplot(self, fname)
return fname
@wraps(saveplot)
def saveplot(self, fname=None):
fname = saveplot(self, fname)
return fname
@wraps(exportplot)
def exportplot(self, fname=None):
fname = exportplot(self, fname=fname)
return fname
def gather_data(sources):
import numpy as np
if not isinstance(sources, list):
sources = [sources]
x, y = [], []
from ..Tools import query
bad_indices, positions, pmras, pmdecs = [], [], [], []
for index, source in enumerate(sources):
gaia_data = query(kind="data", source=source, survey="gaia", level="internal").data
if gaia_data:
ra, dec, pmra, pmdec, gmag, bpmag, rpmag, parallax = (
gaia_data["ra"][0],
gaia_data["dec"][0],
gaia_data["pmra"][0],
gaia_data["pmdec"][0],
gaia_data["phot_g_mean_mag"][0],
gaia_data["phot_bp_mean_mag"][0],
gaia_data["phot_rp_mean_mag"][0],
gaia_data["parallax"][0],
)
positions.append([ra, dec])
pmras.append(pmra)
pmdecs.append(pmdec)
x.append(bpmag - rpmag)
y.append(gmag + 5 * np.log10(parallax / 1000) + 5)
else:
bad_indices.append(index)
sources_formatted = [source for i, source in enumerate(sources) if i not in bad_indices]
data = HrdStruct(sources=sources_formatted, data={"bp-rp": x, "absg": y})
from ..Tools import correctpm
corrected_positions, trace = [], ""
for index, (source, pmra, pmdec, position) in enumerate(zip(sources, pmras, pmdecs, positions)):
pos, success = correctpm(
pos=position, input_time=epochs["gaia"], target_time=[2000, 0], pmra=pmra, pmdec=pmdec, check_success=True
)
corrected_positions.append(pos)
if index == 0:
start_str = "start"
else:
start_str = f"{break_str}"
if index == len(sources) - 1:
if len(sources) > 1:
end_str = f"{break_str} -> end"
else:
end_str = " -> end"
else:
end_str = ""
if success:
trace += f"{start_str} -> {source}: pos extracted from source query, assumed {epochs['gaia']} -> [2000,0]{end_str}"
else:
trace += f"{start_str} -> {source}: pos extracted from source query, assumed {epochs['gaia']} -> proper motion correction failed{end_str}"
data.positions = corrected_positions
data.traces = trace
return data