diff --git a/CHANGES.rst b/CHANGES.rst index 7eb1aa8..2669b83 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -12,6 +12,8 @@ * Raise error when parser can't identify file_obj [#106] +* Fixes compatibility with glue >= 1.19. [#109, #110] + 0.3.0 (04-05-2024) -------------------- diff --git a/lcviz/helper.py b/lcviz/helper.py index 79f9c25..e9207c2 100644 --- a/lcviz/helper.py +++ b/lcviz/helper.py @@ -4,13 +4,31 @@ from lightkurve import LightCurve +from glue.config import settings as glue_settings from glue.core.component_id import ComponentID from glue.core.link_helpers import LinkSame +from glue.core.units import unit_converter from jdaviz.core.helpers import ConfigHelper from lcviz.viewers import TimeScatterView __all__ = ['LCviz'] + +@unit_converter('custom-lcviz') +class UnitConverter: + def equivalent_units(self, data, cid, units): + return set(list(map(str, u.Unit(units).find_equivalent_units(include_prefix_units=True)))) + + def to_unit(self, data, cid, values, original_units, target_units): + # for some reason, glue is trying to request a change for cid='flux' from d to electron / s + if target_units not in self.equivalent_units(data, cid, original_units): + raise ValueError(f"to_unit cannot convert units, cid={cid}, original_units={original_units}, target_units={target_units}, values={values}") # noqa + return values + return (values * u.Unit(original_units)).to_value(u.Unit(target_units)) + + +glue_settings.UNIT_CONVERTER = 'custom-lcviz' + custom_components = {'plugin-ephemeris-select': 'components/plugin_ephemeris_select.vue'} # Register pure vue component. This allows us to do recursive component instantiation only in the diff --git a/pyproject.toml b/pyproject.toml index 225c740..a974fdc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,6 @@ classifiers = [ ] dependencies = [ "astropy>=5.2", - "glue-core<1.19.0", # NOTE: if/when we stop pinning a minor version of jdaviz, add jdaviz # to devdeps in tox.ini "jdaviz==3.9.*",