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

Fix periodogram units and normalization #1253

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
8 changes: 4 additions & 4 deletions .github/workflows/lightkurve-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
python-version: '3.10'
pytest-command: poetry run pytest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand All @@ -63,7 +63,7 @@ jobs:
name: [3.8]
python-version: [3.8]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand All @@ -84,7 +84,7 @@ jobs:
matrix:
python-version: [3.8]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand All @@ -105,7 +105,7 @@ jobs:
matrix:
python-version: [3.8]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ developer, please open an issue!
- `Jessie Dotson <https://github.com/jessie-dotson>`_
- `Nicholas Saunders <https://github.com/nksaunders>`_
- `Michael Gully-Santiago <https://github.com/gully>`_
- `Daniel Hey <https://github.com/danielhey>`_
- `Daniel Hey <https://github.com/danhey>`_
- `Oliver Hall <https://github.com/ojhall94>`_


Expand Down
19 changes: 17 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
2.4.1dev (unreleased)
2.5.0 (unreleased)
=====================

- Fixed memory leak in reading Lightcurve / TargetPixel FITS files in v2.4.2 [#1390]
- Added support for changes in QLP High Level Science Product
in TESS sectors 56 and later. [#1392]


2.4.2 (2023-11-03)
=====================

- Fixed download issue due to MAST API change [#1380]

2.4.1 (2023-09-06)
=====================

- Updated interact features to work with JupyterHub (e.g. TiKE) [#1349]
- Exposed niters parameter in the PCA function of design matrix
- Fixed the aperture parsing functions inside TPFs to be compliant with `numpy` v1.25 [#1360]
- Made `LombScarglePeriodogram` compatible with Astropy v5.3 [#1342]
- Updated the TPF plotting function to work correctly with WCS plotting [#1298]
- Added the ability to open light curves from the TGLC High Level Science Product

2.4.0 (2023-02-14)
==================


- Added the ability to configure the default cache directory used by
``SearchResult.download()`` / ``SearchResult.download_all()``. [#1214]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
"id": "4tPVyNq4XIVl"
},
"source": [
"`search_lightcurve` returns a `SearchResult` table, which contains information about the data products available to download. This search result tells us that KIC 3733346 was observed in *Kepler* Quarters 1–16. \n",
"`search_lightcurve` returns a `SearchResult` table, which contains information about the data products available to download. This search result tells us that KIC 3733346 was observed in *Kepler* Quarters 1–17. \n",
"\n",
"You can select an individual entry in this search result by indexing the search result."
]
Expand Down
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "lightkurve"
version = "2.4.1dev"
version = "2.5.0dev"
description = "A friendly package for Kepler & TESS time series analysis in Python."
license = "MIT"
authors = ["Geert Barentsen <hello@geert.io>"]
Expand Down Expand Up @@ -79,6 +79,3 @@ testpaths = [
"tests",
"src",
]
filterwarnings = [
"error::ResourceWarning",
]
8 changes: 6 additions & 2 deletions src/lightkurve/correctors/designmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def standardize(self, inplace=False):
dm.df = new_df
return dm

def pca(self, nterms=6):
def pca(self, nterms=6, n_iter=10):
"""Returns a new `.DesignMatrix` with a smaller number of regressors.

This method will use Principal Components Analysis (PCA) to reduce
Expand All @@ -260,6 +260,10 @@ def pca(self, nterms=6):
nterms : int
Number of columns in the new matrix.

n_iter : int
Number of iterations that will be run by the power iteration
algorithm to compute the principal components.

Returns
-------
`.DesignMatrix`
Expand All @@ -274,7 +278,7 @@ def pca(self, nterms=6):
# produces more stable results.
from fbpca import pca # local import because not used elsewhere

new_values, _, _ = pca(self.values, nterms, n_iter=10)
new_values, _, _ = pca(self.values, nterms, n_iter=n_iter)
return DesignMatrix(new_values, name=self.name)

def append_constant(self, prior_mu=0, prior_sigma=np.inf, inplace=False):
Expand Down
1 change: 0 additions & 1 deletion src/lightkurve/correctors/regressioncorrector.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ def _fit_coefficients(

if prior_sigma is not None:
sigma_w_inv = sigma_w_inv + np.diag(1.0 / prior_sigma ** 2)
if prior_sigma is not None:
B = B + (prior_mu / prior_sigma ** 2)

# Solve for weights w
Expand Down
7 changes: 6 additions & 1 deletion src/lightkurve/correctors/sffcorrector.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,12 @@ def _estimate_arclength(centroid_col, centroid_row):
"""
col = centroid_col - np.nanmin(centroid_col)
row = centroid_row - np.nanmin(centroid_row)
if np.all((col == 0) & (row == 0)):
raise RuntimeError("Arclength cannot be computed because there is no "
"centroid motion. Make sure that the aperture of "
"the TPF at least two pixels.")
# Force c to be correlated not anticorrelated
if np.polyfit(col.data, row.data, 1)[0] < 0:
col = np.nanmax(col) - col
return (col ** 2 + row ** 2) ** 0.5
arclength = (col ** 2 + row ** 2) ** 0.5
return arclength
27 changes: 18 additions & 9 deletions src/lightkurve/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import pandas as pd
from pandas import Series

from .utils import KeplerQualityFlags, LightkurveWarning, LightkurveError

from .utils import KeplerQualityFlags, LightkurveWarning, LightkurveError, finalize_notebook_url

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -138,8 +139,8 @@ def _get_corrected_coordinate(tpf_or_lc):
ra_corrected, dec_corrected, pm_corrected = _correct_with_proper_motion(
ra * u.deg, dec *u.deg,
pm_ra * pm_unit, pm_dec * pm_unit,
# e.g., equinox 2000 is treated as J2000 is set to be noon of 2000-01-01 TT
Time(equinox, format="decimalyear", scale="tt") + 0.5,
# we assume the data is in J2000 epoch
Time('2000', format='byear'),
new_time)
return ra_corrected.to(u.deg).value, dec_corrected.to(u.deg).value, pm_corrected

Expand Down Expand Up @@ -460,7 +461,6 @@ def _add_nearby_tics_if_tess(tpf, magnitude_limit, result):

# nearby TICs from ExoFOP
tab = _search_nearby_of_tess_target(tic_id)

gaia_ids = result['Source'].array

# merge the TICs with matching Gaia entries
Expand Down Expand Up @@ -536,7 +536,7 @@ def add_gaia_figure_elements(tpf, fig, magnitude_limit=18):
"""Make the Gaia Figure Elements"""

result = _get_nearby_gaia_objects(tpf, magnitude_limit)

source_colnames_extras = []
tooltips_extras = []
try:
Expand All @@ -555,7 +555,6 @@ def add_gaia_figure_elements(tpf, fig, magnitude_limit=18):
tpf.time[0])
result.RA_ICRS = ra_corrected.to(u.deg).value
result.DE_ICRS = dec_corrected.to(u.deg).value

# Convert to pixel coordinates
radecs = np.vstack([result["RA_ICRS"], result["DE_ICRS"]]).T
coords = tpf.wcs.all_world2pix(radecs, 0)
Expand Down Expand Up @@ -978,7 +977,7 @@ def make_default_export_name(tpf, suffix="custom-lc"):

def show_interact_widget(
tpf,
notebook_url="localhost:8888",
notebook_url=None,
lc=None,
max_cadences=200000,
aperture_mask="default",
Expand Down Expand Up @@ -1013,6 +1012,9 @@ def show_interact_widget(
will need to supply this value for the application to display
properly. If no protocol is supplied in the URL, e.g. if it is
of the form "localhost:8888", then "http" will be used.
For use with JupyterHub, set the environment variable LK_JUPYTERHUB_EXTERNAL_URL
to the public hostname of your JupyterHub and notebook_url will
be defined appropriately automatically.
max_cadences: int
Raise a RuntimeError if the number of cadences shown is larger than
this value. This limit helps keep browsers from becoming unresponsive.
Expand Down Expand Up @@ -1065,6 +1067,8 @@ def show_interact_widget(
)
return None

notebook_url = finalize_notebook_url(notebook_url)

aperture_mask = tpf._parse_aperture_mask(aperture_mask)
if ~aperture_mask.any():
log.error(
Expand Down Expand Up @@ -1297,7 +1301,8 @@ def jump_to_lightcurve_position(attr, old, new):
return show(create_interact_ui, notebook_url=notebook_url)


def show_skyview_widget(tpf, notebook_url="localhost:8888", aperture_mask="empty", magnitude_limit=18):

def show_skyview_widget(tpf, notebook_url=None, aperture_mask="empty", magnitude_limit=18):
"""skyview

Parameters
Expand All @@ -1313,6 +1318,9 @@ def show_skyview_widget(tpf, notebook_url="localhost:8888", aperture_mask="empty
will need to supply this value for the application to display
properly. If no protocol is supplied in the URL, e.g. if it is
of the form "localhost:8888", then "http" will be used.
For use with JupyterHub, set the environment variable LK_JUPYTERHUB_EXTERNAL_URL
to the public hostname of your JupyterHub and notebook_url will
be defined appropriately automatically.
aperture_mask : array-like, 'pipeline', 'threshold', 'default', 'background', or 'empty'
Highlight pixels selected by aperture_mask.
Default is 'empty': no pixel is highlighted.
Expand All @@ -1333,6 +1341,8 @@ def show_skyview_widget(tpf, notebook_url="localhost:8888", aperture_mask="empty
)
return None

notebook_url = finalize_notebook_url(notebook_url)

# Try to identify the "fiducial frame", for which the TPF WCS is exact
zp = (tpf.pos_corr1 == 0) & (tpf.pos_corr2 == 0)
(zp_loc,) = np.where(zp)
Expand All @@ -1343,7 +1353,6 @@ def show_skyview_widget(tpf, notebook_url="localhost:8888", aperture_mask="empty
fiducial_frame = 0

aperture_mask = tpf._parse_aperture_mask(aperture_mask)

def create_interact_ui(doc):
tpf_source = prepare_tpf_datasource(tpf, aperture_mask)

Expand Down
8 changes: 6 additions & 2 deletions src/lightkurve/interact_bls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from astropy.timeseries import BoxLeastSquares
import astropy.units as u

from .utils import LightkurveWarning
from .utils import LightkurveWarning, finalize_notebook_url

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -598,7 +598,7 @@ def _preprocess_lc_for_bls(lc):

def show_interact_widget(
lc,
notebook_url="localhost:8888",
notebook_url=None,
minimum_period=None,
maximum_period=None,
resolution=2000,
Expand All @@ -616,6 +616,9 @@ def show_interact_widget(
will need to supply this value for the application to display
properly. If no protocol is supplied in the URL, e.g. if it is
of the form "localhost:8888", then "http" will be used.
For use with JupyterHub, set the environment variable LK_JUPYTERHUB_EXTERNAL_URL
to the public hostname of your JupyterHub and notebook_url will
be defined appropriately automatically.
minimum_period : float or None
Minimum period to assess the BLS to. If None, default value of 0.3 days
will be used.
Expand Down Expand Up @@ -1001,4 +1004,5 @@ def _update_bls_plot_help(attr, old, new):
lc = _preprocess_lc_for_bls(lc)

output_notebook(verbose=False, hide_banner=True)
notebook_url = finalize_notebook_url(notebook_url)
return show(_create_interact_ui, notebook_url=notebook_url)
6 changes: 4 additions & 2 deletions src/lightkurve/io/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ def detect_filetype(hdulist: HDUList) -> str:

# Is it a K2VARCAT file?
# There are no self-identifying keywords in the header, so go by filename.
if "hlsp_k2varcat" in (hdulist.filename() or ""):
return "K2VARCAT"
fname = hdulist.filename() if callable(hdulist.filename) else hdulist.filename
if fname is not None:
if "hlsp_k2varcat" in fname:
return "K2VARCAT"

# Is it a K2SC file?
if "k2sc" in hdulist[0].header.get("creator", "").lower():
Expand Down