Browse Source

#66 resolves v3 driver refactor

master
jim 9 years ago
parent
commit
89d78030f1
6 changed files with 54 additions and 21 deletions
  1. +0
    -0
      nd2reader/driver/v2.py
  2. +26
    -3
      nd2reader/driver/v3.py
  3. +0
    -1
      nd2reader/imreader/__init__.py
  4. +7
    -10
      nd2reader/model/image.py
  5. +11
    -1
      nd2reader/model/metadata.py
  6. +10
    -6
      nd2reader/parser/v3.py

nd2reader/imreader/v2.py → nd2reader/driver/v2.py View File


nd2reader/imreader/v3.py → nd2reader/driver/v3.py View File


+ 0
- 1
nd2reader/imreader/__init__.py View File

@ -1 +0,0 @@
from nd2reader.driver.driver import get_driver

+ 7
- 10
nd2reader/model/image.py View File

@ -7,6 +7,13 @@ class Image(np.ndarray):
def __new__(cls, array):
return np.asarray(array).view(cls)
def __init__(self, array):
self._timestamp = None
self._frame_number = None
self._field_of_view = None
self._channel = None
self._z_level = None
def add_params(self, timestamp, frame_number, field_of_view, channel, z_level):
"""
A wrapper around the raw pixel data of an image.
@ -29,16 +36,6 @@ class Image(np.ndarray):
self._channel = channel
self._z_level = z_level
def __repr__(self):
return "\n".join(["<ND2 Image>",
"%sx%s (HxW)" % (self.height, self.width),
"Timestamp: %s" % self.timestamp,
"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]


+ 11
- 1
nd2reader/model/metadata.py View File

@ -1,12 +1,22 @@
class Metadata(object):
""" A simple container for ND2 metadata. """
def __init__(self, channels, date, fields_of_view, frames, z_levels):
def __init__(self, height, width, channels, date, fields_of_view, frames, z_levels):
self._height = height
self._width = width
self._channels = channels
self._date = date
self._fields_of_view = fields_of_view
self._frames = frames
self._z_levels = z_levels
@property
def height(self):
return self._height
@property
def width(self):
return self._width
@property
def date(self):
"""


+ 10
- 6
nd2reader/parser/v3.py View File

@ -4,6 +4,7 @@ import array
from datetime import datetime
from nd2reader.model.metadata import Metadata
from nd2reader.parser.base import BaseParser
from nd2reader.driver.v3 import V3Driver
import re
import six
import struct
@ -19,6 +20,7 @@ class V3Parser(BaseParser):
self._filename = filename
self._fh = None
self._metadata = None
self._label_map = None
@property
def metadata(self):
@ -28,7 +30,7 @@ class V3Parser(BaseParser):
@property
def driver(self):
raise NotImplementedError
return V3Driver(self.metadata, self._label_map, self._get_file_handle())
def _parse_metadata(self):
"""
@ -36,19 +38,21 @@ class V3Parser(BaseParser):
"""
metadata_dict = {}
label_map = self._build_label_map()
for label in label_map.keys():
self._label_map = self._build_label_map()
for label in self._label_map.keys():
if label.endswith(six.b("LV!")) or six.b("LV|") in label:
data = self._read_chunk(label_map[label])
data = self._read_chunk(self._label_map[label])
stop = label.index(six.b("LV"))
metadata_dict[label[:stop]] = self._read_metadata(data, 1)
height = metadata_dict[six.b('ImageAttributes')][six.b('SLxImageAttributes')][six.b('uiHeight')]
width = metadata_dict[six.b('ImageAttributes')][six.b('SLxImageAttributes')][six.b('uiWidth')]
channels = self._parse_channels(metadata_dict)
date = self._parse_fields_of_view(metadata_dict)
date = self._parse_date(metadata_dict)
fields_of_view = self._parse_fields_of_view(metadata_dict)
frames = self._parse_frames(metadata_dict)
z_levels = self._parse_z_levels(metadata_dict)
self._metadata = Metadata(channels, date, fields_of_view, frames, z_levels)
self._metadata = Metadata(height, width, channels, date, fields_of_view, frames, z_levels)
def _parse_date(self, metadata_dict):
"""


Loading…
Cancel
Save