gunz_cm.io#
Module contents#
- class gunz_cm.io.GZCMReader(fpath: str | pathlib.Path)[source]#
Bases:
objectReader for GZCM container format.
Supports reading GZCM v1, v2, and v3 files.
- Parameters:
fpath (str | pathlib.Path) – Input file path.
Examples
>>> reader = GZCMReader("data.gzcm") >>> version = reader.version >>> metadata = reader.get_metadata() >>> matrix = reader.get_array("matrix")
- decode_compressed_tile(payload: bytes) ndarray[source]#
Decode a compressed tile using CMC.
- Parameters:
payload (bytes) – Encoded compressed data.
- Returns:
Decoded contact matrix tile.
- Return type:
np.ndarray
- get_compressed_tile(name: str, index: int = 0, return_shape: bool = False) bytes | tuple[bytes, tuple[int, int]][source]#
Read a compressed tile without decoding.
v3 GZCM tiles carry an 8-byte (rows, cols) int32 header that the zstd/bsc decoders consume. Pass
return_shape=Trueto also recover the tile shape from that header alongside the raw payload bytes.- Parameters:
- Returns:
Encoded compressed data; optionally paired with the (rows, cols) shape decoded from the 8-byte header.
- Return type:
- Raises:
ValueError – If the payload is shorter than 8 bytes when
return_shapeis requested, or if the CRC32 checksum does not match.
- class gunz_cm.io.GZCMWriter(fpath: str | pathlib.Path, overwrite: bool = False, version: int = 1)[source]#
Bases:
objectWriter for GZCM container format.
Supports writing GZCM v1, v2 (dense arrays) and GZCM v3 (compressed tiles).
- Parameters:
fpath (str | pathlib.Path) – Output file path.
overwrite (bool, default=False) – Overwrite existing file.
version (int, default=1) – GZCM format version. Use 3 for compressed tiles.
Examples
>>> writer = GZCMWriter("output.gzcm", overwrite=True) >>> writer.add_array("matrix", data) >>> writer.write()
- add_array(name: str, data: ndarray, dtype: str | numpy.dtype | None = None) None[source]#
Register a complete array to be written.
Data is not written until write() is called.
- add_compressed_tile(name: str, payload: bytes, uncompressed_size: int, checksum: int | None = None) None[source]#
Add a pre-encoded compressed tile.
- get_array_writable(name: str) memmap[source]#
Returns a writable memmap for a specific array in the container.
- Parameters:
name (str) – Array name.
- Returns:
Writable memory-mapped array.
- Return type:
np.memmap
- init_compressed_tile_stream(name: str, n_tiles: int, max_tile_size: int) None[source]#
Reserve space for streaming tile writes.
- init_streaming_array(name: str, shape: tuple[int, ...], dtype: str | numpy.dtype) None[source]#
Reserve space for an array to be written incrementally.