Commit ecde89a2 authored by Pierre Paleo's avatar Pierre Paleo
Browse files

Raise error if no dark/flat in a NX file

parent 48cdfdb5
Pipeline #35469 passed with stages
in 10 minutes and 53 seconds
......@@ -46,6 +46,7 @@ class NXFlatField:
self, data_url, image_keys, lookup_files=None, results_file=None,
dont_write_results=False, force_load_existing_results=False, logger=None,
flats_reduction="mean", darks_reduction="mean",
Initialize a FlatFieldLoader helper.
......@@ -84,6 +85,10 @@ class NXFlatField:
darks_reduction: str, optional
Reduction function to use for darks. Can be "mean", "median" or "sum".
Default is "mean".
need_flats_and_darks: bool, optional
Whether both flats and darks are needed to compute the final darks/flats.
If set to True and either no flat/dark is found, an error will be raised.
Default is True.
......@@ -96,6 +101,7 @@ class NXFlatField:
self.results_file = results_file
self.dont_write_results = dont_write_results
self.force_load_existing_results = force_load_existing_results
self._need_flats_and_darks = need_flats_and_darks
self.logger = LoggerOrPrint(logger)
self.reduction_function = {}
self._set_reduction_method("flats", flats_reduction)
......@@ -330,7 +336,10 @@ class NXFlatField:
for what in res.keys():
img_slices = self.get_data_slices(self.image_keys, val_to_nxkey[what])
if img_slices == []:
self.logger.error("No %s found in %s" % (what, self.data_url.file_path()))
err_msg = "No %s found in %s" % (what, self.data_url.file_path())
if self._need_flats_and_darks:
raise ValueError(err_msg)
res[what] = None
for data_slice in img_slices:
data_chunk = self.get_data_chunk(data_slice)
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