Skip to main content

Command-line tool and python library for visualising small 3D datasets

Project description

smalldataviewer

Travis PyPI PyPI - Python Version

Simple matplotlib-based tool for viewing small amounts of 3D image data; helpful for debugging. Supports python 2.7 and 3.4+.

Adapted from this matplotlib recipe.

Small ssTEM Volume

Installation

pip install smalldataviewer[all]

The all installation includes all of these optional extras:

  • hdf5: HDF5 file support via h5py
  • img: volumetric and animated images via imageio
  • fits: FITS images via imageio[fits], which uses astropy
  • itk: ITK images via imageio[simpleitk], which uses SimpleITK

Support for N5 and zarr arrays is also available via z5py. This must be installed with conda (conda install -c conda-forge -c cpape z5py).

Usage

The DataViewer opens a matplotlib figure of the data volume.

  • Dimension 0 can be scrolled through with the mouse wheel
  • Dimension 1 is shown on the vertical axis
  • Dimension 2 is shown on the horizontal axis
  • Dimension 3, if it exists, is a colour tuple

As executable

Available as a command-line utility at smalldataviewer or sdv

usage: smalldataviewer [-h] [--version] [-i INTERNAL_PATH] [-t TYPE]
                       [-o ORDER] [-f OFFSET] [-s SHAPE] [-v] [-l]
                       path

positional arguments:
  path                  Path to file containing a 3D dataset

optional arguments:
  -h, --help            show this help message and exit
  --version             Print version information and exit
  -i INTERNAL_PATH, --internal_path INTERNAL_PATH
                        Internal path of dataset inside HDF5, N5, zarr or npz
                        file. If JSON, assumes the outer object is a dict, and
                        internal_path is the key of the array
  -t TYPE, --type TYPE  Dataset file type. Inferred from extension if not
                        given.
  -o ORDER, --order ORDER
                        Order of non-channel axes for axis labelling purposes
                        (data is not transposed): dimension 0 will be scrolled
                        through, dimension 1 will be on the up-down axis,
                        dimension 2 will be on the left-right axis, and
                        dimension 3, if it exists, will be used as the colour
                        channels. Default "zyx".
  -f OFFSET, --offset OFFSET
                        3D offset of ROI from (0, 0, 0) in pixels, in the form
                        "<scroll>,<vertical>,<horizontal>"
  -s SHAPE, --shape SHAPE
                        3D shape of ROI in pixels, in the form
                        "<scroll>,<vertical>,<horizontal>"
  -v, --verbose         Increase logging verbosity
  -l, --label           Whether to treat images as a label volume

e.g.

smalldataviewer my_data.hdf5 -i /my_group/my_volume

Note: because of the circumstances under which python holds file descriptors open, and under which matplotlib blocks, the executable form reads the data into memory in its entirety. If your data are too big for this, look at small chunks with the --offset (-f) and --shape (-s) options.

As library

import smalldataviewer as sdv

import numpy as np
data = np.random.random((30, 100, 100))
viewer = sdv.DataViewer(data)
viewer.show()  # or matplotlib.pyplot.show()

viewer2 = sdv.DataViewer.from_file(
    "my_data.npz", offset=(10, 20, 30), shape=(256, 512, 512), internal_path="volume"
)
viewer2.show()

reader = sdv.FileReader("my_cat_video.gif")
data2 = reader.read()  # returns a numpy array
viewer3 = sdv.DataViewer(data2)
viewer3.show()

Note: FileReader (and by extension Dataviewer.from_file) reads the requested data from the file into memory. Passing an indexable representation of a file, like a numpy memmap or an hdf5 dataset, will not. However, you may need to copy it into memory for performance, or depending on the rest of your script.

Contributing

Install a development environment (not including z5py) with make install-dev

Run tests in your current python environment with make test

Run tests against all supported python versions with make test-all

If you would like to add support for a new file type:

  1. Add to tests/common a function which creates such a file and returns whether it needs an internal path, and add it to file_constructors.

  2. Add to smalldataviewer.files.FileReader a method which reads such a file, returning a numpy array, and add a mapping from likely file extensions to a single file type in NORMALISED_TYPES (see existing methods for examples).

  3. Don't forget to specify any dependencies in smalldataviewer.ext, extras_require in setup.py, and requirements.txt

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smalldataviewer-0.10.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smalldataviewer-0.10.0-py2.py3-none-any.whl (11.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file smalldataviewer-0.10.0.tar.gz.

File metadata

  • Download URL: smalldataviewer-0.10.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for smalldataviewer-0.10.0.tar.gz
Algorithm Hash digest
SHA256 a2b64333a51a0cc1c5a8e7b94dac5f412aa7cd12a72c33d76c7813491047f0fb
MD5 15a69d7ad566a96de4472646150ca572
BLAKE2b-256 45a15c2ec7fdf51bb6c92e330b214fca827f8ba910a8f4e5b54fd09d249594e4

See more details on using hashes here.

File details

Details for the file smalldataviewer-0.10.0-py2.py3-none-any.whl.

File metadata

  • Download URL: smalldataviewer-0.10.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for smalldataviewer-0.10.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3299f28572101d169a1585963861e97cb3e993c143916268c5699b5a3c25f053
MD5 01da12e01b391eee496f533a0ad00689
BLAKE2b-256 74e9a0d3c8a5c21be7099d5e7491f66fb9cd002b4fd700253001c774f7ec88df

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page