13.4. openwfs.processors
- class CropProcessor(source, shape=Ellipsis, pos=None, padding_value=0.0, multi_threaded=False)[source]
Bases:
ProcessorProcessor to crop data from the source to some region of interest.
Works on any number of dimensions. If the cropped area extends beyond the size of the source data, the data is padded with ‘padding_value’
- property data_shape: tuple
Size of the cropped data
- property pos: tuple
Start (‘top-left’ corner) of the cropped region.
- class FunctionProcessor(source, func, **kwargs)[source]
Bases:
ProcessorProcessor that applies a user-defined function to the data from the source.
- busy()[source]
Returns true if the device is measuring or moving (see wait()).
Note: if a device does not define a finite duration, it must override this function to poll for finalization.
- class HDRCamera(camera, background, saturation_threshold, exposure_factors=(1.0, 0.1, 0.01))[source]
Bases:
DetectorWrapper to convert a camera to a high dynamic range (HDR) camera.
This wrapper forwards all method calls and attribute acces to the camera object, except for the trigger method, which is replaced by a method that triggers the camera multiple times with different exposure times.
todo: find out why the HDR camera is so slow.
- Parameters:
camera – The camera object to wrap.
background (
Union[Sequence[float],float]) – The background value to subtract from each image before scaling. If a sequence is passed, each value corresponds to the background for a different exposure factor.saturation_threshold (
int) – The threshold value to consider a pixel saturated, in which case it will not be taken into account in the computation of the result.exposure_factors (
Sequence[float]) – A sequence of exposure factors to use for HDR imaging.
- trigger(*args, out=None, immediate=False, **kwargs)[source]
Trigger the camera multiple times with different exposure times.
todo: at the moment, this method is always blocking, the immediate flag is ignored.
- Parameters:
*args – Positional arguments to pass to the camera’s trigger method.
out – Optional output buffer.
immediate – If True, trigger the camera immediately.
**kwargs – Keyword arguments to pass to the camera’s trigger method.
- Returns:
A Future object representing the result of the trigger operation.
- class MultipleRoi(source, rois, multi_threaded=True)[source]
Bases:
ProcessorProcessor that averages signals over multiple regions of interest (ROIs).
- class Roi(pos, radius=0.1, mask_type='disk', waist=None, source_shape=None)[source]
Bases:
objectRepresents a Region of Interest (ROI) to compute a (weighted) average over.
This class defines an ROI with specified properties such as coordinates, radius, mask type, and parameters specific to the mask type.
- apply(image, order=1.0)[source]
Applies the mask to the frame data by computing the weighted average. Optionally, the image data can be raised to a power before the mask is applied. This is useful for simulating multi-photon excitation, or for computing weighted contrast over the mask.
- Parameters:
image (np.ndarray) – The source image data.
order (float) – The order of the mask. Default is 1.0.
- property mask_type: str
The type of mask used for the ROI.
Must be one of ‘disk’, ‘gaussian’, or ‘square’.
- property pos: tuple[int, int]
Get the position of the ROI center.
- Returns:
tuple[int, int] – y,x coordinates of the center of the ROI, measured in pixels from the top-left corner.
- property radius: float
Radius of the ROI in pixels.
- property waist: float
Width of the Gaussian distribution in pixels.
- property x: int
x-coordinate of the center of the ROI, relative to the center of the image.
- property y: int
y-coordinate of the center of the ROI, relative to the center of the image.
- class SingleRoi(source, pos=None, radius=0.1, mask_type='disk', waist=0.5, **kwargs)[source]
Bases:
MultipleRoiProcessor that averages a signal over a single region of interest (ROI).
This is a specialized version of MultipleRoi that works with a single ROI. It provides direct access to the ROI properties (pos, radius, mask_type, waist).
- class TransformProcessor(source, transform=None, data_shape=None, pixel_size=None, multi_threaded=True)[source]
Bases:
ProcessorPerforms a 2-D transform of the input data (including shifting, padding, cropping, resampling).
By default, the output shape and pixel_size are the same as the input shape. If desired, explicit values can be provided for the output shape and pixel_size. The unit of the pixel_size should match the unit of the input data after applying the transform.
todo: make more robust to missing pixel_size and data_shape in the source, etc.
- property data_shape
This default implementation returns the data shape of the first source.
- property pixel_size: Quantity | None
This default implementation returns the pixel size of the first source.
- select_roi(source, mask_type)[source]
Opens a window that allows the user to select a region of interest.
This function displays an image from the source detector and allows the user to interactively select a region of interest by clicking and dragging.
- Parameters:
source (
Detector) – The detector to read the image from.mask_type (
str) – Type of the mask to create. Options are ‘disk’, ‘gaussian’, or ‘square’.
- Returns:
Roi – A Roi object representing the selected region, or None if the selection was cancelled.
- Raises:
ValueError – If the mask_type is not one of the supported types.