# pynpoint.util package#

## pynpoint.util.analysis module#

Functions for point source analysis.

pynpoint.util.analysis.compute_aperture_flux_elements(image: ndarray, x_pos: float, y_pos: float, size: float, ignore: bool)[source]#

Computes the average fluxes inside apertures with the same separation from the center. This function can be used to to estimate the residual flux of a planet at position (x_pos, y_pos) and the respective noise elements with same separation (see function false_alarm) It can also be used to compute the noise apertures is if no planet is present (needed for contrast curves).

Parameters:
• image (numpy.ndarray) – The input image as a 2D numpy array. For example, this could be a residual frame returned by a PcaPsfSubtractionModule.

• x_pos (float) – The planet position (in pixels) along the horizontal axis. The pixel coordinates of the bottom-left corner of the image are (-0.5, -0.5). If no planet is present x_pos and y_pos determine the separation from the center.

• y_pos (float) – The planet position (pix) along the vertical axis. The pixel coordinates of the bottom-left corner of the image are (-0.5, -0.5). If no planet is present x_pos and y_pos determine the separation from the center.

• size (float) – The radius of the reference apertures (in pixels). Usually, this value is chosen close to one half of the typical FWHM of the PSF (0.514 lambda over D for a perfect Airy pattern; in practice, however, the FWHM is often larger than this).

• ignore (bool) – Whether or not to ignore the immediate neighboring apertures for the noise estimate. This is desirable in case there are “self-subtraction wings” left and right of the planet which would bias the estimation of the noise level at the separation of the planet if not ignored.

Returns:

A list of aperture photometry values. If a planet was present ap_phot[0] contains the flux of the planet and ap_phot[1:] contains the noise. If not planet was present ap_phot[…] gives the aperture photometry of the noise elements.

Return type:

ap_phot

pynpoint.util.analysis.fake_planet(images: ndarray, psf: ndarray, parang: ndarray, position: Tuple[float, float], magnitude: float, psf_scaling: float, interpolation: str = 'spline') ndarray[source]#

Function to inject artificial planets in a dataset.

Parameters:
• images (numpy.ndarray) – Input images (3D).

• psf (numpy.ndarray) – PSF template (3D).

• parang (numpy.ndarray) – Parallactic angles (deg).

• position (tuple(float, float)) – Separation (pix) and position angle (deg) measured in counterclockwise with respect to the upward direction.

• magnitude (float) – Magnitude difference used to scale input PSF.

• psf_scaling (float) – Extra factor used to scale input PSF.

• interpolation (str) – Interpolation type (‘spline’, ‘bilinear’, or ‘fft’).

Returns:

Images with artificial planet injected.

Return type:

numpy.ndarray

pynpoint.util.analysis.false_alarm(image: ndarray, x_pos: float, y_pos: float, size: float, ignore: bool) Tuple[float, float, float, float][source]#

Compute the signal-to-noise ratio (SNR), which is formally defined as the test statistic of a two-sample t-test, and related quantities (such as the FPF) at a given position in an image.

For more detailed information about the definition of the signal-to-noise ratio and the motivation behind it, please see the following paper:

Mawet, D. et al. (2014): “Fundamental limitations of high contrast imaging set by small sample statistics”. The Astrophysical Journal, 792(2), 97. DOI: 10.1088/0004-637X/792/2/97.

Parameters:
• image (numpy.ndarray) – The input image as a 2D numpy array. For example, this could be a residual frame returned by a PcaPsfSubtractionModule.

• x_pos (float) – The planet position (in pixels) along the horizontal axis. The pixel coordinates of the bottom-left corner of the image are (-0.5, -0.5).

• y_pos (float) – The planet position (pix) along the vertical axis. The pixel coordinates of the bottom-left corner of the image are (-0.5, -0.5).

• size (float) – The radius of the reference apertures (in pixels). Usually, this value is chosen close to one half of the typical FWHM of the PSF (0.514 lambda over D for a perfect Airy pattern; in practice, however, the FWHM is often larger than this).

• ignore (bool) – Whether or not to ignore the immediate neighboring apertures for the noise estimate. This is desirable in case there are “self-subtraction wings” left and right of the planet which would bias the estimation of the noise level at the separation of the planet if not ignored.

Returns:

• signal_sum – The integrated (summed up) flux inside the signal aperture.

Please note that this is not identical to the numerator of the fraction defining the SNR (which is given by the signal_sum minus the mean of the noise apertures).

• noise – The denominator of the SNR, i.e., the standard deviation of the integrated flux of the noise apertures, times a correction factor that accounts for small sample statistics.

• snr – The signal-to-noise ratio (SNR) as defined by Mawet et al. (2014) in eq. (8).

• fpf – The false positive fraction (FPF) as defined by Mawet et al. (2014) in eq. (10).

pynpoint.util.analysis.merit_function(residuals: ndarray, merit: str, aperture: Tuple[int, int, float], sigma: float, var_noise: float | None) float[source]#

Function to calculate the figure of merit at a given position in the image residuals.

Parameters:
• residuals (numpy.ndarray) – Residuals of the PSF subtraction (2D).

• merit (str) – Figure of merit for the chi-square function (‘hessian’, ‘poisson’, or ‘gaussian’).

• aperture (tuple(int, int, float)) – Position (y, x) of the aperture center (pix) and aperture radius (pix).

• sigma (float) – Standard deviation (pix) of the Gaussian kernel which is used to smooth the residuals before the chi-square is calculated.

• var_noise (float, None) – Variance of the noise which is required when merit is set to ‘gaussian’ or ‘hessian’.

Returns:

Chi-square value.

Return type:

float

pynpoint.util.analysis.pixel_variance(var_type: str, images: ndarray, parang: ndarray, cent_size: float | None, edge_size: float | None, pca_number: int, residuals: str, aperture: Tuple[int, int, float], sigma: float) float[source]#

Function to calculate the variance of the noise. After the PSF subtraction, images are rotated in opposite direction of the regular derotation, therefore dispersing any companion or disk signal. The noise is measured within an annulus.

Parameters:
• var_type (str) – Variance type (‘gaussian’ or ‘hessian’).

• images (numpy.ndarray) – Input images (3D).

• parang (numpy.ndarray) – Parallactic angles.

• cent_size (float, None) – Radius of the central mask (pix). No mask is used when set to None.

• edge_size (float, None) – Outer radius (pix) beyond which pixels are masked. No outer mask is used when set to None.

• pca_number (int) – Number of principal components (PCs) used for the PSF subtraction.

• residuals (str) – Method for combining the residuals (‘mean’, ‘median’, ‘weighted’, or ‘clipped’).

• aperture (tuple(int, int, float)) – Aperture position (y, x) and radius (pix).

• sigma (float, None) – Standard deviation (pix) of the Gaussian kernel which is used to smooth the images.

Returns:

Variance of the pixel values. Either the variance of the pixel values (‘gaussian’) or the variance of the determinant of the Hessian (‘hessian’).

Return type:

float

pynpoint.util.analysis.student_t(t_input: Tuple[str, float], radius: float, size: float, ignore: bool) float[source]#

Function to calculate the false positive fraction for a given sigma level (Mawet et al. 2014).

Parameters:
• t_input (tuple(str, float)) – Tuple with the input type (‘sigma’ or ‘fpf’) and the input value.

• size (float) – Separation of the aperture center from the center of the frame (in pixels).

• ignore (bool) – Whether or not to ignore the immediate neighboring apertures of the point source to exclude potential self-subtraction lobes.

Returns:

False positive fraction (FPF).

Return type:

float

## pynpoint.util.apply_func module#

Functions that are executed with apply_function_to_images() and apply_function_in_time(). The functions are placed here such that they are pickable by the multiprocessing functionalities. The first two parameters are always the sliced data and the index in the dataset.

TODO Docstrings are missing for most of the functions.

pynpoint.util.apply_func.align_image(image_in: ndarray, im_index: int, interpolation: str, accuracy: float, resize: float | None, num_references: int, subframe: float | None, ref_images_reshape: ndarray, ref_images_shape: Tuple[int, int, int]) ndarray[source]#
pynpoint.util.apply_func.apply_shift(image_in: ndarray, im_index: int, shift: Tuple[float, float] | ndarray, interpolation: str) ndarray[source]#

Internal function to interpolate bad pixels.

Parameters:
• image_in (np.ndarray) – Input image.

• iterations (int) – Number of iterations.

Returns:

Image in which the bad pixels have been interpolated.

Return type:

np.ndarray

pynpoint.util.apply_func.bad_pixel_sigma_filter(image_in: ndarray, im_index: int, box: int, sigma: float, iterate: int, map_out_port: OutputPort | None) ndarray[source]#
pynpoint.util.apply_func.calc_fast_convolution(F_roof_tmp: complex128, W: ndarray, tmp_s: tuple, N_size: float, tmp_G: ndarray, N: Tuple[int, ...]) ndarray[source]#
pynpoint.util.apply_func.crop_around_star(image: ndarray, im_index: int, position: Tuple[int, int, float] | Tuple[None, None, float] | None, im_size: int, fwhm: int, pixscale: float, index_out_port: OutputPort | None, image_out_port: OutputPort) ndarray[source]#
pynpoint.util.apply_func.crop_rotating_star(image: ndarray, im_index: int, position: Tuple[float, float] | ndarray, im_size: int, filter_size: int | None, search_size: int) ndarray[source]#
pynpoint.util.apply_func.cwt_denoise_line_in_time(signal_in: ndarray, im_index: int, threshold_function: bool, padding: str, median_filter: bool, wavelet_conf) ndarray[source]#

Definition of temporal denoising for CWT.

Parameters:

signal_in (np.ndarray) – 1D input signal.

Returns:

1D output signal.

Return type:

np.ndarray

pynpoint.util.apply_func.dwt_denoise_line_in_time(signal_in: ndarray, im_index: int, threshold_function: bool, padding: str, wavelet_conf) ndarray[source]#

Definition of the temporal denoising for DWT.

Parameters:

signal_in (np.ndarray) – 1D input signal.

Returns:

Multilevel 1D inverse discrete wavelet transform.

Return type:

np.ndarray

pynpoint.util.apply_func.fit_2d_function(image: ndarray, im_index: int, mask_radii: Tuple[float, float], sign: str, model: str, filter_size: float | None, guess: Tuple[float, float, float, float, float, float, float] | Tuple[float, float, float, float, float, float, float, float], mask_out_port: OutputPort | None, xx_grid: ndarray, yy_grid: ndarray, rr_ap: ndarray, pixscale: float) ndarray[source]#
pynpoint.util.apply_func.image_interpolation(image_in: ndarray, im_index: int, iterations: int, bad_pixel_map: ndarray) ndarray[source]#
pynpoint.util.apply_func.image_scaling(image_in: ndarray, im_index: int, scaling_y: float, scaling_x: float, scaling_flux: float) ndarray[source]#
pynpoint.util.apply_func.image_stat(image_in: ndarray, im_index: int, indices: ndarray | None) ndarray[source]#
pynpoint.util.apply_func.normalization(image_in: ndarray, im_index: int) ndarray[source]#
pynpoint.util.apply_func.photometry(image: ndarray, im_index: int, aperture: Aperture | List[Aperture]) ndarray[source]#
pynpoint.util.apply_func.replace_pixels(image: ndarray, im_index: int, index: ndarray, size: int, replace: str) ndarray[source]#
pynpoint.util.apply_func.sigma_filter(dev_image: ndarray, var_image: ndarray, mean_image: ndarray, source_image: ndarray, out_image: ndarray, bad_pixel_map: ndarray) None[source]#
pynpoint.util.apply_func.subtract_line(image_in: ndarray, im_index: int, mask: ndarray, combine: str, im_shape: Tuple[int, int]) ndarray[source]#
pynpoint.util.apply_func.subtract_psf(image: ndarray, im_index: int, parang_thres: float | None, nref: int | None, reference: ndarray | None, ang_diff: ndarray, image_in_port: InputPort) ndarray[source]#
pynpoint.util.apply_func.time_filter(timeline: ndarray, im_index: int, sigma: Tuple[float, float]) ndarray[source]#

## pynpoint.util.attributes module#

Functions for adding attributes to a dataset in the central database.

pynpoint.util.attributes.set_extra_attr(fits_file: str, nimages: int, config_port: ConfigPort, image_out_port: OutputPort, first_index: int) int[source]#

Function which adds extra attributes to the central database.

Parameters:
• fits_file (str) – Absolute path and filename of the FITS file.

• nimages (int) – Number of images.

• config_port (pynpoint.core.dataio.ConfigPort) – Configuration port.

• image_out_port (pynpoint.core.dataio.OutputPort) – Output port of the images to which the attributes are stored.

• first_index (int) – First image index of the current subset.

Returns:

First image index for the next subset.

Return type:

int

Function which adds the non-static attributes to the central database.

Parameters:
Returns:

None

Return type:

NoneType

pynpoint.util.attributes.set_static_attr(fits_file: str, header: Header, config_port: ConfigPort, image_out_port: OutputPort, check: bool = True) None[source]#

Function which adds the static attributes to the central database.

Parameters:
• fits_file (str) – Name of the FITS file.

• config_port (pynpoint.core.dataio.ConfigPort) – Configuration port.

• image_out_port (pynpoint.core.dataio.OutputPort) – Output port of the images to which the static attributes are stored.

• check (bool) – Print a warning if certain attributes from the configuration file are not present in the FITS header. If set to False, attributes are still written to the dataset but there will be no warning if a keyword is not found in the FITS header.

Returns:

None

Return type:

NoneType

## pynpoint.util.continuous module#

pynpoint.util.continuous.angularfreq(N: int, dt: int) ndarray[source]#

Compute angular frequencies.

Parameters:
• N (int) – Number of data samples.

• dt (int) – Time step.

Returns:

Angular frequencies (1D).

Return type:

numpy.ndarray

pynpoint.util.continuous.autoscales(N: int, dt: int, dj: float, wf: str, p: int) ndarray[source]#

Compute scales as fractional power of two.

Parameters:
• N (int) – Number of data samples.

• dt (int) – Time step.

• dj (float) – Scale resolution (smaller values of give finer resolution).

• wf (str) – Wavelet function (“morlet”, “paul”, or “dog”).

• p (int) – omega0 (“morlet”) or order (“paul”, “dog”).

Returns:

Scales (1D).

Return type:

numpy.ndarray

pynpoint.util.continuous.cwt(x: ndarray, dt: int, scales: ndarray, wf: str = 'dog', p: int = 2) ndarray[source]#

Continuous Wavelet Transform.

Parameters:
• x (numpy.ndarray) – Data (1D).

• dt (int) – Time step.

• scales (numpy.ndarray) – Scales (1D).

• wf (str) – Wavelet function (“morlet”, “paul”, or “dog”).

• p (int) – omega0 (“morlet”) or order (“paul”, “dog”).

Returns:

Transformed data (2D).

Return type:

numpy.ndarray

pynpoint.util.continuous.dogft(s: ndarray, w: ndarray, order: int, dt: int) ndarray[source]#

Fourier transformed DOG function.

Parameters:
• s (numpy.ndarray) – Scales.

• w (numpy.ndarray) – Angular frequencies.

• order (int) – Wavelet order.

• dt (int) – Time step.

Returns:

Normalized Fourier transformed DOG function.

Return type:

numpy.ndarray

pynpoint.util.continuous.icwt(X: ndarray, scales: ndarray) ndarray[source]#

Inverse Continuous Wavelet Transform. The reconstruction factor is not applied.

Parameters:
• X (numpy.ndarray) – Transformed data (2D).

• scales (numpy.ndarray) – Scales (1D).

Returns:

1D data.

Return type:

numpy.ndarray

pynpoint.util.continuous.morletft(s: ndarray, w: ndarray, w0: int, dt: int) ndarray[source]#

” Fourier transformed morlet function.

Parameters:
• s (numpy.ndarray) – Scales.

• w (numpy.ndarray) – Angular frequencies.

• w0 (int) – Omega0 frequency.

• dt (int) – Time step.

Returns:

Normalized Fourier transformed morlet function

Return type:

numpy.ndarray

pynpoint.util.continuous.normalization(s: ndarray | generic, dt: int) ndarray | generic[source]#

” :param s: Scales. :type s: numpy.ndarray :param dt: Time step. :type dt: int

Returns:

Normalized data.

Return type:

numpy.ndarray

## pynpoint.util.image module#

Functions for image processing.

pynpoint.util.image.cartesian_to_polar(center: Tuple[float, float], y_pos: float, x_pos: float) Tuple[float, float][source]#

Function to convert pixel coordinates to polar coordinates.

Parameters:
• center (tuple(float, float)) – Image center (y, x) from center_subpixel().

• y_pos (float) – Pixel coordinate along the vertical axis. The bottom left corner of the image is (-0.5, -0.5).

• x_pos (float) – Pixel coordinate along the horizontal axis. The bottom left corner of the image is (-0.5, -0.5).

Returns:

Separation (pix) and position angle (deg). The angle is measured counterclockwise with respect to the positive y-axis.

Return type:

tuple(float, float)

pynpoint.util.image.center_pixel(image: ndarray) Tuple[int, int][source]#

Function to get the pixel position of the image center. Note that this position can not be unambiguously defined for an even-sized image. Python indexing starts at 0 so the coordinates of the pixel in the bottom-left corner are (0, 0).

Parameters:

image (np.ndarray) – Input image (2D or 3D).

Returns:

Pixel position (y, x) of the image center.

Return type:

tuple(int, int)

pynpoint.util.image.center_subpixel(image: ndarray) Tuple[float, float][source]#

Function to get the precise position of the image center. The center of the pixel in the bottom left corner of the image is defined as (0, 0), so the bottom left corner of the image is located at (-0.5, -0.5).

Parameters:

image (np.ndarray) – Input image (2D or 3D).

Returns:

Subpixel position (y, x) of the image center.

Return type:

tuple(float, float)

pynpoint.util.image.create_mask(im_shape: Tuple[int, int], size: Tuple[float, float] | Tuple[float, None] | Tuple[None, float] | Tuple[None, None]) ndarray[source]#

Function to create a mask for the central and outer image regions.

Parameters:
• im_shape (tuple(int, int)) – Image size in both dimensions.

• size (tuple(float, float)) – Size (pix) of the inner and outer mask.

Returns:

Return type:

np.ndarray

pynpoint.util.image.crop_image(image: ndarray, center: tuple | None, size: int, copy: bool = True) ndarray[source]#

Function to crop square images around a specified position.

Parameters:
• image (np.ndarray) – Input image (2D or 3D).

• center (tuple(int, int), None) – The new image center (y, x). The center of the image is used if set to None.

• size (int) – Image size (pix) for both dimensions. Increased by 1 pixel if size is an even number.

• copy (bool) – Whether or not to return a copy (instead of a view) of the cropped image (default: True).

Returns:

Cropped odd-sized image (2D or 3D).

Return type:

np.ndarray

pynpoint.util.image.pixel_distance(im_shape: Tuple[int, int], position: Tuple[int, int] | None = None) Tuple[ndarray, ndarray, ndarray][source]#

Function to calculate the distance of each pixel with respect to a given pixel position. Supports both odd and even sized images.

Parameters:
• im_shape (tuple(int, int)) – Image shape (y, x).

• position (tuple(int, int)) – Pixel center (y, x) from which the distance is calculated. The image center is used if set to None. Python indexing starts at zero so the center of the bottom left pixel is (0, 0).

Returns:

• np.ndarray – 2D array with the distances of each pixel from the provided pixel position.

• np.ndarray – 2D array with the x coordinates.

• np.ndarray – 2D array with the y coordinates.

pynpoint.util.image.polar_to_cartesian(image: ndarray, sep: float, ang: float) Tuple[float, float][source]#

Function to convert polar coordinates to pixel coordinates.

Parameters:
• image (np.ndarray) – Input image (2D or 3D).

• sep (float) – Separation (pixels).

• ang (float) – Position angle (deg), measured counterclockwise with respect to the positive y-axis.

Returns:

Cartesian coordinates (y, x). The bottom left corner of the image is (-0.5, -0.5).

Return type:

tuple(float, float)

pynpoint.util.image.rotate_coordinates(center: Tuple[float, float], position: Tuple[float, float] | ndarray, angle: float) Tuple[float, float][source]#

Function to rotate coordinates around the image center.

Parameters:
• center (tuple(float, float)) – Image center (y, x) with subpixel accuracy.

• position (tuple(float, float)) – Position (y, x) in the image, or a 2D numpy array of positions.

• angle (float) – Angle (deg) to rotate in counterclockwise direction.

Returns:

New position (y, x).

Return type:

tuple(float, float)

pynpoint.util.image.rotate_images(images: ndarray, angles: ndarray) ndarray[source]#

Function to rotate all images in clockwise direction.

Parameters:
• images (np.ndarray) – Stack of images (3D).

• angles (np.ndarray) – Rotation angles (deg).

Returns:

Rotated images.

Return type:

np.ndarray

pynpoint.util.image.scale_image(image: ndarray, scaling_y: float | float32, scaling_x: float | float32) ndarray[source]#

Function to spatially scale an image.

Parameters:
• image (np.ndarray) – Input image (2D).

• scaling_y (float) – Scaling factor y.

• scaling_x (float) – Scaling factor x.

Returns:

Shifted image (2D).

Return type:

np.ndarray

image_innp.ndarray

Input image.

Inner radius of the annulus (pix).

Outer radius of the annulus (pix).

Center (pix) position (y, x) in of the circular region that is excluded. Not used if set to None.

Radius (pix) of the circular region that is excluded. Not used if set to None.

pynpoint.util.image.shift_image(image: ndarray, shift_yx: Tuple[float, float] | ndarray, interpolation: str, mode: str = 'constant') ndarray[source]#

Function to shift an image.

Parameters:
• image (np.ndarray) – Input image (2D or 3D). If 3D the image is not shifted along the 0th axis.

• shift_yx (tuple(float, float), np.ndarray) – Shift (y, x) to be applied (pix). An additional shift of zero pixels will be added for the first dimension in case the input image is 3D.

• interpolation (str) – Interpolation type (‘spline’, ‘bilinear’, or ‘fft’).

• mode (str) – Interpolation mode.

Returns:

Shifted image.

Return type:

np.ndarray

pynpoint.util.image.subpixel_distance(im_shape: Tuple[int, int], position: Tuple[float, float], shift_center: bool = True) ndarray[source]#

Function to calculate the distance of each pixel with respect to a given subpixel position. Supports both odd and even sized images.

Parameters:
• im_shape (tuple(int, int)) – Image shape (y, x).

• position (tuple(float, float)) – Pixel center (y, x) from which the distance is calculated. Python indexing starts at zero so the bottom left image corner is (-0.5, -0.5).

• shift_center (bool) – Apply the coordinate correction for the image center.

Returns:

2D array with the distances of each pixel from the provided pixel position.

Return type:

np.ndarray

## pynpoint.util.limits module#

Functions for calculating detection limits.

pynpoint.util.limits.contrast_limit(path_images: str, path_psf: str, noise: ndarray, mask: ndarray, parang: ndarray, psf_scaling: float, extra_rot: float, pca_number: int, threshold: Tuple[str, float], aperture: float, residuals: str, snr_inject: float, position: Tuple[float, float]) Tuple[float, float, float, float][source]#

Function for calculating the contrast limit at a specified position for a given sigma level or false positive fraction, both corrected for small sample statistics.

Parameters:
• path_images (str) – System location of the stack of images (3D).

• path_psf (str) – System location of the PSF template for the fake planet (3D). Either a single image or a stack of images equal in size to science data.

• noise (numpy.ndarray) – Residuals of the PSF subtraction (3D) without injection of fake planets. Used to measure the noise level with a correction for small sample statistics.

• parang (numpy.ndarray) – Derotation angles (deg).

• psf_scaling (float) – Additional scaling factor of the planet flux (e.g., to correct for a neutral density filter). Should have a positive value.

• extra_rot (float) – Additional rotation angle of the images in clockwise direction (deg).

• pca_number (int) – Number of principal components used for the PSF subtraction.

• threshold (tuple(str, float)) – Detection threshold for the contrast curve, either in terms of ‘sigma’ or the false positive fraction (FPF). The value is a tuple, for example provided as (‘sigma’, 5.) or (‘fpf’, 1e-6). Note that when sigma is fixed, the false positive fraction will change with separation. Also, sigma only corresponds to the standard deviation of a normal distribution at large separations (i.e., large number of samples).

• aperture (float) – Aperture radius (pix) for the calculation of the false positive fraction.

• residuals (str) – Method used for combining the residuals (‘mean’, ‘median’, ‘weighted’, or ‘clipped’).

• snr_inject (float) – Signal-to-noise ratio of the injected planet signal that is used to measure the amount of self-subtraction.

• position (tuple(float, float)) – The separation (pix) and position angle (deg) of the fake planet.

Returns:

• float – Separation (pix).

• float – Position angle (deg).

• float – Contrast (mag).

• float – False positive fraction.

## pynpoint.util.mcmc module#

Functions for MCMC sampling.

pynpoint.util.mcmc.lnprob(param: ndarray, bounds: Tuple[Tuple[float, float], Tuple[float, float], Tuple[float, float]], images: ndarray, psf: ndarray, mask: ndarray, parang: ndarray, psf_scaling: float, pixscale: float, pca_number: int, extra_rot: float, aperture: Tuple[int, int, float], indices: ndarray, merit: str, residuals: str, var_noise: float | None) float[source]#

Function for the log posterior function. Should be placed at the highest level of the Python module to be pickable for the multiprocessing.

Parameters:
• param (numpy.ndarray) – The separation (arcsec), angle (deg), and contrast (mag). The angle is measured in counterclockwise direction with respect to the positive y-axis.

• bounds (tuple(tuple(float, float), tuple(float, float), tuple(float, float))) – The boundaries of the separation (arcsec), angle (deg), and contrast (mag). Each set of boundaries is specified as a tuple.

• images (numpy.ndarray) – Stack with images.

• psf (numpy.ndarray) – PSF template, either a single image (2D) or a cube (3D) with the dimensions equal to images.

• mask (numpy.ndarray) – Array with the circular mask (zeros) of the central and outer regions.

• parang (numpy.ndarray) – Array with the angles for derotation.

• psf_scaling (float) – Additional scaling factor of the planet flux (e.g., to correct for a neutral density filter). Should be negative in order to inject negative fake planets.

• pixscale (float) – Additional scaling factor of the planet flux (e.g., to correct for a neutral density filter). Should be negative in order to inject negative fake planets.

• pca_number (int) – Number of principal components used for the PSF subtraction.

• extra_rot (float) – Additional rotation angle of the images (deg).

• aperture (tuple(int, int, float)) – Position (y, x) of the aperture center (pix) and aperture radius (pix).

• indices (numpy.ndarray) – Non-masked image indices.

• merit (str) – Figure of merit that is used for the likelihood function (‘gaussian’ or ‘poisson’). Pixels are assumed to be independent measurements which are expected to be equal to zero in case the best-fit negative PSF template is injected. With ‘gaussian’, the variance is estimated from the pixel values within an annulus at the separation of the aperture (but excluding the pixels within the aperture). With ‘poisson’, a Poisson distribution is assumed for the variance of each pixel value.

• residuals (str) – Method used for combining the residuals (‘mean’, ‘median’, ‘weighted’, or ‘clipped’).

• var_noise (float, None) – Variance of the noise which is required when merit is set to ‘gaussian’ or ‘hessian’.

Returns:

Log posterior probability.

Return type:

float

## pynpoint.util.module module#

Functions for Pypeline modules.

pynpoint.util.module.angle_average(angles: ndarray) float[source]#

Function to calculate the average value of a list of angles.

Parameters:

angles (numpy.ndarray) – Parallactic angles (deg).

Returns:

Average angle (deg).

Return type:

float

pynpoint.util.module.angle_difference(angle_1: float, angle_2: float) float[source]#

Function to calculate the difference between two angles.

Parameters:
• angle_1 (float) – First angle (deg).

• angle_2 (float) – Second angle (deg).

Returns:

Angle difference (deg).

Return type:

float

pynpoint.util.module.input_info(pipeline_module: PypelineModule) None[source]#

Function to print information about the input data.

Parameters:

pipeline_module (PypelineModule) – Pipeline module.

Returns:

None

Return type:

NoneType

pynpoint.util.module.memory_frames(memory: int | int64, nimages: int) ndarray[source]#

Function to subdivide the input images is in quantities of MEMORY.

Parameters:
• memory (int) – Number of images that is simultaneously loaded into the memory.

• nimages (int) – Number of images in the stack.

Returns:

Array with the indices where a stack of images is subdivided.

Return type:

numpy.ndarray

pynpoint.util.module.module_info(pipeline_module: PypelineModule) None[source]#

Function to print the module name.

Parameters:

pipeline_module (PypelineModule) – Pipeline module.

Returns:

None

Return type:

NoneType

pynpoint.util.module.output_info(pipeline_module: PypelineModule, output_shape: Dict[str, Tuple[int, ...]]) None[source]#

Function to print information about the output data.

Parameters:
• pipeline_module (PypelineModule) – Pipeline module.

• output_shape (dict) – Dictionary with the output dataset names and shapes.

Returns:

None

Return type:

NoneType

pynpoint.util.module.progress(current: int, total: int, message: str, start_time: float | None = None) None[source]#

Function to show and update the progress as standard output.

Parameters:
• current (int) – Current index.

• total (int) – Total index number.

• message (str) – Message that is printed.

• start_time (float, None, optional) – Start time in seconds. Not used if set to None.

Returns:

None

Return type:

NoneType

pynpoint.util.module.stack_angles(memory: int | int64, parang: ndarray, max_rotation: float) ndarray[source]#

Function to subdivide the input images is in quantities of MEMORY with a restriction on the maximum field rotation across a subset of images.

Parameters:
• memory (int) – Number of images that is simultaneously loaded into the memory.

• parang (numpy.ndarray) – Parallactic angles (deg).

• max_rotation (float) – Maximum field rotation (deg).

Returns:

Array with the indices where a stack of images is subdivided.

Return type:

numpy.ndarray

pynpoint.util.module.update_arguments(index: int, nimages: int, args_in: tuple | None) tuple | None[source]#

Function to update the arguments of an input function. Specifically, arguments which contain an array with the first dimension equal in size to the total number of images will be substituted by the array element of the image index.

Parameters:
• index (int) – Image index in the stack.

• nimages (int) – Total number of images in the stack.

• args_in (tuple, None) – Function arguments that have to be updated.

Returns:

Updated function arguments.

Return type:

tuple, None

## pynpoint.util.multiline module#

Utilities for multiprocessing of lines in time with the poison pill pattern.

class pynpoint.util.multiline.LineProcessingCapsule(image_in_port: InputPort, image_out_port: OutputPort, num_proc: int, function: Callable, function_args: tuple | None, data_length: int)[source]#

Bases: MultiprocessingCapsule

Capsule for parallel processing of lines in time with the poison pill pattern. A function is applied in parallel to each line in time, for example as in WaveletTimeDenoisingModule.

Parameters:
• image_in_port (pynpoint.core.dataio.InputPort) – Input port.

• image_out_port (pynpoint.core.dataio.OutputPort) – Output port.

• num_proc (int) – Number of processors.

• function (function) – Input function that is applied to the lines.

• function_args (tuple, None, optional) – Function arguments.

• data_length (int) – Length of the processed data.

Returns:

None

Return type:

NoneType

Returns:

Return type:

init_creator(image_in_port: InputPort) [source]#
Parameters:

image_in_port (pynpoint.core.dataio.InputPort) – Input port from where the subsets of lines are read.

Returns:

Return type:

Parameters:
• data_port_in (pynpoint.core.dataio.InputPort) – Input port.

• data_mutex_in (multiprocessing.synchronize.Lock) – A mutex shared with the writer to ensure that no read and write operations happen at the same time.

• num_proc (int) – Number of processors.

• data_length (int) – Length of the processed data.

Returns:

None

Return type:

NoneType

run() None[source]#
Returns:

None

Return type:

NoneType

Processor of task inputs for LineProcessingCapsule. A processor applies a function on a row of lines in time.

Parameters:

• result_queue_in (multiprocessing.queues.JoinableQueue) – Results queue.

• function (function) – Input function.

• function_args (tuple, None) – Optional function arguments.

Returns:

None

Return type:

NoneType

Parameters:

Returns:

Return type:

## pynpoint.util.multipca module#

Capsule for multiprocessing of the PSF subtraction with PCA. Residuals are created in parallel for a range of principal components for which the PCA basis is required as input.

class pynpoint.util.multipca.PcaMultiprocessingCapsule(mean_out_port: OutputPort | None, median_out_port: OutputPort | None, weighted_out_port: OutputPort | None, clip_out_port: OutputPort | None, num_proc: int, pca_numbers: tuple | ndarray, pca_model: PCA | None, star_reshape: ndarray, angles: ndarray, scales: ndarray | None, im_shape: tuple, indices: ndarray | None, processing_type: str)[source]#

Bases: MultiprocessingCapsule

Capsule for PCA multiprocessing with the poison pill pattern.

Constructor of PcaMultiprocessingCapsule.

Parameters:
• mean_out_port (pynpoint.core.dataio.OutputPort) – Output port for the mean residuals.

• median_out_port (pynpoint.core.dataio.OutputPort) – Output port for the median residuals.

• weighted_out_port (pynpoint.core.dataio.OutputPort) – Output port for the noise-weighted residuals.

• clip_out_port (pynpoint.core.dataio.OutputPort) – Output port for the mean clipped residuals.

• num_proc (int) – Number of processors.

• pca_numbers (np.ndarray) – Number of principal components.

• pca_model (sklearn.decomposition.pca.PCA) – PCA object with the basis.

• star_reshape (np.ndarray) – Reshaped (2D) input images.

• angles (np.ndarray) – Derotation angles (deg).

• scales (np.ndarray) – scaling factors.

• im_shape (tuple(int, int, int)) – Original shape of the input images.

• indices (np.ndarray) – Non-masked pixel indices.

• processing_type (str) – selection of processing type

Returns:

None

Return type:

NoneType

Method to create a list of instances of PcaTaskProcessor.

Returns:

Return type:
create_writer(image_out_port: None) [source]#

Method to create an instance of PcaTaskWriter.

Parameters:

image_out_port (None) – Output port, not used.

Returns:

Return type:

init_creator(image_in_port: None) [source]#

Method to create an instance of PcaTaskCreator.

Parameters:

image_in_port (None) – Input port, not used.

Returns:

Return type:

The TaskCreator of the PCA multiprocessing. Creates one task for each principal component number. Does not require an input port since the data is directly given to the task processors.

Parameters:

• num_proc (int) – Number of processors.

• pca_numbers (np.ndarray, tuple) – Principal components for which the residuals are computed.

Returns:

None

Return type:

NoneType

run() None[source]#

Returns:

None

Return type:

NoneType

class pynpoint.util.multipca.PcaTaskProcessor(tasks_queue_in: JoinableQueue, result_queue_in: JoinableQueue, star_reshape: ndarray, angles: ndarray, scales: ndarray | None, pca_model: PCA | None, im_shape: tuple, indices: ndarray | None, requirements: Tuple[bool, bool, bool, bool], processing_type: str)[source]#

The TaskProcessor of the PCA multiprocessing is the core of the parallelization. An instance of this class will calculate one forward and backward PCA transformation given the pre-trained scikit-learn PCA model. It does not get data from the TaskCreator but uses its own copy of the input data, which are the same and independent for each task. The following residuals can be created:

• Mean residuals – requirements[0] = True

• Median residuals – requirements[1] = True

• Noise-weighted residuals – requirements[2] = True

• Clipped mean of the residuals – requirements[3] = True

Parameters:

• result_queue_in (multiprocessing.queues.JoinableQueue) – Input result queue.

• star_reshape (np.ndarray) – Reshaped (2D) stack of images.

• angles (np.ndarray) – Derotation angles (deg).

• scales (np.ndarray) – scaling factors

• pca_model (sklearn.decomposition.pca.PCA) – PCA object with the basis.

• im_shape (tuple(int, int, int)) – Original shape of the stack of images.

• indices (np.ndarray) – Non-masked image indices.

• requirements (tuple(bool, bool, bool, bool)) – Required output residuals.

• processing_type (str) – selected processing type.

Returns:

None

Return type:

NoneType

Parameters:

Returns:

Output residuals.

Return type:

class pynpoint.util.multipca.PcaTaskWriter(result_queue_in: JoinableQueue, mean_out_port: OutputPort | None, median_out_port: OutputPort | None, weighted_out_port: OutputPort | None, clip_out_port: OutputPort | None, data_mutex_in: Lock, requirements: Tuple[bool, bool, bool, bool])[source]#

The TaskWriter of the PCA parallelization. Four different ports are used to save the results of the task processors (mean, median, weighted, and clipped).

Parameters:
• result_queue_in (multiprocessing.queues.JoinableQueue) – Input result queue.

• mean_out_port (pynpoint.core.dataio.OutputPort) – Output port with the mean residuals. Not used if set to None.

• median_out_port (pynpoint.core.dataio.OutputPort) – Output port with the median residuals. Not used if set to None.

• weighted_out_port (pynpoint.core.dataio.OutputPort) – Output port with the noise-weighted residuals. Not used if set to None.

• clip_out_port (pynpoint.core.dataio.OutputPort) – Output port with the clipped mean residuals. Not used if set to None.

• data_mutex_in (multiprocessing.synchronize.Lock) – A mutual exclusion variable which ensure that no read and write simultaneously occur.

• requirements (tuple(bool, bool, bool, bool)) – Required output residuals.

Returns:

None

Return type:

NoneType

run() None[source]#

Run method of PcaTaskWriter. Writes the residuals to the output ports.

Returns:

None

Return type:

NoneType

## pynpoint.util.multiproc module#

Abstract interfaces for multiprocessing applications with the poison pill pattern.

class pynpoint.util.multiproc.MultiprocessingCapsule(image_in_port: InputPort | None, image_out_port: OutputPort | None, num_proc: int)[source]#

Bases: object

Abstract interface for multiprocessing capsules based on the poison pill pattern.

Parameters:
Returns:

None

Return type:

NoneType

abstract create_processors() None[source]#

Function that is called from the constructor to create a list of instances of TaskProcessor.

Returns:

None

Return type:

NoneType

create_writer(image_out_port: OutputPort | None) [source]#

Function that is called from the constructor to create the TaskWriter.

Parameters:

image_out_port (pynpoint.core.dataio.OutputPort, None) – Output port for the creator.

Returns:

Return type:

abstract init_creator(image_in_port: InputPort | None) None[source]#

Function that is called from the constructor to create a TaskCreator.

Parameters:

image_in_port (pynpoint.core.dataio.InputPort, None) – Input port for the task creator.

Returns:

None

Return type:

NoneType

run() None[source]#

Run method that starts the TaskCreator, the instances of TaskProcessor, and the TaskWriter. They will be shut down when all tasks have finished.

Returns:

None

Return type:

NoneType

class pynpoint.util.multiproc.TaskCreator(data_port_in: InputPort | None, tasks_queue_in: JoinableQueue, data_mutex_in: Lock | None, num_proc: int)[source]#

Bases: Process

Abstract interface for TaskCreator classes. A TaskCreator creates instances of TaskInput, which will be processed by the TaskProcessor, and appends them to the central task queue. In general there is only one TaskCreator running for a poison pill multiprocessing application. A TaskCreator communicates with to the TaskWriter in order to avoid simultaneously access to the central database.

Parameters:
• data_port_in (pynpoint.core.dataio.InputPort, None) – An input port which links to the data that has to be processed.

• data_mutex_in (multiprocessing.synchronize.Lock, None) – A mutex shared with the writer to ensure that no read and write operations happen at the same time.

• num_proc (int) – Maximum number of instances of TaskProcessor that run simultaneously.

Returns:

None

Return type:

NoneType

create_poison_pills() None[source]#

Creates poison pills for the TaskProcessor and TaskWriter. A process will shut down if it receives a poison pill as a new task. This method should be executed at the end of the run() method.

Returns:

None

Return type:

NoneType

abstract run() None[source]#

Returns:

None

Return type:

NoneType

class pynpoint.util.multiproc.TaskInput(input_data: ndarray | integer | tuple, job_parameter: tuple)[source]#

Bases: object

Parameters:
• input_data (int, float, np.ndarray) – Input data for by the TaskProcessor.

• job_parameter (tuple) – Additional data or parameters.

Returns:

None

Return type:

NoneType

Bases: Process

Abstract interface for TaskProcessor classes. The number of instances of TaskProcessor that run simultaneously in a poison pill multiprocessing application can be set with CPU parameter in the central configuration file. A TaskProcessor takes tasks from a task queue, processes the task, and stores the results back into a result queue. The process will shut down if the next task is a poison pill. The order in which process finish is not fixed.

Parameters:

• result_queue_in (multiprocessing.queues.JoinableQueue) – The result task queue with instances of TaskResult.

Returns:

None

Return type:

NoneType

Function to check if the next task is a poison pill.

Parameters:

Returns:

True if the next task is a poison pill, False otherwise.

Return type:

bool

run() None[source]#

Run method to start the TaskProcessor. The run method will continue to process tasks from the input task queue until it receives a poison pill.

Returns:

None

Return type:

NoneType

Abstract interface for the run_job() method which is called from the run() method for each task individually.

Parameters:

Returns:

None

Return type:

NoneType

Bases: object

Class for results that can be stored by the TaskWriter.

Parameters:
• data_array (np.ndarray) – Array with the results for a given position.

• position (tuple(tuple(int, int, int), tuple(int, int, int), tuple(int, int, int))) – The position where the results will be stored.

Returns:

None

Return type:

NoneType

class pynpoint.util.multiproc.TaskWriter(result_queue_in: JoinableQueue, data_out_port_in: OutputPort | None, data_mutex_in: Lock)[source]#

Bases: Process

The TaskWriter receives results from the result queue, which have been computed by a TaskProcessor, and stores the results in the central database. The position parameter of the TaskResult is used to slice the result to the correct position in the complete output dataset.

Parameters:
• result_queue_in (multiprocessing.queues.JoinableQueue) – The result queue.

• data_out_port_in (pynpoint.core.dataio.OutputPort, None) – The output port where the results will be stored.

• data_mutex_in (multiprocessing.synchronize.Lock) – A mutex that is shared with the TaskWriter which ensures that read and write operations to the database do not occur simultaneously.

Returns:

None

Return type:

NoneType

Function to check if the next result is a poison pill.

Parameters:

next_result (None, pynpoint.util.multiproc.TaskResult) – The next result.

Returns:

0 -> no poison pill, 1 -> poison pill, 2 -> poison pill but still results in the queue (rare error case).

Return type:

int

run() None[source]#

Run method of the TaskWriter. It is called once when it has to start storing the results until it receives a poison pill.

Returns:

None

Return type:

NoneType

pynpoint.util.multiproc.apply_function(tmp_data: ndarray, data_index: int, func: Callable, func_args: tuple | None) ndarray[source]#

Apply a function with optional arguments to the input data.

Parameters:
• tmp_data (np.ndarray) – Input data.

• data_index (int) – Index of the data subset. When processing a stack of images, the argument of data_index is the image index in the full stack.

• func (function) – Function.

• func_args (tuple, None) – Function arguments.

Returns:

The results of the function.

Return type:

np.ndarray

pynpoint.util.multiproc.to_slice(tuple_slice: tuple) tuple[source]#

Function to convert tuples into slices for a multiprocessing queue.

Parameters:

tuple_slice (tuple) – Tuple to be converted into a slice.

Returns:

Tuple with three slices.

Return type:

tuple(slice, slice, slice)

## pynpoint.util.multistack module#

Utilities for multiprocessing of stacks of images.

class pynpoint.util.multistack.StackProcessingCapsule(image_in_port: InputPort, image_out_port: OutputPort, num_proc: int, function: Callable, function_args: tuple | None, stack_size: int, result_shape: tuple, nimages: int)[source]#

Bases: MultiprocessingCapsule

Capsule for parallel processing of stacks of images with the poison pill pattern. A function is applied in parallel to each stack of images.

Parameters:
• image_in_port (pynpoint.core.dataio.InputPort) – Input port.

• image_out_port (pynpoint.core.dataio.OutputPort) – Output port.

• num_proc (int) – Number of processors.

• function (function) – Input function.

• function_args (tuple, None) – Function arguments.

• stack_size (int) – Number of images per stack.

• result_shape (tuple(int, )) – Shape of the array with output results (usually a stack of images).

• nimages (int) – Total number of images.

Returns:

None

Return type:

NoneType

Returns:

Return type:

init_creator(image_in_port: InputPort) [source]#
Parameters:

image_in_port (pynpoint.core.dataio.InputPort) – Input port from where the subsets of images are read.

Returns:

Return type:

class pynpoint.util.multistack.StackReader(data_port_in: InputPort, tasks_queue_in: JoinableQueue, data_mutex_in: Lock, num_proc: int, stack_size: int, result_shape: tuple)[source]#

Parameters:
• data_port_in (pynpoint.core.dataio.InputPort) – Input port.

• data_mutex_in (multiprocessing.synchronize.Lock) – A mutex shared with the writer to ensure that no read and write operations happen at the same time.

• num_proc (int) – Number of processors.

• stack_size (int) – Number of images per stack.

• result_shape (tuple(int, )) – Shape of the array with the output results (usually a stack of images).

Returns:

None

Return type:

NoneType

run() None[source]#
Returns:

None

Return type:

NoneType

class pynpoint.util.multistack.StackTaskProcessor(tasks_queue_in: JoinableQueue, result_queue_in: JoinableQueue, function: Callable, function_args: tuple | None, nimages: int)[source]#

Processor of task inputs for StackProcessingCapsule. A processor applies a function on a stack of images.

Parameters:

• result_queue_in (multiprocessing.queues.JoinableQueue) – Results queue.

• function (function) – Input function that is applied to the images.

• function_args (tuple, None) – Function arguments.

• nimages (int) – Total number of images.

Returns:

None

Return type:

NoneType

Parameters:

Returns:

Return type:

## pynpoint.util.postproc module#

Functions for post-processing.

pynpoint.util.postproc.postprocessor(images: ndarray, angles: ndarray, scales: ndarray | None, pca_number: int | Tuple[int | int32 | int64, int | int32 | int64], pca_sklearn: PCA | None = None, im_shape: None | tuple = None, indices: ndarray | None = None, mask: ndarray | None = None, processing_type: str = 'ADI')[source]#

Function to apply different kind of post processings. It is equivalent to pca_psf_subtraction() if processing_type='ADI'` and ``mask=None.

Parameters:
• images (np.array) – Input images which should be reduced.

• angles (np.ndarray) – Derotation angles (deg).

• scales (np.array) – Scaling factors

• pca_number (tuple(int, int)) – Number of principal components used for the PSF subtraction.

• pca_sklearn (sklearn.decomposition.pca.PCA, None) – PCA object with the basis if not set to None.

• im_shape (tuple(int, int, int), None) – Original shape of the stack with images. Required if pca_sklearn is not set to None.

• indices (np.ndarray, None) – Non-masked image indices. All pixels are used if set to None.

• processing_type (str) –

Post-processing type:

• SDI: Spectral differential imaging.

• SDI+ADI: Spectral and angular differential imaging.

• ADI+SDI: Angular and spectral differential imaging.

Returns:

• np.ndarray – Residuals of the PSF subtraction.

• np.ndarray – Derotated residuals of the PSF subtraction.

## pynpoint.util.psf module#

Functions for PSF subtraction.

pynpoint.util.psf.pca_psf_subtraction(images: ndarray, angles: ndarray | None, pca_number: int | int32 | int64, scales: ndarray | None = None, pca_sklearn: PCA | None = None, im_shape: tuple | None = None, indices: ndarray | None = None) Tuple[ndarray, ndarray][source]#

Function for PSF subtraction with PCA.

Parameters:
• images (np.ndarray) – Stack of images. Also used as reference images if `pca_sklearn` is set to None. The data should have the original 3D shape if pca_sklearn is set to None or it should be in a 2D reshaped format if pca_sklearn is not set to None.

• angles (np.ndarray) – Parallactic angles (deg).

• pca_number (int) – Number of principal components.

• scales (np.ndarray, None) – Scaling factors for SDI. Not used if set to None.

• pca_sklearn (sklearn.decomposition.pca.PCA, None) – PCA object with the principal components.

• im_shape (tuple(int, int, int), None) – The original 3D shape of the stack with images. Only required if pca_sklearn is not set to None.

• indices (np.ndarray, None) – Array with the indices of the pixels that are used for the PSF subtraction. All pixels are used if set to None.

Returns:

• np.ndarray – Residuals of the PSF subtraction.

• np.ndarray – Derotated residuals of the PSF subtraction.

## pynpoint.util.remove module#

Functions to write selected data and attributes to the database.

pynpoint.util.remove.write_selected_attributes(indices: ndarray, image_in_port: InputPort, selected_out_port: OutputPort | None, removed_out_port: OutputPort | None, module_type: str, history: str) None[source]#

Function to write the attributes of the selected and removed data.

Parameters:
• indices (numpy.ndarray) – Image indices that will be removed.

• image_in_port (pynpoint.core.dataio.InputPort) – Port to the input data.

• selected_out_port (pynpoint.core.dataio.OutputPort, None) – Port to store the attributes of the selected images. Not written if set to None.

• removed_out_port (pynpoint.core.dataio.OutputPort, None) – Port to store the attributes of the removed images. Not written if set to None.

• module_type (str) –

• history (str) –

Returns:

None

Return type:

NoneType

pynpoint.util.remove.write_selected_data(memory: int | int64, indices: ndarray, image_in_port: InputPort, selected_out_port: OutputPort | None, removed_out_port: OutputPort | None) None[source]#

Function to write the selected and removed data.

Parameters:
• memory (int) – Number of images that is simultaneously loaded into the memory.

• indices (numpy.ndarray) – Image indices that will be removed.

• image_in_port (pynpoint.core.dataio.InputPort) – Port to the input images.

• selected_out_port (pynpoint.core.dataio.OutputPort, None) – Port to store the selected images. No data is written if set to None.

• removed_out_port (pynpoint.core.dataio.OutputPort, None) – Port to store the removed images. No data is written if set to None.

Returns:

None

Return type:

NoneType

## pynpoint.util.residuals module#

Functions for combining the residuals of the PSF subtraction.

pynpoint.util.residuals.combine_residuals(method: str, res_rot: ndarray, residuals: ndarray | None = None, angles: ndarray | None = None) ndarray[source]#

Wavelength wrapper for the combine_residual function. Produces an array with either 1 or number of wavelengths sized array.

Parameters:
• method (str) – Method used for combining the residuals (‘mean’, ‘median’, ‘weighted’, or ‘clipped’).

• res_rot (np.ndarray) – Derotated residuals of the PSF subtraction (3D).

• residuals (np.ndarray, None) – Non-derotated residuals of the PSF subtraction (3D). Only required for the noise-weighted residuals.

• angles (np.ndarray, None) – Derotation angles (deg). Only required for the noise-weighted residuals.

Returns:

Collapsed residuals (3D).

Return type:

np.ndarray

## pynpoint.util.sdi module#

Functions for spectral differential imaging.

pynpoint.util.sdi.scaling_factors(wavelengths: ndarray) ndarray[source]#

Function to calculate the scaling factors for SDI.

Parameters:

wavelengths (np.ndarray) – Array with the wavelength of each frame.

Returns:

Scaling factors.

Return type:

np.ndarray

pynpoint.util.sdi.sdi_scaling(image_in: ndarray, scaling: ndarray) ndarray[source]#

Function to rescale the images by their wavelength ratios.

Parameters:
• image_in (np.ndarray) – Data to rescale

• scaling (np.ndarray) – Scaling factors.

Returns:

Rescaled images with the same shape as image_in.

Return type:

np.ndarray

## pynpoint.util.star module#

Functions for stellar extraction.

pynpoint.util.star.locate_star(image: ndarray, center: tuple | None, width: int | None, fwhm: int | None) ndarray[source]#

Function to locate the star by finding the brightest pixel.

Parameters:
• image (numpy.ndarray) – Input image (2D).

• center (tuple(int, int), None) – Pixel center (y, x) of the subframe. The full image is used if set to None.

• width (int, None) – The width (pix) of the subframe. The full image is used if set to None.

• fwhm (int, None) – Full width at half maximum (pix) of the Gaussian kernel. Not used if set to None.

Returns:

Position (y, x) of the brightest pixel.

Return type:

numpy.ndarray

pynpoint.util.star.star_positions(input_port: InputPort, fwhm: int | None, position: Tuple[int, int, float] | Tuple[None, None, float] | Tuple[int, int, None] | None = None) ndarray[source]#

Function to return the position of the star in each image.

Parameters:
• input_port (pynpoint.core.dataio.InputPort) – Input port where the images are stored.

• fwhm (int, None) – The FWHM (pix) of the Gaussian kernel that is used to smooth the images before the brightest pixel is located. No smoothing is applied if set to None.

• position (tuple(int, int, int), None) – Subframe that is selected to search for the star. The tuple contains the center (pix) and size (pix) (pos_x, pos_y, size). Setting position to None will use the full image to search for the star. If position=(None, None, size) then the center of the image will be used. If position=(pos_x, pos_y, None) then a fixed position is used for the aperture.

Returns:

Positions (y, x) of the brightest pixel.

Return type:

numpy.ndarray

## pynpoint.util.tests module#

Functions for testing the pipeline and its modules.

pynpoint.util.tests.create_config(filename: str) None[source]#

Create a configuration file.

Parameters:

filename (str) – Configuration filename.

Returns:

None

Return type:

NoneType

pynpoint.util.tests.create_dither_data(path: str) None[source]#

Create a dithering dataset with a stellar PSF.

Parameters:

path (str) – Working folder.

Returns:

None

Return type:

NoneType

pynpoint.util.tests.create_fake_data(path: str) None[source]#

Create an ADI dataset with a star and planet.

Parameters:

path (str) – Working folder.

Returns:

None

Return type:

NoneType

pynpoint.util.tests.create_fits(path: str, filename: str, image: ndarray, ndit: int, exp_no: int, dither_x: float, dither_y: float) None[source]#

Create a FITS file with images and header information.

Parameters:
• path (str) – Working folder.

• filename (str) – FITS filename.

• image (np.ndarray) – Images.

• ndit (int) – Number of integrations.

• exp_no (int) – Exposure number.

• dither_x (float) – Horizontal dither position relative to the image center.

• dither_y (float) – Vertical dither position relative to the image center.

Returns:

None

Return type:

NoneType

pynpoint.util.tests.create_ifs_data(path: str) None[source]#

Create an IFS dataset with a star and planet.

Parameters:

path (str) – Working folder.

Returns:

None

Return type:

NoneType

pynpoint.util.tests.create_near_data(path: str) None[source]#

Create a stack of images with Gaussian distributed pixel values.

Parameters:

path (str) – Working folder.

Returns:

None

Return type:

NoneType

pynpoint.util.tests.create_random(path: str, nimages: float = 5) None[source]#

Create a dataset of images with Gaussian distributed pixel values.

Parameters:
• path (str) – Working folder.

• nimages (int) – Number of images.

Returns:

None

Return type:

NoneType

pynpoint.util.tests.create_star_data(path: str, npix: int = 11, pos_star: float = 5.0) None[source]#

Create a dataset with a PSF and Gaussian noise.

Parameters:
• path (str) – Working folder.

• npix (int) – Number of pixels in each dimension.

Returns:

None

Return type:

NoneType

pynpoint.util.tests.create_waffle_data(path: str) None[source]#

Create data with satellite spots and Gaussian noise.

Parameters:

path (str) – Working folder.

Returns:

None

Return type:

NoneType

pynpoint.util.tests.remove_test_data(path: str, folders: List[str] | None = None, files: List[str] | None = None) None[source]#

Function to remove data created by the test cases.

Parameters:
• path (str) – Working folder.

• folders (list(str, )) – Folders to remove.

• files (list(str, )) – Files to removes.

Returns:

None

Return type:

NoneType

## pynpoint.util.wavelets module#

Wrapper utils for the wavelet functions for the mlpy cwt implementation (see continous.py)

class pynpoint.util.wavelets.WaveletAnalysisCapsule(signal_in: ndarray, wavelet_in: str = 'dog', order: int = 2, padding: str = 'none', frequency_resolution: float = 0.5)[source]#

Bases: object

Capsule class to process one 1d time series using the CWT and wavelet de-nosing by wavelet shrinkage.

Parameters:
• signal_in (numpy.ndarray) – 1D input signal.

• wavelet_in (str) – Wavelet function (‘dog’ or ‘morlet’).

• order (int) – Order of the wavelet function.

• frequency_resolution (float) – Wavelet space resolution in scale/frequency.

Returns:

None

Return type:

NoneType

compute_cwt() None[source]#

Compute the wavelet space of the given input signal.

Returns:

None

Return type:

NoneType

denoise_spectrum(soft: bool = False) None[source]#

Applies wavelet shrinkage on the current wavelet space (m_spectrum) by either a hard of soft threshold function.

Parameters:

soft (bool) – If True a soft threshold is used, hard otherwise.

Returns:

None

Return type:

NoneType

get_signal() ndarray[source]#

Returns the current version of the 1d signal. Use update_signal() in advance in order to get the current reconstruction of the wavelet space. Removes padded values as well.

Returns:

Current version of the 1D signal.

Return type:

numpy.ndarray

median_filter() None[source]#

Applies a median filter on the internal 1d signal. Can be useful for cosmic ray correction after temporal de-noising

Returns:

None

Return type:

NoneType

update_signal() None[source]#

Updates the internal signal by the reconstruction of the current wavelet space.

Returns:

None

Return type:

NoneType