From 8b01f7ff653b1264d8546686545e17c2ce508979 Mon Sep 17 00:00:00 2001 From: Jim Rybarski Date: Thu, 28 Aug 2014 01:04:42 -0500 Subject: [PATCH] reads the chunk map location --- nd2reader/__init__.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 nd2reader/__init__.py diff --git a/nd2reader/__init__.py b/nd2reader/__init__.py new file mode 100644 index 0000000..bf83a19 --- /dev/null +++ b/nd2reader/__init__.py @@ -0,0 +1,37 @@ +import array +import numpy as np +import struct +import StringIO + + +class Nd2Reader(object): + """ + Reads .nd2 files, provides an interface to the metadata, and generates numpy arrays from the image data. + + """ + def __init__(self, filename): + self._filename = filename + self._file_handler = None + + @property + def file_handler(self): + if self._file_handler is None: + self._file_handler = open(self._filename, "rb") + return self._file_handler + + @property + def chunk_map_location(self): + """ + The position in bytes from the beginning of the file where the chunk map begins. + The chunk map is a series of string labels followed by the position (in bytes) of the respective data. + + """ + self.file_handler.seek(-8, 2) + return struct.unpack("Q", self.file_handler.read(8))[0] + + def read_chunk(self, location): + pass + + @staticmethod + def as_numpy_array(arr): + return np.frombuffer(arr) \ No newline at end of file