From 2e9b558b1572e0dc4e4f11c2a6f9d9532a9a8a48 Mon Sep 17 00:00:00 2001 From: jim Date: Mon, 10 Nov 2014 13:06:56 -0600 Subject: [PATCH] got images sorta working again --- nd2reader/__init__.py | 89 ++++++++++++++++++++++--------------------- run.py | 21 +++++----- 2 files changed, 56 insertions(+), 54 deletions(-) diff --git a/nd2reader/__init__.py b/nd2reader/__init__.py index 3dd9ebc..5520ddf 100644 --- a/nd2reader/__init__.py +++ b/nd2reader/__init__.py @@ -5,7 +5,7 @@ from collections import namedtuple from StringIO import StringIO chunk = namedtuple('Chunk', ['location', 'length']) -field_of_view = namedtuple('FOV', ['x', 'y', 'z', 'pfs_offset']) +field_of_view = namedtuple('FOV', ['number', 'x', 'y', 'z', 'pfs_offset']) channel = namedtuple('Channel', ['name', 'camera', 'exposure_time']) @@ -23,8 +23,8 @@ class Nd2(object): @property def fields_of_view(self): - for fov in self.metadata['ImageMetadata']['SLxExperiment']['ppNextLevelEx'][''][0]['uLoopPars']['Points']['']: - yield field_of_view(x=fov['dPosX'], y=fov['dPosY'], z=fov['dPosZ'], pfs_offset=fov['dPFSOffset']) + for number, fov in enumerate(self.metadata['ImageMetadata']['SLxExperiment']['ppNextLevelEx']['']['uLoopPars']['Points']['']): + yield field_of_view(number=number + 1, x=fov['dPosX'], y=fov['dPosY'], z=fov['dPosZ'], pfs_offset=fov['dPFSOffset']) @property def fov_count(self): @@ -43,14 +43,17 @@ class Nd2(object): def metadata(self): return self._parser.metadata + def get_images(self, fov_number, channel_name, z_axis): + pass - - - - - - - + def get_image(self, nr): + d = self._parser._read_chunk(self._parser._label_map["ImageDataSeq|%d!" % nr].location) + acqtime = struct.unpack("d", d[:8])[0] + res = [acqtime] + for i in range(self.metadata['ImageAttributes']["SLxImageAttributes"]["uiComp"]): + a = array.array("H", d) + res.append(a[4+i::self.metadata['ImageAttributes']["SLxImageAttributes"]["uiComp"]]) + return res class Nd2Parser(object): @@ -244,42 +247,42 @@ class Nd2Parser(object): if not name in res: res[name] = value else: - if type(res[name]) != type([]): + if not isinstance(res[name], list): res[name] = [res[name]] res[name].append(value) x = data.read() assert not x, "skip %d %s" % (len(x), repr(x[:30])) return res - -class LVLine(object): - def __init__(self, line): - self._line = line - self._extract() - - def _extract(self): - if self._type == 11: - count, length = struct.unpack("