Commit 52f09cb1 authored by Pierre Paleo's avatar Pierre Paleo
Browse files

[hdf5tomoscan] convert to static method for re-usability

parent 6054c45f
Pipeline #22679 passed with stages
in 2 minutes
...@@ -615,13 +615,19 @@ class HDF5TomoScan(TomoScanBase): ...@@ -615,13 +615,19 @@ class HDF5TomoScan(TomoScanBase):
else: else:
return None return None
def _get_compacted_projections(self): @staticmethod
def _get_compacted_projections(projections):
""" """
Regroup urls to get the data more efficiently. Regroup urls to get the data more efficiently.
Build a structure mapping projections indices to information on Build a structure mapping projections indices to information on
how to load the data: `{indices_set: data_location}` how to load the data: `{indices_set: data_location}`
where `data_location` contains contiguous indices. where `data_location` contains contiguous indices.
Parameters
-----------
projections: dict
Dictionary where the key is an integer and the value is a silx `DataUrl`.
Returns Returns
-------- --------
merged_projections: dict merged_projections: dict
...@@ -645,9 +651,9 @@ class HDF5TomoScan(TomoScanBase): ...@@ -645,9 +651,9 @@ class HDF5TomoScan(TomoScanBase):
def merge_slices(slice1, slice2): def merge_slices(slice1, slice2):
return slice(slice1.start, slice2.stop) return slice(slice1.start, slice2.stop)
sorted_files_indices = sorted(self.projections.keys()) sorted_files_indices = sorted(projections.keys())
idx0 = sorted_files_indices[0] idx0 = sorted_files_indices[0]
first_url = self.projections[idx0] first_url = projections[idx0]
merged_indices = [ merged_indices = [
[idx0] [idx0]
...@@ -662,7 +668,7 @@ class HDF5TomoScan(TomoScanBase): ...@@ -662,7 +668,7 @@ class HDF5TomoScan(TomoScanBase):
pos = 0 pos = 0
curr_fp, curr_dp, curr_slice = data_location[pos] curr_fp, curr_dp, curr_slice = data_location[pos]
for idx in sorted_files_indices[1:]: for idx in sorted_files_indices[1:]:
url = self.projections[idx] url = projections[idx]
next_slice = _convert_to_slice(url.data_slice()) next_slice = _convert_to_slice(url.data_slice())
if (url.file_path() == curr_fp) and (url.data_path() == curr_dp) and is_contiguous_slice(curr_slice, next_slice): if (url.file_path() == curr_fp) and (url.data_path() == curr_dp) and is_contiguous_slice(curr_slice, next_slice):
merged_indices[pos].append(idx) merged_indices[pos].append(idx)
...@@ -695,7 +701,7 @@ class HDF5TomoScan(TomoScanBase): ...@@ -695,7 +701,7 @@ class HDF5TomoScan(TomoScanBase):
is the corresponding `silx.io.url.DataUrl` with merged data_slice is the corresponding `silx.io.url.DataUrl` with merged data_slice
""" """
if self._projections_compacted is None: if self._projections_compacted is None:
self._projections_compacted = self._get_compacted_projections() self._projections_compacted = self._get_compacted_projections(self.projections)
return self._projections_compacted return self._projections_compacted
def __str__(self): def __str__(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment