Gaussianity#

Functions to evaluate the noise in high-contrast-imaging residuals. Note, none of the tests implemented here can proof that the residual noise is Gaussian. But they can provide useful insides whether the noise deviates for Gaussian.

applefy.gaussianity.residual_tests.extract_circular_annulus(input_residual_frame, separation, size_resolution_elements, annulus_width=0.5)#

Function to extract the pixel positions and values around a circular annulus at a given separation form the center of an image.

Parameters
  • input_residual_frame (ndarray) – The input frame from which the pixel values are extracted.

  • separation (float) – The separation from the center at which the annulus is placed (in units of size_resolution_elements).

  • size_resolution_elements (float) – The size of the resolution elements i.e. the diameter of the PSF FWHM in pixel.

  • annulus_width (float) – The width of the annulus radius in units of size_resolution_elements.

Return type

Tuple[ndarray, ndarray, ndarray]

Returns

  1. The pixel values in the annulus extracted from the frame

  2. The 2D positions of the pixels in the annulus

  3. A 2D image of the annulus mask

applefy.gaussianity.residual_tests.gaussian_r2(noise_samples, fit_method='linear regression', return_fit=False)#

Simple function to calculate how well the given noise samples can be explained by the normal distribution.

Parameters
  • noise_samples (ndarray) – Noise values to be compared against gaussian noise.

  • fit_method (str) –

    Method used to do the fit the noise samples w.r.t the normal distribution. This is needed to compute the r2 metric.

    Option 1: “linear regression” - A linear regression.

    Option 2: “theil sen” - TheilSenRegressor linear fit. More robust towards outliers.

  • return_fit (bool) – If set to true the function will return the model fit and the gaussian quantile points. This can be useful to plot Q-Q plots.

Return type

Union[float, Tuple[float, Union[TheilSenRegressor, LinearRegression], ndarray]]

Returns

  1. R2 - Coefficient of determination

  2. The linear model used for the fit (only if return_fit is True)

  3. The gaussian_quantile points (only if return_fit is True)

applefy.gaussianity.residual_tests.estimate_gaussian_r2(input_residual_frame, separation, size_resolution_elements, annulus_width=0.5, fit_method='linear regression')#

Extracts pixel values inside a circular annulus around the center of the input_residual_frame and computes the r2 of the pixel values w.r.t. to the gaussian distribution. As neighbouring pixel values in HCI residuals are usually not independent the result of the test should only be used as an indicator against not a proof for gaussian residual noise.

Parameters
  • input_residual_frame (ndarray) – The input input_residual_frame on which the test i s performed.

  • separation (float) – The separation from the center at which the annulus is placed and the noise gets extracted (in units of size_resolution_elements).

  • size_resolution_elements (float) – The size of the resolution elements i.e. the diameter of the PSF FWHM in pixel.

  • annulus_width (float) – The width of the annulus radius in units of size_resolution_elements

  • fit_method (str) –

    Method used to do the fit the noise samples w.r.t the normal distribution. This is needed to compute the r2 metric.

    Option 1: “linear regression” - A linear regression.

    Option 2: “theil sen” - TheilSenRegressor linear fit. More robust towards outliers.

Return type

float

Returns

R2 - Coefficient of determination for the pixel values in the annulus.

applefy.gaussianity.residual_tests.test_normality_shapiro_wilk(input_residual_frame, separation, size_resolution_elements, num_rot_iter, photometry_mode)#

Runs a Shapiro-Wilk test on photometry values at a given separation around the center of the input_residual_frame. The noise elements are sampled such that measurements are independent as required by the Shapiro-Wilk test. However, due to the small number of residual elements at small separation the test has only very limited sensitivity. Further the test can never proof that the noise is Gaussian.

Parameters
  • input_residual_frame (ndarray) – The frame on which the test is performed.

  • separation (float) – The separation from the center at which the noise photometry is taken (in units of size_resolution_elements).

  • size_resolution_elements (float) – The size of the resolution elements i.e. the diameter of the PSF FWHM in pixel.

  • num_rot_iter (int) – Number of different noise positions at which the Shapiro-Wilk test is evaluated. See Figure 10 for more information.

  • photometry_mode (AperturePhotometryMode) – An instance of AperturePhotometryMode which defines how the noise photometry is measured.

Return type

Tuple[float, float]

Returns

  1. The average test statistic of the Shapiro-Wilk test over all

    num_rot_iter

  2. The average p-value of the Shapiro-Wilk test over all num_rot_iter