Skip to content

Standalone python script#669

Merged
will-moore merged 23 commits into
ome:masterfrom
will-moore:standalone_python_script
Mar 26, 2026
Merged

Standalone python script#669
will-moore merged 23 commits into
ome:masterfrom
will-moore:standalone_python_script

Conversation

@will-moore
Copy link
Copy Markdown
Member

@will-moore will-moore commented Feb 23, 2026

As part of the work to support figure usage and PDF/TIFF generation with OME-Zarr data (without using OMERO),
this PR focusses on the Figure_To_Pdf.py (see #619 for front-end changes).

We want to be able to use the same PDF/TIFF generation code both in OMERO and as a stand-alone script (in a python environment that doesn't have omero-py installed, but has zarr, dask etc instead).

Basic idea is that you go to a stand-alone OMERO.figure app (from #619) e.g. https://will-moore.github.io/omero-figure/?file=https://gist.githubusercontent.com/will-moore/75a7f0de5be0f7b4202d5f0229cadcc9/raw/8d9681c70354189420c1c0adfe1f442dd1caac3e/ngff_images_figure.json and File > Save to download the figure.json file.
NB: LUTs not yet supported for Zarrs

Then, you run below (also added this to README):

# All images in figure are zarr images
# so we don't need omero-py - `[export]` install will include reportlab and markdown

$ conda create --name figure_export python=3.12
$ conda activate figure_export

# Once on pypi, this will just be: pip install omero-figure[export]
$ pip install "omero-figure[export] @ git+https://github.com/ome/omero-figure.git@refs/pull/669/head"
...
Successfully installed charset-normalizer-3.4.6 click-8.3.1 cloudpickle-3.1.2 dask-2026.1.2 donfig-0.8.1.post1 
fsspec-2026.2.0 google-crc32c-1.8.0 locket-1.0.0 numcodecs-0.16.5 numpy-2.4.3 omero-figure-7.4.2.dev0 
packaging-26.0 partd-1.4.2 pillow-12.1.1 pyyaml-6.0.3 reportlab-4.4.10 toolz-1.1.0 typing-extensions-4.15.0 zarr-3.1.5

$ figure_export figure_json/OME-Zarr_demo.json OME-Zarr_demo.pdf

TODO:

  • Support LUTs for zarrs (or ignore)?

This was referenced Feb 26, 2026
@will-moore will-moore marked this pull request as ready for review March 17, 2026 21:03
@will-moore will-moore force-pushed the standalone_python_script branch from 567f85c to 0affd4b Compare March 18, 2026 11:24
@jburel
Copy link
Copy Markdown
Member

jburel commented Mar 23, 2026

./setup.py:85:80: E501 line too long (86 > 79 characters)

@will-moore will-moore requested a review from pwalczysko March 23, 2026 09:45
@will-moore
Copy link
Copy Markdown
Member Author

@pwalczysko This PR wasn't included in merge-ci today, but you can still test the pip install workflow above to test locally, Thanks

@pwalczysko
Copy link
Copy Markdown
Member

wfm, but it feels strange to test it only on the one single json which is mentioned in teh header of the PR. Would this work also on a Figure which was created in OMERO with all the images as Zarrs ?

@pwalczysko
Copy link
Copy Markdown
Member

wfm, but it feels strange to test it only on the one single json which is mentioned in teh header of the PR. Would this work also on a Figure which was created in OMERO with all the images as Zarrs ?

Answer is: Yes, this is possible. Created a json out of the (purely zarr-containing) figure https://merge-ci.openmicroscopy.org/web/figure/file/8175. Then run the cmd

figure_export test-omero.json OME-Zarr_demo.pdf # this did not overwrite the already existing OME-Zarr_demo.pdf
ls -lah | grep .pdf
...

-rw-r--r--    1 pwalczysko  staff   1.1M 23 Mar 11:47 OME-Zarr_demo_page_02.pdf
-rw-r--r--    1 pwalczysko  staff   1.1M 23 Mar 11:48 OME-Zarr_demo_page_03.pdf
-rw-r--r--@   1 pwalczysko  staff    72M 23 Mar 11:36 OME-Zarr_demo.pdf

Basically, the pdf once created is not overwritten if another json is fed into the cmd figure_export.....
Instead, some new pdfs with similar names are (silently) created. This is highly unusual.

Copy link
Copy Markdown
Member

@pwalczysko pwalczysko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the comment ^^^ thank you

@will-moore
Copy link
Copy Markdown
Member Author

@pwalczysko Done:

$ figure_export ngff_images_figure.json TEST_labels2.pdf 
input:  ngff_images_figure.json
output: TEST_labels2.pdf
Output file TEST_labels2.pdf already exists; Exiting.

@pwalczysko
Copy link
Copy Markdown
Member

Tried to test what happens if I use LUTs in a figure.
Figure: https://merge-ci.openmicroscopy.org/web/figure/file/8175

Exported the colorbar.json from the figure ^^^ and then run the below which errored.

Error

figure_export colorbar.json  testcolobar-aha.pdf
input:  colorbar.json
output: testcolobar-aha.pdf
render_zarr_to_pil: URL https://uk1s3.embassy.ebi.ac.uk/idr/share/ome2024-ngff-challenge/idr0036/20633.ome.zarr/I/6/0
Traceback (most recent call last):
  File "/Users/pwalczysko/opt/anaconda3/envs/figure_export/bin/figure_export", line 6, in <module>
    sys.exit(figure_export())
             ^^^^^^^^^^^^^^^
  File "/Users/pwalczysko/opt/anaconda3/envs/figure_export/lib/python3.12/site-packages/omero_figure/cli.py", line 57, in figure_export
    export_figure(None, script_args)
  File "/Users/pwalczysko/opt/anaconda3/envs/figure_export/lib/python3.12/site-packages/omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py", line 3428, in export_figure
    return fig_export.build_figure()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pwalczysko/opt/anaconda3/envs/figure_export/lib/python3.12/site-packages/omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py", line 1257, in build_figure
    self.add_panels_to_page(panels_json, page)
  File "/Users/pwalczysko/opt/anaconda3/envs/figure_export/lib/python3.12/site-packages/omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py", line 2752, in add_panels_to_page
    pil_img = self.draw_panel(panel, page, i)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pwalczysko/opt/anaconda3/envs/figure_export/lib/python3.12/site-packages/omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py", line 2571, in draw_panel
    pil_img = self.get_panel_image(panel, orig_name)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pwalczysko/opt/anaconda3/envs/figure_export/lib/python3.12/site-packages/omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py", line 2483, in get_panel_image
    scale, pil_img = self.render_zarr_to_pil(panel)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pwalczysko/opt/anaconda3/envs/figure_export/lib/python3.12/site-packages/omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py", line 2434, in render_zarr_to_pil
    r = int(hex_color[0:2], 16)
        ^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 16: 'ra'

Imho it is fine not to support LUTs (simple colorbar was working fine, I think the error is rather about the LUTs).
But do not let the user experience the error

@will-moore
Copy link
Copy Markdown
Member Author

@pwalczysko OK, so I've ignored LUTs for now, and added a NB note to the README about it.

Comment thread README.rst Outdated
Copy link
Copy Markdown
Member

@pwalczysko pwalczysko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

figure_export colorbar.json  testcolobar-aha.pdf    
input:  colorbar.json
output: testcolobar-aha.pdf
render_zarr_to_pil: URL https://uk1s3.embassy.ebi.ac.uk/idr/share/ome2024-ngff-challenge/idr0036/20633.ome.zarr/I/6/0
Traceback (most recent call last):
  File "/Users/pwalczysko/opt/anaconda3/envs/figure_export/bin/figure_export", line 6, in <module>
    sys.exit(figure_export())
             ^^^^^^^^^^^^^^^
  File "/Users/pwalczysko/opt/anaconda3/envs/figure_export/lib/python3.12/site-packages/omero_figure/cli.py", line 57, in figure_export
    export_figure(None, script_args)
  File "/Users/pwalczysko/opt/anaconda3/envs/figure_export/lib/python3.12/site-packages/omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py", line 3431, in export_figure
    return fig_export.build_figure()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pwalczysko/opt/anaconda3/envs/figure_export/lib/python3.12/site-packages/omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py", line 1257, in build_figure
    self.add_panels_to_page(panels_json, page)
  File "/Users/pwalczysko/opt/anaconda3/envs/figure_export/lib/python3.12/site-packages/omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py", line 2763, in add_panels_to_page
    self.draw_colorbar(panel, page)
  File "/Users/pwalczysko/opt/anaconda3/envs/figure_export/lib/python3.12/site-packages/omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py", line 2002, in draw_colorbar
    color_ramp = self.get_color_ramp(channel)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pwalczysko/opt/anaconda3/envs/figure_export/lib/python3.12/site-packages/omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py", line 1935, in get_color_ramp
    script_service = self.conn.getScriptService()
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^

The error above is different than previously. I have reinstalled omero-figure in my env. The non-colorbar figure is working fine.

@will-moore
Copy link
Copy Markdown
Member Author

@pwalczysko Thanks for that - LUTs now also grey in colorbars, removed extra line, and also fixed handling of "inactive" channels for Zarr.

@pwalczysko
Copy link
Copy Markdown
Member

Tested again, with LUTs, colorbar and fresh ROIs. lgtm, thanks

Copy link
Copy Markdown
Member

@pwalczysko pwalczysko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a second. I have realized you are overwriting the existing script in this PR ?

I have uploaded the Figure_to_pdf.py script from this PR to merge-ci.

Then I have exported the figure (the old way) and see that there is a discrepancy between the generated pdf and the Figure https://merge-ci.openmicroscopy.org/web/figure/file/8175/

Possibly this is expected, but I would like us to have a look, thanks.

Screenshot 2026-03-25 at 18 42 38 Screenshot 2026-03-25 at 18 42 31

@will-moore
Copy link
Copy Markdown
Member Author

@pwalczysko The issue you're seeing there is the lack of support for rendering LUT channels of OME-Zarr images, so it's greyscale in the image.
I guess it's confusing because the colorbar is rendered correctly because you are connected to OMERO.

@pwalczysko
Copy link
Copy Markdown
Member

Tested couple of more figures on merge-ci, mostly non-zarr, but also zarr, with ROIs and LuTs as well as switched-off channels.

Copy link
Copy Markdown
Member

@pwalczysko pwalczysko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@will-moore will-moore merged commit 91c9a46 into ome:master Mar 26, 2026
1 check passed
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

Successfully merging this pull request may close these issues.

3 participants