Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ashlar fails if ome.tiff data is float32 #172

Open
joaomamede opened this issue Mar 4, 2023 · 2 comments
Open

Ashlar fails if ome.tiff data is float32 #172

joaomamede opened this issue Mar 4, 2023 · 2 comments

Comments

@joaomamede
Copy link

joaomamede commented Mar 4, 2023

In the ome.tiff metadata the pixel type is "float" while numpy conversion is np.float32.

$ ashlar Cycle0.companion.ome Cycle1.companion.ome -c0

Stitching and registering input images
Cycle 0:
    reading Cycle0.companion.ome
WARNING: Stage coordinates' measurement unit is undefined; assuming μm.
    assembling thumbnail 1/439Traceback (most recent call last):
  File "/home/jmamede/anaconda3/envs/tensorflow/bin/ashlar", line 8, in <module>
    sys.exit(main())
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/scripts/ashlar.py", line 212, in main
    return process_single(
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/scripts/ashlar.py", line 243, in process_single
    edge_aligner.run()
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/reg.py", line 486, in run
    self.make_thumbnail()
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/reg.py", line 497, in make_thumbnail
    self.reader.thumbnail = thumbnail.make_thumbnail(
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/thumbnail.py", line 20, in make_thumbnail
    img = reader.read(c=channel, series=i)
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/reg.py", line 431, in read
    img = self.reader.read(series, c)
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/reg.py", line 405, in read
    dtype = self.metadata.pixel_dtype
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/reg.py", line 304, in pixel_dtype
    return self._pixel_dtypes[self._metadata.getPixelsType(0).value]
KeyError: 'float'

I tried to comment line 405 in reg.py

# dtype = self.metadata.pixel_dtype
to
dtype = np.float32

and the error goes away.
if I try to do something like

        if dtype == 'float':
            dtype = np.float32
            print('manually changing dtype')

It still fails as the error happens at the moment of the self.metadata_pixel_dtype call.

@joaomamede
Copy link
Author

Same later when appending the mosaic:

Traceback (most recent call last):
  File "/home/jmamede/anaconda3/envs/tensorflow/bin/ashlar", line 8, in <module>
    sys.exit(main())
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/scripts/ashlar.py", line 212, in main
    return process_single(
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/scripts/ashlar.py", line 250, in process_single
    mosaics.append(reg.Mosaic(edge_aligner, mshape, **mosaic_args_final))
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/reg.py", line 996, in __init__
    self.dtype = aligner.metadata.pixel_dtype
  File "/home/jmamede/anaconda3/envs/tensorflow/lib/python3.9/site-packages/ashlar/reg.py", line 304, in pixel_dtype
    return self._pixel_dtypes[self._metadata.getPixelsType(0).value]
KeyError: 'float'

@joaomamede
Copy link
Author

joaomamede commented Mar 4, 2023

By modifying line 200-203 to:

class BioformatsMetadata(PlateMetadata):

    _pixel_dtypes = {
        'uint8': np.dtype(np.uint8),
        'uint16': np.dtype(np.uint16),
        'float' : np.dtype(np.float32),
    }

made it go through.

However, the output is between 0 and 1 and very saturated. I believe it to be the light correction. I also tried pushing the 'float' be assume to be a uint32 or uint16 dtype and the same happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant