fractal-analytics-platform / fractal-tasks-core

Main tasks for the Fractal analytics platform
https://fractal-analytics-platform.github.io/fractal-tasks-core/
BSD 3-Clause "New" or "Revised" License
12 stars 6 forks source link

Fix error in yokogawa-to-zarr (due to Pillow v10.1.0) #570

Closed tcompa closed 10 months ago

tcompa commented 10 months ago

Running fractal-demos example 01 via a fresh version of fractal-containers leads to a failed job, with the traceback below. The obvious candidate explanation is https://pillow.readthedocs.io/en/stable/releasenotes/10.1.0.html#setting-image-mode:

If you attempt to set the mode of an image directly, e.g. im.mode = "RGBA", you will now receive an AttributeError. This is not about removing existing functionality, but instead about raising an explicit error to prevent later consequences. The convert method is the correct way to change an image’s mode.


TASK ERROR:Task id: 2 (Convert Yokogawa to OME-Zarr), e.workflow_task_order=1
TRACEBACK:
2023-10-16 08:56:03,815; INFO; START yokogawa_to_ome_zarr task
2023-10-16 08:56:03,825; INFO; NGFF image has num_levels=5
2023-10-16 08:56:03,825; INFO; NGFF image has coarsening_xy=2
2023-10-16 08:56:03,825; INFO; NGFF image has full-res pixel sizes [1.0, 0.1625, 0.1625]
2023-10-16 08:56:03,833; INFO; [glob_with_multiple_patterns] patterns=['*_B03_*.png']
2023-10-16 08:56:03,833; INFO; [glob_with_multiple_patterns] Found 4 items
Traceback (most recent call last):
  File "/home/fractal_share/tasks/.fractal/fractal_tasks_core0.12.2/venv/lib/python3.11/site-packages/fractal_tasks_core/tasks/yokogawa_to_ome_zarr.py", line 271, in <module>
    run_fractal_task(
  File "/home/fractal_share/tasks/.fractal/fractal_tasks_core0.12.2/venv/lib/python3.11/site-packages/fractal_tasks_core/tasks/_utils.py", line 79, in run_fractal_task
    metadata_update = task_function(**pars)
                      ^^^^^^^^^^^^^^^^^^^^^
  File "pydantic/decorator.py", line 40, in pydantic.decorator.validate_arguments.validate.wrapper_function
    from contextlib import _GeneratorContextManager
  File "pydantic/decorator.py", line 134, in pydantic.decorator.ValidatedFunction.call

  File "pydantic/decorator.py", line 206, in pydantic.decorator.ValidatedFunction.execute

  File "/home/fractal_share/tasks/.fractal/fractal_tasks_core0.12.2/venv/lib/python3.11/site-packages/fractal_tasks_core/tasks/yokogawa_to_ome_zarr.py", line 184, in yokogawa_to_ome_zarr
    sample = imread(tmp_images.pop())
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fractal_share/tasks/.fractal/fractal_tasks_core0.12.2/venv/lib/python3.11/site-packages/dask/array/image.py", line 56, in imread
    sample = imread(filenames[0])
             ^^^^^^^^^^^^^^^^^^^^
  File "/home/fractal_share/tasks/.fractal/fractal_tasks_core0.12.2/venv/lib/python3.11/site-packages/skimage/io/_io.py", line 53, in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fractal_share/tasks/.fractal/fractal_tasks_core0.12.2/venv/lib/python3.11/site-packages/skimage/io/manage_plugins.py", line 205, in call_plugin
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/fractal_share/tasks/.fractal/fractal_tasks_core0.12.2/venv/lib/python3.11/site-packages/skimage/io/_plugins/imageio_plugin.py", line 11, in imread
    out = np.asarray(imageio_imread(*args, **kwargs))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fractal_share/tasks/.fractal/fractal_tasks_core0.12.2/venv/lib/python3.11/site-packages/imageio/v3.py", line 54, in imread
    return np.asarray(img_file.read(**call_kwargs))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fractal_share/tasks/.fractal/fractal_tasks_core0.12.2/venv/lib/python3.11/site-packages/imageio/plugins/pillow.py", line 231, in read
    image = self._apply_transforms(
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fractal_share/tasks/.fractal/fractal_tasks_core0.12.2/venv/lib/python3.11/site-packages/imageio/plugins/pillow.py", line 312, in _apply_transforms
    image.mode = desired_mode
    ^^^^^^^^^^
AttributeError: property 'mode' of 'PngImageFile' object has no setter
tcompa commented 10 months ago

Current versions in fractal-tasks-core: Required in pyproject.toml: >=9.1.1,<11.0.0 Used for tests: 10.0.1

tcompa commented 10 months ago

I checked in https://github.com/fractal-analytics-platform/fractal-tasks-core/actions/runs/6531523635/job/17732909815?pr=571, and the latest Pillow version (10.1) is indeed responsible for this issue.

I opened an issue at imageio: https://github.com/imageio/imageio/issues/1044. Depending on how it works over there, we may want to temporarily constrain the Pillow version to <10.1.

I suspect a similar issue may appear in scikit-image (see https://github.com/search?q=repo%3Ascikit-image%2Fscikit-image+%22.mode+%3D%22&type=code), but I'm not able to say whether we rely on these features.

tcompa commented 10 months ago

I checked (through a fractal-containers run of examples 01 and 02 from fractal-demos, using the 570-fix-error-in-yokogawa-to-zarr-due-to-pillow-version fractal-tasks-core branch) that restricting the Pillow version to be <10.1 does fix the issue.

I'm merging #571 for now, and will open a new issue as a reminder for relaxing this constraint as soon as there are relevant updates in imageio or pillow.