GitLab will be upgraded on June 23rd evening. During the upgrade the service will be unavailable, sorry for the inconvenience.

Commit 0559c556 authored by payno's avatar payno

Merge branch 'EDFTomoScan_lazy_loading' into 'master'

lazy loading for EDFTomoscan

See merge request !33
parents c5ec1ac4 7e09103a
Pipeline #44248 passed with stages
in 17 minutes and 6 seconds
......@@ -96,7 +96,6 @@ class EDFTomoScan(TomoScanBase):
self.__distance = None
self.__energy = None
self.__estimated_cor_frm_motor = None
self.update()
@docstring(TomoScanBase.clear_caches)
def clear_caches(self):
......@@ -209,6 +208,20 @@ class EDFTomoScan(TomoScanBase):
self._flats = self.get_refs_url(scan_path=self.path)
return self._flats
@property
@docstring(TomoScanBase.projections)
def projections(self) -> Union[None, dict]:
if self._projections is None and self.path is not None:
self._reload_projections()
return self._projections
@property
@docstring(TomoScanBase.alignment_projections)
def alignment_projections(self) -> None and self.path is not None:
if self._alignment_projections is None and self.path is not None:
self._reload_projections()
return self._alignment_projections
@docstring(TomoScanBase.is_tomoscan_dir)
@staticmethod
def is_tomoscan_dir(directory: str, **kwargs) -> bool:
......@@ -264,30 +277,7 @@ class EDFTomoScan(TomoScanBase):
@docstring(TomoScanBase.update)
def update(self):
if self.path is not None:
all_projections = EDFTomoScan.get_proj_urls(
self.path, n_frames=self._edf_n_frames
)
def select_proj(ddict, from_, to_):
indexes = sorted(set(ddict.keys()))
sel_indexes = indexes[from_:to_]
res = {}
for index in sel_indexes:
res[index] = ddict[index]
return res
if self.tomo_n is not None and len(all_projections) > self.tomo_n:
self._projections = select_proj(all_projections, 0, self.tomo_n)
self._alignment_projections = select_proj(
all_projections, self.tomo_n, None
)
else:
self._projections = all_projections
self._alignment_projections = {}
if self.ignore_projections is not None:
for idx in self.ignore_projections:
self._projections.pop(idx, None)
self._reload_projections()
self._darks = EDFTomoScan.get_darks_url(self.path)
self._flats = EDFTomoScan.get_refs_url(self.path)
......@@ -647,6 +637,32 @@ class EDFTomoScan(TomoScanBase):
res[key_] = urls[key]
return res
def _reload_projections(self):
if self.path is not None:
all_projections = EDFTomoScan.get_proj_urls(
self.path, n_frames=self._edf_n_frames
)
def select_proj(ddict, from_, to_):
indexes = sorted(set(ddict.keys()))
sel_indexes = indexes[from_:to_]
res = {}
for index in sel_indexes:
res[index] = ddict[index]
return res
if self.tomo_n is not None and len(all_projections) > self.tomo_n:
self._projections = select_proj(all_projections, 0, self.tomo_n)
self._alignment_projections = select_proj(
all_projections, self.tomo_n, None
)
else:
self._projections = all_projections
self._alignment_projections = {}
if self.ignore_projections is not None:
for idx in self.ignore_projections:
self._projections.pop(idx, None)
@staticmethod
def retrieve_information(
scan: str,
......
......@@ -666,9 +666,14 @@ class HDF5TomoScan(TomoScanBase):
if self.master_file and os.path.exists(self.master_file):
if self.projections is not None:
if len(self.projections) > 0:
self._dim_2, self._dim_1 = get_data(
list(self.projections.values())[0]
).shape
url = list(self.projections.values())[0]
try:
with HDF5File(url.file_path(), mode="r") as h5s:
self._dim_2, self._dim_1 = h5s[url.data_path()].shape[-2:]
except Exception:
self._dim_2, self._dim_1 = get_data(
list(self.projections.values())[0]
).shape
@property
def y_pixel_size(self) -> typing.Union[None, float]:
......
Markdown is supported
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