Skip to content

Commit

Permalink
create new ephem viewers from query results
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorris3 committed Jul 16, 2024
1 parent 3c81476 commit ba8e717
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 35 deletions.
83 changes: 57 additions & 26 deletions lcviz/plugins/ephemeris/ephemeris.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from jdaviz.core.events import (NewViewerMessage, ViewerAddedMessage, ViewerRemovedMessage)
from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import (PluginTemplateMixin, DatasetSelectMixin,
SelectPluginComponent, EditableSelectPluginComponent)
SelectPluginComponent, EditableSelectPluginComponent,
with_spinner)
from jdaviz.core.user_api import PluginUserApi

from lightkurve import periodogram, FoldedLightCurve
Expand Down Expand Up @@ -98,7 +99,7 @@ class Ephemeris(PluginTemplateMixin, DatasetSelectMixin):
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_items = 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)
Expand Down Expand Up @@ -144,12 +145,16 @@ def __init__(self, *args, **kwargs):

@property
def user_api(self):
expose = ['component', 'period', 'dpdt', 't0', 'wrap_at',
'ephemeris', 'ephemerides',
'update_ephemeris', 'create_phase_viewer',
'add_component', 'remove_component', 'rename_component',
'times_to_phases', 'phases_to_times', 'get_data',
'dataset', 'method', 'period_at_max_power', 'adopt_period_at_max_power']
expose = [
'component', 'period', 'dpdt', 't0', 'wrap_at',
'ephemeris', 'ephemerides',
'update_ephemeris', 'create_phase_viewer',
'add_component', 'remove_component', 'rename_component',
'times_to_phases', 'phases_to_times', 'get_data',
'dataset', 'method', 'period_at_max_power',
'adopt_period_at_max_power', 'query_for_ephemeris',
'query_result'
]
return PluginUserApi(self, expose=expose)

def _phase_comp_lbl(self, component=None):
Expand Down Expand Up @@ -611,42 +616,63 @@ def _query_params_from_metadata(self, *args):
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):
def query_for_ephemeris(self):
query_result = None

if self.query_name:
self._query_result = self.nasa_exoplanet_archive.query_object(
# first query by object name:
query_result = self.nasa_exoplanet_archive.query_object(
self.query_name, table='pscomppars'
)

elif None not in (self.query_ra, self.query_dec):
if (
(query_result is None or len(query_result) == 0) and
(None not in (self.query_ra, self.query_dec))
):
# next query by coordinates:
coord = SkyCoord(ra=self.query_ra, dec=self.query_dec, unit=u.deg)
self._query_result = self.nasa_exoplanet_archive.query_region(
query_result = self.nasa_exoplanet_archive.query_region(
coord, self.query_radius * u.arcsec,
table='pscomppars'
)

else:
if query_result is None or len(query_result) == 0:
# no metadata found for RA, Dec, or object name
return None

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

self.query_result_items = [
{
'name': name,
'period': period,
'epoch': epoch if not np.isnan(epoch) else 0
}
for name, period, epoch in zip(
sorted(list(self.query_result['pl_name'])),
np.array(self.query_result['pl_orbper'].to_value(u.day)),
np.array(self.query_result['pl_tranmid'].to_value(u.day))
)
]

@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
def _select_query_result(self, *args):
selected_query_result = self.query_result.loc[self.query_result_selected]
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 = (
selected_query_result['pl_tranmid'].base.to_value(u.day) - ref_time
) % self.period_from_catalog
if np.isnan(selected_query_result['pl_tranmid'].base.to_value(u.day)):
self.t0_from_catalog = 0
else:
self.t0_from_catalog = (
selected_query_result['pl_tranmid'].base.to_value(u.day) - ref_time
) % self.period_from_catalog

@with_spinner('query_spinner')
def vue_query_for_ephemeris(self, *args):
self.query_spinner = True
self._query_for_ephemeris()
self.query_spinner = False
self.query_for_ephemeris()

def adopt_from_catalog(self, *args):
if not np.any(np.isnan([self.period_from_catalog, self.t0_from_catalog])):
Expand All @@ -660,3 +686,8 @@ def adopt_from_catalog(self, *args):

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

def vue_adopt_from_catalog_in_new_viewer(self, *args):
self.add_component(self.query_result_selected.replace(' ', ''))
self.create_phase_viewer()
self.adopt_from_catalog()
72 changes: 63 additions & 9 deletions lcviz/plugins/ephemeris/ephemeris.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@
</div>

<j-plugin-section-header>Query NASA Exoplanet Archive</j-plugin-section-header>
<v-row>
<span class="v-messages v-messages__message text--secondary">
Query the
<a href="https://exoplanetarchive.ipac.caltech.edu/docs/pscp_about.html" target="_blank">
Planetary Systems Composite Data</a> table from
<a href="https://exoplanetarchive.ipac.caltech.edu/" target="_blank">
NASA Exoplanet Archive</a>. Queries first by name, then falls back on
coordinates if the object name is not recognized.
</span>
</v-row>

<v-row>
<v-text-field
ref="query_name"
Expand Down Expand Up @@ -173,6 +184,17 @@
persistent-hint
></v-text-field>
</v-row>
<v-row>
<v-text-field
ref="query_radius"
type="number"
label="Radius (arcseconds)"
v-model.number="query_radius"
:step="1"
hint="Radius around the query coordinate."
persistent-hint
></v-text-field>
</v-row>

<v-row justify="end">
<j-tooltip tooltipcontent="Query for this object.">
Expand All @@ -184,24 +206,56 @@
</plugin-action-button>
</j-tooltip>
</v-row>
<div v-if="query_result_names.length > 0">
<div v-if="query_result_items.length > 0">
<v-row>
<v-select
:menu-props="{ left: true }"
attach
:items="query_result_names"
:items="query_result_items"
:item-value="item => item.name"
v-model="query_result_selected"
label="Ephemeris from query result"
:hint="'Ephemeris parameters from ' + query_result_names.length + ' available query result(s)'"
label="Ephemerides available"
:hint="'Ephemeris parameters from ' + query_result_items.length + ' available query result(s)'"
persistent-hint
></v-select>
dense
>

<template v-slot:selection="{ item }">
<span>
{{ item.name }}
</span>
</template>
<template v-slot:item="{ item }">
<span style="margin-top: 8px; margin-bottom: 0px">
{{ item.name }}
<v-row style="line-height: 1.0; margin: 0px; opacity: 0.85; font-size: 8pt">
Period: {{ item.period }} d, Epoch: {{ item.epoch }} d
</v-row>
</span>
</template>

</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>
<span class="v-messages v-messages__message text--secondary">
Period: {{period_from_catalog}} d, Epoch: {{t0_from_catalog}} d
</span>
<j-tooltip :tooltipcontent="'Adopt period and epoch into '+component_selected+' ephemeris.'">
<v-row justify="end">
<v-col>
<div v-if="phase_viewer_exists">
<plugin-action-button
@click="adopt_from_catalog">
Adopt in this viewer
</plugin-action-button>
</div>
<plugin-action-button
@click="adopt_from_catalog_in_new_viewer">
Adopt in a new viewer
</plugin-action-button>
</v-col>
</v-row>
</j-tooltip>
</v-row>
</div>
Expand Down

0 comments on commit ba8e717

Please sign in to comment.