Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding TPF translator and parser #75

Merged
merged 6 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lcviz/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
def light_curve_parser(app, file_obj, data_label=None, show_in_viewer=True, **kwargs):
time_viewer_reference_name = app._jdaviz_helper._default_time_viewer_reference_name

# load a LightCurve or TargetPixelFile object:
cls_with_translator = (
lightkurve.LightCurve,
lightkurve.targetpixelfile.KeplerTargetPixelFile,
lightkurve.targetpixelfile.TessTargetPixelFile
)

# load local FITS file from disk by its path:
if isinstance(file_obj, str) and os.path.exists(file_obj):
if data_label is None:
Expand All @@ -18,8 +25,7 @@ def light_curve_parser(app, file_obj, data_label=None, show_in_viewer=True, **kw
# read the light curve:
light_curve = lightkurve.read(file_obj)

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

# make a data label:
Expand All @@ -30,7 +36,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' or (flux_origin is None and 'flux' in light_curve.columns):
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
# plugin
light_curve['flux:orig'] = light_curve['flux']
Expand Down
13 changes: 12 additions & 1 deletion lcviz/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from glue.core.roi import XRangeROI, YRangeROI
from astropy.time import Time
from astropy.utils.data import download_file
from lightkurve import LightCurve
from lightkurve import LightCurve, KeplerTargetPixelFile, search_targetpixelfile
from lightkurve.io import kepler
import astropy.units as u

Expand Down Expand Up @@ -50,6 +50,17 @@ def test_kepler_via_mast_preparsed(helper):
assert flux.unit.is_equivalent(u.electron / u.s)


@pytest.mark.remote_data
def test_kepler_tpf_via_lightkurve(helper):
tpf = search_targetpixelfile("KIC 001429092",
mission="Kepler",
cadence="long",
quarter=10).download()
helper.load_data(tpf)
assert helper.get_data().shape == (4447, 4, 6) # (time, x, y)
assert helper.app.data_collection[0].get_object(cls=KeplerTargetPixelFile).shape == (4447, 4, 6)


def test_synthetic_lc(helper):
time = Time(np.linspace(2460050, 2460060), format='jd')
flux = np.ones(len(time)) * u.electron / u.s
Expand Down
Loading