-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add parser for TESS DVT files #164
Changes from all commits
4356aa5
ae43506
d03863c
81a1ebf
acc8bdf
577b84e
9ebdd19
0c0b470
2dad851
6522156
10999ce
ef0835a
febc67b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,7 +1,11 @@ | ||||||
import os | ||||||
|
||||||
from astropy.io import fits | ||||||
from astropy.table import Table | ||||||
from glue.config import data_translator | ||||||
from jdaviz.core.registries import data_parser_registry | ||||||
import lightkurve | ||||||
import numpy as np | ||||||
|
||||||
from lcviz.viewers import PhaseScatterView, TimeScatterView | ||||||
from lcviz.plugins.plot_options import PlotOptions | ||||||
|
@@ -12,9 +16,55 @@ | |||||
'kepler': {'prefix': 'Q', 'card': 'QUARTER'}, | ||||||
'k2': {'prefix': 'C', 'card': 'CAMPAIGN'}, | ||||||
'tess': {'prefix': 'S', 'card': 'SECTOR'}, | ||||||
'tess dvt': {'prefix': '', 'card': 'EXTNAME'} | ||||||
} | ||||||
|
||||||
|
||||||
@data_parser_registry("tess_dvt_parser") | ||||||
def tess_dvt_parser(app, file_obj, data_label=None, show_in_viewer=True, **kwargs): | ||||||
''' | ||||||
Read a TESS DVT file and create a lightkurve object | ||||||
''' | ||||||
hdulist = fits.open(file_obj) | ||||||
ephem_plugin = app._jdaviz_helper.plugins.get('Ephemeris', None) | ||||||
extname = kwargs.pop('extname') | ||||||
|
||||||
# Loop through the TCEs in the file. If we only want one (specified by | ||||||
# `extname` keyword) then only load that one into the viewers and ephemeris. | ||||||
for hdu in hdulist[1:]: | ||||||
data = Table(hdu.data) | ||||||
# don't load some columns with names that may | ||||||
# conflict with components generated later by lcviz | ||||||
data.remove_column('PHASE') | ||||||
data.remove_column('CADENCENO') | ||||||
# Remove rows that have NaN data | ||||||
data = data[~np.isnan(data['LC_INIT'])] | ||||||
header = hdu.header | ||||||
time_offset = int(header['TUNIT1'] .split('- ')[1].split(',')[0]) | ||||||
data['TIME'] += time_offset | ||||||
lc = lightkurve.LightCurve(data=data, | ||||||
time=data['TIME'], | ||||||
flux=data['LC_INIT'], | ||||||
flux_err=data['LC_INIT_ERR']) | ||||||
lc.meta = hdulist[0].header | ||||||
lc.meta['MISSION'] = 'TESS DVT' | ||||||
lc.meta['FLUX_ORIGIN'] = "LC_INIT" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the (near?) future, we should either add flux column validation or work to ensure that non-standard flux columns are selectable. By default, all of the table columns will be options in the Flux Column plugin. So far, we haven't written any intentional support for plotting models, but there are pre-computed transit light curve models in the DVT files, stored under the "MODEL_INIT" and "MODEL_WHITE" columns. This causes a hiccup if you try to set "MODEL_WHITE" as the flux column, since we look for a corresponding lcviz/lcviz/components/components.py Lines 224 to 225 in 0f18bec
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 Down the road, it'll be great to change the plot options defaults for "MODEL_*" columns. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I fixed this in |
||||||
lc.meta['EXTNAME'] = header['EXTNAME'] | ||||||
|
||||||
if extname is not None and header['EXTNAME'] != extname: | ||||||
show_ext_in_viewer = False | ||||||
else: | ||||||
show_ext_in_viewer = show_in_viewer | ||||||
|
||||||
light_curve_parser(app, lc, data_label=data_label, | ||||||
show_in_viewer=show_ext_in_viewer, **kwargs) | ||||||
|
||||||
# add ephemeris information from the DVT extension | ||||||
if ephem_plugin is not None and show_ext_in_viewer: | ||||||
ephem_plugin.period = header['TPERIOD'] | ||||||
ephem_plugin.t0 = header['TEPOCH'] + time_offset - app.data_collection[0].coords.reference_time.jd # noqa | ||||||
|
||||||
|
||||||
@data_parser_registry("light_curve_parser") | ||||||
def light_curve_parser(app, file_obj, data_label=None, show_in_viewer=True, **kwargs): | ||||||
# load a LightCurve or TargetPixelFile object: | ||||||
|
@@ -29,7 +79,6 @@ | |||||
if data_label is None: | ||||||
data_label = os.path.splitext(os.path.basename(file_obj))[0] | ||||||
|
||||||
# read the light curve: | ||||||
light_curve = lightkurve.read(file_obj) | ||||||
|
||||||
elif isinstance(file_obj, cls_with_translator): | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be just as easy to support HDUList too, which would be helpful for writing tests and for files we make/edit on the fly. Can we add that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but handling HDULists in general is probably a separate ticket/PR.