Browse Source

reads the chunk map location

master
Jim Rybarski 10 years ago
parent
commit
8b01f7ff65
1 changed files with 37 additions and 0 deletions
  1. +37
    -0
      nd2reader/__init__.py

+ 37
- 0
nd2reader/__init__.py View File

@ -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)

Loading…
Cancel
Save