Skip to content

Commit

Permalink
re-rename origin->column
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Jan 5, 2024
1 parent 040c9cc commit 227c7c5
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 73 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

* Clone viewer tool. [#74]

* Flux origin plugin to choose which column is treated as the flux column for each dataset. [#77]
* Flux column plugin to choose which column is treated as the flux column for each dataset. [#77]

* Flatten plugin no longer creates new data entries, but instead appends a new column to the input
light curve and selects as the flux origin. [#77]
light curve and selects as the flux column (origin). [#77]

0.1.0 (12-14-2023)
------------------
Expand Down
14 changes: 7 additions & 7 deletions docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ This plugin allows viewing of any metadata associated with the selected data.
:ref:`Jdaviz Metadata Viewer <jdaviz:imviz_metadata-viewer>`
Jdaviz documentation on the Metadata Viewer plugin.

.. _flux-origin:
.. _flux-column:

Flux Origin
Flux Column
===========

This plugin allows choosing which column in the underlying data should be used as the flux origin
throughout the app (when plotting and in any data analysis plugins).
This plugin allows choosing which column in the underlying data should be used as the flux column
(origin) throughout the app (when plotting and in any data analysis plugins).


.. admonition:: User API Example
Expand All @@ -58,9 +58,9 @@ throughout the app (when plotting and in any data analysis plugins).
lcviz.load_data(lc)
lcviz.show()
flux_origin = lcviz.plugins['Flux Origin']
print(flux_origin.flux_origin.choices)
flux_origin.flux_origin = 'sap_flux'
flux_col = lcviz.plugins['Flux Column']
print(flux_col.flux_column.choices)
flux_col.flux_column = 'sap_flux'
.. seealso::
Expand Down
44 changes: 22 additions & 22 deletions lcviz/components/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

from jdaviz.core.template_mixin import SelectPluginComponent

from lcviz.events import FluxOriginChangedMessage
from lcviz.events import FluxColumnChangedMessage

__all__ = ['FluxOriginSelect', 'FluxOriginSelectMixin']
__all__ = ['FluxColumnSelect', 'FluxColumnSelectMixin']


class FluxOriginSelect(SelectPluginComponent):
class FluxColumnSelect(SelectPluginComponent):
def __init__(self, plugin, items, selected, dataset):
super().__init__(plugin,
items=items,
Expand All @@ -22,8 +22,8 @@ def __init__(self, plugin, items, selected, dataset):
self._on_change_dataset)

# sync between instances in different plugins
self.hub.subscribe(self, FluxOriginChangedMessage,
handler=self._on_flux_origin_changed_msg)
self.hub.subscribe(self, FluxColumnChangedMessage,
handler=self._on_flux_column_changed_msg)

def _on_change_dataset(self, *args):
def _include_col(lk_obj, col):
Expand Down Expand Up @@ -53,28 +53,28 @@ def _include_col(lk_obj, col):
if lk_obj is None:
return
self.choices = [col for col in lk_obj.columns if _include_col(lk_obj, col)]
flux_origin = lk_obj.meta.get('FLUX_ORIGIN')
if flux_origin in self.choices:
self.selected = flux_origin
flux_column = lk_obj.meta.get('FLUX_ORIGIN')
if flux_column in self.choices:
self.selected = flux_column
else:
self.selected = ''

def _on_flux_origin_changed_msg(self, msg):
def _on_flux_column_changed_msg(self, msg):
if msg.dataset != self.dataset.selected:
return

# need to clear the cache due to the change in metadata made to the data-collection entry
self.dataset._clear_cache('selected_obj', 'selected_dc_item')
self._on_change_dataset()
self.selected = msg.flux_origin
self.selected = msg.flux_column

def _on_change_selected(self, *args):
if self.selected == '':
return

dc_item = self.dataset.selected_dc_item
old_flux_origin = dc_item.meta.get('FLUX_ORIGIN')
if self.selected == old_flux_origin:
old_flux_column = dc_item.meta.get('FLUX_ORIGIN')
if self.selected == old_flux_column:
# nothing to do here!
return

Expand All @@ -85,8 +85,8 @@ def _on_change_selected(self, *args):
self.app._jdaviz_helper._set_data_component(dc_item, 'flux_err', dc_item[self.selected+"_err"]) # noqa
dc_item.meta['FLUX_ORIGIN'] = self.selected

self.hub.broadcast(FluxOriginChangedMessage(dataset=self.dataset.selected,
flux_origin=self.selected,
self.hub.broadcast(FluxColumnChangedMessage(dataset=self.dataset.selected,
flux_column=self.selected,
sender=self))

def add_new_flux_column(self, flux, flux_err, label, selected=False):
Expand All @@ -99,19 +99,19 @@ def add_new_flux_column(self, flux, flux_err, label, selected=False):
flux_err)

# broadcast so all instances update to get the new column and selection (if applicable)
self.hub.broadcast(FluxOriginChangedMessage(dataset=self.dataset.selected,
flux_origin=label if selected else self.selected, # noqa
self.hub.broadcast(FluxColumnChangedMessage(dataset=self.dataset.selected,
flux_column=label if selected else self.selected, # noqa
sender=self))


class FluxOriginSelectMixin(VuetifyTemplate, HubListener):
flux_origin_items = List().tag(sync=True)
flux_origin_selected = Unicode().tag(sync=True)
class FluxColumnSelectMixin(VuetifyTemplate, HubListener):
flux_column_items = List().tag(sync=True)
flux_column_selected = Unicode().tag(sync=True)
# assumes DatasetSelectMixin is also used (DatasetSelectMixin must appear after in inheritance)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.flux_origin = FluxOriginSelect(self,
'flux_origin_items',
'flux_origin_selected',
self.flux_column = FluxColumnSelect(self,
'flux_column_items',
'flux_column_selected',
dataset='dataset')
12 changes: 6 additions & 6 deletions lcviz/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__all__ = ['EphemerisComponentChangedMessage',
'EphemerisChangedMessage',
'FluxOriginChangedMessage']
'FluxColumnChangedMessage']


class EphemerisComponentChangedMessage(Message):
Expand Down Expand Up @@ -30,10 +30,10 @@ def __init__(self, ephemeris_label, *args, **kwargs):
self.ephemeris_label = ephemeris_label


class FluxOriginChangedMessage(Message):
"""Message emitted by the FluxOriginSelect component when the selection has been changed.
To subscribe to a change for a particular dataset, consider using FluxOriginSelect directly
class FluxColumnChangedMessage(Message):
"""Message emitted by the FluxColumnSelect component when the selection has been changed.
To subscribe to a change for a particular dataset, consider using FluxColumnSelect directly
and observing the traitlet, rather than subscribing to this message"""
def __init__(self, dataset, flux_origin, *args, **kwargs):
def __init__(self, dataset, flux_column, *args, **kwargs):
self.dataset = dataset
self.flux_origin = flux_origin
self.flux_column = flux_column
2 changes: 1 addition & 1 deletion lcviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class LCviz(ConfigHelper):
'dense_toolbar': False,
'context': {'notebook': {'max_height': '600px'}}},
'toolbar': ['g-data-tools', 'g-subset-tools', 'lcviz-coords-info'],
'tray': ['lcviz-metadata-viewer', 'flux-origin',
'tray': ['lcviz-metadata-viewer', 'flux-column',
'lcviz-plot-options', 'lcviz-subset-plugin',
'lcviz-markers', 'flatten', 'frequency-analysis', 'ephemeris',
'binning', 'lcviz-export-plot'],
Expand Down
2 changes: 1 addition & 1 deletion lcviz/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .ephemeris.ephemeris import * # noqa
from .export_plot.export_plot import * # noqa
from .flatten.flatten import * # noqa
from .flux_origin.flux_origin import * # noqa
from .flux_column.flux_column import * # noqa
from .frequency_analysis.frequency_analysis import * # noqa
from .markers.markers import * # noqa
from .metadata_viewer.metadata_viewer import * # noqa
Expand Down
6 changes: 3 additions & 3 deletions lcviz/plugins/binning/binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
with_spinner)
from jdaviz.core.user_api import PluginUserApi

from lcviz.components import FluxOriginSelectMixin
from lcviz.components import FluxColumnSelectMixin
from lcviz.events import EphemerisChangedMessage
from lcviz.helper import _default_time_viewer_reference_name
from lcviz.marks import LivePreviewBinning
Expand All @@ -25,7 +25,7 @@


@tray_registry('binning', label="Binning")
class Binning(PluginTemplateMixin, FluxOriginSelectMixin, DatasetSelectMixin,
class Binning(PluginTemplateMixin, FluxColumnSelectMixin, DatasetSelectMixin,
EphemerisSelectMixin, AddResultsMixin):
"""
See the :ref:`Binning Plugin Documentation <binning>` for more details.
Expand Down Expand Up @@ -152,7 +152,7 @@ def _toggle_marks(self, event={}):
# then the marks themselves need to be updated
self._live_update(event)

@observe('flux_origin_selected', 'dataset_selected',
@observe('flux_column_selected', 'dataset_selected',
'ephemeris_selected',
'n_bins', 'previews_temp_disable')
@skip_if_no_updates_since_last_active()
Expand Down
22 changes: 11 additions & 11 deletions lcviz/plugins/flatten/flatten.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
with_spinner)
from jdaviz.core.user_api import PluginUserApi

from lcviz.components import FluxOriginSelectMixin
from lcviz.components import FluxColumnSelectMixin
from lcviz.marks import LivePreviewTrend, LivePreviewFlattened
from lcviz.utils import data_not_folded
from lcviz.viewers import TimeScatterView, PhaseScatterView
Expand All @@ -23,7 +23,7 @@


@tray_registry('flatten', label="Flatten")
class Flatten(PluginTemplateMixin, FluxOriginSelectMixin, DatasetSelectMixin):
class Flatten(PluginTemplateMixin, FluxColumnSelectMixin, DatasetSelectMixin):
"""
See the :ref:`Flatten Plugin Documentation <flatten>` for more details.
Expand All @@ -44,7 +44,7 @@ class Flatten(PluginTemplateMixin, FluxOriginSelectMixin, DatasetSelectMixin):
* ``unnormalize``
* ``flux_label`` (:class:`~jdaviz.core.template_mixin.AutoTextField`):
Label for the resulting flux column added to ``dataset`` and automatically selected as the new
flux origin.
flux column (origin).
* :meth:`flatten`
"""
template_file = __file__, "flatten.vue"
Expand Down Expand Up @@ -122,19 +122,19 @@ def marks(self):

return trend_marks, flattened_marks

@observe('dataset_selected', 'flux_origin_selected')
@observe('dataset_selected', 'flux_column_selected')
def _set_default_label(self, event={}):
'''Generate a label and set the results field to that value'''
if not hasattr(self, 'dataset'): # pragma: no cover
return

# TODO: have an option to create new data entry and drop other columns?
# (or should that just go through future data cloning)
self.flux_label.default = f"{self.flux_origin_selected}_flattened"
self.flux_label.default = f"{self.flux_column_selected}_flattened"

@observe('flux_label_label', 'dataset')
def _update_label_valid(self, event={}):
if self.flux_label.value in self.flux_origin.choices:
if self.flux_label.value in self.flux_column.choices:
self.flux_label.invalid_msg = ''
self.flux_label_overwrite = True
elif self.flux_label.value in getattr(self.dataset.selected_obj, 'columns', []):
Expand All @@ -152,7 +152,7 @@ def flatten(self, add_data=True):
----------
add_data : bool
Whether to add the resulting light curve as a flux column and select that as the new
flux origin for that data entry.
flux column (origin) for that data entry.
Returns
-------
Expand Down Expand Up @@ -180,9 +180,9 @@ def flatten(self, add_data=True):

if add_data:
# add data as a new flux and corresponding err columns in the existing data entry
# and select as flux origin
# and select as flux column (origin)
data = _data_with_reftime(self.app, output_lc)
self.flux_origin.add_new_flux_column(flux=data['flux'],
self.flux_column.add_new_flux_column(flux=data['flux'],
flux_err=data['flux_err'],
label=self.flux_label.value,
selected=True)
Expand Down Expand Up @@ -212,14 +212,14 @@ def _toggle_marks(self, event={}):
# then the marks themselves need to be updated
self._live_update(event)

@observe('dataset_selected', 'flux_origin_selected',
@observe('dataset_selected', 'flux_column_selected',
'window_length', 'polyorder', 'break_tolerance',
'niters', 'sigma', 'previews_temp_disable')
@skip_if_no_updates_since_last_active()
def _live_update(self, event={}):
if self.previews_temp_disable:
return
if self.dataset_selected == '' or self.flux_origin_selected == '':
if self.dataset_selected == '' or self.flux_column_selected == '':
self._clear_marks()
return

Expand Down
2 changes: 1 addition & 1 deletion lcviz/plugins/flatten/flatten.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
</v-alert>

<v-row justify="end">
<j-tooltip tooltipcontent="Flatten and select new column as flux origin">
<j-tooltip tooltipcontent="Flatten and select the new column as the adopted flux column">
<plugin-action-button
:spinner="spinner"
:disabled="flux_label_invalid_msg.length > 0"
Expand Down
1 change: 1 addition & 0 deletions lcviz/plugins/flux_column/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .flux_column import * # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@
DatasetSelectMixin)
from jdaviz.core.user_api import PluginUserApi

from lcviz.components import FluxOriginSelectMixin
from lcviz.components import FluxColumnSelectMixin

__all__ = ['FluxOrigin']
__all__ = ['FluxColumn']


@tray_registry('flux-origin', label="Flux Origin")
class FluxOrigin(PluginTemplateMixin, FluxOriginSelectMixin, DatasetSelectMixin):
@tray_registry('flux-column', label="Flux Column")
class FluxColumn(PluginTemplateMixin, FluxColumnSelectMixin, DatasetSelectMixin):
"""
See the :ref:`Flux Origin Plugin Documentation <flux-origin>` for more details.
See the :ref:`Flux Column Plugin Documentation <flux-column>` for more details.
Only the following attributes and methods are available through the
public plugin API.
* ``dataset`` (:class:`~jdaviz.core.template_mixin.DatasetSelect`):
Dataset to bin.
* ``flux_column`` (:class:`~lcviz.components.FluxColumnSelect`)
"""
template_file = __file__, "flux_origin.vue"
template_file = __file__, "flux_column.vue"

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

@property
def user_api(self):
expose = ['dataset', 'flux_origin']
expose = ['dataset', 'flux_column']
return PluginUserApi(self, expose=expose)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<j-tray-plugin
description='Choose which column to use as flux across lcviz.'
:link="'https://lcviz.readthedocs.io/en/'+vdocs+'/plugins.html#flux-origin'"
:link="'https://lcviz.readthedocs.io/en/'+vdocs+'/plugins.html#flux-column'"
:uses_active_status="uses_active_status"
@plugin-ping="plugin_ping($event)"
:keep_active.sync="keep_active"
Expand All @@ -19,8 +19,8 @@
<v-select
:menu-props="{ left: true }"
attach
:items="flux_origin_items.map(i => i.label)"
v-model="flux_origin_selected"
:items="flux_column_items.map(i => i.label)"
v-model="flux_column_selected"
label="Flux Column"
hint="Select the column to adopt as flux."
persistent-hint
Expand Down
1 change: 0 additions & 1 deletion lcviz/plugins/flux_origin/__init__.py

This file was deleted.

Loading

0 comments on commit 227c7c5

Please sign in to comment.