Documentation for TPFMachine
Class to load PRF models computed from FFI, to create photometric apertures
__init__(self, prf_ws, n_r_knots=5, n_phi_knots=15, rmin=0.25, rmax=5)
special
A KeplerPRF object is build by providing the hyperparameters of the spline
model, and the weights of each basis spline. The hyperparameters allow to reconstruct the same basis splines while the weights are used at evaluation of the model in new data.
Parameters
prf_ws : numpy.ndarray Weights corresponding to each basis of the design matrix. rmin : float The minimum radius for the PRF model to be fit. rmax : float The maximum radius for the PRF model to be fit. n_r_knots : int Number of radial knots in the spline model. n_phi_knots : int Number of azimuthal knots in the spline model.
Attributes:
Name | Type | Description |
---|---|---|
prf_w |
numpy.ndarray |
Weights corresponding to each basis of the design matrix. |
rmin |
float |
The minimum radius for the PRF model to be fit. |
rmax |
float |
The maximum radius for the PRF model to be fit. |
n_r_knots |
int |
Number of radial knots in the spline model. |
n_phi_knots |
int |
Number of azimuthal knots in the spline model. |
compute_CROWDSAP(psf_models, mask, idx)
staticmethod
Compute the ratio of target flux relative to flux from all sources within
the photometric aperture (i.e. 1 - Crowdeness).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
psf_models |
numpy ndarray |
Array with the PSF models for all targets in the cutout. It has shape [n_sources, n_pixels]. |
required |
mask |
boolean array |
Array of boolean indicating the aperture for the target source. |
required |
idx |
int |
Index of the source to compute the metric. It has to be a number between 0 and psf_models.shape[0]. |
required |
Returns:
Type | Description |
---|---|
float |
Crowdeness metric |
compute_FLFRCSAP(psf_model, mask)
staticmethod
Compute fraction of target flux enclosed in the optimal aperture to total flux
for a given source (flux completeness).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
psf_model |
numpy ndarray |
Array with the PSF model for the target source. It has shape [n_pixels] |
required |
mask |
boolean array |
Array of boolean indicating the aperture for the target source. |
required |
Returns:
Type | Description |
---|---|
float |
Completeness metric |
create_aperture_mask(self, psf_models, percentile=0, idx=None)
Function to create the aperture mask of a given source for a given aperture
size. This function can compute aperutre mask for one or all sources available in the psf_models
Parameters:
Name | Type | Description | Default |
---|---|---|---|
psf_models |
scipy.sparse.csr_matrix |
Sparse matrix with the PSF models of all sources in the field. It has shape of [n_sources, n_pixels] |
required |
percentile |
float |
Percentile value that defines the isophote from the distribution of values in the psf model of the source |
0 |
idx |
int |
Index of the source for which the metrcs will be computed. Has to be a number between 0 and psf_models.shape[0]. If None, then it computes the apertures for all sources in psf_models. |
None |
Returns:
Type | Description |
---|---|
numpy.ndarray |
Boolean array with the aperture mask. |
diagnose_metrics(self, psf_models, idx=0, ax=None, plot=True)
Function to evaluate the flux metrics for a single source as a function of
the parameter that controls the aperture size. The flux metrics are computed by taking into account the PSF models of neighbor sources.
This function is meant to be used only to generate the diagnostic or as a
helping function of optimize_aperture()
to precalculate the values of the
metrics and find the optimal aperture in case of isolated sources, where the
optimal is the full aperture.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
psf_models |
scipy.sparse.csr_matrix |
Sparse matrix with the PSF models of all sources in the field. It has shape of [n_sources, n_pixels] |
required |
idx |
int |
Index of the source for which the metrcs will be computed. Has to be a number between 0 and psf_models.shape[0]. |
0 |
ax |
matplotlib.axes |
Axis to be used to plot the figure |
None |
plot |
boolean |
Plot the metrics values. |
True |
Returns:
Type | Description |
---|---|
matplotlib.axes |
Figure axes |
evaluate_PSF(self, dx, dy)
Function to evaluate the PRF model in a grid of data. THe function returns
a the prediction of the model as normalized flux. The model is evaluated in pixels up to r < 7 from the location of the source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dx |
numpy.ndarray |
Distance between pixels (row direction) and source coordinates. |
required |
dx |
numpy.ndarray |
Distance between pixels (column direction) and source coordinates. |
required |
Returns:
Type | Description |
---|---|
scipy.sparse.csr_matrix |
Normalized fluxvalues of the PRF model evaluation in the dx, dy grid |
load_from_file(quarter=5, channel=1)
staticmethod
Loads a PRF model build from Kepler's FFI for a given quarter and channel.
Note: the file with the PRF models is csv file with a multiindex pandas DataFrame, the FITS version is in development.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
channel |
int |
Channel number of the FFI to be used to model the PRF. Valid values are between 1 and 84. |
1 |
quarter |
int |
Number of the quarter that will be used to model the PRF. Valid values are between 1 and 17. |
5 |
Returns:
Type | Description |
---|---|
KeplerPRF |
An object with the PRF model ready to be evaluated in new data. |
optimize_aperture(self, psf_models, idx=0, target_complet=0.9, target_crowd=0.9, max_iter=100)
Function to optimize the aperture mask for a given source. There are two
special cases:
* Isolated sources, the optimal aperture is the full aperture.
* If optimizing for one single metric.
For these last two case, no actual optimization if performed, and we use the
results from diagnose_metrics()
.
The optimization is done using scipy Brent's algorithm and it uses a custom loss function that uses a Leaky ReLU term to achive the target value for both metrics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
psf_models |
scipy.sparse.csr_matrix |
Sparse matrix with the PSF models of all sources in the field. It has shape of [n_sources, n_pixels] |
required |
idx |
int |
Index of the source for which the metrcs will be computed. Has to be a number between 0 and psf_models.shape[0]. If None, then it computes the apertures for all sources in psf_models. |
0 |
target_complet |
float |
Value of the target completeness metric. |
0.9 |
target_crowd |
float |
Value of the target crowdeness metric. |
0.9 |
max_iter |
int |
Numer of maximum iterations to be performed by the optimizer. |
100 |
Returns:
Type | Description |
---|---|
numpy.ndarray |
Boolean array with the aperture mask. |
plot_aperture(self, flux, mask=None, ax=None, log=False)
Function to plot the photometric aperture for a given source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flux |
numpy.ndarray |
Data array with the flux image. |
required |
mask |
numpy.ndarray |
Boolean array with the aperture mask |
None |
log |
boolean |
Plot the image in log or linear scale. |
False |
ax |
matplotlib.axes |
Matlotlib axis can be provided, if not one will be created and returned |
None |
Returns:
Type | Description |
---|---|
matplotlib.axes |
Matlotlib axis with the figure |