diff --git a/src/pyFAI/io/integration_config.py b/src/pyFAI/io/integration_config.py index 874b12564..33c06950e 100644 --- a/src/pyFAI/io/integration_config.py +++ b/src/pyFAI/io/integration_config.py @@ -52,6 +52,7 @@ 5: Migrate to dataclass Support for integrator_name/integrator_method and extra_options. + rename some attributes In a similar way, PixelwiseWorkerConfig and DistortionWorkerConfig are dataclasses to hold parameters for handling PixelwiseWorker and DistortionWorker, respectively. @@ -65,6 +66,7 @@ __date__ = "20/12/2024" __docformat__ = 'restructuredtext' +import sys import os import json import logging @@ -80,9 +82,14 @@ from ..integrator import load_engines as load_integrators _logger = logging.getLogger(__name__) - CURRENT_VERSION = 5 +if sys.version_info>=(3,10): + mydataclass = dataclass(slots=True) +else: + mydataclass = dataclass + + def _normalize_v1_darkflat_files(config, key): """Normalize dark and flat filename list from the version 1 to version 2. """ @@ -411,7 +418,7 @@ def pop_method(self, default=None): return method -@dataclass(slots=True) +@mydataclass class WorkerConfig: """Class with the configuration from the worker.""" application: str="worker" @@ -479,10 +486,6 @@ def from_dict(cls, dico, inplace=False): return self - def _upgrade(self): - """Upgrade an elder version of the config ot the latest one""" - pass - def save(self, filename): """Dump the content of the dataclass as JSON file""" with open(filename, "w") as w: diff --git a/src/pyFAI/test/test_worker.py b/src/pyFAI/test/test_worker.py index 7f9d400f7..ae22db0d0 100644 --- a/src/pyFAI/test/test_worker.py +++ b/src/pyFAI/test/test_worker.py @@ -32,7 +32,7 @@ __contact__ = "valentin.valls@esrf.fr" __license__ = "MIT" __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" -__date__ = "04/07/2024" +__date__ = "20/12/2024" import unittest import logging @@ -46,7 +46,7 @@ from ..integrator.azimuthal import AzimuthalIntegrator from ..containers import Integrate1dResult from ..containers import Integrate2dResult -from ..io.integration_config import ConfigurationReader +from ..io.integration_config import ConfigurationReader, WorkerConfig from ..io.ponifile import PoniFile from .. import detector_factory from . import utilstest @@ -557,6 +557,15 @@ def test_v3_equal_to_v4(self): poni_v4_from_config = PoniFile(data=config_v4) self.assertEqual(poni_v3_from_config.as_dict(), poni_v4_from_config.as_dict(), "PONI dictionaries from config match") + def test_dataclass(self): + test_files = "0.14_verson0.json id11_v0.json id13_v0.json id15_1_v0.json id15_v0.json id16_v3.json id21_v0.json version0.json version3.json version4.json" + for fn in test_files.split(): + js = utilstest.UtilsTest.getimage(fn) + with utilstest.TestLogging(logger='pyFAI.io.integrarion_config', warning=0): + # with self.assertLogs('pyFAI.io.integrarion_config', level='WARNING') as cm: + wc = WorkerConfig.load(js) + self.assertEqual(wc, WorkerConfig.from_dict(wc.as_dict()), f"Idempotent {fn}") + diff --git a/src/pyFAI/worker.py b/src/pyFAI/worker.py index 76193ac63..5c565682c 100644 --- a/src/pyFAI/worker.py +++ b/src/pyFAI/worker.py @@ -82,7 +82,7 @@ __contact__ = "Jerome.Kieffer@ESRF.eu" __license__ = "MIT" __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" -__date__ = "03/07/2024" +__date__ = "20/12/2024" __status__ = "development" import threading @@ -463,10 +463,11 @@ def set_config(self, config, consume_keys=False): consumed when used. """ config = integration_config.normalize(config, inplace=consume_keys, do_raise=False) + print(config) _init_ai(self.ai, config, consume_keys=True, read_maps=False) # Do it here before reading the AI to be able to catch the io - filename = config.pop("mask_file", "") + filename = config.pop("mask_image", "") apply_process = config.pop("do_mask", True) if filename and apply_process: try: @@ -478,24 +479,24 @@ def set_config(self, config, consume_keys=False): self.mask_image = filename # Do it here while we have to store metadata - filename = config.pop("dark_current", "") + filename = config.pop("dark_current_image", "") apply_process = config.pop("do_dark", True) if filename and apply_process: filenames = _normalize_filenames(filename) method = "mean" data = _reduce_images(filenames, method=method) self.ai.detector.set_darkcurrent(data) - self.dark_current_image = "%s(%s)" % (method, ",".join(filenames)) + self.dark_current_image = filenames #"%s(%s)" % (method, ",".join(filenames)) # Do it here while we have to store metadata - filename = config.pop("flat_field", "") + filename = config.pop("flat_field_image", "") apply_process = config.pop("do_flat", True) if filename and apply_process: filenames = _normalize_filenames(filename) method = "mean" data = _reduce_images(filenames, method=method) self.ai.detector.set_flatfield(data) - self.flat_field_image = "%s(%s)" % (method, ",".join(filenames)) + self.flat_field_image = filenames# "%s(%s)" % (method, ",".join(filenames)) # Uses it anyway in case do_2D is customed after the configuration value = config.pop("nbpt_azim", None)