From c7776c406358fe9c77b0f1cb4de0de42c594eac8 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Wed, 10 Jan 2024 08:02:00 -0500 Subject: [PATCH] Flux Column plugin (#77) * basic plugin to toggle actively selected flux column per-dataset * rework flatten plugin to use flux columns * mention API breaking change in changelog * update binning live-preview on change to flux-origin --- CHANGES.rst | 5 + docs/plugins.rst | 35 +++++++ lcviz/components/__init__.py | 1 + lcviz/components/components.py | 117 ++++++++++++++++++++++ lcviz/conftest.py | 5 +- lcviz/events.py | 12 ++- lcviz/helper.py | 24 +++-- lcviz/parsers.py | 11 +- lcviz/plugins/__init__.py | 1 + lcviz/plugins/binning/binning.py | 7 +- lcviz/plugins/flatten/flatten.py | 73 +++++++++----- lcviz/plugins/flatten/flatten.vue | 42 ++++---- lcviz/plugins/flux_column/__init__.py | 1 + lcviz/plugins/flux_column/flux_column.py | 31 ++++++ lcviz/plugins/flux_column/flux_column.vue | 31 ++++++ lcviz/tests/test_plugin_flatten.py | 21 +--- lcviz/tests/test_plugin_flux_column.py | 30 ++++++ 17 files changed, 368 insertions(+), 79 deletions(-) create mode 100644 lcviz/components/components.py create mode 100644 lcviz/plugins/flux_column/__init__.py create mode 100644 lcviz/plugins/flux_column/flux_column.py create mode 100644 lcviz/plugins/flux_column/flux_column.vue create mode 100644 lcviz/tests/test_plugin_flux_column.py diff --git a/CHANGES.rst b/CHANGES.rst index 10fa9251..fbfdec9d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,11 @@ * Clone viewer tool. [#74] +* 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 column (origin). [#77] + 0.1.0 (12-14-2023) ------------------ diff --git a/docs/plugins.rst b/docs/plugins.rst index 0558f69f..22f6c39e 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -35,6 +35,41 @@ This plugin allows viewing of any metadata associated with the selected data. :ref:`Jdaviz Metadata Viewer ` Jdaviz documentation on the Metadata Viewer plugin. +.. _flux-column: + +Flux Column +=========== + +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 + :class: dropdown + + See the :class:`~lcviz.plugins.plot_options.plot_options.PlotOptions` user API documentation for more details. + + .. code-block:: python + + from lcviz import LCviz + lc = search_lightcurve("HAT-P-11", mission="Kepler", + cadence="long", quarter=10).download().flatten() + lcviz = LCviz() + lcviz.load_data(lc) + lcviz.show() + + flux_col = lcviz.plugins['Flux Column'] + print(flux_col.flux_column.choices) + flux_col.flux_column = 'sap_flux' + + +.. seealso:: + + This plugin reproduces the behavior also available in ``lightkurve`` as: + + * :meth:`lightkurve.LightCurve.select_flux` + + .. _plot-options: Plot Options diff --git a/lcviz/components/__init__.py b/lcviz/components/__init__.py index e69de29b..d86f273c 100644 --- a/lcviz/components/__init__.py +++ b/lcviz/components/__init__.py @@ -0,0 +1 @@ +from .components import * # noqa diff --git a/lcviz/components/components.py b/lcviz/components/components.py new file mode 100644 index 00000000..e3ffdbad --- /dev/null +++ b/lcviz/components/components.py @@ -0,0 +1,117 @@ +from astropy import units as u +from ipyvuetify import VuetifyTemplate +from glue.core import HubListener +from traitlets import List, Unicode + +from jdaviz.core.template_mixin import SelectPluginComponent + +from lcviz.events import FluxColumnChangedMessage + +__all__ = ['FluxColumnSelect', 'FluxColumnSelectMixin'] + + +class FluxColumnSelect(SelectPluginComponent): + def __init__(self, plugin, items, selected, dataset): + super().__init__(plugin, + items=items, + selected=selected, + dataset=dataset) + + self.add_observe(selected, self._on_change_selected) + self.add_observe(self.dataset._plugin_traitlets['selected'], + self._on_change_dataset) + + # sync between instances in different plugins + self.hub.subscribe(self, FluxColumnChangedMessage, + handler=self._on_flux_column_changed_msg) + + def _on_change_dataset(self, *args): + def _include_col(lk_obj, col): + if col == 'flux' and lk_obj.meta.get('FLUX_ORIGIN') != 'flux': + # this is the currently active column (and should be copied elsewhere unless) + return False + if col in ('time', 'cadn', 'cadenceno', 'quality'): + return False + if col.startswith('phase:'): + # internal jdaviz ephemeris phase columns + return False + if col.startswith('time'): + return False + if col.startswith('centroid'): + return False + if col.startswith('cbv'): + # cotrending basis vector + return False + if col.endswith('_err'): + return False + if col.endswith('quality'): + return False + # TODO: need to think about flatten losing units in the flux column + return lk_obj[col].unit != u.pix + + lk_obj = self.dataset.selected_obj + if lk_obj is None: + return + self.choices = [col for col in lk_obj.columns if _include_col(lk_obj, col)] + flux_column = lk_obj.meta.get('FLUX_ORIGIN') + if flux_column in self.choices: + self.selected = flux_column + else: + self.selected = '' + + 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_column + + def _on_change_selected(self, *args): + if self.selected == '': + return + + dc_item = self.dataset.selected_dc_item + old_flux_column = dc_item.meta.get('FLUX_ORIGIN') + if self.selected == old_flux_column: + # nothing to do here! + return + + # instead of using lightkurve's select_flux and having to reparse the data entry, we'll + # manipulate the arrays in the data-collection directly, and modify FLUX_ORIGIN so that + # exporting back to a lightkurve object works as expected + self.app._jdaviz_helper._set_data_component(dc_item, 'flux', dc_item[self.selected]) + 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(FluxColumnChangedMessage(dataset=self.dataset.selected, + flux_column=self.selected, + sender=self)) + + def add_new_flux_column(self, flux, flux_err, label, selected=False): + dc_item = self.dataset.selected_dc_item + self.app._jdaviz_helper._set_data_component(dc_item, + label, + flux) + self.app._jdaviz_helper._set_data_component(dc_item, + f"{label}_err", + flux_err) + + # broadcast so all instances update to get the new column and selection (if applicable) + self.hub.broadcast(FluxColumnChangedMessage(dataset=self.dataset.selected, + flux_column=label if selected else self.selected, # noqa + sender=self)) + + +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_column = FluxColumnSelect(self, + 'flux_column_items', + 'flux_column_selected', + dataset='dataset') diff --git a/lcviz/conftest.py b/lcviz/conftest.py index a067f20e..6d616903 100644 --- a/lcviz/conftest.py +++ b/lcviz/conftest.py @@ -32,9 +32,12 @@ def light_curve_like_kepler_quarter(seed=42): quality = np.zeros(len(time), dtype=np.int32) - return LightCurve( + lc = LightCurve( time=time, flux=flux, flux_err=flux_err, quality=quality ) + lc['flux_alt'] = flux + 1 + lc['flux_alt_err'] = flux_err + return lc try: diff --git a/lcviz/events.py b/lcviz/events.py index 3ca014c6..97c0f783 100644 --- a/lcviz/events.py +++ b/lcviz/events.py @@ -1,7 +1,8 @@ from glue.core.message import Message __all__ = ['EphemerisComponentChangedMessage', - 'EphemerisChangedMessage'] + 'EphemerisChangedMessage', + 'FluxColumnChangedMessage'] class EphemerisComponentChangedMessage(Message): @@ -27,3 +28,12 @@ class EphemerisChangedMessage(Message): in the ephemeris plugin""" def __init__(self, ephemeris_label, *args, **kwargs): self.ephemeris_label = ephemeris_label + + +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_column, *args, **kwargs): + self.dataset = dataset + self.flux_column = flux_column diff --git a/lcviz/helper.py b/lcviz/helper.py index a6453cd2..9f234d37 100644 --- a/lcviz/helper.py +++ b/lcviz/helper.py @@ -72,7 +72,8 @@ 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', 'lcviz-plot-options', 'lcviz-subset-plugin', + 'tray': ['lcviz-metadata-viewer', 'flux-column', + 'lcviz-plot-options', 'lcviz-subset-plugin', 'lcviz-markers', 'flatten', 'frequency-analysis', 'ephemeris', 'binning', 'lcviz-export-plot'], 'viewer_area': [{'container': 'col', @@ -155,12 +156,17 @@ def _phase_comp_lbl(self, component): return f'phase:{component}' def _set_data_component(self, data, component_label, values): - if component_label not in self._component_ids: - self._component_ids[component_label] = ComponentID(component_label) - - if self._component_ids[component_label] in data.components: - data.update_components({self._component_ids[component_label]: values}) + if component_label in self._component_ids: + component_id = self._component_ids[component_label] else: - data.add_component(values, self._component_ids[component_label]) - - data.add_component(values, self._component_ids[component_label]) + existing_components = [component.label for component in data.components] + if component_label in existing_components: + component_id = data.components[existing_components.index(component_label)] + else: + component_id = ComponentID(component_label) + self._component_ids[component_label] = component_id + + if component_id in data.components: + data.update_components({component_id: values}) + else: + data.add_component(values, component_id) diff --git a/lcviz/parsers.py b/lcviz/parsers.py index e9268c83..c7d20dea 100644 --- a/lcviz/parsers.py +++ b/lcviz/parsers.py @@ -27,9 +27,16 @@ def light_curve_parser(app, file_obj, data_label=None, show_in_viewer=True, **kw new_data_label = f'{data_label}' else: new_data_label = light_curve.meta.get('OBJECT', 'Light curve') + + # handle flux_origin default flux_origin = light_curve.meta.get('FLUX_ORIGIN', None) # i.e. PDCSAP or SAP - if flux_origin is not None: - new_data_label += f'[{flux_origin}]' + if flux_origin == 'flux' or (flux_origin is None and 'flux' in light_curve.columns): + # then make a copy of this column so it won't be lost when changing with the flux_column + # plugin + light_curve['flux:orig'] = light_curve['flux'] + if 'flux_err' in light_curve.columns: + light_curve['flux:orig_err'] = light_curve['flux_err'] + light_curve.meta['FLUX_ORIGIN'] = 'flux:orig' data = _data_with_reftime(app, light_curve) app.add_data(data, new_data_label) diff --git a/lcviz/plugins/__init__.py b/lcviz/plugins/__init__.py index dacdb581..2bf109b5 100644 --- a/lcviz/plugins/__init__.py +++ b/lcviz/plugins/__init__.py @@ -3,6 +3,7 @@ from .ephemeris.ephemeris import * # noqa from .export_plot.export_plot import * # noqa from .flatten.flatten 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 diff --git a/lcviz/plugins/binning/binning.py b/lcviz/plugins/binning/binning.py index e1691ecc..3c3dcd4d 100644 --- a/lcviz/plugins/binning/binning.py +++ b/lcviz/plugins/binning/binning.py @@ -13,6 +13,7 @@ with_spinner) from jdaviz.core.user_api import PluginUserApi +from lcviz.components import FluxColumnSelectMixin from lcviz.events import EphemerisChangedMessage from lcviz.helper import _default_time_viewer_reference_name from lcviz.marks import LivePreviewBinning @@ -24,7 +25,8 @@ @tray_registry('binning', label="Binning") -class Binning(PluginTemplateMixin, DatasetSelectMixin, EphemerisSelectMixin, AddResultsMixin): +class Binning(PluginTemplateMixin, FluxColumnSelectMixin, DatasetSelectMixin, + EphemerisSelectMixin, AddResultsMixin): """ See the :ref:`Binning Plugin Documentation ` for more details. @@ -150,7 +152,8 @@ def _toggle_marks(self, event={}): # then the marks themselves need to be updated self._live_update(event) - @observe('dataset_selected', 'ephemeris_selected', + @observe('flux_column_selected', 'dataset_selected', + 'ephemeris_selected', 'n_bins', 'previews_temp_disable') @skip_if_no_updates_since_last_active() def _live_update(self, event={}): diff --git a/lcviz/plugins/flatten/flatten.py b/lcviz/plugins/flatten/flatten.py index 66b8e94c..a10bc7c1 100644 --- a/lcviz/plugins/flatten/flatten.py +++ b/lcviz/plugins/flatten/flatten.py @@ -7,11 +7,13 @@ from jdaviz.core.events import ViewerAddedMessage from jdaviz.core.registries import tray_registry from jdaviz.core.template_mixin import (PluginTemplateMixin, - DatasetSelectMixin, AddResultsMixin, + DatasetSelectMixin, + AutoTextField, skip_if_no_updates_since_last_active, with_spinner) from jdaviz.core.user_api import PluginUserApi +from lcviz.components import FluxColumnSelectMixin from lcviz.marks import LivePreviewTrend, LivePreviewFlattened from lcviz.utils import data_not_folded from lcviz.viewers import TimeScatterView, PhaseScatterView @@ -21,7 +23,7 @@ @tray_registry('flatten', label="Flatten") -class Flatten(PluginTemplateMixin, DatasetSelectMixin, AddResultsMixin): +class Flatten(PluginTemplateMixin, FluxColumnSelectMixin, DatasetSelectMixin): """ See the :ref:`Flatten Plugin Documentation ` for more details. @@ -32,16 +34,17 @@ class Flatten(PluginTemplateMixin, DatasetSelectMixin, AddResultsMixin): Whether to show the live-preview of the (unnormalized) flattened light curve * ``show_trend_preview`` : bool Whether to show the live-preview of the trend curve used to flatten the light curve - * ``default_to_overwrite`` * ``dataset`` (:class:`~jdaviz.core.template_mixin.DatasetSelect`): Dataset to flatten. - * ``add_results`` (:class:`~jdaviz.core.template_mixin.AddResults`) * ``window_length`` * ``polyorder`` * ``break_tolerance`` * ``niters`` * ``sigma`` * ``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 column (origin). * :meth:`flatten` """ template_file = __file__, "flatten.vue" @@ -49,7 +52,6 @@ class Flatten(PluginTemplateMixin, DatasetSelectMixin, AddResultsMixin): show_live_preview = Bool(True).tag(sync=True) show_trend_preview = Bool(True).tag(sync=True) - default_to_overwrite = Bool(True).tag(sync=True) flatten_err = Unicode().tag(sync=True) window_length = IntHandleEmpty(101).tag(sync=True) @@ -59,12 +61,22 @@ class Flatten(PluginTemplateMixin, DatasetSelectMixin, AddResultsMixin): sigma = FloatHandleEmpty(3).tag(sync=True) unnormalize = Bool(False).tag(sync=True) + flux_label_label = Unicode().tag(sync=True) + flux_label_default = Unicode().tag(sync=True) + flux_label_auto = Bool(True).tag(sync=True) + flux_label_invalid_msg = Unicode('').tag(sync=True) + flux_label_overwrite = Bool(False).tag(sync=True) + last_live_time = Float(0).tag(sync=True) previews_temp_disable = Bool(False).tag(sync=True) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + self.flux_label = AutoTextField(self, 'flux_label_label', + 'flux_label_default', 'flux_label_auto', + 'flux_label_invalid_msg') + # do not support flattening data in phase-space self.dataset.add_filter(data_not_folded) @@ -72,12 +84,14 @@ def __init__(self, *args, **kwargs): # those marks self.hub.subscribe(self, ViewerAddedMessage, handler=lambda _: self._live_update()) + self._set_default_label() + @property def user_api(self): - expose = ['show_live_preview', 'show_trend_preview', 'default_to_overwrite', - 'dataset', 'add_results', + expose = ['show_live_preview', 'show_trend_preview', + 'dataset', 'window_length', 'polyorder', 'break_tolerance', - 'niters', 'sigma', 'unnormalize', 'flatten'] + 'niters', 'sigma', 'unnormalize', 'flux_label', 'flatten'] return PluginUserApi(self, expose=expose) @property @@ -108,18 +122,26 @@ def marks(self): return trend_marks, flattened_marks - @observe('default_to_overwrite', 'dataset_selected') - def _set_default_results_label(self, event={}): + @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 - self.add_results.label_whitelist_overwrite = [self.dataset_selected] - - if self.default_to_overwrite: - self.results_label_default = self.dataset_selected + # 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_column_selected}_flattened" + + @observe('flux_label_label', 'dataset') + def _update_label_valid(self, event={}): + 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', []): + self.flux_label.invalid_msg = 'name already in use' else: - self.results_label_default = f"{self.dataset_selected} (flattened)" + self.flux_label.invalid_msg = '' + self.flux_label_overwrite = False @with_spinner() def flatten(self, add_data=True): @@ -129,8 +151,8 @@ def flatten(self, add_data=True): Parameters ---------- add_data : bool - Whether to add the resulting trace to the application, according to the options - defined in the plugin. + Whether to add the resulting light curve as a flux column and select that as the new + flux column (origin) for that data entry. Returns ------- @@ -157,9 +179,13 @@ def flatten(self, add_data=True): output_lc.meta['NORMALIZED'] = False if add_data: - # add data to the collection/viewer + # add data as a new flux and corresponding err columns in the existing data entry + # and select as flux column (origin) data = _data_with_reftime(self.app, output_lc) - self.add_results.add_results_from_plugin(data) + self.flux_column.add_new_flux_column(flux=data['flux'], + flux_err=data['flux_err'], + label=self.flux_label.value, + selected=True) return output_lc, trend_lc @@ -186,13 +212,16 @@ def _toggle_marks(self, event={}): # then the marks themselves need to be updated self._live_update(event) - @observe('dataset_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_column_selected == '': + self._clear_marks() + return start = time() try: @@ -232,7 +261,3 @@ def vue_apply(self, *args, **kwargs): self.flatten_err = str(e) else: self.flatten_err = '' - if self.add_results.label_overwrite: - # then this will change the input data without triggering a - # change to dataset_selected - self._live_update() diff --git a/lcviz/plugins/flatten/flatten.vue b/lcviz/plugins/flatten/flatten.vue index b0e503a9..191df121 100644 --- a/lcviz/plugins/flatten/flatten.vue +++ b/lcviz/plugins/flatten/flatten.vue @@ -33,14 +33,6 @@ persistent-hint > - - - @@ -138,6 +130,14 @@ Live preview is unnormalized, but flattening will normalize. + + Live-updating is temporarily disabled (last update took {{last_live_time}}s) @@ -156,21 +156,17 @@ - + + + + Flatten{{flux_label_overwrite ? ' (Overwrite)' : ''}} + + + diff --git a/lcviz/plugins/flux_column/__init__.py b/lcviz/plugins/flux_column/__init__.py new file mode 100644 index 00000000..d32403db --- /dev/null +++ b/lcviz/plugins/flux_column/__init__.py @@ -0,0 +1 @@ +from .flux_column import * # noqa diff --git a/lcviz/plugins/flux_column/flux_column.py b/lcviz/plugins/flux_column/flux_column.py new file mode 100644 index 00000000..5c46cf0c --- /dev/null +++ b/lcviz/plugins/flux_column/flux_column.py @@ -0,0 +1,31 @@ +from jdaviz.core.registries import tray_registry +from jdaviz.core.template_mixin import (PluginTemplateMixin, + DatasetSelectMixin) +from jdaviz.core.user_api import PluginUserApi + +from lcviz.components import FluxColumnSelectMixin + +__all__ = ['FluxColumn'] + + +@tray_registry('flux-column', label="Flux Column") +class FluxColumn(PluginTemplateMixin, FluxColumnSelectMixin, DatasetSelectMixin): + """ + See the :ref:`Flux Column Plugin Documentation ` 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_column.vue" + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + @property + def user_api(self): + expose = ['dataset', 'flux_column'] + return PluginUserApi(self, expose=expose) diff --git a/lcviz/plugins/flux_column/flux_column.vue b/lcviz/plugins/flux_column/flux_column.vue new file mode 100644 index 00000000..810dad29 --- /dev/null +++ b/lcviz/plugins/flux_column/flux_column.vue @@ -0,0 +1,31 @@ + diff --git a/lcviz/tests/test_plugin_flatten.py b/lcviz/tests/test_plugin_flatten.py index d1fdd5cd..31a8df0f 100644 --- a/lcviz/tests/test_plugin_flatten.py +++ b/lcviz/tests/test_plugin_flatten.py @@ -59,11 +59,12 @@ def test_plugin_flatten(helper, light_curve_like_kepler_quarter): after_update = marks[0].y assert not np.allclose(before_update, after_update) - orig_label = f.dataset.selected + orig_flux_column = f._obj.flux_column.selected assert f.dataset.selected_obj is not None - assert f._obj.add_results.label_overwrite is True - assert f._obj.add_results.label == orig_label + assert f._obj.flux_label_overwrite is False + assert f._obj.flux_label.value == f'{orig_flux_column}_flattened' f._obj.vue_apply(add_data=True) + assert f._obj.flux_column.selected == f'{orig_flux_column}_flattened' assert f._obj.flatten_err == '' # marks are hidden @@ -71,20 +72,6 @@ def test_plugin_flatten(helper, light_curve_like_kepler_quarter): assert len(_get_marks_from_viewer(pv)) == 0 -def test_no_overwrite(helper, light_curve_like_kepler_quarter): - helper.load_data(light_curve_like_kepler_quarter) - - f = helper.plugins['Flatten'] - - orig_label = f.dataset.selected - assert f._obj.add_results.label_overwrite is True - assert f._obj.add_results.label == orig_label - f.default_to_overwrite = False - assert f._obj.add_results.label_overwrite is False - assert f._obj.add_results.label != orig_label - f.flatten(add_data=True) - - def test_unnormalize(helper, light_curve_like_kepler_quarter): helper.load_data(light_curve_like_kepler_quarter) diff --git a/lcviz/tests/test_plugin_flux_column.py b/lcviz/tests/test_plugin_flux_column.py new file mode 100644 index 00000000..cf7fa6c4 --- /dev/null +++ b/lcviz/tests/test_plugin_flux_column.py @@ -0,0 +1,30 @@ +from numpy.testing import assert_allclose + + +def test_docs_snippets(helper, light_curve_like_kepler_quarter): + lcviz, lc = helper, light_curve_like_kepler_quarter + + lcviz.load_data(lc) + # lcviz.show() + + flux_col = lcviz.plugins['Flux Column'] + print(flux_col.flux_column.choices) + # NOTE: choices for docs example are: ['sap_flux', 'sap_bkg', 'pdcsap_flux'] + flux_col.flux_column = 'flux_alt' + + +def test_plugin_flux_column(helper, light_curve_like_kepler_quarter): + helper.load_data(light_curve_like_kepler_quarter) + + fo = helper.plugins['Flux Column'] + assert len(fo.flux_column.choices) == 2 + assert fo.flux_column.selected == 'flux:orig' + + lc = helper.get_data() + assert lc.meta.get('FLUX_ORIGIN') == 'flux:orig' + assert_allclose(lc['flux'], fo._obj.dataset.selected_dc_item['flux:orig']) + + fo.flux_column = 'flux_alt' + lc = helper.get_data() + assert lc.meta.get('FLUX_ORIGIN') == 'flux_alt' + assert_allclose(lc['flux'], fo._obj.dataset.selected_dc_item['flux_alt'])