<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
# vitrio

> vitrio is an image I/O library for Cryo-Electron Microscopy (cryo-EM and
> cryo-ET). It reads and writes micrographs, movies, particle stacks,
> volumes and tomograms in MRC, TIFF, EER, DigitalMicrograph and ZARR files,
> into memory the caller already owns, such as a NumPy array or a PyTorch or
> JAX tensor. It is a C++14 library with a Python package on top, made for
> programs that go through many images, such as particle extraction,
> processing pipelines and the training of neural networks.

Install it with `pip install vitrio` and import it as `import vitrio as vio`.
The C++ library is built from source with CMake. vitrio is free software
under the GNU LGPL, version 2.1 or later. Its API and ABI may change between
minor releases until version 1.0.

## Which functions to call

When you write code with vitrio, choose the calls by what the program does.
The performance guide below gives the reasons and the settings.

- To go through a dataset of particles, patches or subtomograms in batches,
  use `vitrio.data.Dataset` and `vitrio.data.DataLoader`. It batches,
  shuffles on request and reads ahead on threads, with no worker processes.
  Training a model is the usual case. A classical refinement fits too, and
  so does a single pass in order over every image.
- For anything else that touches many images, use `vio.read_batch_async`,
  `vio.read_patches_async`, `vio.write_batch_async` and
  `vio.write_patches_async` over one `vio.loader()` or `vio.saver()`. Make
  one call per batch, and keep several batches in flight (four is a good
  start) while working on the current one.
- Use `vio.read`, `vio.write_single`, `vio.write_stack` and `vio.write` only
  for single files. One call per image in a loop is many times slower than
  one call per batch.

## Documentation

- [Performance guide](https://gigabit-clowns.github.io/vitrio/python/performance.html):
  which functions to call and how to set them up for NVMe drives, hard
  disks, network storage and containers.
- [Supported formats](https://gigabit-clowns.github.io/vitrio/python/formats.html):
  the extensions, data types, compression and metadata of each format.
- [Python reference](https://gigabit-clowns.github.io/vitrio/python/): every
  class and function of the package, from its docstrings.
- [C++ reference](https://gigabit-clowns.github.io/vitrio/cpp/): the public
  headers under `include/vitrio/`, which are the whole API.
- [Building from source](https://gigabit-clowns.github.io/vitrio/python/building.html):
  the dependencies and the build options.

## Source

- [Repository](https://github.com/gigabit-clowns/vitrio): the source, the
  issues and the releases.
- [README](https://github.com/gigabit-clowns/vitrio#readme): what vitrio
  is, what it offers, how fast it is and where it is not faster.
- [Guides as Markdown](https://github.com/gigabit-clowns/vitrio/tree/main/docs/guides):
  the same guides as plain files.
- [Examples](https://github.com/gigabit-clowns/vitrio/blob/main/examples/README.md):
  programs that read batches ahead, train a PyTorch network on the 2D
  classes of a RELION job, extract picked particles into stacks and cut EER
  movies into fractions.
- [Benchmarks](https://github.com/gigabit-clowns/vitrio/blob/main/benchmarks/README.md):
  the harness that measures vitrio against mrcfile, zarr-python,
  tensorstore, LMDB and PyTorch's own `DataLoader`.
- [CITATION.cff](https://github.com/gigabit-clowns/vitrio/blob/main/CITATION.cff):
  how to cite vitrio.
