For now, the package is only available via GitHub. Install it using:
pip install --upgrade https://github.com/rbnvrw/nd2reader/tarball/master
If you don't already have the packages numpy
, pims
, six
and xmltodict
, they will be installed automatically if you use the setup.py
script.
nd2reader
is an order of magnitude faster in Python 3. I recommend using it unless you have no other choice. Python 2.7 and Python >= 3.4 are supported.
nd2reader
follows the pims framework. To open a file and show the first frame:
from nd2reader import ND2Reader
import matplotlib.pyplot as plt
with ND2Reader('my_directory/example.nd2') as images:
plt.imshow(images[0])
After opening the file, all pims
features are supported. Please refer to the pims documentation.
The ND2 file contains various metadata, such as acquisition information, regions of interest and custom user comments. Most of this metadata is parsed and available in dictionary form. For example:
from nd2reader import ND2Reader
with ND2Reader('my_directory/example.nd2') as images:
# width and height of the image
print('%d x %d px' % (images.metadata['width'], images.metadata['height']))
All metadata properties are:
width
: the width of the image in pixelsheight
: the height of the image in pixelsdate
: the date the image was takenfields_of_view
: the fields of view in the imageframes
: a list of all frame numbersz_levels
: the z levels in the imagetotal_images_per_channel
: the number of images per color channelchannels
: the color channelspixel_microns
: the amount of microns per pixelrois
: the regions of interest (ROIs) defined by the userexperiment
: information about the nature and timings of the ND experiment