ClearAnatomics / ClearMap

ClearMap 2 with WobblyStitcher, TubeMap and CellMap
https://clearanatomics.github.io/ClearMapDocumentation/
GNU General Public License v3.0
114 stars 45 forks source link

[BUG] IO: Unable to read TIF file that was written by ClearMap (custom script) #151

Open edoumazane opened 1 week ago

edoumazane commented 1 week ago

Operating System

Linux

OS Version

Ubuntu 20.04.6 LTS

Code Version

2.1.0

How are you using the application?

New scripts

Expected Behavior

A TIF file saved with ClearMap's ClearMap.IO.IO.write can be read by the ClearMap.IO.IO.read function

Actual Behavior

NotImplementedError.

The file is actually written and can be read with tifffile.imread (or Fiji)

Steps to Reproduce

import os
import tempfile
import numpy as np
import tifffile
import ClearMap.IO.IO as cmio

# temporary file path
tmp_dir = tempfile.gettempdir()
path = os.path.join(tmp_dir, "image.tif")
print(path)

# random 3D array, uint16
dtype = np.uint16
rng = np.random.RandomState(1234)
arr = rng.randint(0, 2**16-1, (10, 20, 30)).astype(dtype)

# write file
cmio.write(path, arr)

# read file with ClearMap -> error
cmio.read(path)

Logs and Screenshots

Traceback (most recent call last):
  File "/home/etienne.doumazane/code/ClearAnatomics/clear-deformation/scratch.py", line 21, in <module>
    cmio.read(path)
  File "/home/etienne.doumazane/programs/miniconda3/envs/ClearMapUi311/lib/python3.11/site-packages/ClearMap2-2.1.3-py3.11-linux-x86_64.egg/ClearMap/IO/IO.py", line 437, in read
    return mod.read(source_, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/etienne.doumazane/programs/miniconda3/envs/ClearMapUi311/lib/python3.11/site-packages/ClearMap2-2.1.3-py3.11-linux-x86_64.egg/ClearMap/IO/TIF.py", line 516, in read
    return source.array
           ^^^^^^^^^^^^
  File "/home/etienne.doumazane/programs/miniconda3/envs/ClearMapUi311/lib/python3.11/site-packages/ClearMap2-2.1.3-py3.11-linux-x86_64.egg/ClearMap/IO/TIF.py", line 128, in array
    return self.to_clearmap_order(array)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/etienne.doumazane/programs/miniconda3/envs/ClearMapUi311/lib/python3.11/site-packages/ClearMap2-2.1.3-py3.11-linux-x86_64.egg/ClearMap/IO/TIF.py", line 173, in to_clearmap_order
    transposed = tif_to_clearmap_order(array, self.axes_order)
                                              ^^^^^^^^^^^^^^^
  File "/home/etienne.doumazane/programs/miniconda3/envs/ClearMapUi311/lib/python3.11/site-packages/ClearMap2-2.1.3-py3.11-linux-x86_64.egg/ClearMap/IO/TIF.py", line 66, in axes_order
    md = self.metadata(info=['shape'])
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/etienne.doumazane/programs/miniconda3/envs/ClearMapUi311/lib/python3.11/site-packages/ClearMap2-2.1.3-py3.11-linux-x86_64.egg/ClearMap/IO/TIF.py", line 234, in metadata
    parser.parse()
  File "/home/etienne.doumazane/programs/miniconda3/envs/ClearMapUi311/lib/python3.11/site-packages/ClearMap2-2.1.3-py3.11-linux-x86_64.egg/ClearMap/IO/TIF.py", line 301, in parse
    self.parse_pixel_metadata()
  File "/home/etienne.doumazane/programs/miniconda3/envs/ClearMapUi311/lib/python3.11/site-packages/ClearMap2-2.1.3-py3.11-linux-x86_64.egg/ClearMap/IO/TIF.py", line 346, in parse_pixel_metadata
    self.parse_order()
  File "/home/etienne.doumazane/programs/miniconda3/envs/ClearMapUi311/lib/python3.11/site-packages/ClearMap2-2.1.3-py3.11-linux-x86_64.egg/ClearMap/IO/TIF.py", line 471, in parse_order
    super().parse_order()
  File "/home/etienne.doumazane/programs/miniconda3/envs/ClearMapUi311/lib/python3.11/site-packages/ClearMap2-2.1.3-py3.11-linux-x86_64.egg/ClearMap/IO/TIF.py", line 327, in parse_order
    self.info['order'] = self.pixels_metadata.get('DimensionOrder', None)
                         ^^^^^^^^^^^^^^^^^^^^
  File "/home/etienne.doumazane/programs/miniconda3/envs/ClearMapUi311/lib/python3.11/functools.py", line 1001, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "/home/etienne.doumazane/programs/miniconda3/envs/ClearMapUi311/lib/python3.11/site-packages/ClearMap2-2.1.3-py3.11-linux-x86_64.egg/ClearMap/IO/TIF.py", line 374, in pixels_metadata
    raise NotImplementedError("Subclasses should implement this method")
NotImplementedError: Subclasses should implement this method
edoumazane commented 1 week ago

Issue #148 is related (similar error message)