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/parsers.py b/lcviz/parsers.py index 637e0cd5..c7d20dea 100644 --- a/lcviz/parsers.py +++ b/lcviz/parsers.py @@ -30,7 +30,7 @@ def light_curve_parser(app, file_obj, data_label=None, show_in_viewer=True, **kw # handle flux_origin default flux_origin = light_curve.meta.get('FLUX_ORIGIN', None) # i.e. PDCSAP or SAP - if flux_origin == 'flux': + 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'] diff --git a/lcviz/plugins/flux_origin/flux_origin.py b/lcviz/plugins/flux_origin/flux_origin.py index 65c1f557..d1781d8d 100644 --- a/lcviz/plugins/flux_origin/flux_origin.py +++ b/lcviz/plugins/flux_origin/flux_origin.py @@ -61,6 +61,8 @@ def _include_col(lk_obj, col): return lk_obj[col].unit == lk_obj['flux'].unit lk_obj = self.dataset.selected_obj + if lk_obj is None: + return self.origin.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.origin.choices: diff --git a/lcviz/tests/test_plugin_flux_origin.py b/lcviz/tests/test_plugin_flux_origin.py new file mode 100644 index 00000000..6cb6c6e2 --- /dev/null +++ b/lcviz/tests/test_plugin_flux_origin.py @@ -0,0 +1,18 @@ +from numpy.testing import assert_allclose + + +def test_plugin_flux_origin(helper, light_curve_like_kepler_quarter): + helper.load_data(light_curve_like_kepler_quarter) + + fo = helper.plugins['Flux Origin'] + assert len(fo.origin.choices) == 2 + assert fo.origin.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.origin = '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'])