Localize¶
Bases: object
__init__(time, flux, flux_err, tces, id, ra_targ, dec_targ, wcs, epoch, mission=None, ra_bonus=None, dec_bonus=None, prf=None, headers=None, **mission_keywords)
¶
Initialize the Localize object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
ndarray
|
1D array of time values in BJD. |
required |
flux
|
ndarray
|
3D flux cube with shape (n_time, n_rows, n_cols). |
required |
flux_err
|
ndarray
|
3D array of per-pixel uncertainties matching |
required |
tces
|
DataFrame
|
DataFrame containing Threshold Crossing Event (TCE) information.
Must contain the columns |
required |
id
|
str
|
Target identifier. Do not include the mission prefix (TIC/KIC/etc.). |
required |
ra_targ
|
float
|
J2000 right ascension of the target, in degrees. |
required |
dec_targ
|
float
|
J2000 declination of the target, in degrees. |
required |
wcs
|
WCS
|
WCS solution for pixel-to-sky transformations. |
required |
epoch
|
Time
|
Epoch of the input coordinates. |
required |
mission
|
str
|
Mission name (e.g., 'kepler', 'tess'). |
None
|
ra_bonus
|
float
|
J2000 right ascension of a source different from the nominal mission target, in degrees. |
None
|
dec_bonus
|
float
|
J2000 declination of a source different from the nominal mission target, in degrees. |
None
|
prf
|
object
|
Precomputed PRF model. |
None
|
headers
|
list of astropy.io.fits.Header
|
FITS headers from the original FITS file. Each entry corresponds to the header of a single HDU. |
None
|
**mission_keywords
|
Additional mission-specific keyword arguments stored directly in the instance dictionary. Common entries include sector/quarter, channel, CCD, camera, and other instrument metadata required for PRF evaluation. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TypeError
|
If |
from_tpf_info(filename, tces, id, mission, ra_bonus=None, dec_bonus=None)
staticmethod
¶
Create a Localize object from a Kepler or TESS Target Pixel File (TPF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Path to the TPF FITS file. |
required |
tces
|
DataFrame
|
DataFrame containing Threshold Crossing Event (TCE) information associated with the target. |
required |
id
|
str
|
Identifier for the target. |
required |
mission
|
str
|
Name of the mission ('kepler' or 'tess'). |
required |
ra_bonus
|
float
|
J2000 right ascension of a source different from the nominal mission target, in degrees. |
None
|
dec_bonus
|
float
|
J2000 declination of a source different from the nominal mission target, in degrees. |
None
|
Returns:
| Type | Description |
|---|---|
Localize
|
Initialized Localize object containing the data and metadata extracted from the TPF. |
build_design_matrix(order=3, spacing_mult=3.0, tdur_frac=3.0, transit_method='box', batman_kws=None)
¶
Construct the full design matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order
|
int
|
Order of the spline used to model short-term variability. Default is 3. |
3
|
spacing_mult
|
float
|
Multiplier applied to the maximum transit duration to set the spline knot spacing. Default is 3.0. |
3.0
|
tdur_frac
|
float
|
Factor used to determine the width of the box-shaped transit
model. The transit mask extends to |
3.0
|
transit_method
|
str
|
Method used to generate the transit component. Options are
|
'box'
|
batman_kws
|
list of dict
|
List of dictionaries containing additional arguments passed to
the |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Attributes:
| Name | Type | Description |
|---|---|---|
valid_tces |
ndarray
|
Indices of TCEs in |
tce_mapping |
dict
|
Mapping from TCE indices in the |
design_matrix |
ndarray or None
|
Final design matrix combining transit, polynomial, and spline components. Set to None if no valid transits are found. |
solve_transit_weights()
¶
Solve for the spatial transit depth maps for all TCEs.
Attributes:
| Name | Type | Description |
|---|---|---|
self.transit_weights |
list of numpy.ndarray
|
List of 2D transit depth maps, one per TCE. |
self.transit_weights_err |
list of numpy.ndarray
|
List of 2D 1-sigma uncertainty maps corresponding to each transit depth map. |
fit_to_heatmap(model_func=None, which_tce=None, method='prf', initial_loc=None, **fit_kw)
¶
Fit a model to the per-pixel transit depth heatmap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_func
|
callable
|
Custom residual function used when |
None
|
which_tce
|
int
|
Index of the TCE to fit. For |
None
|
method
|
str
|
Fitting method. Must be |
'prf'
|
initial_loc
|
tuple of float
|
Initial guess for the centroid position as |
None
|
**fit_kw
|
Additional keyword arguments passed to the custom model. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
ModelResult or MinimizerResult
|
Full fit result object. |
fit_metrics |
dict
|
Dictionary containing the best-fit centroid position and
corresponding 1-sigma uncertainties. Keys are |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unsupported fitting method is provided, if |
KeyError
|
If |
RuntimeError
|
If an unexpected error occurs during fitting. |
get_offset(fit_metrics)
¶
Compute the centroid offset in units of sigma.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit_metrics
|
dict
|
Dictionary containing the fitted centroid positions and their
uncertainties. Must contain |
required |
Returns:
| Name | Type | Description |
|---|---|---|
nsigma |
float
|
Radial offset between the fitted centroid and the expected source position, expressed in units of the propagated positional uncertainty. |
dist |
float
|
Euclidean distance between the fitted centroid and the expected source position in pixels. |
sigma_dist |
float
|
Propagated 1-sigma uncertainty on the radial distance in pixels. |
mah_dist |
float
|
Mahalanobis distance between the fitted centroid and the expected source position. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If a required key is missing from |
plot_heatmap(metrics, which_tce, savefig=False, save_directory='.')
¶
Generate a localization report plot for a given TCE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
dict
|
Dictionary containing the fitted centroid positions and their
uncertainties. Must contain |
required |
which_tce
|
int
|
Index of the TCE in |
required |
savefig
|
bool
|
If True, save the figure to disk. Default is False. |
False
|
save_directory
|
str
|
Directory where the figure will be saved. Default is the current directory. |
'.'
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If |