Skip to content

Commit

Permalink
typo
Browse files Browse the repository at this point in the history
  • Loading branch information
kif committed Feb 7, 2025
1 parent 78dd167 commit e90bb37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 18 additions & 10 deletions src/pyFAI/io/integration_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
from .. import method_registry
from ..integrator import load_engines as load_integrators
from ..utils import decorators
from ..units import Unit, to_unit
_logger = logging.getLogger(__name__)
CURRENT_VERSION = 5

Expand Down Expand Up @@ -451,7 +452,7 @@ class WorkerConfig:
poni: PoniFile = None
nbpt_rad: int = None
nbpt_azim: int = None
unit: object = None
unit: Unit = None
chi_discontinuity_at_0: bool = False
do_solid_angle: bool = True
polarization_description: PolarizationDescription = None
Expand All @@ -462,7 +463,7 @@ class WorkerConfig:
dark_current: Union[str, list] = None
flat_field: Union[str, list] = None
mask_file: str = None
error_model: ErrorModel = None
error_model: ErrorModel = ErrorModel.NO
method: object = None
opencl_device: list = None
azimuth_range: list = None
Expand All @@ -477,7 +478,7 @@ class WorkerConfig:
"integrator_name", "do_poisson"]
GUESSED: ClassVar[list] = ["do_2D", "do_mask", "do_dark", "do_flat", 'do_polarization',
'do_dummy', "do_radial_range", 'do_azimuthal_range']
ENFORCED: ClassVar[list] = ["polarization_description", "poni"]
ENFORCED: ClassVar[list] = ["polarization_description", "poni", "error_model", "unit"]

def __repr__(self):
return json.dumps(self.as_dict(), indent=4)
Expand All @@ -489,10 +490,15 @@ def as_dict(self):
"""
dico = {}
for key, value in asdict(self).items():
if "as_dict" in dir(value): # ponifile
dico[key] = value.as_dict()
elif "_asdict" in dir(value): # namedtuple
dico[key] = tuple(value)
if key in self.ENFORCED:
if "as_dict" in dir(value): # ponifile
dico[key] = value.as_dict()
elif "as_str" in dir(value):
dico[key] = value.as_str()
elif "_asdict" in dir(value): # namedtuple
dico[key] = tuple(value)
else:
dico[key] = value
else:
dico[key] = value
return dico
Expand All @@ -519,14 +525,16 @@ def from_dict(cls, dico, inplace=False):
if key in cls.ENFORCED:
"Enforce a specific class type"
klass = field.type
if isinstance(value, klass):
if value is None:
to_init[key] = value
elif isinstance(value, klass):
to_init[key] = value
elif isinstance(value, dict):
to_init[key] = klass(**value)
elif isinstance(value, (list, tuple)):
to_init[key] = klass(*value)
elif value is None:
to_init[key] = value
elif isinstance(value, str) and ("parse" in klass.__dict__): # There is an issue with Enum!
to_init[key] = klass.parse(value)
else:
_logger.warning(f"Unable to construct class {klass} with input {value} for key {key} in WorkerConfig.from_dict()")
to_init[key] = value
Expand Down
2 changes: 1 addition & 1 deletion src/pyFAI/io/ponifile.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def as_dict(self):
"rot1": self._rot1,
"rot2": self._rot2,
"rot3": self._rot3,
"detector": self._detector.__class__.__name__
"detector": self._detector.__class__.__name__ if self._detector is not None else None
}
if self._detector is not None:
config["detector_config"] = self._detector.get_config()
Expand Down

0 comments on commit e90bb37

Please sign in to comment.