Skip to content

Documentation for TPFMachine

Subclass of Machine that specifically works with TPFs

__init__(self, tpfs, time, flux, flux_err, ra, dec, sources, column, row, limit_radius=24.0, time_mask=None, n_r_knots=10, n_phi_knots=15, time_nknots=10, time_resolution=200, time_radius=8, rmin=1, rmax=16, cut_r=6, pix2obs=None, pos_corr1=None, pos_corr2=None, focus_mask=None, tpf_meta=None, cartesian_knot_spacing='sqrt', bkg_subtracted=True, sparse_dist_lim=40, sources_flux_column='phot_g_mean_flux') special

Parameters are similar to Machine. Additional arguments are:

Parameters:

Name Type Description Default
tpfs lightkurve.TargetPixelFileCollection

Collection of TPFs from the lightkurve package.

required
pix2obs np.ndarray

Array of values indicating the TPF of origin for each pixel. Has shape [npixels].

None
pos_corr1 np.ndarray

Array with position corrector vectors for axis 1 from the TPF

None
pos_corr2 np.ndarray

Array with position corrector vectors for axis 2 from the TPF

None
focus_mask np.ndarray boolean

Array of boolean indicating masked cadences due to focus change. This is useful to mask out cadences when building shape or time model.

None
tpf_meta dictionary

Dictionary containing metadata information related to the data.

None
cartesian_knot_spacing string

Type of spacing "linear" or "sqrt" between knots when creating a cartesian design matrix.

'sqrt'
bkg_subtracted bool

Data is background subtracted or not.

True

fit_lightcurves(self, plot=False, fit_bkg=False, fit_va=True, iter_negative=True, load_shape_model=False, shape_model_file=None, sap=True)

Fit the sources inside the TPFs passed to TPFMachine.

This function creates the lcs attribuite that contains a collection of light curves in the form of lightkurve.LightCurveCollection. Each entry in the collection is a lightkurve.KeplerLightCurve object with the different type of photometry (SAP, PSF, and PSF velocity-aberration corrected). Also each lightkurve.KeplerLightCurve object includes its asociated metadata. The photometry can also be accessed independently from the following attribuites that fit_lightcurves create: * ws and werrs have the uncorrected PSF flux and flux errors. * ws_va and werrs_va have the PSF flux and flux errors corrected by velocity aberration. * sap_flux and sap_flux_err have the flux and flux errors computed using aperture mask.

Parameters:

Name Type Description Default
plot bool

Whether or not to show some diagnostic plots. These can be helpful for a user to see if the PRF and time dependent models are being calculated correctly.

False
fit_bkg bool

Fit and remove background. Useful when providing flux values without background substraction.

False
fit_va bool

Whether or not to fit Velocity Aberration (which implicitly will try to fit other kinds of time variability). This will try to fit the "long term" trends in the dataset. If True, this will take slightly longer to fit. If you are interested in short term phenomena, like transits, you may find you do not need this to be set to True. If you have the time, it is recommended to run it.

True
iter_negative bool

When fitting light curves, it isn't possible to force the flux to be positive. As such, when we find there are light curves that deviate into negative flux values, we can clip these targets out of the analysis and rerun the model. If iter_negative is True, PSFmachine will run up to 3 times, clipping out any negative targets each round.

True
load_shape_model bool

Load PRF shape model from disk or not. Default models were computed from FFI of the same channel and quarter.

False
shape_model_file string

Path to PRF model file to be passed to load_shape_model(input). If None, then precomputed models will be download from Zenodo repo.

None
sap boolean

Compute or not Simple Aperture Photometry. See Machine.compute_aperture_photometry() for details.

True

from_TPFs(tpfs, magnitude_limit=18, dr=3, sources=None, time_mask=None, apply_focus_mask=True, renormalize_tpf_bkg=False, query_ra=None, query_dec=None, query_rad=None, **kwargs) staticmethod

Convert TPF input into Machine object:

  • Parse TPFs to extract time, flux, clux erros, and bookkeeping of the TPF-pixel correspondance
    • Convert pixel-based coordinates (row, column) into WCS (ra, dec) for all pixels
    • Clean pixels with no values, bad cadences, and remove duplicated pixels due to overlapping TPFs
    • Query Gaia DR2 data base to find all sources present in the TPF images
    • Clean unresolve sources (within 6`` = 1.5 pixels) and sources off silicon with a 1 pixel tolerance (distance from source gaia pocition and TPF edge)

Parameters:

Name Type Description Default
tpfs lightkurve TargetPixelFileCollection

Collection of Target Pixel files

required
magnitude_limit float

Limiting magnitude to query Gaia catalog.

18
dr int

Gaia data release to be use, default is 3, options are DR2 and EDR3

3
sources pandas.DataFrame

Catalog with sources to be extracted by PSFMachine

None
time_mask boolean array

Mask to be applied to discard cadences if needed.

None
apply_focus_mask boolean

Mask or not cadances near observation gaps to remove focus change.

True
renormalize_tpf_bkg boolean

Add or not background to the flux array.

False
query_ra numpy.array

Array of RA to query Gaia catalog. Default is None and will use the coordinate centers of each TPF.

None
query_dec numpy.array

Array of Dec to query Gaia catalog. Default is None and will use the coordinate centers of each TPF.

None
query_rad numpy.array

Array of radius to query Gaia catalog. Default is None and will use the coordinate centers of each TPF.

None
**kwargs None

Keyword arguments to be passed to TPFMachine.

{}

Returns:

Type Description
Machine object

A Machine class object built from TPFs.

get_source_centroids(self, method='poscor')

Compute centroids for sources in pixel coordinates.

It implements three different methods to calculate centroids: * "aperture": computes centroids from moments Machine.estimate_source_centroids_aperture(). This needs the aperture masks to becomputed in advance with Machine.compute_aperture_photometry. Note that for sources with partial data (i.e. near TPF edges) the this method is illdefined. * "poscor": uses Gaia RA and Dec coordinates converted to pixel space using the TPFs WCS solution and the apply each TPF 'pos_corr' correction * "scene": uses Gaia coordinates again, but correction is computed from the TPF scene jitter using 'Machine._get_centroids()'.

Parameters:

Name Type Description Default
method string

What type of corrected centroid will be computed. If "aperture", it creates attributes source_centroids_[column/row]_ap. If "poscor" (default), it creates attributes source_centroids_[column/row]_poscor. If "scene", it creates attributes source_centroids_[column/row]_scene.

Note: "poscor" and "scene" show consistent results below 10th of a pixel.

'poscor'

lcs_in_tpf(self, tpf_number)

Returns the light curves from a given TPF as a lightkurve.LightCurveCollection.

Parameters:

Name Type Description Default
tpf_number int

Index of the TPF

required

load_shape_model(self, input=None, plot=False)

Loads a PRF shape model from a FITs file.

Not implemented: By default this function will load PRF shapes computed from FFI data (Kepler, K2, or TESS).

Parameters:

Name Type Description Default
input string

Name of the file containing the shape parameters and weights. The file has to be FITS format. If None, then previously computed shape model from Kepler's FFI will be download from https://zenodo.org/record/5504503/ and used as default. The file download from Zenodo happens only the first time that shape models of a given mission (e.g. Kepler, K2) are asked. Then, shape models for all channels and quarters will be locally available for future use. The file is stored in psfmachine/src/psfmachine/data/.

None
plot boolean

Plot or not the mean model.

False

plot_background_model(self, frame_index=100)

Diagnostic plot of background model

Parameters:

Name Type Description Default
frame_index int

The frame index to be shown.

100

plot_tpf(self, tdx, sap=True)

Make a diagnostic plot of a given TPF in the stack

If you passed a stack of TPFs, this function will show an image of that TPF, and all the light curves inside it, alongside a diagnostic of which source the light curve belongs to.

Parameters:

Name Type Description Default
tdx int

Index of the TPF to plot

required
sap boolean

Overplot the pixel mask used for aperture photometry.

True

remove_background_model(self, plot=False, data_augment=None, zero_centered=True)

Function to fit and remove the background signal of the TPF stack using

kbackground package. This is a Kepler/K2 specific tool. Fits a smooth polynomial to the TPF background pixels (inverse of machine.source_mask) that can also be augmented with the mission background pixels (https://archive.stsci.edu/missions-and-data/kepler/kepler-bulk-downloads).

This helps removing the known 'rolling band' effect seen in some Kepler CCD channels. The function changes the attribute self.flux removing the background (just once) and creates the following new attributes: - self.bkg_row has the bacground pixel row number (can be augmented) - self.bkg_column has the bacground pixel column number (can be augmented) - self.bkg_flux has the bacground pixel flux value (can be augmented) - self.bkg_estimator has the background estimator from kbackground - self.bkg_pixel_mask is the background pixel mask

Parameters:

Name Type Description Default
plot boolean

Show diagnostic plot

False
data_augment dictionary

Dictionary with the pixel row, column and flux value to augment the background pixels. This argument is useful to include Kepler's background pixels from the mission. The dictionary has to have the following keys; "column", "row", and "flux".

None
zero_centered boolean

If True the pixel background level will be zero centered. If False pixels will be positive.

True

save_shape_model(self, output=None)

Saves the weights of a PRF fit to disk as a FITS file.

Parameters:

Name Type Description Default
output str, None

Output file name. If None, one will be generated.

None