hdrl.func

HDRL Functionalities submodule This module provides the features to implement the HDRL functionalities.

class hdrl.func.AirmassApprox

Members:

Hardie

YoungIrvine

Young

property name
class hdrl.func.BPM

The hdrl.func.BPM class provides an interface to various Bad Pixel Mask algorithms. This module contains static functions to detect bad pixels on single images, on a stack of identical images, and on a sequence of images.

static filter(input_mask: cpl.core.Mask, kernel_nx: SupportsInt, kernel_ny: SupportsInt, filter: _cpl_filter_mode_) cpl.core.Mask

Sets pixels to bad if the pixel is surrounded by other bad pixels. Allows the growing and shrinking of bad pixel masks.

The algorithm assumes that all pixels outside the mask are good, i.e. it enlarges the mask by the kernel size and marks this border as good. It applies on the enlarged mask during the operation and extracts the original-size mask at the very end.

Parameters:
  • input_mask (cpl.core.Mask) – Input mask

  • kernel_nx (int) – Size in x-direction of the filtering kernel

  • kernel_ny (int) – Size in y-direction of the filtering kernel

  • filter (cpl.core.Filter mode) – Filter modes as defined in PyCPL. Supported modes: cpl.core.Filter.EROSION, cpl.core.Filter.DILATION, cpl.core.Filter.OPENING, cpl.core.Filter.CLOSING, cpl.core.Filter.LINEAR

Returns:

mask of a defined size.

Return type:

cpl.core.Mask

See also

hdrl.func.BPM.filter_list

Wrapper around hdrl.func.BPM.filter() to filter list of images.

static filter_list(inlist: cpl.core.ImageList, kernel_nx: SupportsInt, kernel_ny: SupportsInt, filter: _cpl_filter_mode_) cpl.core.ImageList

Wrapper around hdrl.func.BPM.filter() to filter list of images

Parameters:
  • inlist (cpl.core.ImageList) – Input image list

  • kernel_nx (int) – Size in x-direction of the filtering kernel

  • kernel_ny (int) – Size in y-direction of the filtering kernel

  • filter (cpl.core.Filter mode) – Filter modes as defined in PyCPL. Supported modes: cpl.core.Filter.EROSION, cpl.core.Filter.DILATION, cpl.core.Filter.OPENING, cpl.core.Filter.CLOSING, cpl.core.Filter.LINEAR

Returns:

the filtered image list.

Return type:

cpl.core.ImageList

See also

hdrl.func.BPM.filter

Sets pixels to bad if the pixel is surrounded by other bad pixels.

class hdrl.func.BPM2D

The hdrl.func.BPM2D class provides an interface to the bad pixel mask 2D algorithm. Bad pixels on single images, on a stack of identical images, and on a sequence of images can be detected.

The algorithm first smoothes the image by applying different methods. Then it subtracts the smoothed image and derives bad pixels by thresholding the residual image, i.e. all pixels exceeding the threshold are considered bad.

In order to create instances of the hdrl.func.BPM2D class, two methods are available depending on the smoothing algorithm used, namely hdrl.func.BPM2D.Method.Filter and hdrl.func.BPM2D.Method.Legendre.

class Method

The method to be used when creating an instance of the hdrl.func.BPM2D class.

Members:

Legendre :

This algorithm will use Legendre smoothing techniques to detect bad pixels. Fitting a Legendre polynomial to the image of order order_x in x and order_y in y direction. This method allows you to define steps_x \(\times\) steps_y sampling points (the latter are computed as the median within a box of filter_size_x and filter_size_y) where the polynomial is fitted. This substantially decreases the fitting time for the Legendre polynomial.

Filter :

This algorithm will use Filter smoothing techniques to detect bad pixels. Applying a filter like a median filter to the image. The filtering can be done by all modes currently supported by PyCPL and is controlled by the cpl.core.Filter type filter, the cpl.core.Border type border, and by the kernel size in x and y, i.e. smooth_x, and smooth_y.

property name
static Filter(kappa_low: SupportsFloat, kappa_high: SupportsFloat, maxiter: SupportsInt, filter: _cpl_filter_mode_, border: _cpl_border_mode_, smooth_x: SupportsInt, smooth_y: SupportsInt) hdrl.func.BPM2D

Creates an instance of hdrl.func.BPM2D class for the method hdrl.func.BPM2D.Method.Filter

Parameters:
  • kappa_low (float) – Low kappa factor for thresholding algorithm

  • kappa_high (float) – High kappa factor for thresholding algorithm

  • maxiter (int) – Maximum number of iterations

  • filter (cpl.core.Filter mode) – Filter mode as defined in PyCPL. Supported modes: cpl.core.Filter.EROSION, cpl.core.Filter.DILATION, cpl.core.Filter.OPENING, cpl.core.Filter.CLOSING, cpl.core.Filter.LINEAR

  • border (cpl.core.Border mode) – Border mode as defined in PyCPL. Supported modes: cpl.core.Border.FILTER. cpl.core.Border.ZERO, cpl.core.Border.CROP, cpl.core.Border.NOP, cpl.core.Border.COPY

  • smooth_x (int) – Smoothing kernel size in the x-direction

  • smooth_y (int) – Smoothing kernel size in the y-direction

Returns:

An instance of the hdrl.func.BPM2D class for the method hdrl.func.BPM2D.Method.Filter.

Return type:

The hdrl.func.BPM2D

Example

fs = hdrl.func.BPM2D.Filter(4.0, 5.0, 6, cpl.core.Filter.MEDIAN, cpl.core.Border.NOP, 7, 9)

Notes

Filter smooth algorithm: This instance applies a filter like e.g. a median filter to the image. The filtering can be done by all modes currently supported by CPL and is controlled by the filter type, the border type and the kernel size in x and y.

See also

hdrl.func.BPM2D.Legendre

Creates an instance of hdrl.func.BPM2D class for the method hdrl.func.BPM2D.Method.Legendre.

hdrl.func.BPM2D.compute

Detect bad pixels on a single image with an iterative process.

static Legendre(kappa_low: SupportsFloat, kappa_high: SupportsFloat, maxiter: SupportsInt, steps_x: SupportsInt, steps_y: SupportsInt, filter_size_x: SupportsInt, filter_size_y: SupportsInt, order_x: SupportsInt, order_y: SupportsInt) hdrl.func.BPM2D

Creates an instance of hdrl.func.BPM2D class for the method hdrl.func.BPM2D.Method.Legendre.

Parameters:
  • kappa_low (float) – Low kappa factor for the thresholding algorithm

  • kappa_high (float) – High kappa factor for the thresholding algorithm

  • maxiter (int) – Maximum number of iterations

  • steps_x (int) – Number of sampling points in the x-direction

  • steps_y (int) – Number of sampling points in the y-direction

  • filter_size_x (int) – Size of the median box in the x-direction

  • filter_size_y (int) – Size of the median box in the y-direction

  • order_x (int) – Order of polynomial in the x-direction

  • order_y (int) – Order of polynomial in the y-direction

Returns:

An instance of the hdrl.func.BPM2D class for the method hdrl.func.BPM2D.Method.Legendre.

Return type:

The hdrl.func.BPM2D

Example

ls = hdrl.func.BPM2D.Legendre(4, 5, 6, 20, 21, 11, 12, 2, 10)

Notes

This instance of a hdrl.func.BPM2D class fits a Legendre polynomial to the image of order order_x, in x and order_y in y direction. This method allows you to define steps_x and steps_y sampling points (the latter are computed as the median within a box of filter_size_x and filter_size_y) where the polynomial is fitted. This substantially decreases the fitting time for the Legendre polynomial.

See also

hdrl.func.BPM2D.compute

Detect bad pixels on a single image with an iterative process.

hdrl.func.BPM2D.Filter

Creates an instance of hdrl.func.BPM2D for the method hdrl.func.BPM2D.Method.Filter.

compute(self: hdrl.func.BPM2D, img_in: hdrl.core.Image) cpl.core.Mask

Detects bad pixels on a single image with an iterative process

Parameters:

img_in (hdrl.core.Image) – Input image

Returns:

Bad pixel mask with the newly found bad pixels.

Return type:

cpl.core.Mask

Notes

The algorithm first smoothes the image by applying the methods described under hdrl.func.BPM2D.Filter or hdrl.func.BPM2D.Legendre. Then it subtracts the smoothed image and derives bad pixels by thresholding the residual image, i.e. all pixels exceeding the threshold are considered bad. To compute the upper and lower thresholds, it measures a robust rms (a properly scaled Median Absolute Deviation), which is then scaled by the parameters kappa_low and kappa_high. Furthermore, the algorithm is applied iteratively controlled by maxiter. During each iteration, the newly found bad pixels are ignored. Please note that the thresholding values are applied as median (residual-image) \(\pm\) thresholds. This makes the algorithm more robust in the case that the methods are not able to completely remove the background level, e.g due to an exceeding number of bad pixels in the first iteration.

See also

hdrl.func.BPM2D.Filter

Creates an instance of hdrl.func.BPM2D class for the method hdrl.func.BPM2D.Method.Filter.

hdrl.func.BPM2D.Legendre

Creates an instance of hdrl.func.BPM2D class for the method hdrl.func.BPM2D.Method.Legendre.

property border

border mode

Type:

cpl.core.Border

property filter

filter mode

Type:

cpl.core.Filter

property filter_size_x

Size of the median box in the x-direction

Type:

int

property filter_size_y

Size of the median box in the y-direction

Type:

int

property kappa_high

High kappa factor for thresholding algorithm

Type:

float

property kappa_low

Low kappa factor for thresholding algorithm

Type:

float

property maxiter

Maximum number of iterations

Type:

int

property method

Selected algorithm method

Type:

hdrl.func.BPM2D.Method

property order_x

Order of polynomial in the x-direction

Type:

int

property order_y

Order of polynomial in the y-direction

Type:

int

property smooth_x

Smoothing kernel size in the x-direction

Type:

int

property smooth_y

Smoothing kernel size in the y-direction

Type:

int

property steps_x

Number of sampling points in the x-direction

Type:

int

property steps_y

Number of sampling points in the y-direction

Type:

int

class hdrl.func.BPM3D

The hdrl.func.BPM3D class provides an interface to the bad pixel mask 3D algorithm. This algorithm detects bad pixels on a stack of identical images in an imagelist. Once the class is instantiated with the desired parameters, the compute function may be called to run the algorithm.

Parameters:
  • kappa_low (float) – Low kappa factor for thresholding algorithm

  • kappa_high (float) – High kappa factor for thresholding algorithm

  • method (hdrl.func.BPM3D.Method) – Selected algorithm method

Return type:

hdrl.func.BPM3D

Notes

There are three algorithm methods to be selected from:

  • hdrl.func.BPM3D.Method.Absolute: It uses kappa_low and kappa_high as absolute threshold.

  • hdrl.func.BPM3D.Method.Relative: It scales the measured rms on the residual-image with kappa_low and kappa_high and uses it as threshold. For the rms a properly scaled Median Absolute Deviation (MAD) is used.

  • hdrl.func.BPM3D.Method.Error: It scales the propagated error of each individual pixel with kappa_low and kappa_high and uses it as threshold.

Example

bpm_3d = hdrl.func.BPM3D(4, 5, hdrl.func.BPM3D.Method.Absolute)
bpm_3d = hdrl.func.BPM3D(4, 5, hdrl.func.BPM3D.Method.Relative)
bpm_3d = hdrl.func.BPM3D(4, 5, hdrl.func.BPM3D.Method.Error)

See also

hdrl.func.BPM3D.compute

Detect bad pixels on a stack of identical images.

class Method

The method to be used when creating an instance of the hdrl.func.BPM3D class.

Members:

Absolute :

Uses kappa_low and kappa_high as absolute thresholds.

Relative :

Scales the measured RMS on the residual image with kappa_low and kappa_high and uses it as thresholds. For the rms a properly scaled Median Absolute Deviation (MAD) is used.

Error :

Scales the propagated error of each individual pixel with kappa_low and kappa_high and uses it as a threshold.

property name
compute(self: hdrl.func.BPM3D, imglist_in: hdrl.core.ImageList) cpl.core.ImageList

Detects bad pixels on a stack of identical images.

Parameters:

imglist (hdrl.core.ImageList) – input imagelist.

Returns:

imagelist containing the newly found bad pixels for each input image with the same pixel coding as for a cpl.core.Mask bad pixel mask, i.e. 0 for good pixels and 1 for bad pixels. Please note that already known bad pixels given to the routine will not be included in the output mask.

Return type:

cpl.core.ImageList

Notes

The algorithm first collapses the stack of images by using the median in order to generate a master image. Then it subtracts the master image from each individual image and derives the bad pixels on the residual images by thresholding, i.e. all pixels exceeding the threshold are considered bad.

Please note that the algorithm assumes that the mean level of the different images is the same. If this is not the case, then the master image as described above will be biased.

See also

hdrl.func.BPM3D

Creates an instance of the hdrl.func.BPM3D class for the imagelist method.

property kappa_high

High kappa factor for thresholding algorithm

Type:

float

property kappa_low

Low kappa factor for thresholding algorithm

Type:

float

property method

Selected algorithm method

Type:

hdrl.func.BPM3D.Method

class hdrl.func.BPMFit

The hdrl.func.BPMFit module provides an interface to various bad pixel mask fit algorithms to detect bad pixels on a sequence of images e.g. domeflats.

The algorithm fits a polynomial to each pixel sequence and determines bad pixels based on this fit and various thresholding methods.

Three thresholding methods are available to convert the information from the fit into a bad pixel map:

  • PVal: Pixels with p-values below the mentioned threshold are considered as bad pixels.

  • RelChi: Pixels with a chi value below the mentioned threshold are considered as bad pixels.

  • RelCoef: Pixels with a fit coefficient below the mentioned threshold are considered as bad pixels.

In order to create an instance of the hdrl.func.BPMFit class, three constructors corresponding to the above methods are available.

static PVal(degree: SupportsInt, pval: SupportsFloat) hdrl.func.BPMFit

Creates an instance of hdrl.func.BPMFit class for the p-value method.

Parameters:
  • degree (int) – The degree of the fit

  • pval (float) – The p-value bpm cutoff

Notes

Pixels with low p-value. When the errors of the pixels are correct the p-value can be interpreted as the probability with which the pixel response fits the chosen model.

See also

hdrl.func.BPMFit.compute

Derives bad pixels on a sequence of images by fitting a polynomial along each pixel sequence of the images.

hdrl.func.BPMFit.RelChi

Creates an instance of hdrl.func.BPMFit class with relative chi bpm threshold.

hdrl.func.BPMFit.RelCoef

Creates an instance of hdrl.func.BPMFit class with relative coefficient bpm threshold.

static RelChi(degree: SupportsInt, low: SupportsFloat, high: SupportsFloat) hdrl.func.BPMFit

Creates an instance of hdrl.func.BPMFit class with a relative chi bpm threshold.

Parameters:
  • degree (int) – The degree of the fit

  • low (float) – Relative chi distribution bpm lower threshold

  • high (float) – Relative chi distribution bpm upper threshold

Return type:

hdrl.func.BPMFit

Notes

Relative cutoff on the chi distribution of all fits. Pixels with chi values which exceed mean \(\pm\) cutoff \(\times\) standard deviation are considered bad.

See also

hdrl.func.BPMFit.compute

Derives bad pixels on a sequence of images by fitting a polynomial along each pixel sequence of the images.

hdrl.func.BPMFit.PVal

Creates an instance of hdrl.func.BPMFit class with p-value bpm threshold.

hdrl.func.BPMFit.RelCoef

Creates an instance of hdrl.func.BPMFit class with relative coefficient bpm threshold.

static RelCoef(degree: SupportsInt, low: SupportsFloat, high: SupportsFloat) hdrl.func.BPMFit

Creates an instance of hdrl.func.BPMFit class with relative coefficient bpm threshold.

Parameters:
  • degree (int) – The degree of the fit

  • low (float) – Relative fit coefficient distribution bpm lower threshold

  • high (float) – Relative fit coefficient distribution bpm upper threshold

Return type:

hdrl.func.BPMFit

Notes

Relative cutoff on the distribution of the fit coefficients. Pixels with fit coefficients which exceed mean \(\pm\) cutoff \(\times\) standard deviation are considered bad.

See also

hdrl.func.BPMFit.compute

Derives bad pixels on a sequence of images by fitting a polynomial along each pixel sequence of the images.

hdrl.func.BPMFit.PVal

Creates an instance of hdrl.func.BPMFit class with p-value bpm threshold.

hdrl.func.BPMFit.RelChi

Creates an instance of hdrl.func.BPMFit class with relative chi bpm threshold.

compute(self: hdrl.func.BPMFit, imglist_in: hdrl.core.ImageList, sample_position: cpl.core.Vector) cpl.core.Image

Derives bad pixels on a sequence of images by fitting a polynomial along each pixel sequence of the images.

Parameters:
  • imglist_in (hdrl.core.ImageList) – imagelist to fit

  • sample_position (cpl.core.Vector) – vector of sampling position of the images in data, e.g. exposure time

Returns:

image with cpl.core.Type.INT pixels containing the newly found bad pixels for each input image

Return type:

cpl.core.Image

Notes

When using hdrl.func.BPMFit.RelCoef the value of the returned image encodes the coefficient that was outside the relative threshold as a power of two. e.g. if coefficient 0 and 3 of the fit were not within the threshold for a pixel, it will have the value \(2^0 + 2^3 = 9\). The other hdrl.func.BPMFit algorithms return an image with non-zero values marking pixels outside the selection thresholds.

Please note that already known bad pixels given to the routine will not be included in the output mask.

See also

hdrl.func.BPMFit.PVal

Creates an instance of hdrl.func.BPMFit class with p-value bpm threshold.

hdrl.func.BPMFit.RelChi

Creates an instance of hdrl.func.BPMFit class with relative chi bpm threshold.

hdrl.func.BPMFit.RelCoef

Creates an instance of hdrl.func.BPMFit class with relative coefficient bpm threshold.

property chi_high

Relative chi distribution bpm upper threshold

Type:

float

property chi_low

Relative chi distribution bpm lower threshold

Type:

float

property coef_high

Relative fit coefficient distribution bpm upper threshold

Type:

float

property coef_low

Relative fit coefficient distribution bpm lower threshold

Type:

float

property degree

The degree of the fit

Type:

int

property pval

The p-value bpm cutoff

Type:

float

class hdrl.func.Catalogue

A hdrl.func.Catalogue class provides an interface to object detection and catalogue generation from astronomical images.

compute(self: hdrl.func.Catalogue, image: cpl.core.Image, confidence_map: cpl.core.Image = None, wcs: cpl.drs.WCS = None) hdrl.func.CatalogueResult

Compute object catalogue from an astronomical image.

This function builds an object catalogue from the input image. The algorithm performs local sky background estimation and removal, detects objects and blends, assigns image pixels to each object, and performs astrometry, photometry and shape analysis on the detected objects.

Parameters:
  • image (cpl.core.Image) – Input image for catalogue computation. The image should be in units of ADU (Analog-to-Digital Units).

  • confidence_map (cpl.core.Image, optional) – Optional confidence map providing uncertainty information for each pixel. If None, no confidence map is used. Must contain only positive numbers if provided.

  • wcs (cpl.core.WCS, optional) – Optional WCS information for astrometric measurements. If None, no WCS information is used and astrometry will not be performed.

Returns:

A result object containing: - catalogue: cpl.core.Table with the object catalogue including positions, fluxes, and shape parameters - segmentation_map: cpl.core.Image with the segmentation map showing object assignments - background: cpl.core.Image with the estimated background - qclist: cpl.core.PropertyList with quality control information

Return type:

hdrl.func.CatalogueResult

Example

# Load image and WCS
image = cpl.core.Image.load("science_image.fits")
wcs = cpl.drs.WCS(cpl.core.PropertyList.load("science_image.fits"))

# Create catalogue object
cat = hdrl.func.Catalogue(
    obj_min_pixels=10,
    obj_threshold=3.0,
    obj_deblending=True,
    obj_core_radius=2.0,
    bkg_estimate=True,
    bkg_mesh_size=64,
    bkg_smooth_fwhm=2.0,
    det_eff_gain=1.0,
    det_saturation=65535.0,
    resulttype=7
)

# Compute catalogue
result = cat.compute(image, wcs=wcs)

# Access results
catalogue = result.catalogue
segmap = result.segmentation_map
background = result.background
qc_info = result.qclist

Notes

The confidence_map must contain only positive numbers if provided.

The function automatically handles image type conversion to double precision if needed.

Raises:
  • hdrlcore.NullInputError – If image is None.

  • hdrlcore.IllegalInputError – If parameter validation fails (e.g., invalid parameter values).

  • hdrlcore.IncompatibleInputError – If confidence_map contains negative values or other incompatible inputs.

property bkg_estimate

Estimate background from input

Type:

bool

property bkg_mesh_size

Background smoothing box size

Type:

int

property bkg_smooth_fwhm

FWHM of Gaussian kernel for object detection

Type:

float

property det_eff_gain

Detector gain value

Type:

float

property det_saturation

Detector saturation value

Type:

float

property obj_core_radius

Value of Rcore in pixels

Type:

float

property obj_deblending

Use deblending algorithm

Type:

bool

property obj_min_pixels

Minimum pixel area for each detected object

Type:

int

property obj_threshold

Detection threshold in sigma above sky

Type:

float

property resulttype

Requested output type

Type:

int

class hdrl.func.CatalogueResult

A hdrl.func.CatalogueResult class is a container for the results of hdrl.func.Catalogue.compute(). The results consist of a catalogue table, segmentation map, background image, and quality control information.

These can be accessed via the catalogue, segmentation_map, background, and qclist attributes of the object.

Example

result = hdrl.func.Catalogue.compute(image, wcs=wcs)
catalogue = result.catalogue
segmap = result.segmentation_map
background = result.background
qc_info = result.qclist
property background

Estimated background image

Type:

cpl.core.Image

property catalogue

Object catalogue with positions, fluxes, and shape parameters

Type:

cpl.core.Table

property qclist

Quality control information

Type:

cpl.core.PropertyList

property segmentation_map

Segmentation map showing object assignments

Type:

cpl.core.Image

class hdrl.func.Collapse

A hdrl.func.Collapse is a helper class consisting of static functions that conduct Collapse operations like sum, mean, or standard deviation with an hdrl.core.Imagelist. hdrl.func.Collapse class cannot be instantiated on its own, but only via one of the following constructors: - hdrl.func.Collapse.Mean: Mean Collapse operation on HDRL ImageList. - hdrl.func.Collapse.Median: Median Collapse operation on HDRL ImageList. - hdrl.func.Collapse.SigClip: Sigma Clipped Collapse operation on HDRL ImageList. - hdrl.func.Collapse.MinMax: Min-Max Clipped Collapse operation on HDRL ImageList. - hdrl.func.Collapse.Mode: Mode Collapse operation on HDRL ImageList.

Once the constructors are set up with the desired parameters, you can call hdrl.core.Collapse.compute() or pass it to a function that accepts the Collapse instance (e.g. hdrl.func.Flat.compute).

Notes

Sigma Clipping or Median Collapse methods are recommended for robust application against outliers (e.g. cosmic ray hits). However, Median has a low statistical efficiency, so will display higher uncertainty than images collapsed using sigma clipping with few outliers.

class Method

Method to use for the mode computation.

Members:

Median :

This method is the most robust method and can/should be used for very asymmetric point distributions.

Fit :

This method gives accurate results for symmetric distributions but is also more likely to fail.

Weighted :

This method can/should be used with asymmetric distributions.

property name
static Mean() hdrl.func.Collapse

Creates an instance of hdrl.func.Collapse class with Mean parameters.

Mean and associated error are computed with standard formulae.

Returns:

The namedtuple has two components- one hdrl.core.Image (out), containing the collapsed image and one cpl.core.Image (contrib), which is the output mask containing an integer map that counts how many pixels contributed to each pixel image.

Return type:

namedtuple

See also

hdrl.core.ImageList.collapse

Perform Collapse operation on HDRL ImageList.

hdrl.core.ImageList.collapse_mean

Perform Mean Collapse operation on HDRL ImageList.

static Median() hdrl.func.Collapse

The median collapse of an ImageList to a single image.

Median and associated error are computed with standard formulae.

Returns:

The namedtuple has two components- one hdrl.core.Image (out), containing the collapsed image, one cpl.core.Image (contrib), which is the output mask containing an integer map that counts how many pixels contributed to each pixel image.

Return type:

namedtuple

See also

hdrl.core.ImageList.collapse_median

Perform Median Collapse operation on HDRL ImageList.

hdrl.func.Collapse.compute

Perform Collapse function on an HDRL ImageList to create one HDRL Image.

static MinMax(nlow: SupportsFloat, nhigh: SupportsFloat) hdrl.func.Collapse

Creates an instance of hdrl.func.Collapse class with Min-Max clipped parameters.

Minmax-clipped mean and associated error, computed similarly as for mean but without taking the clipped values into account

Returns:

The namedtuple has four components- one hdrl.core.Image (out), containing the collapsed image, one cpl.core.Image (contrib), which is the output mask containing an integer map that counts how many pixels contributed to each pixel image, one cpl.core.Image (reject_low) containing low rejection threshold, one cpl.core.Image (reject_high) containing high rejection threshold.

Return type:

namedtuple

See also

hdrl.core.ImageList.collapse

Perform Collapse operation on HDRL ImageList.

hdrl.core.ImageList.collapse_minmax

Perform MinMax Collapse operation on HDRL ImageList.

static Mode(histo_min: SupportsFloat, histo_max: SupportsFloat, bin_size: SupportsFloat, mode_method: hdrl.func.Collapse.Method, error_niter: SupportsInt) hdrl.func.Collapse

Creates an instance of hdrl.func.Collapse class with Mode parameters.

Parameters:
  • histo_min (float) – minimum value of low pixels to use

  • histo_max (float) – maximum value of high pixels to be use

  • bin_size (float) – size of the histogram bin

  • mode_method (hdrl.func.Collapse.Mode) – mode_method to use for the mode computation

  • error_niter (int) – size of the histogram bin

Returns:

The namedtuple has two components- one hdrl.core.Image (out), containing the collapsed image and one cpl.core.Image (contrib), which is the output mask containing an integer map that counts how many pixels contributed to each pixel image.

Return type:

namedtuple

See also

hdrl.core.ImageList.collapse

Perform Collapse operation on HDRL ImageList.

hdrl.core.ImageList.collapse_mode

Perform Mode Collapse operation on HDRL ImageList.

static Sigclip(kappa_low: SupportsFloat, kappa_high: SupportsFloat, niter: SupportsInt) hdrl.func.Collapse

The sigma clipped collapse of an ImageList to a single image.

Sigma-clipped mean and associated error, computed similarly as for mean but without taking the clipped values into account.

Parameters:
  • kappa_low (float) – low sigma bound

  • kappa_high (float) – high sigma bound

  • niter (int) – number of clipping iterators

Returns:

The namedtuple has four components- one hdrl.core.Image (out), containing the collapsed image, one cpl.core.Image (contrib), which is the output mask containing an integer map that counts how many pixels contributed to each pixel image, one cpl.core.Image (reject_low) containing low rejection threshold, one cpl.core.Image (reject_high) containing high rejection threshold.

Return type:

namedtuple

See also

hdrl.core.ImageList.collapse_sigclip

Perform Sigma Clipped Collapse operation on HDRL ImageList.

hdrl.func.Collapse.compute

Perform Collapse function on an HDRL ImageList to create one HDRL Image.

static WeightedMean() hdrl.func.Collapse

Creates an instance of hdrl.func.Collapse class with Weighted Mean parameters.

Weighted mean and associated error are computed with standard formulae

Returns:

The namedtuple has two components- one hdrl.core.Image (out), containing the collapsed image and one cpl.core.Image (contrib), which is the output mask containing an integer map that counts how many pixels contributed to each pixel image.

Return type:

namedtuple

See also

hdrl.core.ImageList.collapse

Perform Collapse operation on HDRL ImageList.

hdrl.core.ImageList.collapse_weighted_mean

Perform Weighted Mean Collapse operation on HDRL ImageList.

compute(self: hdrl.func.Collapse, himlist: hdrl.core.ImageList) object

Implement the Collapse operations for an HDRL Imagelist to a single image.

Parameters:

himlist (hdrl.core.ImageList) – Image to collapse using the operation defined in self.

Returns:

The namedtuple has two components- one hdrl.core.Image (out), containing the collapsed image and one cpl.core.Image (contrib), which is the output mask containing an integer map that counts how many pixels contributed to each pixel image.

Return type:

namedtuple

Notes

These operations can also be accessed directly by the hdrl.core.ImageList objects.

See also

hdrl.core.ImageList.collapse

Perform Collapse operation on HDRL ImageList.

hdrl.core.ImageList.collapse_mean

Perform Mean Collapse operation on HDRL ImageList.

hdrl.core.ImageList.collapse_weighted_mean

Perform Weighted Mean Collapse operation on HDRL ImageList.

hdrl.core.ImageList.collapse_sigclip

Perform Sigma Clipped Collapse operation on HDRL ImageList.

hdrl.core.ImageList.collapse_minmax

Perform Min-max clipped Collapse operation on HDRL ImageList.

hdrl.core.ImageList.collapse_mode

Perform Mode Collapse operation on HDRL ImageList.

class hdrl.func.Flat

The hdrl.func.Flat class provides an interface to combining single flatfields into a master flatfield with increased signal-to-noise ratio.

Once the class has been instantiated with the desired parameters, the master flat can be created using the member function hdrl.func.Flat.compute().

Parameters:
  • filter_size_x (int) – The dimension of the smoothing kernel (median filter) in the x-direction in pixel units.

  • filter_size_y (int) – The dimension of the smoothing kernel (median filter) in the y-direction in pixel units.

  • method (hdrl.func.Flat.Mode) – The flat combination algorithm mode, either hdrl.func.Flat.FreqLow or hdrl.func.Flat.FreqHigh.

Return type:

hdrl.func.Flat

Notes

See hdrl.func.Flat.Mode for descriptions of each algorithm.

Examples

# Example 1: with a stat_mask

# choose a collapse method
collapse = hdrl.func.Collapse.Mean()
# dx and dy are image dimensions
stat_mask = cpl.core.Mask(dx,dy)
# set the mask for a window defined by (r1_llx, r1_lly, r1_urx, r1_ury)
for j in range(r1_lly, r1_ury):
  for i in range(r1_llx, r1_urx):
      stat_mask[j - 1][i - 1] = True
# create the hdrl.func.Flat instance
flat = hdrl.func.Flat(filter_size_x, filter_size_y, hdrl.func.Flat.Mode.FreqLow)
# compute the master flat with imglist being an hdrl.core.ImageList
# holding the images to combine into the master flat
results = flat.compute(imglist, collapse, stat_mask)
mflat = results.master
cmap = results.contrib_map

# Example 2: without a stat_mask

collapse = hdrl.func.Collapse.Median()
stat_mask = None
# create the hdrl.func.Flat instance
flat = hdrl.func.Flat(filter_size_x, filter_size_y, hdrl.func.Flat.Mode.FreqLow)
# compute the master flat with imglist being an hdrl.core.ImageList
# holding the images to combine into the master flat
results = flat.compute(imglist, collapse, stat_mask)
class Mode

The flat combination algorithm mode.

Members:

FreqLow :

This algorithm derives the low frequency part of the master flatfield – often also denoted as the shape of the flatfield.

The algorithm multiplicatively normalizes the input images by the median (considered to be noiseless) of the image to unity. An optional static mask stat_mask can be provided to the algorithm in order to define the pixels that should be taken into account when computing the normalisation factor. This allows the user to normalize the flatfield e.g. only by the illuminated section. In the next step, all normalized images are collapsed into a single master flatfield. The collapsing can be done with all methods currently implemented in HDRL (see hdrl.func.Collapse or Sect. 3.2.2 of the HDRL manual for an overview). Finally, the master flatfield is smoothed by a median filter controlled by filter_size_x and filter_size_y. The associated error of the final master frame is the error derived via error propagation of the previous steps, i.e. the smoothing itself is considered noiseless. Please note that, if the smoothing kernel is set to unity, i.e. filter_size_x = 1 and filter_size_y = 1, no final smoothing will take place but the resulting masterframe is simply the collapsed normalized flatfield.

FreqHigh :

This algorithm derives the high frequency part of the master flatfield – often also denoted as the pixel-to-pixel variation of the flatfield.

The algorithm first divides each input image by the smooth image obtained with a median filter (the latter is controlled by the parameters filter_size_x and filter_size_y). Concerning the error propagation, the smoothed image is considered to be noiseless, i.e. the relative error associated to the normalised images is the same as the one of the input images. Then all residual images are collapsed into a single master flatfield. The collapsing can be done with all methods currently implemented in HDRL (see hdrl.func.Collapse or Sect. 3.2.2 of the HDRL manual for an overview).

To distinguish between illuminated and not illuminated regions/pixels (i.e. orders in an echelle flat image), the user may provide an optional static mask stat_mask to the algorithm. In this case the smoothing procedure is done twice, once for the illuminated region and once for the blanked region. This ensures that the information of one region does not influence the other regions during the smoothing process.

property name
compute(self: hdrl.func.Flat, hdrl_data: hdrl.core.ImageList, collapse: hdrl.func.Collapse, stat_mask: cpl.core.Mask) object

Compute the master flat image and a contribution map image.

Parameters:
  • hdrl_data (hdrl.core.ImageList) – The imagelist of images to combine into the master flat.

  • collapse (hdrl.func.Collapse) – Specifies the collapsing algorithm to apply to hdrl_data.

  • stat_mask (cpl.core.Mask) – A static mask to distinguish between illuminated and dark regions. If no static mask is needed, this can be set to None.

Returns:

The namedtuple FlatResult contains two output products: a master flat image (hdrl.core.Image) and a contribution map image (cpl.core.Image). The respective products may be accessed via the attributes master and contrib_map. If desired, the namedtuple can be converted to a dictionary using its ._asdict() method.

Return type:

namedtuple

Notes

See hdrl.func.Flat.Mode for descriptions of each algorithm.

property method

flat combination algorithm mode.

Type:

hdrl.func.Flat.Mode

property sizex

dimension of the smoothing kernel (median filter) in the x-direction in pixel units.

Type:

int

property sizey

dimension of the smoothing kernel (median filter) in the y-direction in pixel units.

Type:

int

class hdrl.func.Fringe

The hdrl.func.Fringe class provides an interface to fringe pattern detection and correction in astronomical images.

The class provides two main methods: - compute(): Creates a master fringe pattern from a list of fringe images - correct(): Applies fringe correction to images using a master fringe pattern

Parameters:

None – The Fringe class does not require any parameters for initialization.

Return type:

hdrl.func.Fringe

Notes

The fringe functions work with HDRL image lists and can handle optional object masks and static masks for improved fringe detection and correction.

Examples

# Example 1: Compute master fringe pattern

# Create fringe object
fringe = hdrl.func.Fringe()

# Create collapse method for combining images
collapse = hdrl.func.Collapse.Mean()

# Optional: Create static mask for fringe regions
stat_mask = cpl.core.Mask(dx, dy)
# Set mask for fringe-affected regions

# Compute master fringe pattern
# ilist_fringe is an hdrl.core.ImageList with fringe images
# ilist_obj is optional cpl.core.ImageList with object masks (can be None)
result = fringe.compute(ilist_fringe, ilist_obj, stat_mask, collapse)
master_fringe = result.master
contrib_map = result.contrib_map
qctable = result.qctable

# Example 2: Apply fringe correction

# Apply correction to images using master fringe
# ilist_fringe is an hdrl.core.ImageList with images to correct
# masterfringe is the master fringe pattern from compute()
result = fringe.correct(ilist_fringe, ilist_obj, stat_mask, masterfringe)
qctable = result.qctable
compute(self: hdrl.func.Fringe, ilist_fringe: hdrl.core.ImageList, ilist_obj: cpl.core.ImageList = None, stat_mask: cpl.core.Mask = None, collapse_params: hdrl.func.Collapse) hdrl.func.FringeComputeResult

Compute a master fringe pattern from a list of fringe images.

This method combines multiple fringe images to create a master fringe pattern with improved signal-to-noise ratio. The method uses the specified collapse algorithm to combine the images.

Parameters:
  • ilist_fringe (hdrl.core.ImageList) – List of fringe images to combine into master fringe pattern.

  • ilist_obj (cpl.core.ImageList or None, optional) – Optional list of object masks. If provided, must have same size and dimensions as ilist_fringe. Default is None.

  • stat_mask (cpl.core.Mask or None, optional) – Optional static mask for fringe regions. If provided, must have same dimensions as fringe images. Default is None.

  • collapse_params (hdrl.func.Collapse) – Collapse method for combining fringe images.

Returns:

Result object containing: - master: hdrl.core.Image - Master fringe pattern - contrib_map: cpl.core.Image - Contribution map - qctable: cpl.core.Table - Quality control table

Return type:

FringeComputeResult

Raises:
correct(self: hdrl.func.Fringe, ilist_fringe: hdrl.core.ImageList, ilist_obj: cpl.core.ImageList = None, stat_mask: cpl.core.Mask = None, masterfringe: hdrl.core.Image) hdrl.func.FringeCorrectResult

Apply fringe correction to images using a master fringe pattern.

This method corrects fringe patterns in images by subtracting a scaled version of the master fringe pattern. The scaling is determined by fitting the fringe amplitude for each image.

Parameters:
  • ilist_fringe (hdrl.core.ImageList) – List of images to correct for fringe patterns.

  • ilist_obj (cpl.core.ImageList or None, optional) – Optional list of object masks. If provided, must have same size and dimensions as ilist_fringe. Default is None.

  • stat_mask (cpl.core.Mask or None, optional) – Optional static mask for fringe regions. If provided, must have same dimensions as fringe images. Default is None.

  • masterfringe (hdrl.core.Image) – Master fringe pattern to use for correction.

Returns:

Result object containing a cpl.core.Table, the quality control table with background levels and fringe amplitudes for each image

Return type:

FringeCorrectResult

Raises:
  • hdrl.core.NullInputError – If ilist_fringe is None or empty, or if masterfringe is None.

  • hdrl.core.IncompatibleInputError – If ilist_obj dimensions don’t match ilist_fringe, if stat_mask dimensions don’t match fringe images, or if masterfringe dimensions don’t match fringe images.

Notes

The correction is applied in-place to the images in ilist_fringe. The method modifies the input images directly.

class hdrl.func.FringeComputeResult

A hdrl.func.FringeComputeResult class is a container for the results of hdrl.func.Fringe.compute(). The results consist of a master fringe pattern, contribution map, and quality control table.

These can be accessed via the master, contrib_map, and qctable attributes of the object.

Example

result = fringe.compute(ilist_fringe, ilist_obj, stat_mask, collapse_params)
master_fringe = result.master
contrib_map = result.contrib_map
qctable = result.qctable
property contrib_map

Contribution map

Type:

cpl.core.Image

property master

Master fringe pattern

Type:

hdrl.core.Image

property qctable

Quality control table

Type:

cpl.core.Table

class hdrl.func.FringeCorrectResult

A hdrl.func.FringeCorrectResult class is a container for the results of hdrl.func.Fringe.correct(). The results consist of a quality control table with background levels and fringe amplitudes.

These can be accessed via the qctable attribute of the object.

Example

result = fringe.correct(ilist_fringe, ilist_obj, stat_mask, masterfringe)
qctable = result.qctable
property qctable

Quality control table with background levels and fringe amplitudes

Type:

cpl.core.Table

class hdrl.func.LaCosmic

The hdrl.func.LaCosmic class provides an interface to the LA-Cosmic algorithm described in van Dokkum et al. 2001, PASP, 113, 1420 to detect bad-pixels and cosmic-rays hits on a single image.

After creating an instance of the class using hdrl.func.LaCosmic() with the desired parameters, the detection is executed using the member function edgedetect().

Parameters:
  • sigma_lim (float) – Limiting sigma for detection on the sampling image.

  • f_lim (float) – Limiting f factor for detection on the modified Laplacian image.

  • max_iter (int) – Maximum number of iterations.

Return type:

hdrl.func.LaCosmic

See also

hdrl.func.LaCosmic.edgedetect

Detect bad-pixels or cosmic-rays on a single image.

Notes

For the algorithm see the paper of van Dokkum et al. 2001, PASP, 113, 1420.

edgedetect(self: hdrl.func.LaCosmic, img_in: hdrl.core.Image) cpl.core.Mask

Detect bad-pixels or cosmic-rays on a single image.

This routine determines bad-pixels on a single image via edge detection following the LA-Cosmic algorithm described in van Dokkum et al. 2001, PASP, 113, 1420. It was originally developed to detect cosmic ray hits, but it can also be used in the more general context to detect bad pixels. The HDRL implementation does not use the error model as described in the paper, but instead uses the error image passed to the function. Moreover, several iterations are performed until no new bad pixels are found or the number of iterations reaches max_iter. In each iteration the detected cosmic ray hits are replaced by the median of the surrounding 5x5 pixels taking into account the pixel quality information. The input parameters sigma_lim and f_lim refer to \(\sigma_{lim}\) and \(f_{lim}\) as described in the paper mentioned above.

Parameters:

ima_in (hdrl.core.Image) – The input image

Returns:

A mask with all detected bad pixels or cosmics-rays marked as bad or None on error

Return type:

cpl.core.Mask

See also

hdrl.func.LaCosmic

Creates an LaCosmic instance.

Notes

Be aware that the implementation only detects positive bad pixels or cosmic ray hits, i.e. no “holes” in the image are detected, but in such a case the pixels surrounding the hole are marked as bad. Holes in the image can be introduced if e.g. one subtracts a not cosmic-ray-cleaned image from another image.

property f_lim

Limiting f factor for detection on the modified Laplacian image.

Type:

float

property max_iter

Maximum number of iterations.

Type:

int

property sigma_lim

Limiting sigma for detection on the sampling image.

Type:

float

class hdrl.func.Maglim

A hdrl.func.Maglim is a helper class for computing limiting magnitudes.

Parameters:
  • zeropoint (float) – Zeropoint for magnitude calculation.

  • fwhm (float) – Full width at half maximum for the PSF.

  • kernel_size_x (int) – Kernel size in x direction.

  • kernel_size_y (int) – Kernel size in y direction.

  • extend_method (hdrl.func.Maglim.ImageExtendMethod) – Image extension method (Nearest or Mirror).

  • mode_param (hdrl.func.Collapse or hdrl.core.Parameter) – Mode parameter for the computation.

class ImageExtendMethod

Image extension method for maglim computation.

Members:

Nearest : Extend using nearest value.

Mirror : Extend using mirror value.

property name
compute(self: hdrl.func.Maglim, image: cpl.core.Image) float

Compute the limiting magnitude for the given image.

Parameters:

image (hdrl.core.Image) – The input image.

Returns:

The computed limiting magnitude.

Return type:

float

property extend_method

Image extension method.

property fwhm

Full width at half maximum for the PSF.

property kernel_size_x

Kernel size in x direction.

property kernel_size_y

Kernel size in y direction.

property mode_param

Mode parameter for the computation.

property zeropoint

Zeropoint for magnitude calculation.

class hdrl.func.Resample

A hdrl.func.Resample class provides an interface to static functions required to resample images and cubes.

static compute(restable: cpl.core.Table, method: hdrl.func.ResampleMethod, outputgrid: hdrl.func.ResampleOutgrid, wcs: cpl.drs.WCS) hdrl.func.ResampleResult

This routine does not work directly on an image or cube but on a table (restable).

For 2D images, the table is created by the function hdrl.func.Resample.image_to_table(), whereas for a 3D data cube the function hdrl.func.Resample.imagelist_to_table() is used.

In the case that many images or cubes have to be combined into a single mosaic, the two functions can be called multiple times and the returned tables should be merged into a single table using cpl.core.Table.insert().

Parameters:
  • restable (cpl.core.Table) –

    A PyCPL table with information on the data to be resampled.

    It can be created either via hdrl.func.Resample.image_to_table() for a 2D image or via hdrl.func.Resample.imagelist_to_table() for a 3D data cube. These functions require either an hdrl.core.Image (2D image) or hdrl.core.ImageList (3D data cube), plus a valid cpl.drs.WCS object that encodes the world coordinate system of the given image or cube.

    Alternatively, in case the above mentioned functions can not be used to create the table, e.g. the pixel to sky mapping is very complex and can not be encoded by the cpl.drs.WCS object, the pipeline developer has to create and fill the table. A template of this table can be generated using the function hdrl.func.Resample.restable_template().

  • method (hdrl.func.ResampleMethod) – The interpolation method to apply as specified via an instance of the hdrl.func.ResampleMethod class, which can be instantiated via one of the following constructors: - hdrl.func.ResampleMethod.Nearest: Nearest neighbour resampling. - hdrl.func.ResampleMethod.Linear: Weighted resampling using an inverse distance weighting function. - hdrl.func.ResampleMethod.Quadratic: Weighted resampling using a quadratic inverse distance weighting function. - hdrl.func.ResampleMethod.Renka: Weighted resampling using a Renka weighting function. - hdrl.func.ResampleMethod.Drizzle: Weighted resampling using a drizzle-like weighting scheme. - hdrl.func.ResampleMethod.Lanczos: Weighted resampling using a Lanczos-like restricted sinc as weighting function.

  • outputgrid (hdrl.func.ResampleOutgrid) – Defines basic properties of the resampled image or cube. Depending on the input data (image or cube), outputgrid should be an instance of the hdrl.func.ResampleOutgrid class, which can be instantiated via one of the following constructors: - hdrl.func.ResampleOutgrid.User2D : User specified function for 2D images. - hdrl.func.ResampleOutgrid.User3D : User specified function for 3D data cubes. - hdrl.func.ResampleOutgrid.Auto2D : Convenience function for 2D images. - hdrl.func.ResampleOutgrid.Auto3D : Convenience function for 3D data cubes. In the case of the Auto2D and Auto3D constructors, only the step sizes in right ascension, declination and wavelength of the output image or cube are required. All the rest are automatically derived from the data by hdrl.func.Resample.compute().

  • wcs (cpl.drs.WCS) – The World Coordinate System representative of the images to be resampled. The resampling functions use the wcs input (CD matrix) mostly to determine the scales between the input and output grid. Please note, that in case the user would like to combine images or cubes with substantially different pixel sizes into a single output image or cube, the single tables have to be properly scaled to the same scales before merging them into the final table.

Returns:

res – An object containing the results consisting of a cpl.core.PropertyList, representing the image or cube header, and an hdrl.core.ImageList. These can be accessed via the hdr and imlist attributes of the object.

Return type:

hdrl.func.ResampleResult

Example

# plist is a cpl.core.PropertyList containing the WCS keywords from the header
wcs = cpl.drs.WCS(plist)
# himg is a hdrl.core.Image to be resampled
table = hdrl.func.Resample.image_to_table(himg, wcs)
rmethod = hdrl.func.ResampleMethod.Lanczos(1,False,2)
outgrid = hdrl.func.ResampleOutgrid.Auto2D(0.01,0.01)
result = hdrl.func.Resample.compute(table,rmethod,outgrid,wcs)
first_img = result.imlist[0].image
first_err = result.imlist[0].error
hdr = result.hdr
static image_to_table(hima: hdrl.core.Image, wcs: cpl.drs.WCS) cpl.core.Table

Creates the restable input table needed by hdrl.func.Resample.compute() for 2D images.

Parameters:
  • himg (hdrl.core.Image) – The image to be resampled.

  • wcs (cpl.drs.WCS) – The World Coordinate System representative of the images to be resampled.

Returns:

restable – The table that is used by hdrl.func.Resample.compute()

Return type:

cpl.core.Table

See also

hdrl.func.Resample.imagelist_to_table

Creates the restable input table needed by hdrl.func.Resample.compute() for 3D data cubes.

hdrl.func.Resample.restable_template

Creates a table template as per Sect. 4.14.3 of the HDRL manual.

static imagelist_to_table(himlist: hdrl.core.ImageList, wcs: cpl.drs.WCS) cpl.core.Table

Creates the restable input table needed by hdrl.func.Resample.compute() for 3D data cubes.

Parameters:
  • himlist (hdrl.core.ImageList) – The imagelist containing the images, i.e. the data cube, to be resampled.

  • wcs (cpl.drs.WCS) – The World Coordinate System representative of the images to be resampled.

Returns:

restable – The table that is used by hdrl.func.Resample.compute()

Return type:

cpl.core.Table

See also

hdrl.func.Resample.image_to_table

Creates the restable input table needed by hdrl.func.Resample.compute() for 2D images.

hdrl.func.Resample.restable_template

Creates a table template as per Sect. 4.14.3 of the HDRL manual.

static restable_template(nrows: SupportsInt) cpl.core.Table

Creates a table template as per Sect. 4.14.3 of the HDRL manual. Useful for instances where the pixel to sky mapping is very complex and can not be encoded in a cpl.drs.WCS object. This template can then be filled by the pipeline developer as required.

Parameters:

nrows (int) – The number of rows to create.

Returns:

restable – The table template with nrows rows.

Return type:

cpl.core.Table

See also

hdrl.func.Resample.image_to_table

Creates the restable input table needed by hdrl.func.Resample.compute() for 2D images.

hdrl.func.Resample.imagelist_to_table

Creates the restable input table needed by hdrl.func.Resample.compute() for 3D data cubes.

class hdrl.func.ResampleMethod

A hdrl.func.ResampleMethod class represents an interpolation algorithm to be applied using hdrl.func.Resample.compute().

The implemented interpolation algorithms are based on the MUSE pipeline and work for 2D images and 3D cubes. The 2D and 3D interpolation is done in 2-dimensional and 3-dimensional spaces, respectively.

Currently there are six different interpolation methods implemented: - Nearest: Nearest neighbour resampling - Linear: Weighted resampling using an inverse distance weighting function - Quadratic: Weighted resampling using a quadratic inverse distance weighting function - Renka: Weighted resampling using a Renka weighting function - Drizzle: Weighted resampling using a drizzle-like weighting scheme - Lanczos: Weighted resampling using a Lanczos-like restricted sinc as weighting function

Each method has its own separate constructor (e.g. hdrl.func.ResampleMethod.Nearest(), hdrl.func.ResampleMethod.Linear()).

static Drizzle(loop_distance: SupportsInt, use_errorweights: bool, pix_frac_x: SupportsFloat, pix_frac_y: SupportsFloat, pix_frac_lambda: SupportsFloat) hdrl.func.ResampleMethod

Creates an instance of hdrl.func.ResampleMethod for the Drizzle method. This method performs weighted resampling using a drizzle-like weighting scheme.

Parameters:
  • loop_distance (int) – Controls the number of surrounding pixels that are taken into account on the final grid.

  • use_errorweights (bool) – Apply an additional weight of 1/variance.

  • pix_frac_x (float) – Fraction of flux of the original pixel/voxel that drizzles into target pixel/voxel in the x-direction.

  • pix_frac_y (float) – Fraction of flux of the original pixel/voxel that drizzles into target pixel/voxel in the y-direction.

  • pix_frac_lambda (float) – Fraction of flux of the original pixel/voxel that drizzles into target pixel/voxel in the lambda-direction.

Returns:

hdrl.func.ResampleMethod for the Drizzle method.

Return type:

hdrl.func.ResampleMethod

Example

loop_distance = 2
use_errorweights = True
pix_frac_drizzle_x = 0.8
pix_frac_drizzle_y = 0.8
pix_frac_drizzle_lambda = 1
rmethod = hdrl.func.ResampleMethod.Drizzle(loop_distance, use_errorweights, pix_frac_drizzle_x, pix_frac_drizzle_y, pix_frac_drizzle_lambda)

Notes

The algorithm uses a drizzle-like distance weighting function for the interpolation. The down-scaling factors pix_frac_x, pix_frac_y, and pix_frac_lambda, for x, y, and wavelength direction control the percentage of flux of the original pixel/voxel that drizzles into the target pixel/voxel. The parameter loop_distance controls the number of surrounding pixels that are taken into account on the final grid, e.g. a loop_distance of 1 uses 3 pixels \((x - 1, x, x + 1)\) in each dimension, i.e. 9 in total for a 2D image and 27 in total for a 3D cube. Moreover, if the parameter use_errorweights is set to True, an additional weight, defined as 1/variance, is taken into account. This additional weight is only applied if the variance of a pixel is greater than 0.

See also

hdrl.func.ResampleMethod.Nearest

Creates an instance of hdrl.func.ResampleMethod for the Nearest method.

hdrl.func.ResampleMethod.Linear

Creates an instance of hdrl.func.ResampleMethod for the Linear method.

hdrl.func.ResampleMethod.Quadratic

Creates an instance of hdrl.func.ResampleMethod for the Quadratic method.

hdrl.func.ResampleMethod.Renka

Creates an instance of hdrl.func.ResampleMethod for the Renka method.

hdrl.func.ResampleMethod.Lanczos

Creates an instance of hdrl.func.ResampleMethod for the Lanczos method.

static Lanczos(loop_distance: SupportsInt, use_errorweights: bool, kernel_size: SupportsInt) hdrl.func.ResampleMethod

Creates an instance of hdrl.func.ResampleMethod for the Lanczos method. This method performs weighted resampling using a Lanczos-like restricted sinc as weighting function.

Parameters:
  • loop_distance (int) – Controls the number of surrounding pixels that are taken into account on the final grid.

  • use_errorweights (bool) – Apply an additional weight of 1/variance.

  • kernel_size (int) – The kernel size in pixel units for the sinc distance weighting function.

Returns:

hdrl.func.ResampleMethod for the Lanczos method.

Return type:

hdrl.func.ResampleMethod

Example

loop_distance = 2
use_errorweights = True
kernel_size = 2
rmethod = hdrl.func.ResampleMethod.Lanczos(loop_distance, use_errorweights, kernel_size)

Notes

The algorithm uses a restricted sinc distance weighting function sinc(r)/sinc(r/kernel_size), with the kernel size given by the parameter kernel_size for the interpolation. The parameter loop_distance controls the number of surrounding pixels that are taken into account on the final grid, e.g. a loop_distance of 1 uses 3 pixels \((x - 1, x, x + 1)\) in each dimension, i.e. 9 in total for a 2D image and 27 in total for a 3D cube. Moreover, if the parameter use_errorweights is set to True, an additional weight, defined as 1/variance, is taken into account. This additional weight is only applied if the variance of a pixel is greater than 0.

See also

hdrl.func.ResampleMethod.Nearest

Creates an instance of hdrl.func.ResampleMethod for the Nearest method.

hdrl.func.ResampleMethod.Linear

Creates an instance of hdrl.func.ResampleMethod for the Linear method.

hdrl.func.ResampleMethod.Quadratic

Creates an instance of hdrl.func.ResampleMethod for the Quadratic method.

hdrl.func.ResampleMethod.Renka

Creates an instance of hdrl.func.ResampleMethod for the Renka method.

hdrl.func.ResampleMethod.Drizzle

Creates an instance of hdrl.func.ResampleMethod for the Drizzle method.

static Linear(loop_distance: SupportsInt, use_errorweights: bool) hdrl.func.ResampleMethod

Creates an instance of hdrl.func.ResampleMethod for the Linear method. This method performs weighted resampling using an inverse distance weighting function.

Parameters:
  • loop_distance (int) – Controls the number of surrounding pixels that are taken into account on the final grid.

  • use_errorweights (bool) – Apply an additional weight of 1/variance.

Returns:

Instance of hdrl.func.ResampleMethod for the Linear method.

Return type:

hdrl.func.ResampleMethod

Example

loop_distance = 2
use_errorweights = True
rmethod = hdrl.func.ResampleMethod.Linear(loop_distance, use_errorweights)

Notes

The algorithm uses a linear inverse distance weighting function \((1/r)\) for the interpolation. The parameter loop_distance controls the number of surrounding pixels that are taken into account on the final grid, e.g. a loop_distance of 1 uses 3 pixels \((x - 1, x, x + 1)\) in each dimension, i.e. 9 in total for a 2D image and 27 in total for a 3D cube. Moreover, if the parameter use_errorweights is set to True, an additional weight, defined as 1/variance, is taken into account. This additional weight is only applied if the variance of a pixel is greater than 0.

See also

hdrl.func.ResampleMethod.Nearest

Creates an instance of hdrl.func.ResampleMethod for the Nearest method.

hdrl.func.ResampleMethod.Quadratic

Creates an instance of hdrl.func.ResampleMethod for the Quadratic method.

hdrl.func.ResampleMethod.Renka

Creates an instance of hdrl.func.ResampleMethod for the Renka method.

hdrl.func.ResampleMethod.Drizzle

Creates an instance of hdrl.func.ResampleMethod for the Drizzle method.

hdrl.func.ResampleMethod.Lanczos

Creates an instance of hdrl.func.ResampleMethod for the Lanczos method.

static Nearest() hdrl.func.ResampleMethod

Creates an instance of hdrl.func.ResampleMethod for the Nearest method. This method performs nearest neighbour resampling.

Returns:

Instance of hdrl.func.ResampleMethod for Nearest method

Return type:

hdrl.func.ResampleMethod

Example

rmethod = hdrl.func.ResampleMethod.Nearest()

Notes

The algorithm does not use any weighting function, but simply uses the value of the nearest neighbour inside an output voxel [1] centre as the final output value. If there is no nearest neighbour inside the voxel (but e.g. only outside), the voxel is marked as bad. This speeds up the algorithm considerably. There are no control parameters for this method.

See also

hdrl.func.ResampleMethod.Linear

Creates an instance of hdrl.func.ResampleMethod for the Linear method.

hdrl.func.ResampleMethod.Quadratic

Creates an instance of hdrl.func.ResampleMethod for the Quadratic method.

hdrl.func.ResampleMethod.Renka

Creates an instance of hdrl.func.ResampleMethod for the Renka method.

hdrl.func.ResampleMethod.Drizzle

Creates an instance of hdrl.func.ResampleMethod for the Drizzle method.

hdrl.func.ResampleMethod.Lanczos

Creates an instance of hdrl.func.ResampleMethod for the Lanczos method.

static Quadratic(loop_distance: SupportsInt, use_errorweights: bool) hdrl.func.ResampleMethod

Creates an instance of hdrl.func.ResampleMethod for the Quadratic method. This method performs weighted resampling using a quadratic inverse distance weighting function.

Parameters:
  • loop_distance (int) – Controls the number of surrounding pixels that are taken into account on the final grid.

  • use_errorweights (bool) – Apply an additional weight of 1/variance.

Returns:

Instance of hdrl.func.ResampleMethod for the Quadratic method.

Return type:

hdrl.func.ResampleMethod

Example

loop_distance = 2
use_errorweights = True
rmethod = hdrl.func.ResampleMethod.Quadratic(loop_distance, use_errorweights)

Notes

The algorithm uses a quadratic inverse distance weighting function \((1/r^2)\) for the interpolation. The parameter loop_distance controls the number of surrounding pixels that are taken into account on the final grid, e.g. a loop_distance of 1 uses 3 pixels \((x - 1, x, x + 1)\) in each dimension, i.e. 9 in total for a 2D image and 27 in total for a 3D cube. Moreover, if the parameter use_errorweights is set to True, an additional weight, defined as 1/variance, is taken into account. This additional weight is only applied if the variance of a pixel is greater than 0.

See also

hdrl.func.ResampleMethod.Nearest

Creates an instance of hdrl.func.ResampleMethod for the Nearest method.

hdrl.func.ResampleMethod.Linear

Creates an instance of hdrl.func.ResampleMethod for the Linear method.

hdrl.func.ResampleMethod.Renka

Creates an instance of hdrl.func.ResampleMethod for the Renka method.

hdrl.func.ResampleMethod.Drizzle

Creates an instance of hdrl.func.ResampleMethod for the Drizzle method.

hdrl.func.ResampleMethod.Lanczos

Creates an instance of hdrl.func.ResampleMethod for the Lanczos method.

static Renka(loop_distance: SupportsInt, use_errorweights: bool, critical_radius: SupportsFloat) hdrl.func.ResampleMethod

Creates an instance of hdrl.func.ResampleMethod for the Renka method. This method performs weighted resampling using a Renka weighting function.

Parameters:
  • loop_distance (int) – Controls the number of surrounding pixels that are taken into account on the final grid.

  • use_errorweights (bool) – Apply an additional weight of 1/variance.

  • critical_radius (float) – The distance beyond which the weights are set to 0.

Returns:

Instance of hdrl.func.ResampleMethod for the Renka method.

Return type:

hdrl.func.ResampleMethod

Example

loop_distance = 2
use_errorweights = True
critical_radius = 3
rmethod = hdrl.func.ResampleMethod.Renka(loop_distance, use_errorweights, critical_radius)

Notes

The algorithm uses a modified Shepard-like distance weighting function following Renka for the interpolation. The parameter critical_radius defines the distance beyond which the weights are set to 0 and the pixels are therefore not taken into account. The parameter loop_distance controls the number of surrounding pixels that are taken into account on the final grid, e.g. a loop_distance of 1 uses 3 pixels \((x - 1, x, x + 1)\) in each dimension, i.e. 9 in total for a 2D image and 27 in total for a 3D cube. Moreover, if the parameter use_errorweights is set to True, an additional weight, defined as 1/variance, is taken into account. This additional weight is only applied if the variance of a pixel is greater than 0.

See also

hdrl.func.ResampleMethod.Nearest

Creates an instance of hdrl.func.ResampleMethod for the Nearest method.

hdrl.func.ResampleMethod.Linear

Creates an instance of hdrl.func.ResampleMethod for the Linear method.

hdrl.func.ResampleMethod.Quadratic

Creates an instance of hdrl.func.ResampleMethod for the Quadratic method.

hdrl.func.ResampleMethod.Drizzle

Creates an instance of hdrl.func.ResampleMethod for the Drizzle method.

hdrl.func.ResampleMethod.Lanczos

Creates an instance of hdrl.func.ResampleMethod for the Lanczos method.

class hdrl.func.ResampleOutgrid

A hdrl.func.ResampleOutgrid class defines the basic properties of the resampled image or cube that are to be considered by hdrl.func.Resample.compute().

It can be instantiated via one of the following constructors: - hdrl.func.ResampleOutgrid.User2D : User specified function for 2D images. - hdrl.func.ResampleOutgrid.User3D : User specified function for 3D data cubes. - hdrl.func.ResampleOutgrid.Auto2D : Convenience function for 2D images. - hdrl.func.ResampleOutgrid.Auto3D : Convenience function for 3D data cubes. In the case of the Auto2D and Auto3D constructors, only the step sizes in right ascension, declination and wavelength of the output image or cube are required. All the rest are automatically derived from the data by hdrl.func.Resample.compute().

static Auto2D(delta_ra: SupportsFloat, delta_dec: SupportsFloat) hdrl.func.ResampleOutgrid

Creates an instance of hdrl.func.ResampleOutgrid for 2D images.

Parameters:
  • delta_ra (float) – Output grid step in right ascension

  • delta_dec (float) – Output grid step in declination

Returns:

Instance of hdrl.func.ResampleOutgrid for 2D images.

Return type:

hdrl.func.ResampleOutgrid

Example

outputgrid = hdrl.func.ResampleOutgrid.Auto2D(0.1,0.2)

See also

hdrl.func.ResampleOutgrid.User2D

Creates an instance of hdrl.func.ResampleOutgrid for 2D images.

static Auto3D(delta_ra: SupportsFloat, delta_dec: SupportsFloat, delta_lambda: SupportsFloat) hdrl.func.ResampleOutgrid

Creates an instance of hdrl.func.ResampleOutgrid for 3D data cubes.

Parameters:
  • delta_ra (float) – Output grid step in right ascension

  • delta_dec (float) – Output grid step in declination

  • delta_lambda (float) – Output grid step in wavelength

Returns:

Instance of hdrl.func.ResampleOutgrid for 3D data cubes.

Return type:

hdrl.func.ResampleOutgrid

Example

outputgrid = hdrl.func.ResampleOutgrid.Auto3D(0.1,0.2,0.001)

See also

hdrl.func.ResampleOutgrid.User3D

Creates an instance of hdrl.func.ResampleOutgrid for 3D data cubes.

static User2D(delta_ra: SupportsFloat, delta_dec: SupportsFloat, ra_min: SupportsFloat, ra_max: SupportsFloat, dec_min: SupportsFloat, dec_max: SupportsFloat, fieldmargin: SupportsFloat) hdrl.func.ResampleOutgrid

Creates an instance of hdrl.func.ResampleOutgrid for 2D images.

Parameters:
  • delta_ra (float) – Output grid step in right ascension

  • delta_dec (float) – Output grid step in declination

  • ra_min (float) – Minimum boundary of the image in right ascension

  • ra_max (float) – Maximum boundary of the image in right ascension

  • dec_min (float) – Minimum boundary of the image in declination

  • dec_max (float) – Maximum boundary of the image in declination

  • fieldmargin (float) – Percentage of how much margin to add to the output image in all spatial directions. A value of 0 adds no margin.

Returns:

instance of hdrl.func.ResampleOutgrid for 2D images.

Return type:

hdrl.func.ResampleOutgrid

Example

delta_ra = 0.1
delta_dec = 0.2
ra_min = 48.069416667
ra_max = 48.0718125
dec_min = -20.6229925
dec_max = -20.620708611
field_margin = 5
outputgrid = hdrl.func.ResampleOutgrid.User2D(delta_ra, delta_dec, ra_min, ra_max, dec_min, dec_max, field_margin)

See also

hdrl.func.ResampleOutgrid.Auto2D

Creates an instance of hdrl.func.ResampleOutgrid for 2D images.

static User3D(delta_ra: SupportsFloat, delta_dec: SupportsFloat, delta_lambda: SupportsFloat, ra_min: SupportsFloat, ra_max: SupportsFloat, dec_min: SupportsFloat, dec_max: SupportsFloat, lambda_min: SupportsFloat, lambda_max: SupportsFloat, fieldmargin: SupportsFloat) hdrl.func.ResampleOutgrid

Creates an instance of hdrl.func.ResampleOutgrid for 3D data cubes.

Parameters:
  • delta_ra (float) – Output grid step in right ascension

  • delta_dec (float) – Output grid step in declination

  • delta_lambda (float) – Output grid step in wavelength

  • ra_min (float) – Minimum boundary of the image in right ascension

  • ra_max (float) – Maximum boundary of the image in right ascension

  • dec_min (float) – Minimum boundary of the image in declination

  • dec_max (float) – Maximum boundary of the image in declination

  • lambda_min (float) – Minimum boundary of the image in wavelength

  • lambda_max (float) – Maximum boundary of the image in wavelength

  • fieldmargin (float) – Percentage of how much margin to add to the output image in all spatial directions. A value of 0 adds no margin.

Returns:

instance of hdrl.func.ResampleOutgrid for 3D data cubes.

Return type:

hdrl.func.ResampleOutgrid

Example

delta_ra = 0.1
delta_dec = 0.2
delta_lambda = 0.001
ra_min = 48.069416667
ra_max = 48.0718125
dec_min = -20.6229925
dec_max = -20.620708611
lambda_min = 1.9283e-06
lambda_max = 2.47146e-06
field_margin = 5
outputgrid = hdrl.func.ResampleOutgrid.User3D(delta_ra, delta_dec, delta_lambda, ra_min, ra_max, dec_min, dec_max, lambda_min, lambda_max, field_margin)

See also

hdrl.func.ResampleOutgrid.Auto3D

Creates an instance of hdrl.func.ResampleOutgrid for 3D data cubes.

class hdrl.func.ResampleResult

A hdrl.func.ResampleResult class is a container for the results of hdrl.func.Resample.compute(). The results consist of a cpl.core.PropertyList, representing the image or cube header, and an hdrl.core.ImageList.

These can be accessed via the hdr and imlist attributes of the object.

Example

result = hdrl.func.Resample.compute(table,rmethod,outgrid,wcs)
hdr = result.hdr
himlist = result.imlist
first_img = himlist[0].image
first_err = himlist[0].error
property hdr

image or cube header

Type:

cpl.core.PropertyList

property imlist

imagelist containing the resampled images

Type:

hdrl.core.ImageList

class hdrl.func.StrehlResult

A hdrl.func.StrehlResult class is a container for the results of hdrl.func.Strehl.compute(). The results consist of … a number of values.

These can be accessed via … getters.

Example

result = hdrl.func.Strehl.compute(...)
property computed_background_error
property nbackground_pixels
property star_background
property star_background_error
property star_flux
property star_flux_error
property star_peak
property star_peak_error
property star_x
property star_y
property strehl_error
property strehl_value
hdrl.func.fpn_compute(image: cpl.core.Image, mask: cpl.core.Mask = None, dc_mask_x: SupportsInt = 1, dc_mask_y: SupportsInt = 1) hdrl.func.FpnResult

Compute fixed pattern noise on a single image.

This function detects fixed pattern noise on the input image. The algorithm first computes the power spectrum of the image using the Fast Fourier Transform (FFT), then computes the standard deviation and MAD-based standard deviation of the power spectrum excluding the masked region.

Parameters:
  • image (cpl.core.Image) – Input image (bad pixels are not allowed).

  • mask (cpl.core.Mask, optional) – Optional input mask applied to the power spectrum. If None, no mask is used.

  • dc_mask_x (int, optional) – X-pixel window (>= 1) to discard DC component starting from pixel (1, 1). Default is 1.

  • dc_mask_y (int, optional) – Y-pixel window (>= 1) to discard DC component starting from pixel (1, 1). Default is 1.

Returns:

A result object containing: - power_spectrum: cpl.core.Image with the computed power spectrum - std: float, the standard deviation of the power spectrum - std_mad: float, the MAD-based standard deviation of the power spectrum

Return type:

FpnResult

Notes

The power spectrum contains the DC component (the DC term is the 0 Hz term and is equivalent to the average of all the samples in the window) in pixel (1,1).

The mask created on the fly by setting dc_mask_x and dc_mask_y and the optional mask are combined and are both taken into account when calculating std and std_mad.

The final mask used to derive std and std_mad is attached to the power_spectrum image as a normal cpl mask and can be retrieved using cpl_image_get_bpm(power_spectrum).

Raises:
  • hdrlcore.NullInputError – If image is None.

  • hdrlcore.IllegalInputError – If dc_mask_x < 1 or dc_mask_y < 1, or if image contains bad pixels.

  • hdrlcore.IncompatibleInputError – If mask is not None and its size doesn’t match the image size.