Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Raises
------
ValueError : raised if the data product is not recognized as a Kepler or
TESS product.
Examples
--------
To open a target pixel file using its path or URL, simply use:
>>> tpf = open("mytpf.fits") # doctest: +SKIP
"""
log.debug("Opening {}.".format(path_or_url))
# pass header into `detect_filetype()`
try:
with fits.open(path_or_url) as temp:
filetype = detect_filetype(temp[0].header)
log.debug("Detected filetype: '{}'.".format(filetype))
except OSError as e:
filetype = None
# Raise an explicit FileNotFoundError if file not found
if 'No such file' in str(e):
raise e
# if the filetype is recognized, instantiate a class of that name
if filetype is not None:
return getattr(__import__('lightkurve'), filetype)(path_or_url, **kwargs)
else:
# if these keywords don't exist, raise `ValueError`
raise ValueError("Not recognized as a Kepler or TESS data product: "
"{}".format(path_or_url))
def __init__(self, path, quality_bitmask='default', **kwargs):
super(TessLightCurveFile, self).__init__(path, **kwargs)
# check to make sure the correct filetype has been provided
filetype = detect_filetype(self.header())
if filetype == 'KeplerLightCurveFile':
warnings.warn("A Kepler data product is being opened using the "
"`TessLightCurveFile` class. "
"Please use `KeplerLightCurveFile` instead.",
LightkurveWarning)
elif filetype is None:
warnings.warn("Given fits file not recognized as Kepler or TESS "
"observation.", LightkurveWarning)
elif "TargetPixelFile" in filetype:
warnings.warn("A `TargetPixelFile` object is being opened as a "
"`TessLightCurveFile`. "
"Please use `TessTargetPixelFile` instead.",
LightkurveWarning)
self.quality_bitmask = quality_bitmask
self.quality_mask = TessQualityFlags.create_quality_mask(
def __init__(self, path, quality_bitmask='default', **kwargs):
super(TessTargetPixelFile, self).__init__(path,
quality_bitmask=quality_bitmask,
**kwargs)
self.quality_mask = TessQualityFlags.create_quality_mask(
quality_array=self.hdu[1].data['QUALITY'],
bitmask=quality_bitmask)
# Early TESS releases had cadences with time=NaN (i.e. missing data)
# which were not flagged by a QUALITY flag yet; the line below prevents
# these cadences from being used. They would break most methods!
if (quality_bitmask != 0) and (quality_bitmask != 'none'):
self.quality_mask &= np.isfinite(self.hdu[1].data['TIME'])
# check to make sure the correct filetype has been provided
filetype = detect_filetype(self.header)
if filetype == 'KeplerTargetPixelFile':
warnings.warn("A Kepler data product is being opened using the "
"`TessTargetPixelFile` class. "
"Please use `KeplerTargetPixelFile` instead.",
LightkurveWarning)
elif filetype is None:
warnings.warn("File header not recognized as Kepler or TESS "
"observation.", LightkurveWarning)
# Use the TICID keyword as the default targetid
if self.targetid is None:
try:
self.targetid = self.header['TICID']
except KeyError:
pass