module documentation

Module containing routines that operate on point spread function data

Class S Undocumented
Class S1 Undocumented
Function apply_offsets At the moment doesn't actually apply an offset, just shifts the data so the point at offsets is now the center.
Function fit_to_data Fits a model to some data with some error on that data.
Function get_brightest_pixel_offsets Gets the location of the brightest pixel (not an offset from the center)
Function get_centre_of_mass_offsets Gets the location of the center of mass along axes (not an offset from the data center)
Function get_outlier_mask Get a boolean map of outliers in a numpy array. Assumes a normal distribution.
Function get_roi_mask Find regions of interest in a numpy array by thresholding the array.
Function normalise Ensure an array of data fufils the following conditions:
Function objective_function_factory Given a model function, some data, and the error on that data; returns an objective function that for either 'minimise'-ing or 'maximise'-ing the difference/similarity of the model and data.
Function remove_offset Remove the offsets of data over the specified axes, ignore any `mask`ed pixels.
Function scipy_fitting_function_factory Given some function that implements the same protocol as [scipy minimise](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html#scipy.optimize.minimize) returns a callable that accepts a PriorParamSet, a scipy-compatible objective function, a list of variable parameters, a list of constant parameters, and returns the fitted variable parameters.
Function trim_around_centre Truncate a numpy array about it's center.
Constant P Undocumented
Constant Q Undocumented
Type Variable IntVar Undocumented
Type Variable M Undocumented
Type Variable N Undocumented
Type Variable T Undocumented
Type Variable Ts Undocumented
Variable _lgr Undocumented
def apply_offsets(data: np.ndarray, axes: tuple[int, ...], offsets: np.ndarray) -> np.ndarray:

At the moment doesn't actually apply an offset, just shifts the data so the point at offsets is now the center.

# Arguments #

data : np.ndarray
Array to recentre
axes : tuple[int,...]
Axes to get centre of mass and recentre along.
offsets : np.ndarray
Offsets to apply to data, will shift data's grid by this amount.
def fit_to_data(params: PriorParamSet, flattened_psf_model_callable: Callable[P, np.ndarray[S[N], T]], psf_data: np.ndarray[S[N], T], psf_err: np.ndarray[S[N], T], fitting_function: Callable[[PriorParamSet, Callable[Q, float]], Q], objective_function_factory: Callable[[Callable[P, np.ndarray[S[N], T]], np.ndarray[S[N], T], np.ndarray[S[N], T]], Callable[Q, float]] = functools.partial(objective_function_factory, mode='minimise'), plot_mode: str | bool | None = None) -> tuple[np.ndarray[S[N], T], dict[str, Any], dict[str, Any]]:

Fits a model to some data with some error on that data.

def get_brightest_pixel_offsets(data: np.ndarray, axes: tuple[int, ...], roi_mask: np.ndarray | None = None) -> np.ndarray:

Gets the location of the brightest pixel (not an offset from the center)

## ARGUMENTS ##

data : np.ndarray
Array to recentre
axes : tuple[int,...]
Axes to get centre of mass and recentre along.
roi_mask : np.ndarray | None = None
Mask for the region of interest. If present will restrict calculations to this region.
def get_centre_of_mass_offsets(data: np.ndarray, axes: tuple[int, ...], roi_mask: np.ndarray | None = None) -> np.ndarray:

Gets the location of the center of mass along axes (not an offset from the data center)

## ARGUMENTS ##

data : np.ndarray
Array to recentre
axes : tuple[int,...]
Axes to get centre of mass and recentre along.
roi_mask : np.ndarray | None = None
Mask for the region of interest. If present will restrict calculations to this region.
def get_outlier_mask(data: np.ndarray, axes: tuple[int, ...], n_sigma: float = 5) -> np.ndarray:

Get a boolean map of outliers in a numpy array. Assumes a normal distribution.

# ARGUMENTS #

data : np.ndarray
Data to get outlier mask of.
axes : tuple[int,...]
Axes over which to get outlier mask
n_sigma : float = 5
Number of standard deviations away from the mean a member of data must be to be considered an outlier
def get_roi_mask(data: np.ndarray, axes: tuple[int, ...], threshold: float = 0.01, n_largest_regions: None | int = 1) -> np.ndarray:

Find regions of interest in a numpy array by thresholding the array.

## ARGUMENTS ##

data : np.ndarray
Array to get region of interest of
axes : tuple[int,...]
Axes to get region of interest along.
threshold : float = 1E-2
When finding region of interest, only values larger than this fraction of the maximum value are included.
n_largest_regions : None | int = 1
When finding region of interest, if using a threshold will only use the n_largest_regions in the calculation. A region is defined as a contiguous area where value >= threshold along axes. I.e., in a 3D cube, if we recentre about the COM on the sky (CELESTIAL) axes the regions will be calculated on the sky, not in the spectral axis (for example).
def normalise(data: np.ndarray, axes: tuple[int, ...] | None = None, cutout_shape: tuple[int, ...] | None = None, recentre_around_centre_of_mass=False, remove_background=True) -> np.ndarray:

Ensure an array of data fufils the following conditions:

  • odd shape, to ensure a centre pixel exists
  • centre array on brightest pixel
  • ensure array sums to 1
  • cut out a region around the centre to remove unneeded data.
def objective_function_factory(model_flattened_callable, data, err, mode='minimise'):

Given a model function, some data, and the error on that data; returns an objective function that for either 'minimise'-ing or 'maximise'-ing the difference/similarity of the model and data.

def remove_offset(data, axes, mask, model_name='norm'):

Remove the offsets of data over the specified axes, ignore any `mask`ed pixels.

def scipy_fitting_function_factory(scipy_func):

Given some function that implements the same protocol as [scipy minimise](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html#scipy.optimize.minimize) returns a callable that accepts a PriorParamSet, a scipy-compatible objective function, a list of variable parameters, a list of constant parameters, and returns the fitted variable parameters.

def trim_around_centre(data: np.ndarray, axes: tuple[int, ...], output_shape: tuple[int, ...]) -> np.ndarray:

Truncate a numpy array about it's center.

# ARGUMENTS #

data : np.ndarray
Data to trim around centre pixel, will remove pixels that are greater than shape[i]/2 from the centre pixel.
axes : tuple[int,...]
Axes over which to operate
output_shape : tuple[int,...]
Desired shape of axes after trimming
P =

Undocumented

Value
ParamSpec('P')
Q =

Undocumented

Value
ParamSpec('Q')
IntVar =

Undocumented

Value
TypeVar('IntVar',
        bound=int)
M =

Undocumented

Value
TypeVar('N',
        bound=int)
N =

Undocumented

Value
TypeVar('N',
        bound=int)
T =

Undocumented

Value
TypeVar('T')
Ts =

Undocumented

Value
TypeVarTuple('Ts')
_lgr =

Undocumented