Skip to content

Commit

Permalink
Adding TPF translator and parser (#75)
Browse files Browse the repository at this point in the history
* adding Kepler TPF parser
* adding TPF translator to the parser
* adding kepler and tess specific TPF translators
* remote data test via searchtargetpixelfile

---------

Co-authored-by: Kyle Conroy <[email protected]>
  • Loading branch information
bmorris3 and kecnry authored Jan 23, 2024
1 parent 8f5d02e commit 8c680ca
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 15 deletions.
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

0 comments on commit 8c680ca

Please sign in to comment.