Skip to content

Commit 85f0c98

Browse files
authored
Merge pull request #107 from CellKai/fix-h5-resave
Fix function to not split time points by default
2 parents 14024ee + 8a2c295 commit 85f0c98

2 files changed

Lines changed: 74 additions & 10 deletions

File tree

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
)

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
)

0 commit comments

Comments
 (0)