Skip to content

Commit

Permalink
prevent duplicate sub-interval data labels
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorris3 committed Jun 18, 2024
1 parent fcf0785 commit db6f2db
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lcviz/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def light_curve_like_kepler_quarter(seed=42):
)
lc['flux_alt'] = flux + 1
lc['flux_alt_err'] = flux_err
lc.meta['MISSION'] = 'KEPLER'
lc.meta['QUARTER'] = 10

return lc


Expand Down
23 changes: 17 additions & 6 deletions lcviz/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

__all__ = ["light_curve_parser"]

mission_sub_intervals = {
'kepler': {'prefix': 'Q', 'card': 'QUARTER'},
'k2': {'prefix': 'C', 'card': 'CAMPAIGN'},
'tess': {'prefix': 'S', 'card': 'SECTOR'},
}


@data_parser_registry("light_curve_parser")
def light_curve_parser(app, file_obj, data_label=None, show_in_viewer=True, **kwargs):
Expand Down Expand Up @@ -40,14 +46,19 @@ def light_curve_parser(app, file_obj, data_label=None, show_in_viewer=True, **kw
# handle flux_origin default
mission = light_curve.meta.get('MISSION', '').lower()
flux_origin = light_curve.meta.get('FLUX_ORIGIN', None) # i.e. PDCSAP or SAP

if isinstance(light_curve, lightkurve.targetpixelfile.TargetPixelFile):
new_data_label += '[TPF]'
elif mission == 'kepler':
new_data_label += f' Q{light_curve.meta.get("QUARTER")}'
elif mission == 'k2':
new_data_label += f' C{light_curve.meta.get("CAMPAIGN")}'
elif mission == 'tess':
new_data_label += f' S{light_curve.meta.get("SECTOR")}'
elif mission in mission_sub_intervals:
# the sub-interval label is something like "Q9" for Kepler or
# "S9" for TESS. If it's already in the proposed data label, skip;
# otherwise, append it.
sub_interval_label = (
f'{mission_sub_intervals[mission]["prefix"]}'
f'{light_curve.meta.get(mission_sub_intervals[mission]["card"])}'
)
if sub_interval_label not in new_data_label:
new_data_label += f' [{sub_interval_label}]'

if flux_origin == 'flux' or (flux_origin is None and 'flux' in getattr(light_curve, 'columns', [])): # noqa
# then make a copy of this column so it won't be lost when changing with the flux_column
Expand Down
11 changes: 11 additions & 0 deletions lcviz/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,14 @@ def test_apply_yrangerois(helper, light_curve_like_kepler_quarter):
subset_state = subsets['Subset 1'][0]['subset_state']

np.testing.assert_allclose([subset_state.lo, subset_state.hi], [1, 1.05])


def test_data_label(helper, light_curve_like_kepler_quarter):
# add data without specifying data label:
helper.load_data(light_curve_like_kepler_quarter)
assert helper.app.data_collection[-1].label == 'Light curve [Q10]'

# specify label with a quarter, check that quarter isn't appended:
data_label = 'Cool target in Q10'
helper.load_data(light_curve_like_kepler_quarter, data_label=data_label)
assert helper.app.data_collection[-1].label == data_label

0 comments on commit db6f2db

Please sign in to comment.