Browse Source

#66 even more refactoring

feature/load_slices
jim 9 years ago
parent
commit
45c148a1d3
5 changed files with 23 additions and 14 deletions
  1. +2
    -0
      nd2reader/exc.py
  2. +2
    -4
      nd2reader/imreader/v3.py
  3. +9
    -5
      nd2reader/model/image.py
  4. +9
    -1
      nd2reader/parser/parser.py
  5. +1
    -4
      nd2reader/version.py

+ 2
- 0
nd2reader/exc.py View File

@ -0,0 +1,2 @@
class InvalidVersionError(Exception):
pass

+ 2
- 4
nd2reader/imreader/v3.py View File

@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
import array
from datetime import datetime
import numpy as np
import re
import struct
import six
from nd2reader.model.image import Image
@ -59,7 +57,7 @@ class V3ImageReader(object):
"""
channel_offset = {}
for n, channel in enumerate(self._channels):
for n, channel in enumerate(self._metadata.channels):
channel_offset[channel] = n
return channel_offset
@ -86,7 +84,7 @@ class V3ImageReader(object):
# The images for the various channels are interleaved within the same array. For example, the second image
# of a four image group will be composed of bytes 2, 6, 10, etc. If you understand why someone would design
# a data structure that way, please send the author of this library a message.
image_data = np.reshape(image_group_data[image_data_start::len(self.channels)], (height, width))
image_data = np.reshape(image_group_data[image_data_start::len(self._metadata.channels)], (height, width))
# Skip images that are all zeros! This is important, since NIS Elements creates blank "gap" images if you
# don't have the same number of images each cycle. We discovered this because we only took GFP images every
# other cycle to reduce phototoxicity, but NIS Elements still allocated memory as if we were going to take


+ 9
- 5
nd2reader/model/image.py View File

@ -21,10 +21,6 @@ class Image(np.ndarray):
:type channel: str
:param z_level: The label for the location in the Z-plane where this image was taken.
:type z_level: int
:param height: The height of the image in pixels.
:type height: int
:param width: The width of the image in pixels.
:type width: int
"""
self._timestamp = timestamp
@ -37,12 +33,20 @@ class Image(np.ndarray):
return "\n".join(["<ND2 Image>",
"%sx%s (HxW)" % (self.height, self.width),
"Timestamp: %s" % self.timestamp,
"Frame: %s" % self._frame_number,
"Frame: %s" % self.frame_number,
"Field of View: %s" % self.field_of_view,
"Channel: %s" % self.channel,
"Z-Level: %s" % self.z_level,
])
@property
def height(self):
return self.shape[1]
@property
def width(self):
return self.shape[0]
@property
def field_of_view(self):
"""


+ 9
- 1
nd2reader/parser/parser.py View File

@ -1,2 +1,10 @@
from nd2reader.parser.v3 import V3Parser
from nd2reader.exc import InvalidVersionError
def get_parser(filename, major_version, minor_version):
parsers = {}
parsers = {(3, None): V3Parser}
parser = parsers.get((major_version, minor_version)) or parsers.get((major_version, None))
if not parser:
raise InvalidVersionError("No parser is available for that version.")
return parser(filename)

+ 1
- 4
nd2reader/version.py View File

@ -1,8 +1,5 @@
import re
class InvalidVersionError(Exception):
pass
from nd2reader.exc import InvalidVersionError
def get_version(filename):


Loading…
Cancel
Save