-
Notifications
You must be signed in to change notification settings - Fork 158
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
Added in a flux_err mask to remove NaNa and fix Issue 1114 #1327
base: main
Are you sure you want to change the base?
Conversation
fixes #1114 |
Notes from our Lightkurve Party Discussion: (CH: Ignore below:)
|
The only HLSP products that would qualify for PLD correction would be TICA cut outs and TESS-SPOC products. TESS-SPOC products work fine with the PR code. TICA products do not work because they have zeros for the flux_err values. The failure occurs at this point and not because of the added PR code. The error produced is
Following code i have used is
However, while this works on the lc it does not work on the tpf. For the tpf it takes a very long time to process and a warning is returned.
|
|
Test to check that a TPF with all NaN values for flux_err will fail the PR code. import lightkurve as lk
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams.update({'font.size': 15})
%matplotlib inline
from lightkurve.correctors import PLDCorrector
from lightkurve import TessTargetPixelFile as TPF
from astropy.io import fits
s=lk.search_targetpixelfile("KT Eri")
tpf = s[0].download()
fname = tpf.path
a = np.empty((112388,11,11))
a[:] = np.nan
with fits.open(fname, mode='update') as hdulist:
hdulist[1].data['FLUX_ERR'] = a
print(hdulist[1].data['FLUX_ERR'].size)
hdulist.close()
tpf = lk.read(fname)
pld = PLDCorrector(tpf)
corrected_lc = pld.correct() This results in the following error and as such the corrector fails because the NaN mask effectively wipes out the entire data set. ---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[23], line 1
----> 1 corrected_lc = pld.correct()
File ~/miniforge3/lib/python3.10/site-packages/astropy/utils/decorators.py:546, in deprecated_renamed_argument.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
543 msg += f'\n Use {alternative} instead.'
544 warnings.warn(msg, warning_type, stacklevel=2)
--> 546 return function(*args, **kwargs)
File ~/miniforge3/lib/python3.10/site-packages/astropy/utils/decorators.py:546, in deprecated_renamed_argument.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
543 msg += f'\n Use {alternative} instead.'
544 warnings.warn(msg, warning_type, stacklevel=2)
--> 546 return function(*args, **kwargs)
[... skipping similar frames: deprecated_renamed_argument.<locals>.decorator.<locals>.wrapper at line 546 (1 times)]
File ~/miniforge3/lib/python3.10/site-packages/astropy/utils/decorators.py:546, in deprecated_renamed_argument.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
543 msg += f'\n Use {alternative} instead.'
544 warnings.warn(msg, warning_type, stacklevel=2)
--> 546 return function(*args, **kwargs)
File ~/miniforge3/lib/python3.10/site-packages/lightkurve/correctors/pldcorrector.py:405, in PLDCorrector.correct(self, pld_order, pca_components, pld_aperture_mask, background_aperture_mask, spline_n_knots, spline_degree, normalize_background_pixels, restore_trend, sparse, cadence_mask, sigma, niters, propagate_errors, use_gp, gp_timescale, aperture_mask)
402 else:
403 normalize_background_pixels = False
--> 405 dm = self.create_design_matrix(
406 pld_aperture_mask=pld_aperture_mask,
407 background_aperture_mask=background_aperture_mask,
408 pld_order=pld_order,
409 pca_components=pca_components,
410 spline_n_knots=spline_n_knots,
411 spline_degree=spline_degree,
412 normalize_background_pixels=normalize_background_pixels,
413 sparse=sparse,
414 )
416 clc = super().correct(
417 dm,
418 cadence_mask=cadence_mask,
(...)
421 propagate_errors=propagate_errors,
422 )
423 if restore_trend:
File ~/miniforge3/lib/python3.10/site-packages/lightkurve/correctors/pldcorrector.py:206, in PLDCorrector.create_design_matrix(self, pld_order, pca_components, pld_aperture_mask, background_aperture_mask, spline_n_knots, spline_degree, normalize_background_pixels, sparse)
203 prior_sigma = np.nanstd(self.lc.flux.value) * 10
205 # Flux normalize background components for K2 and not for TESS by default
--> 206 bkg_pixels = self.tpf.flux[:, background_aperture_mask].reshape(
207 len(self.tpf.flux), -1
208 )
209 if normalize_background_pixels:
210 bkg_flux = np.nansum(self.tpf.flux[:, background_aperture_mask], -1)
ValueError: cannot reshape array of size 0 into shape (0,newaxis) |
New tests have been added to check that
The second test was based on the original file noted by the user which now seems to run without issue. |
I have added in a NaN mask for flux_err and combined with the flux mask such that the PLD corrector can function.