Skip to content
Snippets Groups Projects
Commit fbdb5a8a authored by Ruben Verweij's avatar Ruben Verweij
Browse files

Version 3.0.6: Add FOV support

parent 31868d27
Branches
Tags
No related merge requests found
Subproject commit 438ef091834dbeab162f0255ff81db3396623b2a Subproject commit f3f986bb87ac932bc45fc494c7b72fa485848a87
from nd2reader.reader import ND2Reader from nd2reader.reader import ND2Reader
from nd2reader.legacy import Nd2 from nd2reader.legacy import Nd2
__version__ = '3.0.5' __version__ = '3.0.6'
from pims.base_frames import FramesSequenceND, Frame from pims.base_frames import FramesSequenceND
from nd2reader.exceptions import EmptyFileError from nd2reader.exceptions import EmptyFileError
from nd2reader.parser import Parser from nd2reader.parser import Parser
...@@ -52,7 +52,7 @@ class ND2Reader(FramesSequenceND): ...@@ -52,7 +52,7 @@ class ND2Reader(FramesSequenceND):
except KeyError: except KeyError:
return 0 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 """Gets a given frame using the parser
Args: Args:
...@@ -61,6 +61,7 @@ class ND2Reader(FramesSequenceND): ...@@ -61,6 +61,7 @@ class ND2Reader(FramesSequenceND):
c: The color channel number c: The color channel number
t: The frame number t: The frame number
z: The z stack number z: The z stack number
v: The field of view index
Returns: Returns:
numpy.ndarray: The requested frame numpy.ndarray: The requested frame
...@@ -73,7 +74,7 @@ class ND2Reader(FramesSequenceND): ...@@ -73,7 +74,7 @@ class ND2Reader(FramesSequenceND):
x = self.metadata["width"] if x <= 0 else x x = self.metadata["width"] if x <= 0 else x
y = self.metadata["height"] if y <= 0 else y 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 @property
def parser(self): def parser(self):
...@@ -136,6 +137,7 @@ class ND2Reader(FramesSequenceND): ...@@ -136,6 +137,7 @@ class ND2Reader(FramesSequenceND):
self._init_axis_if_exists('c', len(self._get_metadata_property("channels", default=[])), min_size=2) 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('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('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: if len(self.sizes) == 0:
raise EmptyFileError("No axes were found for this .nd2 file.") raise EmptyFileError("No axes were found for this .nd2 file.")
...@@ -153,7 +155,7 @@ class ND2Reader(FramesSequenceND): ...@@ -153,7 +155,7 @@ class ND2Reader(FramesSequenceND):
Returns: Returns:
the axis to iterate over the axis to iterate over
""" """
priority = ['t', 'z', 'c'] priority = ['t', 'z', 'c', 'v']
found_axes = [] found_axes = []
for axis in priority: for axis in priority:
try: try:
......
from setuptools import setup from setuptools import setup
VERSION = '3.0.5' VERSION = '3.0.6'
if __name__ == '__main__': if __name__ == '__main__':
setup( setup(
......
...@@ -44,9 +44,9 @@ author = 'Ruben Verweij' ...@@ -44,9 +44,9 @@ author = 'Ruben Verweij'
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = '3.0.5' version = '3.0.6'
# The full version, including alpha/beta/rc tags. # 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 # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.
......
...@@ -57,7 +57,6 @@ from nd2reader import ND2Reader ...@@ -57,7 +57,6 @@ from nd2reader import ND2Reader
with ND2Reader('my_directory/example.nd2') as images: with ND2Reader('my_directory/example.nd2') as images:
# width and height of the image # width and height of the image
print('%d x %d px' % (images.metadata['width'], images.metadata['height'])) print('%d x %d px' % (images.metadata['width'], images.metadata['height']))
``` ```
All metadata properties are: All metadata properties are:
...@@ -74,4 +73,47 @@ All metadata properties are: ...@@ -74,4 +73,47 @@ All metadata properties are:
* `rois`: the regions of interest (ROIs) defined by the user * `rois`: the regions of interest (ROIs) defined by the user
* `experiment`: information about the nature and timings of the ND experiment * `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% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment