m3resp.PixelMask#

class m3resp.PixelMask(name, values, modality='eit', method=None, metadata=<factory>, *, keep_zeros=False, suppress_value_range_error=False, suppress_zero_conversion_warning=False, suppress_all_nan_warning=False)[source]#

Which pixels of an EIT image belong to a region.

Each pixel holds NaN when it is outside the region, 1 when it is included, or a weight from 0 to 1 when it counts partly. Applying the mask multiplies each pixel by this number, so a NaN pixel drops out and a pixel with weight 0 adds nothing to a sum.

The checks follow eitprocessing’s PixelMask:

  • A 0 becomes NaN, with a warning. Pass keep_zeros=True to keep it as weight 0, or suppress_zero_conversion_warning=True to skip the warning.

  • A grid of true/false values is accepted: true becomes 1 and false becomes 0, which then becomes NaN without a warning (or stays 0 with keep_zeros=True).

  • A number below 0 or above 1 raises ValueError, unless suppress_value_range_error=True.

  • A grid that is NaN everywhere gives a warning, unless suppress_all_nan_warning=True.

Variables:
  • name (str) – What the mask is, e.g. 'tiv_lungspace_mask'.

  • values (numpy.ndarray) – The mask as a 2D grid of shape (row, column), stored as floats.

  • modality (str) – The device the mask belongs to.

  • method (str | None) – Name of the method that made the mask.

  • metadata (dict[str, Any]) – Optional extra information.

Raises:
  • ValueError – If values is not a 2D grid, or holds a number below 0 or above 1 while suppress_value_range_error is False.

  • TypeError – If values cannot be stored as floats without changing them.

Parameters:

Methods

to_dict

Return the mask and its descriptive fields as a dictionary.

Attributes

included_pixel_count

Return the count of pixels that are not NaN, weight 0 included.

keep_zeros

method

modality

shape

Return the number of rows and columns, in that order.

suppress_all_nan_warning

suppress_value_range_error

suppress_zero_conversion_warning

name

values

metadata

property included_pixel_count: int#

Return the count of pixels that are not NaN, weight 0 included.

keep_zeros: dataclasses.InitVar[bool] = False#
metadata: dict[str, Any]#
method: str | None = None#
modality: str = 'eit'#
name: str#
property shape: tuple[int, int]#

Return the number of rows and columns, in that order.

suppress_all_nan_warning: dataclasses.InitVar[bool] = False#
suppress_value_range_error: dataclasses.InitVar[bool] = False#
suppress_zero_conversion_warning: dataclasses.InitVar[bool] = False#
to_dict()[source]#

Return the mask and its descriptive fields as a dictionary.

Returns:

The grid as a list of rows, together with name,

modality, method and metadata. Excluded pixels remain NaN. Metadata is copied at the top level.

Return type:

dict[str, Any]

values: ndarray#