Skip to content

Commit 535842a

Browse files
committed
Merge remote-tracking branch 'imcf/devel' into save-script-params
2 parents fd14aa5 + 379487b commit 535842a

7 files changed

Lines changed: 139 additions & 16 deletions

File tree

.github/workflows/pytest-poetry.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
push:
88
branches:
99
- master
10+
- devel
1011
tags:
1112
- "*-[0-9]+.*"
1213
pull_request:

.github/workflows/pytest-python2.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
push:
66
branches:
77
- master
8+
- devel
89
tags:
910
- "*-[0-9]+.*"
1011
pull_request:

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,22 @@ following necessary update sites for this package.
5656
- TrackMate-MorpholibJ
5757

5858
The **`IMCF Uni Basel`** update-site will always provide the latest compatible
59-
combination of *official*`.jar` file to use this package.
59+
combination of *official* `.jar` files to use this package.
60+
61+
### Manual Downloads for OMERO
62+
63+
In addition to the update sites, two manual downloads concerning OMERO are
64+
necessary:
65+
66+
- [simple-omero-client]
67+
- [omero-insight]
6068

6169
### 🏗 Alternative: SciJava Maven Package 👷
6270

6371
💡 **IMPORTANT:** 💡 same as for the *default* installation previously
64-
described, you will need to enable **all Update Sites listed above** in your
65-
Fiji as well when using the method described here!
72+
described, you will need to enable **all Update Sites listed above** (and
73+
obviously the respective OMERO downloads) in your Fiji as well when using the
74+
method described here!
6675

6776
The most up-to-date `.jar` (or any other published version, including
6877
pre-releases) for this package can be always found on the [Scijava Maven
@@ -122,3 +131,5 @@ correct_and_project(raw_image, out_path, model, "Maximum", ".ics")
122131
[apidocs]: https://imcf.one/apidocs/imcflibs/imcflibs.html
123132
[pdoc]: https://pdoc.dev/
124133
[pypi]: https://pypi.org/project/imcflibs/
134+
[simple-omero-client]: https://github.com/GReD-Clermont/simple-omero-client
135+
[omero-insight]: https://github.com/ome/omero-insight

src/imcflibs/imagej/bdv.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ def define_dataset_auto(
807807
file_path,
808808
bf_series_type,
809809
dataset_save_path=None,
810-
timepoints_per_partition=1,
810+
timepoints_per_partition=0,
811811
resave="Re-save as multiresolution HDF5",
812812
subsampling_factors=None,
813813
hdf5_chunk_sizes=None,
@@ -830,8 +830,9 @@ def define_dataset_auto(
830830
Defines how Bio-Formats interprets the series.
831831
timepoints_per_partition : int, optional
832832
Split the output dataset by timepoints. Use `0` for no split, resulting
833-
in a single HDF5 file containing all timepoints. By default `1`,
834-
resulting in a HDF5 per timepoints.
833+
in a single HDF5 file containing all timepoints. Otherwise, choose the
834+
number of timepoints per file. By default `0`.
835+
835836
resave : str, optional
836837
Allow the function to either re-save the images or simply create a
837838
merged xml. Use `Load raw data` to avoid re-saving, by default `Re-save
@@ -864,6 +865,12 @@ def define_dataset_auto(
864865
hdf5_chunk_sizes = "hdf5_chunk_sizes=" + hdf5_chunk_sizes + " "
865866
else:
866867
hdf5_chunk_sizes = ""
868+
if timepoints_per_partition > 0:
869+
split_timepoints = "split_hdf5 timepoints_per_partition=" + str(
870+
timepoints_per_partition
871+
) + " "
872+
else:
873+
split_timepoints = ""
867874

868875
if bf_series_type == "Angles":
869876
angle_rotation = "apply_angle_rotation "
@@ -901,10 +908,7 @@ def define_dataset_auto(
901908
+ angle_rotation
902909
+ subsampling_factors
903910
+ hdf5_chunk_sizes
904-
+ "split_hdf5 "
905-
+ "timepoints_per_partition="
906-
+ str(timepoints_per_partition)
907-
+ " "
911+
+ split_timepoints
908912
+ "setups_per_partition=0 "
909913
+ "use_deflate_compression "
910914
)

src/imcflibs/imagej/misc.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010

1111
from ij import IJ # pylint: disable-msg=import-error
1212
from ij.plugin import Duplicator, ImageCalculator, StackWriter
13+
from org.scijava.widget import TextWidget, WidgetStyle
1314

1415
from .. import pathtools
1516
from ..log import LOG as log
1617
from . import bioformats as bf
1718
from . import prefs
1819

19-
from org.scijava.widget import WidgetStyle
20-
from org.scijava.widget import TextWidget
21-
2220

2321
def show_status(msg):
2422
"""Update the ImageJ status bar and issue a log message.
@@ -740,6 +738,36 @@ def run_imarisconvert(file_path, pixel_calibration=None, output_folder=""):
740738
timed_log("Error converting [%s]: %d" % (file_path, result))
741739

742740

741+
def bytes_to_human_readable(size):
742+
"""Convert a byte count to a human-readable string using binary units.
743+
744+
Parameters
745+
----------
746+
size : int
747+
Byte size (number of bytes).
748+
749+
Returns
750+
-------
751+
str
752+
Human-friendly size string, e.g. `"512.0 bytes"`, `"2.0 KB"`,
753+
`"1.0 MB"`.
754+
755+
Notes
756+
-----
757+
- Uses powers of 1024 (KB = 1024 bytes).
758+
- Always returns a string with one decimal place and the unit.
759+
"""
760+
761+
for unit in ["bytes", "KB", "MB", "GB", "TB"]:
762+
if size < 1024.0:
763+
return "%3.1f %s" % (size, unit)
764+
size /= 1024.0
765+
766+
# If the value is larger than the largest unit, fall back to TB with
767+
# the current value (already divided accordingly).
768+
return "%3.1f %s" % (size, "TB")
769+
770+
743771
def save_script_parameters(
744772
destination, save_file_name="script_parameters.txt", script_globals=None
745773
):

tests/bdv/test_define_dataset_auto.py

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,68 @@ def test_define_dataset_auto_tile(tmp_path, caplog):
8181
# Set the default values for dataset definitions
8282
options = set_default_values(project_filename, file_info["path"])
8383

84+
# Construct the options for dataset definitions
85+
options = (
86+
options
87+
+ "how_to_store_input_images=["
88+
+ "Re-save as multiresolution HDF5"
89+
+ "] "
90+
+ "load_raw_data_virtually "
91+
+ "metadata_save_path=["
92+
+ result_folder
93+
+ "] "
94+
+ "image_data_save_path=["
95+
+ result_folder
96+
+ "] "
97+
+ "check_stack_sizes "
98+
+ "setups_per_partition=0 "
99+
+ "use_deflate_compression "
100+
)
101+
102+
# Construct the final call to ImageJ
103+
final_call = "IJ.run(cmd=[%s], params=[%s])" % (cmd, options)
104+
105+
# Define the dataset using the "Auto-Loader" option
106+
bdv.define_dataset_auto(project_filename, file_info["path"], bf_series_type)
107+
# Check if the final call is in the log
108+
assert final_call == caplog.messages[0]
109+
110+
111+
def test_define_dataset_auto_tile_split_timepoints(tmp_path, caplog):
112+
"""Test automatic dataset definition method for tile series.
113+
114+
Parameters
115+
----------
116+
tmp_path : pytest.fixture
117+
Temporary path for the test.
118+
caplog : pytest.fixture
119+
Log capturing fixture.
120+
"""
121+
122+
# Set the logging level to capture warnings
123+
caplog.set_level(logging.WARNING)
124+
# Clear the log
125+
caplog.clear()
126+
127+
# Define the project and file names
128+
project_filename = "proj_name"
129+
file_path = tmp_path
130+
file_info = pathtools.parse_path(file_path)
131+
132+
# Define the result and dataset save paths
133+
result_folder = pathtools.join2(file_info["path"], project_filename)
134+
135+
# Default settings
136+
137+
# Define the type of Bio-Formats series
138+
bf_series_type = "Tiles"
139+
140+
# Define the ImageJ command
141+
cmd = "Define Multi-View Dataset"
142+
143+
# Set the default values for dataset definitions
144+
options = set_default_values(project_filename, file_info["path"])
145+
84146
# Construct the options for dataset definitions
85147
options = (
86148
options
@@ -105,7 +167,7 @@ def test_define_dataset_auto_tile(tmp_path, caplog):
105167
final_call = "IJ.run(cmd=[%s], params=[%s])" % (cmd, options)
106168

107169
# Define the dataset using the "Auto-Loader" option
108-
bdv.define_dataset_auto(project_filename, file_info["path"], bf_series_type)
170+
bdv.define_dataset_auto(project_filename, file_info["path"], bf_series_type, timepoints_per_partition=1)
109171
# Check if the final call is in the log
110172
assert final_call == caplog.messages[0]
111173

@@ -160,8 +222,6 @@ def test_define_dataset_auto_angle(tmp_path, caplog):
160222
+ "] "
161223
+ "check_stack_sizes "
162224
+ "apply_angle_rotation "
163-
+ "split_hdf5 "
164-
+ "timepoints_per_partition=1 "
165225
+ "setups_per_partition=0 "
166226
+ "use_deflate_compression "
167227
)

tests/test_misc.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Tests for `imcflibs.imagej.misc` utility functions."""
2+
3+
from imcflibs.imagej.misc import bytes_to_human_readable
4+
5+
6+
def test_bytes_to_human_readable_simple():
7+
"""Ensure common sizes are formatted into human-readable strings."""
8+
assert bytes_to_human_readable(500) == "500.0 bytes"
9+
assert bytes_to_human_readable(2048) == "2.0 KB"
10+
assert bytes_to_human_readable(1024 * 1024) == "1.0 MB"
11+
assert bytes_to_human_readable(5 * 1024**3) == "5.0 GB"
12+
13+
14+
def test_bytes_to_human_readable_large():
15+
"""Verify formatting for large sizes such as terabytes."""
16+
# 1.5 TB in bytes should format as 1.5 TB
17+
size = int(1.5 * (1024**4))
18+
assert bytes_to_human_readable(size) == "1.5 TB"

0 commit comments

Comments
 (0)