121 def from_mapping(cls, mapping: Mapping[str, object]) -> CompressionOptions:
122 """Construct from a dictionary with keys matching this struct's fields.
126 mapping : `~collections.abc.Mapping`
127 Mapping from string to value. Enumeration values may be passed as
128 string value names. Missing keys are mapped to default values.
132 options : `CompressionOptions`
133 An instance of this options class.
139 - ``algorithm``: `str`, one of ``GZIP_1``, ``GZIP_2``, or ``RICE_1``.
140 - ``tile_width``: `int`, zero to use entire rows.
141 - ``tile_height``: `int`, zero to use entire columns.
142 - ``quantization``: `dict` or `None` (see
143 `QuantizationOptions.from_mapping`).
145 Missing keys are replaced by defaults that reflect lossless compression
146 (``GZIP_2``) with single rows as tiles.
150 if "algorithm" in copy:
151 result.algorithm = CompressionAlgorithm[copy.pop(
"algorithm")]
152 if "tile_width" in copy:
153 result.tile_width = copy.pop(
"tile_width")
154 if "tile_height" in copy:
155 result.tile_height = copy.pop(
"tile_height")
156 if (quantization := copy.pop(
"quantization",
None))
is not None:
157 result.quantization = QuantizationOptions.from_mapping(quantization)
159 raise ValueError(f
"Unrecognized compression options: {list(copy.keys())}.")