From c3c0c65b0674186b4310b23046614bead027c858 Mon Sep 17 00:00:00 2001 From: Wim Pomp Date: Mon, 17 Oct 2022 16:56:26 +0200 Subject: [PATCH] Windows compatibility --- issfile/__init__.py | 65 ++++++++++++++++++++++----------------------- setup.py | 2 +- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/issfile/__init__.py b/issfile/__init__.py index e0dd9c0..dc34247 100644 --- a/issfile/__init__.py +++ b/issfile/__init__.py @@ -11,6 +11,33 @@ from yaml import safe_load from argparse import ArgumentParser +class TiffFile(IJTiffFile): + """ Modify the tiff writer so that it can read from the .iss-pt file by itself in parallel processes. """ + def __init__(self, *args, iss, bar, **kwargs): + if 'processes' not in kwargs: + kwargs['processes'] = 'all' + super().__init__(*args, **kwargs) + self.iss = iss + self.bar = bar + + def __getstate__(self): + return {key: value for key, value in self.__dict__.items() if key != 'bar'} + + def update(self): + self.bar.update() + + def compress_frame(self, frame): + if frame[0]: + frame, metadata = self.iss.get_carpet(*frame[1:]) + ifd, offsets = super().compress_frame(frame.astype(self.dtype)) + # ISS = 9*19*19 = 3249; list of t, x, y, z for each row in carpet + ifd[3249] = Tag('float', metadata.T.flatten()) + return ifd, offsets + else: + frame = self.iss.get_image(*frame[1:]) + return super().compress_frame(frame.astype(self.dtype)) + + class IssFile: def __init__(self, file, version=388): self.file = file @@ -65,6 +92,7 @@ class IssFile: frame = c + 2 * t * self.shape[2] frame_bytes = self.shape[0] * self.shape[1] * self.delta data = [] + # TODO: RuntimeWarning: overflow encountered in long_scalars for big files in next line for address in range(frame * frame_bytes, (frame + 1) * frame_bytes, self.delta): self.data.seek(address) data.append(unpack('