Skip to content

Commit 91c9a46

Browse files
authored
Merge pull request #669 from will-moore/standalone_python_script
Standalone python script
2 parents 02728d0 + 8453017 commit 91c9a46

File tree

13 files changed

+275
-62
lines changed

13 files changed

+275
-62
lines changed

README.rst

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,36 +70,37 @@ Optional: To change the maximum active channel count from the default of 10:
7070
Now restart OMERO.web as normal.
7171

7272

73-
Enabling figure export
74-
----------------------
73+
Enabling figure export from OMERO
74+
---------------------------------
7575

7676
This section assumes that an OMERO.server is already installed.
7777

7878
Figures can be exported as PDF or TIFF files using a script that runs on the OMERO.server. This script needs to be uploaded to the OMERO.server and its dependencies
7979
installed in the OMERO.server virtual environment.
8080

81-
The script can be uploaded using two alternative workflows, both of which require you to have the correct admin privileges.
82-
To find where OMERO.figure has been installed using pip, run:
81+
The script can be uploaded using various workflows, all of which require you to have the correct admin privileges.
82+
83+
*Option 1*: Log in to the webclient as an Admin and open the OMERO.figure app. If the OMERO script is not found or is not up to date, you will
84+
see a warning message with a button to upload the script. Click the button to upload the script from the OMERO.figure app.
85+
86+
*Option 2*: Upload the script from the installation directory. To find where OMERO.figure has been installed using pip, run:
8387

8488
::
8589

8690
$ pip show omero-figure
8791

8892
The command will display the absolute path to the directory where the application is installed e.g. ``~/<virtualenv_name>/lib/python3.6/site-packages``. Go to that directory.
8993

90-
*Option 1*: Connect to the OMERO server and upload the script via the CLI. It is important to be in the correct directory when uploading so that the script is uploaded with the full path: ``omero/figure_scripts/Figure_To_Pdf.py``:
94+
Connect to the OMERO server and upload the script via the CLI. It is important to be in the correct directory when uploading so that the script is uploaded with the full path: ``omero/figure_scripts/Figure_To_Pdf.py``:
9195

9296
::
9397

9498
$ cd omero_figure/scripts
9599
$ omero script upload omero/figure_scripts/Figure_To_Pdf.py --official
96100

97-
*Option 2*: Alternatively, before starting the OMERO.server, copy the script from the figure install
101+
*Option 3*: Alternatively, before starting the OMERO.server, copy the script from the figure install
98102
``/omero_figure/scripts/omero/figure_scripts/Figure_To_Pdf.py`` to the OMERO.server ``path/to/OMERO.server/lib/scripts/omero/figure_scripts``. Then restart the OMERO.server.
99103

100-
*Option 3*: Upload the script through the OMERO web interface: For this, log into your OMERO web interface as admin, select the scripts icon and click on the "Upload Script" button.
101-
Select the ``Figure_To_Pdf.py`` script from the directory where you copied it to locally and upload it into the directory ``omero/figure_scripts``.
102-
103104
Now install the script's dependencies:
104105

105106

@@ -117,6 +118,34 @@ Now install the script's dependencies:
117118

118119
$ pip install markdown
119120

121+
122+
Run Figure export locally
123+
-------------------------
124+
125+
If your figure contains only OME-Zarr images (no images from OMERO), then
126+
the export script can be run locally to convert a figure JSON file to PDF or TIFF.
127+
NB: the OME-Zarr URLs must be accessible from the machine where the export script is run.
128+
NB: channel LUTs are not currently supported when rendering OME-Zarr images for PDF or TIFFs.
129+
Any LUTs will be rendered with white color.
130+
131+
Download the figure JSON (File > Save, in the standalone app) then install the export script.
132+
Here, we create a new conda environment and install the export script:
133+
134+
::
135+
136+
$ conda create --name figure_export python=3.12
137+
$ conda activate figure_export
138+
$ pip install "omero-figure[export]"
139+
140+
To export the figure as PDF or TIFF, run the script with the path to the figure JSON and the output file path as arguments:
141+
Use the ``.pdf`` extension for PDF export and ``.tiff`` for TIFF export. This example exports the
142+
downloaded `figure_json/my_figure.json` to `my_figure.pdf` in the current directory:
143+
144+
::
145+
146+
$ figure_export figure_json/my_figure.json my_figure.pdf
147+
148+
120149
Upgrading OMERO.figure
121150
----------------------
122151

omero_figure/cli.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#
2+
# Copyright (c) 2014-2026 University of Dundee.
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU Affero General Public License as
6+
# published by the Free Software Foundation, either version 3 of the
7+
# License, or (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU Affero General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Affero General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
#
17+
18+
import argparse
19+
import os
20+
21+
from omero_figure.scripts.omero.figure_scripts.Figure_To_Pdf \
22+
import export_figure
23+
24+
25+
def figure_export() -> None:
26+
parser = argparse.ArgumentParser(
27+
prog="figure_export",
28+
description="Export an OMERO Figure file.",
29+
)
30+
parser.add_argument("input", type=str, help="Path to the input file")
31+
parser.add_argument("output", type=str, help="Path to the output file")
32+
33+
args = parser.parse_args()
34+
output_path = args.output
35+
print(f"input: {args.input}")
36+
print(f"output: {args.output}")
37+
38+
if os.path.exists(output_path):
39+
print(f"Output file {output_path} already exists; Exiting.")
40+
return
41+
42+
# open and read the input file
43+
with open(args.input, 'r') as f:
44+
figure_json = f.read()
45+
46+
fext = output_path.split('.')[-1].lower()
47+
file_type = "TIFF" if fext in ['tif', 'tiff'] else "PDF"
48+
49+
script_args = {
50+
"Figure_JSON": figure_json,
51+
"outputPathName": output_path,
52+
"Export_Option": file_type,
53+
# TODO: Fix URL
54+
"Webclient_URI": "http://localhost:8080/"
55+
}
56+
57+
export_figure(None, script_args)
58+
59+
print("Figure export completed.")
60+
61+
62+
if __name__ == "__main__":
63+
figure_export()

omero_figure/scripts/__init__.py

Whitespace-only changes.

omero_figure/scripts/omero/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)