Skip to content

Commit

Permalink
Version 3.0.6: Add FOV support
Browse files Browse the repository at this point in the history
  • Loading branch information
rbnvrw committed Oct 30, 2017
1 parent dc4e31c commit 3367707
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs
Submodule docs updated from 438ef0 to f3f986
2 changes: 1 addition & 1 deletion nd2reader/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from nd2reader.reader import ND2Reader
from nd2reader.legacy import Nd2

__version__ = '3.0.5'
__version__ = '3.0.6'
10 changes: 6 additions & 4 deletions nd2reader/reader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pims.base_frames import FramesSequenceND, Frame
from pims.base_frames import FramesSequenceND

from nd2reader.exceptions import EmptyFileError
from nd2reader.parser import Parser
Expand Down Expand Up @@ -52,7 +52,7 @@ def _get_default(self, coord):
except KeyError:
return 0

def get_frame_2D(self, c=0, t=0, z=0, x=0, y=0):
def get_frame_2D(self, c=0, t=0, z=0, x=0, y=0, v=0):
"""Gets a given frame using the parser
Args:
Expand All @@ -61,6 +61,7 @@ def get_frame_2D(self, c=0, t=0, z=0, x=0, y=0):
c: The color channel number
t: The frame number
z: The z stack number
v: The field of view index
Returns:
numpy.ndarray: The requested frame
Expand All @@ -73,7 +74,7 @@ def get_frame_2D(self, c=0, t=0, z=0, x=0, y=0):

x = self.metadata["width"] if x <= 0 else x
y = self.metadata["height"] if y <= 0 else y
return self._parser.get_image_by_attributes(t, 0, c_name, z, y, x)
return self._parser.get_image_by_attributes(t, v, c_name, z, y, x)

@property
def parser(self):
Expand Down Expand Up @@ -136,6 +137,7 @@ def _setup_axes(self):
self._init_axis_if_exists('c', len(self._get_metadata_property("channels", default=[])), min_size=2)
self._init_axis_if_exists('t', len(self._get_metadata_property("frames", default=[])))
self._init_axis_if_exists('z', len(self._get_metadata_property("z_levels", default=[])), min_size=2)
self._init_axis_if_exists('v', len(self._get_metadata_property("fields_of_view", default=[])), min_size=2)

if len(self.sizes) == 0:
raise EmptyFileError("No axes were found for this .nd2 file.")
Expand All @@ -153,7 +155,7 @@ def _guess_default_iter_axis(self):
Returns:
the axis to iterate over
"""
priority = ['t', 'z', 'c']
priority = ['t', 'z', 'c', 'v']
found_axes = []
for axis in priority:
try:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

VERSION = '3.0.5'
VERSION = '3.0.6'

if __name__ == '__main__':
setup(
Expand Down
4 changes: 2 additions & 2 deletions sphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
# built documents.
#
# The short X.Y version.
version = '3.0.5'
version = '3.0.6'
# The full version, including alpha/beta/rc tags.
release = '3.0.5'
release = '3.0.6'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
44 changes: 43 additions & 1 deletion sphinx/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ 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:
Expand All @@ -74,4 +73,47 @@ All metadata properties are:
* `rois`: the regions of interest (ROIs) defined by the user
* `experiment`: information about the nature and timings of the ND experiment

### Iterating over fields of view

Using `NDExperiments` in the Nikon software, it is possible to acquire images on different `(x, y)` positions.
This is referred to as different fields of view. Using this reader, the fields of view are on the `v` axis.
For example:
```python
from nd2reader import ND2Reader

with ND2Reader('my_directory/example.nd2') as images:
# width and height of the image
print(images.metadata)
```
will output
```python
{'channels': ['BF100xoil-1x-R', 'BF+RITC'],
'date': datetime.datetime(2017, 10, 30, 14, 35, 18),
'experiment': {'description': 'ND Acquisition',
'loops': [{'duration': 0,
'sampling_interval': 0.0,
'start': 0,
'stimulation': False}]},
'fields_of_view': [0, 1],
'frames': [0],
'height': 1895,
'num_frames': 1,
'pixel_microns': 0.09214285714285715,
'total_images_per_channel': 6,
'width': 2368,
'z_levels': [0, 1, 2]}
```
for our example file. As you can see from the metadata, it has two fields of view. We can also look at the sizes of the axes:
```python
print(images.sizes)
```
```python
{'c': 2, 't': 1, 'v': 2, 'x': 2368, 'y': 1895, 'z': 3}
```
As you can see, the fields of view are listed on the `v` axis. It is therefore possible to loop over them like this:
```python
images.iter_axes = 'v'
for fov in images:
print(fov) # Frame containing one field of view
```
For more information on axis bundling and iteration, refer to the [pims documentation](http://soft-matter.github.io/pims/v0.4/multidimensional.html#axes-bundling).

0 comments on commit 3367707

Please sign in to comment.