regularizepsf.fitter#
Attributes#
Classes#
A representation of a PatchCollection that operates on pixel coordinates from a set of images. |
Module Contents#
- class regularizepsf.fitter.PatchCollectionABC(patches: dict[Any, numpy.ndarray], counts: dict[Any, int] | None = None)#
- patches#
- counts#
- __len__() int#
- classmethod extract(images: list[numpy.ndarray], coordinates: list, size: int) PatchCollectionABC#
- Abstractmethod:
Construct a PatchCollection from a set of images using the specified coordinates and patch size.
- Parameters:
images (list of np.ndarrays) – the images loaded
coordinates (list) –
- A list of coordinates for the lower left pixel of each patch,
specified in each type of PatchCollection
size (int) – size of one side of the square patches extracted
- Returns:
the square patches extracted into a PatchCollection
- Return type:
np.ndarray
- __getitem__(identifier: Any) numpy.ndarray#
Access a patch with square brackets.
- Parameters:
identifier (Any) – identifier for a given patch, specifically implemented for each PatchCollection
- Returns:
a patch’s data
- Return type:
np.ndarray
- __contains__(identifier: Any) bool#
Determines if a patch is in the collection.
- Parameters:
identifier (Any) –
- identifier for a given patch,
specifically implemented for each PatchCollection
- Returns:
- True if patch with specified identifier is in the collection,
False otherwise
- Return type:
bool
- add(identifier: Any, patch: numpy.ndarray, count: int | None = None) None#
Add a new patch to the collection.
- Parameters:
identifier (Any) –
- identifier for a given patch,
specifically implemented for each PatchCollection
patch (np.ndarray) – the data for a specific patch
count (int) – Optionally, a corresponding item to add to the counts dictionary
- Return type:
None
- abstract average(corners: numpy.ndarray, step: int, size: int, mode: str) PatchCollectionABC#
Construct a new PatchCollection where patches lying inside a new grid are averaged together.
- Parameters:
corners (np.ndarray) – an Nx2 np.ndarray of the lower left corners of the new patch grid
step (int) – how far apart each corner patch is
size (int) – dimension of the new (size, size) shaped square patches
mode (str) – either average using “mean” or “median”
- Returns:
a PatchCollection where data is sampled at the new grid
- Return type:
- abstract fit(base_psf: regularizepsf.psf.SimplePSF, is_varied: bool = False) regularizepsf.psf.PointSpreadFunctionABC#
- Parameters:
base_psf
is_varied
- abstract save(path: str) None#
Save the PatchCollection to a file.
- Parameters:
path (str) – where to save the patch collection
- Return type:
None
- classmethod load(path: str) PatchCollectionABC#
- Abstractmethod:
Load a PatchCollection from a file.
- Parameters:
path (str) – file path to load from
- Returns:
the new patch collection
- Return type:
- keys() list#
Get identifiers for all patches.
- values() list#
Get values of all patches.
- items() dict#
Get a dictionary like iterator over the patches.
- _fit_lmfit(base_psf: regularizepsf.psf.SimplePSF, initial_guesses: dict[str, numbers.Real]) dict[Any, lmfit.minimizer.MinimizerResult]#
Fit a patch using lmfit.
- Parameters:
base_psf (SimplePSF) – the PSF model to use in fitting
initial_guesses (dict[str, Real]) – the initial guesses for all the PSF parameters
- Returns:
keys are the identifiers, values are the MinimizerResults from lmfit
- Return type:
dict
- regularizepsf.fitter.CoordinateIdentifier#
- class regularizepsf.fitter.CoordinatePatchCollection(patches: dict[Any, numpy.ndarray], counts: dict[Any, int] | None = None)#
Bases:
PatchCollectionABCA representation of a PatchCollection that operates on pixel coordinates from a set of images.
- classmethod extract(images: list[numpy.ndarray], coordinates: list[CoordinateIdentifier], size: int) PatchCollectionABC#
Construct a PatchCollection from a set of images using the specified coordinates and patch size.
- Parameters:
images (list of np.ndarrays) – the images loaded
coordinates (list) –
- A list of coordinates for the lower left pixel of each patch,
specified in each type of PatchCollection
size (int) – size of one side of the square patches extracted
- Returns:
the square patches extracted into a PatchCollection
- Return type:
np.ndarray
- classmethod find_stars_and_average(images: list[str] | numpy.ndarray | collections.abc.Generator, psf_size: int, patch_size: int, interpolation_scale: int = 1, average_mode: str = 'median', percentile: float = 10, star_threshold: int = 3, star_mask: list[str] | numpy.ndarray | collections.abc.Generator | None = None, hdu_choice: int = 0) CoordinatePatchCollection#
Load a series of images, finds stars in each and build a CoordinatePatchCollection with averaged stars.
- Parameters:
images (List[str] or np.ndarray or Generator) – The images to be processed. Can be a list of FITS filenames, a numpy array of shape (n_images, ny, nx), or a Generator that yields each data array in turn.
psf_size (int) – size of the PSF model to use
patch_size (int) – square size that each PSF model applies to
interpolation_scale (int) –
- if >1, the image are first scaled by this factor.
This results in stars being aligned at a subpixel scale
average_mode (str) – “median”, “percentile”, or “mean”: determines how patches are combined
percentile (float) – If average_mode is “percentile”, use this percentile value (from 0 to 100)
star_threshold (int) –
- SEP’s threshold for finding stars. See threshold
in https://sep.readthedocs.io/en/v1.1.x/api/sep.extract.html#sep-extract
star_mask (List[str] or np.ndarray or Generator) – Masks to apply during star-finding. Can be a list of FITS filenames, a numpy array of shape (n_images, ny, nx), or a Generator that yields each mask array in turn. Where the mask pixel is True, the corresponding data array pixel will not be selected as a star. See mask in https://sep.readthedocs.io/en/v1.1.x/api/sep.extract.html#sep-extract for more details.
hdu_choice (int) –
- Which HDU from each image will be used,
default of 0 is most common but could be 1 for compressed images
- Returns:
An averaged star model built from the provided images
- Return type:
Notes
- Using an interpolation_scale other than 1
for large images can dramatically slow down the execution.
- average(corners: numpy.ndarray, patch_size: int, psf_size: int, mode: str = 'median', percentile: float = 10) PatchCollectionABC#
Construct a new PatchCollection where patches lying inside a new grid are averaged together.
- Parameters:
corners (np.ndarray) – an Nx2 np.ndarray of the lower left corners of the new patch grid
step (int) – how far apart each corner patch is
size (int) – dimension of the new (size, size) shaped square patches
mode (str) – either average using “mean” or “median”
- Returns:
a PatchCollection where data is sampled at the new grid
- Return type:
- static _validate_average_mode(mode: str, percentile: float) None#
Determine if the average_mode is a valid kind.
- _calculate_pad_shape(size: int) tuple[int, int]#
- fit(base_psf: regularizepsf.psf.SimplePSF, is_varied: bool = False) regularizepsf.psf.PointSpreadFunctionABC#
- Parameters:
base_psf
is_varied
- to_array_corrector(target_evaluation: numpy.array) regularizepsf.corrector.ArrayCorrector#
Convert a patch collection that has been averaged into an ArrayCorrector.
- Parameters:
target_evaluation (np.ndarray) – the evaluation of the Target PSF
- Returns:
An array corrector that can be used to correct PSFs
- Return type:
- save(path: str) None#
Save the CoordinatePatchCollection to a file.
- Parameters:
path (str) – where to save the patch collection
- Return type:
None
- classmethod load(path: str) PatchCollectionABC#
Load a PatchCollection from a file.
- Parameters:
path (str) – file path to load from
- Returns:
the new patch collection
- Return type: