Skip to content

Commit

Permalink
adding TPF translator to the parser
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorris3 committed Dec 20, 2023
1 parent 8414500 commit 429888e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
4 changes: 4 additions & 0 deletions lcviz/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def light_curve_parser(app, file_obj, data_label=None, show_in_viewer=True, **kw
elif isinstance(file_obj, lightkurve.LightCurve):
light_curve = file_obj

# load a LightCurve object:
elif isinstance(file_obj, lightkurve.targetpixelfile.KeplerTargetPixelFile):
light_curve = file_obj

Check warning on line 27 in lcviz/parsers.py

View check run for this annotation

Codecov / codecov/patch

lcviz/parsers.py#L26-L27

Added lines #L26 - L27 were not covered by tests

# make a data label:
if data_label is not None:
new_data_label = f'{data_label}'
Expand Down
37 changes: 22 additions & 15 deletions lcviz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
__all__ = ['TimeCoordinates', 'LightCurveHandler', 'data_not_folded', 'enable_hot_reloading']


component_ids = {'dt': ComponentID('dt')}


class TimeCoordinates(Coordinates):
"""
This is a sub-class of Coordinates that is intended for a time axis
Expand Down Expand Up @@ -73,12 +76,18 @@ class PaddedTimeWCS(BaseWCSWrapper, HighLevelWCSMixin):

# NOTE: This class could be updated to use CompoundLowLevelWCS from NDCube.

def __init__(self, wcs, times, ndim=3, reference_time=None):
self.temporal_wcs = TimeCoordinates(times, reference_time=reference_time)
def __init__(self, wcs, times, ndim=3, reference_time=None, unit=u.d):
self.temporal_wcs = TimeCoordinates(

Check warning on line 80 in lcviz/utils.py

View check run for this annotation

Codecov / codecov/patch

lcviz/utils.py#L80

Added line #L80 was not covered by tests
times, reference_time=reference_time, unit=unit
)
self.spatial_wcs = wcs
self.flux_ndim = ndim
self.spatial_keys = [f"spatial{i}" for i in range(0, self.flux_ndim-1)]

Check warning on line 85 in lcviz/utils.py

View check run for this annotation

Codecov / codecov/patch

lcviz/utils.py#L83-L85

Added lines #L83 - L85 were not covered by tests

@property
def time_axis(self):
return self.temporal_wcs.time_axis

Check warning on line 89 in lcviz/utils.py

View check run for this annotation

Codecov / codecov/patch

lcviz/utils.py#L89

Added line #L89 was not covered by tests

@property
def pixel_n_dim(self):
return self.flux_ndim

Check warning on line 93 in lcviz/utils.py

View check run for this annotation

Codecov / codecov/patch

lcviz/utils.py#L93

Added line #L93 was not covered by tests
Expand Down Expand Up @@ -158,7 +167,6 @@ def serialized_classes(self):

@data_translator(LightCurve)
class LightCurveHandler:
lc_component_ids = {}

def to_data(self, obj, reference_time=None):
is_folded = isinstance(obj, FoldedLightCurve)
Expand All @@ -173,7 +181,7 @@ def to_data(self, obj, reference_time=None):
data.meta.update(
{"reference_time": time_coord.reference_time}
)
data['dt'] = (obj.time - time_coord.reference_time).to(time_coord.unit)
data[component_ids['dt']] = (obj.time - time_coord.reference_time).to(time_coord.unit)
data.get_component('dt').units = str(time_coord.unit)

# LightCurve is a subclass of astropy TimeSeries, so
Expand All @@ -187,9 +195,9 @@ def to_data(self, obj, reference_time=None):
continue
component_label = f'phase:{ephem_comp}'

if component_label not in self.lc_component_ids:
self.lc_component_ids[component_label] = ComponentID(component_label)
cid = self.lc_component_ids[component_label]
if component_label not in component_ids:
component_ids[component_label] = ComponentID(component_label)
cid = component_ids[component_label]

data[cid] = component_data
if hasattr(component_data, 'unit'):
Expand Down Expand Up @@ -281,7 +289,6 @@ def to_object(self, data_or_subset):

@data_translator(KeplerTargetPixelFile)
class KeplerTPFHandler:
lc_component_ids = {}
tpf_attrs = ['flux', 'flux_bkg', 'flux_bkg_err', 'flux_err']
meta_attrs = [
'cadenceno',
Expand All @@ -306,8 +313,8 @@ class KeplerTPFHandler:
'wcs'
]

def to_data(self, obj, reference_time=None):
coords = PaddedTimeWCS(obj.wcs, obj.time, reference_time=reference_time)
def to_data(self, obj, reference_time=None, unit=u.d):
coords = PaddedTimeWCS(obj.wcs, obj.time, reference_time=reference_time, unit=unit)
data = Data(coords=coords)

Check warning on line 318 in lcviz/utils.py

View check run for this annotation

Codecov / codecov/patch

lcviz/utils.py#L317-L318

Added lines #L317 - L318 were not covered by tests

flux_shape = obj.flux.shape

Check warning on line 320 in lcviz/utils.py

View check run for this annotation

Codecov / codecov/patch

lcviz/utils.py#L320

Added line #L320 was not covered by tests
Expand All @@ -320,7 +327,7 @@ def to_data(self, obj, reference_time=None):
{"reference_time": coords.temporal_wcs.reference_time}
)

data['dt'] = np.broadcast_to(
data[component_ids['dt']] = np.broadcast_to(

Check warning on line 330 in lcviz/utils.py

View check run for this annotation

Codecov / codecov/patch

lcviz/utils.py#L330

Added line #L330 was not covered by tests
(
obj.time - coords.temporal_wcs.reference_time
).to(coords.temporal_wcs.unit)[:, None, None], flux_shape
Expand All @@ -332,9 +339,9 @@ def to_data(self, obj, reference_time=None):
for component_label in self.tpf_attrs:

Check warning on line 339 in lcviz/utils.py

View check run for this annotation

Codecov / codecov/patch

lcviz/utils.py#L339

Added line #L339 was not covered by tests

component_data = getattr(obj, component_label)
if component_label not in self.lc_component_ids:
self.lc_component_ids[component_label] = ComponentID(component_label)
cid = self.lc_component_ids[component_label]
if component_label not in component_ids:
component_ids[component_label] = ComponentID(component_label)
cid = component_ids[component_label]

Check warning on line 344 in lcviz/utils.py

View check run for this annotation

Codecov / codecov/patch

lcviz/utils.py#L341-L344

Added lines #L341 - L344 were not covered by tests

data[cid] = component_data
if hasattr(component_data, 'unit'):
Expand Down Expand Up @@ -389,7 +396,7 @@ def to_object(self, data_or_subset):
meta.pop(attr)

Check warning on line 396 in lcviz/utils.py

View check run for this annotation

Codecov / codecov/patch

lcviz/utils.py#L396

Added line #L396 was not covered by tests

# extract a Time object out of the TimeCoordinates object:
time = data.coords.temporal_wcs.time_axis
time = data.coords.time_axis

Check warning on line 399 in lcviz/utils.py

View check run for this annotation

Codecov / codecov/patch

lcviz/utils.py#L399

Added line #L399 was not covered by tests

if subset_state is None:

Check warning on line 401 in lcviz/utils.py

View check run for this annotation

Codecov / codecov/patch

lcviz/utils.py#L401

Added line #L401 was not covered by tests
# pass through mask of all True's if no glue subset is chosen
Expand Down
2 changes: 1 addition & 1 deletion lcviz/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def set_plot_axes(self):
self._set_plot_y_axes(dc, component_labels, light_curve)

def _set_plot_x_axes(self, dc, component_labels, light_curve):
self.state.x_att = dc[0].components[component_labels.index('World 0')]
self.state.x_att = dc[0].components[component_labels.index('dt')]

x_unit = self.time_unit
reference_time = light_curve.meta.get('reference_time', None)
Expand Down

0 comments on commit 429888e

Please sign in to comment.