numcodecs_replace

numcodecs_replace

Value replacement codecs for the numcodecs buffer compression API.

Classes:

  • Replacement

    Special replacement values that are derived from the original data.

  • ReplaceFilterCodec

    Filter codec that replaces configured values during encoding and passes through the data during decoding.

Replacement

Bases: Enum

Special replacement values that are derived from the original data.

Methods:

  • compute

    Compute the special replacement value for the array x.

finite_min class-attribute instance-attribute

finite_min = auto()

The finite minimum of the data, or the largest-possible finite value if the data contains no finite values.

finite_mean class-attribute instance-attribute

finite_mean = auto()

The finite mean of the data, or NaN if the data contains no finite values.

finite_max class-attribute instance-attribute

finite_max = auto()

The finite maximum of the data, or the smallest-possible finite value if the data contains no finite values.

nan_min class-attribute instance-attribute

nan_min = auto()

The non-NaN minimum of the data, or the largest-possible value if the data contains no non-NaN values.

nan_mean class-attribute instance-attribute

nan_mean = auto()

The non-NaN mean of the data, or NaN if the data contains no non-NaN values.

nan_max class-attribute instance-attribute

nan_max = auto()

The non-NaN maximum of the data, or the smallest-possible value if the data contains no non-NaN values.

compute

compute(x: ndarray[S, dtype[T]]) -> T

Compute the special replacement value for the array x.

Parameters:
  • x (ndarray[S, dtype[T]]) –

    The numerical input data array.

Returns:
  • replacement( T ) –

    The scalar replacement value.

ReplaceFilterCodec

ReplaceFilterCodec(
    *,
    replacements: dict[
        int | float,
        int
        | float
        | Replacement
        | Literal[
            "finite_min",
            "finite_mean",
            "finite_max",
            "nan_min",
            "nan_mean",
            "nan_max",
        ],
    ],
)

Bases: Codec

Filter codec that replaces configured values during encoding and passes through the data during decoding.

The replacements are processed in order.

The special Replacement values, e.g. Replacement.nan_mean, are derived from the data before any replacements are made. Multiple ReplaceFilterCodecs can be stacked, e.g. using the numcodecs-combinators package, to apply some replacements before computing e.g. the finite mean.

When replacing NaN values, all values that are NaN are replaced, irrespective of their bitpatterns.

Parameters:
  • replacements (dict[int | float, int | float | Replacement | Literal['finite_min', 'finite_mean', 'finite_max', 'nan_min', 'nan_mean', 'nan_max']]) –

    Mapping from values to be replaced to the replacement values.

Methods:

  • encode

    Encode the data in buf.

  • decode

    Decode the data in buf.

  • get_config

    Returns the configuration of this replacement filter codec.

codec_id class-attribute instance-attribute

codec_id: str = 'replace.filter'

encode

encode(buf: Buffer) -> Buffer

Encode the data in buf.

Parameters:
  • buf (Buffer) –

    Data to be encoded. May be any object supporting the new-style buffer protocol.

Returns:
  • enc( Buffer ) –

    Encoded data. May be any object supporting the new-style buffer protocol.

decode

decode(buf: Buffer, out: None | Buffer = None) -> Buffer

Decode the data in buf.

Parameters:
  • buf (Buffer) –

    Encoded data. May be any object supporting the new-style buffer protocol.

  • out (Buffer, default: None ) –

    Writeable buffer to store decoded data. N.B. if provided, this buffer must be exactly the right size to store the decoded data.

Returns:
  • dec( Buffer ) –

    Decoded data. May be any object supporting the new-style buffer protocol.

get_config

get_config() -> dict

Returns the configuration of this replacement filter codec.

numcodecs.registry.get_codec(config) can be used to reconstruct this codec from the returned config.

Returns:
  • config( dict ) –

    Configuration of this replacement filter codec.