Skip to content

Commit

Permalink
add methods for querying NASA Exoplanet Archive for ephemeris
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorris3 committed Jul 16, 2024
1 parent 3dd10ea commit 3c81476
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 5 deletions.
82 changes: 82 additions & 0 deletions lcviz/plugins/ephemeris/ephemeris.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import numpy as np
from astropy.coordinates import SkyCoord
from astropy.time import Time
import astropy.units as u
from astroquery.ipac.nexsci.nasa_exoplanet_archive import NasaExoplanetArchive

from traitlets import Bool, Float, List, Unicode, observe

from glue.core.link_helpers import LinkSame
Expand All @@ -24,6 +28,8 @@
_default_dpdt = 0.0
_default_wrap_at = 1.0

_default_query_radius = 2 # [arcsec]


@tray_registry('ephemeris', label="Ephemeris")
class Ephemeris(PluginTemplateMixin, DatasetSelectMixin):
Expand Down Expand Up @@ -87,13 +93,26 @@ class Ephemeris(PluginTemplateMixin, DatasetSelectMixin):

period_at_max_power = Float().tag(sync=True)

# QUERIES
query_name = Unicode().tag(sync=True)
query_ra = FloatHandleEmpty().tag(sync=True)
query_dec = FloatHandleEmpty().tag(sync=True)
query_radius = FloatHandleEmpty(_default_query_radius).tag(sync=True)
query_result_names = List().tag(sync=True)
query_result_selected = Unicode().tag(sync=True)
ra_dec_step = Float(0.01).tag(sync=True)
period_from_catalog = FloatHandleEmpty().tag(sync=True)
t0_from_catalog = FloatHandleEmpty().tag(sync=True)
query_spinner = Bool().tag(sync=True)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self._default_initialized = False
self._ignore_ephem_change = False
self._ephemerides = {}
self._prev_wrap_at = _default_wrap_at
self._nasa_exoplanet_archive = None

self.dataset.add_filter(is_not_tpf)

Expand Down Expand Up @@ -578,3 +597,66 @@ def get_data(self, dataset, ephem_component=None):
phlc.sort("time")

return phlc

@property
def nasa_exoplanet_archive(self):
if self._nasa_exoplanet_archive is None:
self._nasa_exoplanet_archive = NasaExoplanetArchive()

Check warning on line 604 in lcviz/plugins/ephemeris/ephemeris.py

View check run for this annotation

Codecov / codecov/patch

lcviz/plugins/ephemeris/ephemeris.py#L603-L604

Added lines #L603 - L604 were not covered by tests

return self._nasa_exoplanet_archive

Check warning on line 606 in lcviz/plugins/ephemeris/ephemeris.py

View check run for this annotation

Codecov / codecov/patch

lcviz/plugins/ephemeris/ephemeris.py#L606

Added line #L606 was not covered by tests

@observe('dataset_selected')
def _query_params_from_metadata(self, *args):
self.query_name = self.dataset.selected_obj.meta.get('OBJECT', '')
self.query_ra = self.dataset.selected_obj.meta.get('RA')
self.query_dec = self.dataset.selected_obj.meta.get('DEC')

def _query_for_ephemeris(self, *args):
if self.query_name:
self._query_result = self.nasa_exoplanet_archive.query_object(

Check warning on line 616 in lcviz/plugins/ephemeris/ephemeris.py

View check run for this annotation

Codecov / codecov/patch

lcviz/plugins/ephemeris/ephemeris.py#L615-L616

Added lines #L615 - L616 were not covered by tests
self.query_name, table='pscomppars'
)

elif None not in (self.query_ra, self.query_dec):
coord = SkyCoord(ra=self.query_ra, dec=self.query_dec, unit=u.deg)
self._query_result = self.nasa_exoplanet_archive.query_region(

Check warning on line 622 in lcviz/plugins/ephemeris/ephemeris.py

View check run for this annotation

Codecov / codecov/patch

lcviz/plugins/ephemeris/ephemeris.py#L620-L622

Added lines #L620 - L622 were not covered by tests
coord, self.query_radius * u.arcsec,
table='pscomppars'
)

else:
# no metadata found for RA, Dec, or object name
return None

Check warning on line 629 in lcviz/plugins/ephemeris/ephemeris.py

View check run for this annotation

Codecov / codecov/patch

lcviz/plugins/ephemeris/ephemeris.py#L629

Added line #L629 was not covered by tests

if len(self._query_result):
self._query_result.add_index('pl_name')
self.query_result_names = sorted(list(self._query_result['pl_name']))

Check warning on line 633 in lcviz/plugins/ephemeris/ephemeris.py

View check run for this annotation

Codecov / codecov/patch

lcviz/plugins/ephemeris/ephemeris.py#L631-L633

Added lines #L631 - L633 were not covered by tests

@observe('query_result_selected')
def _select_query_result(self, *args, selected_idx=None):
selected_query_result = self._query_result.loc[self.query_result_selected]
self.query_ra = selected_query_result['ra'].base.value
self.query_dec = selected_query_result['dec'].base.value
self.period_from_catalog = selected_query_result['pl_orbper'].base.to_value(u.day)
ref_time = self.app.data_collection[0].coords.reference_time.jd
self.t0_from_catalog = (

Check warning on line 642 in lcviz/plugins/ephemeris/ephemeris.py

View check run for this annotation

Codecov / codecov/patch

lcviz/plugins/ephemeris/ephemeris.py#L637-L642

Added lines #L637 - L642 were not covered by tests
selected_query_result['pl_tranmid'].base.to_value(u.day) - ref_time
) % self.period_from_catalog

def vue_query_for_ephemeris(self, *args):
self.query_spinner = True
self._query_for_ephemeris()
self.query_spinner = False

Check warning on line 649 in lcviz/plugins/ephemeris/ephemeris.py

View check run for this annotation

Codecov / codecov/patch

lcviz/plugins/ephemeris/ephemeris.py#L647-L649

Added lines #L647 - L649 were not covered by tests

def adopt_from_catalog(self, *args):
if not np.any(np.isnan([self.period_from_catalog, self.t0_from_catalog])):
self.period = self.period_from_catalog
self.t0 = self.t0_from_catalog

Check warning on line 654 in lcviz/plugins/ephemeris/ephemeris.py

View check run for this annotation

Codecov / codecov/patch

lcviz/plugins/ephemeris/ephemeris.py#L652-L654

Added lines #L652 - L654 were not covered by tests

# reset the phase axis wrap to feature the primary transit:
self.wrap_at = 0.5
viewer = self._get_phase_viewers()[0]
viewer.reset_limits()

Check warning on line 659 in lcviz/plugins/ephemeris/ephemeris.py

View check run for this annotation

Codecov / codecov/patch

lcviz/plugins/ephemeris/ephemeris.py#L657-L659

Added lines #L657 - L659 were not covered by tests

def vue_adopt_from_catalog(self, *args):
self.adopt_from_catalog()

Check warning on line 662 in lcviz/plugins/ephemeris/ephemeris.py

View check run for this annotation

Codecov / codecov/patch

lcviz/plugins/ephemeris/ephemeris.py#L662

Added line #L662 was not covered by tests
70 changes: 65 additions & 5 deletions lcviz/plugins/ephemeris/ephemeris.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
label="Period derivative"
v-model.number="dpdt"
:step="dpdt_step"
type="number"
hint="The first time-derivative of the period of the ephemeris."
persistent-hint
:rules="[() => dpdt!=='' || 'This field is required']"
Expand All @@ -81,7 +80,6 @@
label="Wrapping phase"
v-model.number="wrap_at"
:step="0.1"
type="number"
:hint="'Phased data will encompass the range '+wrap_at_range+'.'"
persistent-hint
:rules="[() => wrap_at!=='' || 'This field is required']"
Expand Down Expand Up @@ -110,8 +108,6 @@
></v-select>
</v-row>



<div style="display: grid"> <!-- overlay container -->
<div style="grid-area: 1/1">

Expand All @@ -120,7 +116,7 @@
</v-row>
<v-row v-else>
<j-tooltip :tooltipcontent="'adopt period into '+component_selected+' ephemeris.'">
<v-btn text color='primary '@click='adopt_period_at_max_power' style="padding: 0px">
<v-btn text color='primary' @click='adopt_period_at_max_power' style="padding: 0px">
period: {{period_at_max_power}}
</v-btn>
</j-tooltip>
Expand All @@ -144,7 +140,71 @@
</div>
</div>

<j-plugin-section-header>Query NASA Exoplanet Archive</j-plugin-section-header>
<v-row>
<v-text-field
ref="query_name"
type="string"
label="Object name"
v-model.number="query_name"
hint="Object name."
persistent-hint
></v-text-field>
</v-row>
<v-row>
<v-text-field
ref="query_ra"
type="number"
label="RA (degrees)"
v-model.number="query_ra"
:step="ra_dec_step"
hint="Object right ascension."
persistent-hint
></v-text-field>
</v-row>
<v-row>
<v-text-field
ref="query_dec"
type="number"
label="Dec (degrees)"
v-model.number="query_dec"
:step="ra_dec_step"
hint="Object declination."
persistent-hint
></v-text-field>
</v-row>

<v-row justify="end">
<j-tooltip tooltipcontent="Query for this object.">
<plugin-action-button
:spinner="query_spinner"
:results_isolated_to_plugin="false"
@click="query_for_ephemeris">
Query
</plugin-action-button>
</j-tooltip>
</v-row>
<div v-if="query_result_names.length > 0">
<v-row>
<v-select
:menu-props="{ left: true }"
attach
:items="query_result_names"
v-model="query_result_selected"
label="Ephemeris from query result"
:hint="'Ephemeris parameters from ' + query_result_names.length + ' available query result(s)'"
persistent-hint
></v-select>
</v-row>

<v-row v-if="query_result_selected !== ''">
<j-tooltip :tooltipcontent="'Adopt period into '+component_selected+' ephemeris.'">
<v-btn text color='primary' @click='adopt_from_catalog' style="padding: 0px">
period: {{period_from_catalog}}, t0: {{t0_from_catalog}}
</v-btn>
</j-tooltip>
</v-row>
</div>
</div>

</j-tray-plugin>
Expand Down

0 comments on commit 3c81476

Please sign in to comment.