Skip to content

Commit

Permalink
Polish a bit further ...
Browse files Browse the repository at this point in the history
  • Loading branch information
kif committed Dec 20, 2024
1 parent 39b59b4 commit e534235
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 222 deletions.
2 changes: 1 addition & 1 deletion src/pyFAI/gui/test/test_integrate_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
__contact__ = "[email protected]"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "16/10/2020"
__date__ = "20/12/2024"

import unittest
import logging
Expand Down
288 changes: 124 additions & 164 deletions src/pyFAI/gui/widgets/WorkerConfigurator.py

Large diffs are not rendered by default.

67 changes: 50 additions & 17 deletions src/pyFAI/io/integration_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ def _patch_v4_to_v5(config):
for key1, key2 in[("azimuth_range_min", "azimuthal_range_min"),
("azimuth_range_max", "azimuthal_range_max"),
('do_azimuthal_range', 'do_azimuth_range'),
("flat_field_image","flat_field"),
("dark_current_image", "dark_current"),
("mask_image", "mask_file"),
("flat_field", "flat_field_image"),
("dark_current", "dark_current_image"),
("mask_file", "mask_image"),
("val_dummy", "dummy")]:
if key2 in config and not key1 in config:
config[key1] = config.pop(key2)
Expand Down Expand Up @@ -344,7 +344,7 @@ def normalize(config, inplace=False, do_raise=False, target_version=CURRENT_VERS


class ConfigurationReader(object):

"This class should be deprecated now ..."
def __init__(self, config):
":param config: dictonary"
self._config = config
Expand Down Expand Up @@ -433,12 +433,13 @@ class WorkerConfig:
chi_discontinuity_at_0: bool=False
do_solid_angle: bool=True
polarization_factor: PolarizationDescription = None
normalization_factor: float=1.0
val_dummy: float = None
delta_dummy: float = None
correct_solid_angle: bool = True
dark_current_image: str = None
flat_field_image: str = None
mask_image: str = None
dark_current: Union[str, list] = None
flat_field: Union[str, list] = None
mask_file: str = None
error_model: ErrorModel = None
method: object = None
opencl_device: list = None
Expand All @@ -447,6 +448,7 @@ class WorkerConfig:
integrator_class: str = "AzimuthalIntegrator"
integrator_method: str = None
extra_options: dict = None
monitor_name: str = None
OPTIONAL: ClassVar[list] = ["radial_range_min", "radial_range_max",
"azimuth_range_min", "azimuth_range_max",
"integrator_name", "do_poisson"]
Expand All @@ -471,7 +473,6 @@ def from_dict(cls, dico, inplace=False):
if not inplace:
dico = copy.copy(dico)
normalize(dico, inplace=True)
# for key,value in dico.items():print(key, value)
to_init = {field.name:dico.pop(field.name)
for field in fields(cls)
if field.name in dico}
Expand All @@ -481,7 +482,6 @@ def from_dict(cls, dico, inplace=False):
dico.pop(key)
for key in cls.OPTIONAL:
if key in dico:
# print(key, dico[key])
value = dico.pop(key)
self.__setattr__(key, value)
if len(dico):
Expand All @@ -503,7 +503,7 @@ def load(cls, filename):

@property
def do_2D(self):
return self.nbpt_azim > 1
return False if self.nbpt_azim is None else self.nbpt_azim > 1

@property
def do_azimuthal_range(self):
Expand All @@ -514,7 +514,7 @@ def do_azimuthal_range(self):
@property
def azimuth_range_min(self):
if self.azimuth_range:
self.azimuth_range[0]
return self.azimuth_range[0]
else:
return -numpy.inf
@azimuth_range_min.setter
Expand All @@ -525,7 +525,7 @@ def azimuth_range_min(self, value):
@property
def azimuth_range_max(self):
if self.azimuth_range:
self.azimuth_range[1]
return self.azimuth_range[1]
else:
return numpy.inf
@azimuth_range_max.setter
Expand All @@ -543,7 +543,7 @@ def do_radial_range(self):
@property
def radial_range_min(self):
if self.radial_range:
self.radial_range[0]
return self.radial_range[0]
else:
return -numpy.inf
@radial_range_min.setter
Expand All @@ -554,7 +554,7 @@ def radial_range_min(self, value):
@property
def radial_range_max(self):
if self.radial_range:
self.radial_range[1]
return self.radial_range[1]
else:
return numpy.inf
@radial_range_max.setter
Expand All @@ -571,7 +571,7 @@ def integrator_name(self, value):

@property
def do_mask(self):
return self.mask_image is not None
return self.mask_file is not None
@property
def do_poisson(self):
return int(self.error_model) == int(ErrorModel.POISSON)
Expand All @@ -586,8 +586,41 @@ def dummy(self):
def dummy(self, value):
if value:
self.val_dummy = float(value) if value is not None else value


@property
def do_dummy(self):
return self.val_dummy is not None
@property
def mask_image(self):
return self.mask_file
@mask_image.setter
def mask_image(self, value):
self.mask_file = None if not value else value
@property
def do_dark(self):
return bool(self.dark_current)
@property
def do_flat(self):
return bool(self.flat_field)
@property
def do_polarization(self):
if self.polarization_factor is None:
return False
if "__len__" in dir(self.polarization_factor):
return bool(self.polarization_factor)
else:
return True
@property
def dark_current_image(self):
return self.dark_current
@dark_current_image.setter
def dark_current_image(self, value):
self.dark_current = None if not value else value
@property
def flat_field_image(self):
return self.flat_field
@flat_field_image.setter
def flat_field_image(self, value):
self.flat_field = None if not value else value
# @dataclass(slots=True)
# class PixelwiseWorkerConfig:
# """Configuration for pyFAI.worker.PixelwiseWorker
Expand Down
42 changes: 9 additions & 33 deletions src/pyFAI/io/ponifile.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,39 +270,15 @@ def as_dict(self):
return config

def as_integration_config(self):
from .integration_config import normalize
config = {
"application" : "poni",
"version" : 4,
"poni" : dict(self.as_dict()),
"do_2D" : True,
"nbpt_rad" : 500,
"nbpt_azim" : 360,
"unit" : "q_nm^-1",
"do_mask" : False,
"mask_file" : None,
"do_flat" : False,
"flat_field" : None,
"do_dark" : False,
"dark_current" : None,
"method" : ("bbox", "csr", "cython"),
"do_dummy" : None,
"val_dummy" : None,
"delta_dummy" : None,
"do_solid_angle" : True,
"error_model" : None,
"do_radial_range" : False,
"radial_range_min" : None,
"radial_range_max" : None,
"do_azimuthal_range" : False,
"azimuth_range_min" : None,
"azimuth_range_max" : None,
"chi_discontinuity_at_0" : False,
"do_polarization" : False,
"normalization_factor" : 1.0,
}
return normalize(config=config)

from .integration_config import WorkerConfig
wc = WorkerConfig(application="poni",
poni=dict(self.as_dict()),
nbpt_rad=500,
nbpt_azim=360,
unit="q_nm^-1",
method=("full", "csr", "cython"),
normalization_factor=1.0)
return wc

@property
def detector(self):
Expand Down
8 changes: 4 additions & 4 deletions src/pyFAI/test/test_integrate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ def test_single_flatdark(self):
config = {"dark_current": "abc",
"flat_field": "abd"}
config = integration_config.normalize(config)
self.assertEqual(config["dark_current_image"], "abc")
self.assertEqual(config["flat_field_image"], "abd")
self.assertEqual(config["dark_current"], "abc")
self.assertEqual(config["flat_field"], "abd")

def test_coma_flatdark(self):
config = {"dark_current": "a,b,c",
"flat_field": "a,b,d"}
config = integration_config.normalize(config)
self.assertEqual(config["dark_current_image"], ["a", "b", "c"])
self.assertEqual(config["flat_field_image"], ["a", "b", "d"])
self.assertEqual(config["dark_current"], ["a", "b", "c"])
self.assertEqual(config["flat_field"], ["a", "b", "d"])

def test_pilatus(self):
config = {"detector": "pilatus2m"}
Expand Down
1 change: 1 addition & 0 deletions src/pyFAI/test/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ def test_flatdark(self):
worker.set_config(config)
data = numpy.ones(shape=self.shape)
worker.process(data=data)
print(worker.ai.detector)
self.assertTrue(numpy.isclose(worker.ai.detector.get_darkcurrent()[0, 0], (1 + 2 + 3) / 3))
self.assertTrue(numpy.isclose(worker.ai.detector.get_flatfield()[0, 0], (1 + 2 + 4) / 3))

Expand Down
6 changes: 3 additions & 3 deletions src/pyFAI/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def set_config(self, config, consume_keys=False):
_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_image", "")
filename = config.pop("mask_file", "")
apply_process = config.pop("do_mask", True)
if filename and apply_process:
try:
Expand All @@ -479,7 +479,7 @@ 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_image", "")
filename = config.pop("dark_current", "")
apply_process = config.pop("do_dark", True)
if filename and apply_process:
filenames = _normalize_filenames(filename)
Expand All @@ -489,7 +489,7 @@ def set_config(self, config, consume_keys=False):
self.dark_current_image = filenames #"%s(%s)" % (method, ",".join(filenames))

# Do it here while we have to store metadata
filename = config.pop("flat_field_image", "")
filename = config.pop("flat_field", "")
apply_process = config.pop("do_flat", True)
if filename and apply_process:
filenames = _normalize_filenames(filename)
Expand Down

0 comments on commit e534235

Please sign in to comment.