Skip to content

Commit

Permalink
improve ephemeris test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Aug 23, 2023
1 parent 17f1c61 commit 0d2cd06
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lcviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _get_range_subset_bounds(self, subset_state, *args, **kwargs):
# TODO: use display units once implemented in Glue for ScatterViewer
# units = u.Unit(viewer.state.x_display_unit)
units = u.Unit(viewer.time_unit)
else:
else: # pragma: no cover
raise ValueError("Unable to find time axis units")

region = reference_time + u.Quantity([subset_state.lo * units, subset_state.hi * units])
Expand Down
6 changes: 3 additions & 3 deletions lcviz/plugins/ephemeris/ephemeris.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def _on_component_remove(self, lbl):
_ = self._ephemerides.pop(lbl, {})
# remove the corresponding viewer, if it exists
viewer_item = self.app._viewer_item_by_id(self._phase_viewer_id(lbl))
if viewer_item is None:
if viewer_item is None: # pragma: no cover
return
cid = viewer_item.get('id', None)
if cid is not None:
Expand Down Expand Up @@ -346,7 +346,7 @@ def update_ephemeris(self, component=None, t0=None, period=None, dpdt=None):
if component is None:
component = self.component_selected

if component not in self.component.choices:
if component not in self.component.choices: # pragma: no cover
raise ValueError(f"component must be one of {self.component.choices}")

existing_ephem = self._ephemerides.get(component, {})
Expand Down Expand Up @@ -411,7 +411,7 @@ def _update_periodogram(self, *args):
self.method_spinner = False
self.method_err = str(err)
return
else:
else: # pragma: no cover
self.method_spinner = False
raise NotImplementedError(f"periodogram not implemented for {self.method}")

Expand Down
16 changes: 16 additions & 0 deletions lcviz/tests/test_plugin_ephemeris.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ def test_plugin_ephemeris(helper, light_curve_like_kepler_quarter):
assert 'renamed custom component' in ephem.ephemerides
assert len(helper.app.get_viewer_ids()) == 3

assert ephem.component == 'renamed custom component'
assert ephem.period == 3.14
assert ephem.ephemeris['period'] == 3.14
# modify the ephemeris of the NON-selected ephemeris component
ephem.update_ephemeris(component='default', period=2)
assert ephem.period == 3.14
assert ephem.ephemerides['default']['period'] == 2

ephem.remove_component('renamed custom component')
assert len(ephem.ephemerides) == 1
assert len(helper.app.get_viewer_ids()) == 2
assert ephem.component == 'default'
assert ephem.period == 2

assert ephem.method.selected == 'Lomb-Scargle'
ephem.method = 'Box Least Squares'
assert ephem._obj.method_err == ''
ephem._obj.vue_adopt_period_at_max_power()
assert ephem.period != 2
6 changes: 3 additions & 3 deletions lcviz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TimeCoordinates(Coordinates):
"""

def __init__(self, times, reference_time=None, unit=u.d):
if not isinstance(times, Time):
if not isinstance(times, Time): # pragma: no cover
raise TypeError('values should be a Time instance')
self._index = np.arange(len(times))
self._times = times
Expand All @@ -44,15 +44,15 @@ def time_axis(self):
return self._times

def world_to_pixel_values(self, *world):
if len(world) > 1:
if len(world) > 1: # pragma: no cover
raise ValueError('TimeCoordinates is a 1-d coordinate class '
'and only accepts a single scalar or array to convert')
return interp1d(
self._values.value, self._index, fill_value='extrapolate'
)(world[0])

def pixel_to_world_values(self, *pixel):
if len(pixel) > 1:
if len(pixel) > 1: # pragma: no cover
raise ValueError('SpectralCoordinates is a 1-d coordinate class '
'and only accepts a single scalar or array to convert')
return interp1d(
Expand Down

0 comments on commit 0d2cd06

Please sign in to comment.