bioalpha.h5ad_map.H5ADMap.write
- H5ADMap.write(filename: PathLike | None = None, compression: Literal['gzip', 'lzf'] | None = None, compression_opts: int | Any | None = None, as_dense: Sequence[str] = ())
Write .h5ad-formatted hdf5 file.
Note
Setting compression to ‘gzip’ can save disk space but will slow down writing and subsequent reading. Prior to v0.6.16, this was the default for parameter compression.
Generally, if you have sparse data that are stored as a dense matrix, you can dramatically improve performance and reduce disk space by converting to a
csr_matrix
:from scipy.sparse import csr_matrix adata.X = csr_matrix(adata.X)
- Parameters:
filename – Filename of data file. Defaults to backing file.
compression –
For [lzf, gzip], see the h5py dataset_compression.
Alternative compression filters such as zstd can be passed from the hdf5plugin library. Experimental.
Usage example:
import hdf5plugin adata.write_h5ad( filename, compression=hdf5plugin.FILTERS["zstd"] )
Note
Datasets written with hdf5plugin-provided compressors cannot be opened without first loading the hdf5plugin library using import hdf5plugin. When using alternative compression filters such as zstd, consider writing to zarr format instead of h5ad, as the zarr library provides a more transparent compression pipeline.
compression_opts –
For [lzf, gzip], see the h5py dataset_compression.
Alternative compression filters such as zstd can be configured using helpers from the hdf5plugin library. Experimental.
Usage example (setting zstd compression level to 5):
import hdf5plugin adata.write_h5ad( filename, compression=hdf5plugin.FILTERS["zstd"], compression_opts=hdf5plugin.Zstd(clevel=5).filter_options )
as_dense – Sparse arrays in AnnData object to write as dense. Currently only supports X and raw/X.