Skip to content

Documentation for Aperture

Collection of aperture utils lifted from

Kepler-Apertures and adapted to work with PSFMachine.

Some this functions inputs and operate on a Machine object but we move them out of mahine.py to keep the latter smowhow clean and short.

compute_CROWDSAP(psf_models, aperture_mask, idx=None)

Compute the ratio of target flux relative to flux from all sources within

the photometric aperture (i.e. 1 - Crowdeness). Follows definition by Kinemuchi at al. 2012.

Parameters:

Name Type Description Default
psf_models scipy.sparce.csr_matrix

Sparse matrix with the PSF models for all targets in the scene. It has shape [n_sources, n_pixels].

required
aperture_mask numpy.ndarray

Array of boolean indicating the aperture for the target source. It has shape of [n_sources, n_pixels].

required
idx int

Source index for what the metric is computed. Value has to be betweeen 0 and psf_model first dimension size. If None, it returns the metric for all sources (first dimension of psf_model).

None

Returns:

Type Description
numpy.ndarray

Crowdeness metric

compute_FLFRCSAP(psf_models, aperture_mask)

Compute fraction of target flux enclosed in the optimal aperture to total flux

for a given source (flux completeness). Follows definition by Kinemuchi at al. 2012.

Parameters:

Name Type Description Default
psf_models scipy.sparce.csr_matrix

Sparse matrix with the PSF models for all targets in the scene. It has shape [n_sources, n_pixels].

required
aperture_mask numpy.ndarray

Array of boolean indicating the aperture for the target source. It has shape of [n_sources, n_pixels].

required

Returns:

Type Description
numpy.ndarray

Completeness metric

estimate_source_centroids_aperture(aperture_mask, flux, column, row)

Computes the centroid via 2D moments methods for all sources all times. It needs

aperture_mask to be computed first by runing compute_aperture_photometry.

Parameters:

Name Type Description Default
aperture_mask numpy.ndarray

Aperture mask, shape is [n_surces, n_pixels]

required
flux numpy.ndarray

Flux values at each pixels and times in units of electrons / sec

required
column numpy.ndarray

Data array containing the "columns" of the detector that each pixel is on.

required
row numpy.ndarray

Data array containing the "rows" of the detector that each pixel is on.

required

Returns:

Type Description
numpy.ndarray

Column pixel number of the moments centroid, shape is [nsources, ntimes].

goodness_metric_obj_fun(percentile, optim_params)

The objective function to minimize with scipy.optimize.minimize_scalar called

during optimization of the photometric aperture.

Parameters:

Name Type Description Default
percentile int

Percentile of the normalized flux distribution that defines the isophote.

required
optim_params dictionary

Dictionary with the variables needed to evaluate the metric: * psf_models * sdx * target_complete * target_crowd

required

Returns:

Type Description
float

Value of the objective function to be used for optiization.

optimize_aperture(psf_model, target_complete=0.9, target_crowd=0.9, max_iter=100, percentile_bounds=[0, 100], quiet=False)

Function to optimize the aperture mask for a given source.

The optimization is done using scipy Brent's algorithm and it uses a custom loss function goodness_metric_obj_fun that uses a Leaky ReLU term to achive the target value for both metrics.

Parameters:

Name Type Description Default
psf_model scipy.sparce.csr_matrix

Sparse matrix with the PSF models for all targets in the scene. It has shape [n_sources, n_pixels].

required
target_complete 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
percentile_bounds tuple

Tuple of minimun and maximun values for allowed percentile values during the optimization. Default is the widest range of [0, 100].

[0, 100]

Returns:

Type Description
numpy.ndarray

An array with the percentile value to defines the "optimal" aperture for each source.

plot_flux_metric_diagnose(psf_model, idx=0, ax=None, optimal_percentile=None)

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 diagnostic figures.

Parameters:

Name Type Description Default
psf_model scipy.sparce.csr_matrix

Sparse matrix with the PSF models for all targets in the scene. It has shape [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

Returns:

Type Description
matplotlib.axes

Figure axes