Skip to content
Snippets Groups Projects
Commit e952b59c authored by payno's avatar payno
Browse files

Merge branch 'add_get_min_max_to_vol' into '1.0'

volume: add get_min_max function

See merge request !119
parents de55bcd5 b16ef53b
No related branches found
No related tags found
1 merge request!119volume: add get_min_max function
Pipeline #95639 passed
......@@ -184,6 +184,11 @@ def test_hdf5volume_file_path(tmp_path):
# test hash
hash(volume_from_str)
# test get_min_max values
assert volume_from_str.get_min_max() == (_data.min(), _data.max())
volume_from_str.load_data()
assert volume_from_str.get_min_max() == (_data.min(), _data.max())
def test_hdf5volume_data_url_and_metadata_url(tmp_path):
"""test creation of an hdf5volume by providing a data url and a metadata url"""
......
......@@ -171,6 +171,12 @@ def test_create_volume_from_folder(tmp_path, volume_constructor):
for l_frame, o_frame in zip(volume.browse_slices(), _data):
numpy.testing.assert_allclose(l_frame, o_frame)
# test get_min_max values
volume.data = None
assert volume.get_min_max() == (_data.min(), _data.max())
volume.load_data()
assert volume.get_min_max() == (_data.min(), _data.max())
@pytest.mark.parametrize("volume_constructor", volume_constructors)
def test_data_file_saver_generator(tmp_path, volume_constructor):
......
......@@ -238,6 +238,19 @@ class VolumeBase(TomoObject):
def dims_in_cm(self):
raise NotImplementedError("Base class")
def get_min_max(self) -> tuple:
"""
compute min max of the volume. Can take some time but avoid to load the full volume in memory
"""
if self.data is not None:
return self.data.min(), self.data.max()
else:
min_v, max_v = None, None
for s in self.browse_slices():
min_v = min(min_v, s.min()) if min_v is not None else s.min()
max_v = max(max_v, s.max()) if max_v is not None else s.max()
return min_v, max_v
# load / save stuff
@property
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment