from functools import wraps
from ..Configuration.epochs import EpochStruct
from ..StructureMethods.method_definitions import (exportplot, plot, savedata,
saveplot, showdata,
showplot)
epochs = EpochStruct().epoch_list
[docs]
class SpectrumStruct(object):
"""SpectrumStruct()
This structure is returned from spectrum queries, when read from a data file that was originally created by an spectrum query, or through the Models module (in which case all attributes are set to None).
.. rubric:: Attributes
:heading-level: 1
kind : *str*
"spectrum"
survey : *str*
survey to which the data belongs
source : *int*
Gaia source ID of target system (if given, else None)
pos : *list<float>*
Position of target system [right ascension, declination] in degrees
identifier : *str*
Position of target system 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
"wavelength": [wavelengths (angstroms)]
"flux": [fluxes (erg cm^-2 s^-1 angstrom^-1)]
|
"""
def __init__(self, survey, source, pos, data, identifier=None, trace=None):
self.kind = "spectrum"
self.survey = survey
self.source = source
self.pos = pos
self.identifier = identifier
self.data = data
self.figure = None
self.dataname = None
self.plotname = None
self.trace = trace
def __str__(self):
return "<ATK Spectrum 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
class SurveyMap(object):
"""Base class for spectrum queries"""
def __init__(self, survey, radius, pos=None):
self.survey = survey
self.pos = pos
self.radius = radius
def query(self):
data = globals()[f"{self.survey}_query"](pos=self.pos, radius=self.radius)
return data
def sdss_query(pos, radius):
from astropy import coordinates as coords
from astropy import units as u
from astroquery.sdss import SDSS
position = coords.SkyCoord(pos[0], pos[1], unit="deg")
radius = radius / 3600 * u.deg
data = SDSS.get_spectra(coordinates=position, radius=radius, timeout=120)
if data:
data = data[0][1].data
wavelength = 10 ** data["loglam"]
flux = data["flux"] * 10**-17
return {"wavelength": list(wavelength), "flux": list(flux)}
else:
print("Note: SDSS spectrum query returned no data.")
return None
def query(survey, radius, pos=None, source=None):
if source:
from ..Tools import correctpm
pos, success = correctpm(target_survey="sdss", source=source, check_success=True)
if success:
final_pos = correctpm(source=source, target_time=[2000, 0])
else:
final_pos = pos
if success:
trace = f"start -> extracted pos from source query, assumed {epochs['gaia']} -> {survey}: {epochs[survey]} -> {survey} query performed -> [2000,0] -> end"
else:
trace = f"start -> extracted pos from source query, assumed {epochs['gaia']} -> proper motion correction failed -> {survey} query performed -> end"
else:
final_pos = pos
trace = None
data = SurveyMap(survey=survey, radius=radius, pos=pos).query()
struct = SpectrumStruct(survey=survey, source=source, pos=pos, data=data)
struct.trace = trace
struct.pos = final_pos
return struct