Skip to content

Commit e7fb670

Browse files
author
Ruben Verweij
committed
Version 3.3.0
1 parent af7ce89 commit e7fb670

File tree

5 files changed

+151
-122
lines changed

5 files changed

+151
-122
lines changed

Diff for: .gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[submodule "docs"]
22
path = docs
3-
url = https://github.com/rbnvrw/nd2reader.git
3+
url = git@github.com:rbnvrw/nd2reader.git
44
branch = gh-pages

Diff for: docs

Submodule docs updated from f700c23 to 42dbfdf

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup
22

3-
VERSION = '3.2.3'
3+
VERSION = '3.3.0'
44

55
if __name__ == '__main__':
66
setup(

Diff for: sphinx/tutorial.md

-119
This file was deleted.

Diff for: sphinx/tutorial.rst

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
Tutorial
2+
========
3+
4+
Installation
5+
~~~~~~~~~~~~
6+
7+
The package is available on PyPi. Install it using:
8+
9+
::
10+
11+
pip install nd2reader
12+
13+
If you don't already have the packages ``numpy``, ``pims``, ``six`` and
14+
``xmltodict``, they will be installed automatically if you use the
15+
``setup.py`` script. ``nd2reader`` is an order of magnitude faster in
16+
Python 3. I recommend using it unless you have no other choice. Python
17+
2.7 and Python >= 3.4 are supported.
18+
19+
Installation via Conda Forge
20+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21+
22+
Installing ``nd2reader`` from the ``conda-forge`` channel can be
23+
achieved by adding ``conda-forge`` to your channels with:
24+
25+
::
26+
27+
conda config --add channels conda-forge
28+
29+
Once the ``conda-forge`` channel has been enabled, ``nd2reader`` can be
30+
installed with:
31+
32+
::
33+
34+
conda install nd2reader
35+
36+
It is possible to list all of the versions of ``nd2reader`` available on
37+
your platform with:
38+
39+
::
40+
41+
conda search nd2reader --channel conda-forge
42+
43+
Opening ND2s
44+
~~~~~~~~~~~~
45+
46+
``nd2reader`` follows the `pims <https://github.com/soft-matter/pims>`__
47+
framework. To open a file and show the first frame:
48+
49+
.. code:: python
50+
51+
from nd2reader import ND2Reader
52+
import matplotlib.pyplot as plt
53+
54+
with ND2Reader('my_directory/example.nd2') as images:
55+
plt.imshow(images[0])
56+
57+
After opening the file, all ``pims`` features are supported. Please
58+
refer to the `pims
59+
documentation <http://soft-matter.github.io/pims/>`__.
60+
61+
ND2 metadata
62+
~~~~~~~~~~~~
63+
64+
The ND2 file contains various metadata, such as acquisition information,
65+
regions of interest and custom user comments. Most of this metadata is
66+
parsed and available in dictionary form. For example:
67+
68+
.. code:: python
69+
70+
from nd2reader import ND2Reader
71+
72+
with ND2Reader('my_directory/example.nd2') as images:
73+
# width and height of the image
74+
print('%d x %d px' % (images.metadata['width'], images.metadata['height']))
75+
76+
All metadata properties are:
77+
78+
- ``width``: the width of the image in pixels
79+
- ``height``: the height of the image in pixels
80+
- ``date``: the date the image was taken
81+
- ``fields_of_view``: the fields of view in the image
82+
- ``frames``: a list of all frame numbers
83+
- ``z_levels``: the z levels in the image
84+
- ``total_images_per_channel``: the number of images per color channel
85+
- ``channels``: the color channels
86+
- ``pixel_microns``: the amount of microns per pixel
87+
- ``rois``: the regions of interest (ROIs) defined by the user
88+
- ``experiment``: information about the nature and timings of the ND
89+
experiment
90+
91+
Iterating over fields of view
92+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93+
94+
Using ``NDExperiments`` in the Nikon software, it is possible to acquire
95+
images on different ``(x, y)`` positions. This is referred to as
96+
different fields of view. Using this reader, the fields of view are on
97+
the ``v`` axis. For example:
98+
99+
.. code:: python
100+
101+
from nd2reader import ND2Reader
102+
103+
with ND2Reader('my_directory/example.nd2') as images:
104+
# width and height of the image
105+
print(images.metadata)
106+
107+
will output
108+
109+
.. code:: python
110+
111+
{'channels': ['BF100xoil-1x-R', 'BF+RITC'],
112+
'date': datetime.datetime(2017, 10, 30, 14, 35, 18),
113+
'experiment': {'description': 'ND Acquisition',
114+
'loops': [{'duration': 0,
115+
'sampling_interval': 0.0,
116+
'start': 0,
117+
'stimulation': False}]},
118+
'fields_of_view': [0, 1],
119+
'frames': [0],
120+
'height': 1895,
121+
'num_frames': 1,
122+
'pixel_microns': 0.09214285714285715,
123+
'total_images_per_channel': 6,
124+
'width': 2368,
125+
'z_levels': [0, 1, 2]}
126+
127+
for our example file. As you can see from the metadata, it has two
128+
fields of view. We can also look at the sizes of the axes:
129+
130+
.. code:: python
131+
132+
print(images.sizes)
133+
134+
.. code:: python
135+
136+
{'c': 2, 't': 1, 'v': 2, 'x': 2368, 'y': 1895, 'z': 3}
137+
138+
As you can see, the fields of view are listed on the ``v`` axis. It is
139+
therefore possible to loop over them like this:
140+
141+
.. code:: python
142+
143+
images.iter_axes = 'v'
144+
for fov in images:
145+
print(fov) # Frame containing one field of view
146+
147+
For more information on axis bundling and iteration, refer to the `pims
148+
documentation <http://soft-matter.github.io/pims/v0.4/multidimensional.html#axes-bundling>`__.

0 commit comments

Comments
 (0)