Commit a8362348 authored by Pierre Paleo's avatar Pierre Paleo Committed by Pierre Paleo
Browse files

Integrate NXFlatField into HDF5Dataset

parent bfaa1926
import os
import numpy as np
from silx.io.url import DataUrl
from tomoscan.esrf.edfscan import EDFTomoScan
from tomoscan.esrf.hdf5scan import HDF5TomoScan
from ..thirdparty.tomwer_load_flats_darks import get_flats_frm_process_file, get_darks_frm_process_file
from .nxflatfield import NXFlatField
dataset_infos = {
"num_radios": None,
......@@ -149,10 +151,7 @@ class HDF5DatasetAnalyzer(DatasetAnalyzer):
tomwer_processes_fname = tomwer_processes_fname or "tomwer_processes.h5"
tomwer_processes_file = os.path.join(self.dataset_scanner.path, "tomwer_processes.h5")
if not(os.path.isfile(tomwer_processes_file)):
raise NotImplementedError(
"Flat-fielding with raw flats/darks is not implemented yet - Expected to find %s"
% tomwer_processes_file
)
return False
print("Loading darks and refs from %s" % tomwer_processes_file)
new_flats = get_flats_frm_process_file(
tomwer_processes_file, self.dataset_scanner.entry
......@@ -162,11 +161,35 @@ class HDF5DatasetAnalyzer(DatasetAnalyzer):
)
self.flats = new_flats
self.darks = new_darks
return True
def _compute_or_load_flats(self):
processes_file = os.path.join(self.dataset_scanner.path, "nabu_processes.h5")
lookup_files = [
DataUrl(file_path=processes_file, data_path="/entry/flat_field")
]
self._nxflatfield = NXFlatField(
self._get_dataset_hdf5_url(),
self.dataset_scanner.image_key,
lookup_files=lookup_files,
results_file=processes_file,
flats_reduction="mean",
darks_reduction="mean"
)
self._nxflatfield.get_final_images()
def _get_flats_darks(self):
if len(self.flats) > 2:
self._load_flats_from_tomwer()
if len(self.flats) == 0:
# No flats at all in the dataset. Do nothing.
return
if self._load_flats_from_tomwer():
# Loaded from tomwer_processes.h5
return
# Otherwise load or compute flats/darks with nabu
self._compute_or_load_flats()
def _get_rotation_angles(self):
......@@ -178,6 +201,21 @@ class HDF5DatasetAnalyzer(DatasetAnalyzer):
return self._rot_angles
def _get_dataset_hdf5_url(self):
first_proj_idx = sorted(self.projections.keys())[0]
first_proj_url = self.projections[first_proj_idx]
return DataUrl(
file_path=first_proj_url.file_path(),
data_path=first_proj_url.data_path(),
data_slice=None
)
@property
def dataset_hdf5_url(self):
return self._get_dataset_hdf5_url()
def analyze_dataset(dataset_path):
if not(os.path.isdir(dataset_path)):
if not(os.path.isfile(dataset_path)):
......
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