Skip to content

Commit 60a6c7e

Browse files
author
Edgar
committed
parse unit fiber correctly
1 parent 1906476 commit 60a6c7e

File tree

5 files changed

+37
-22
lines changed

5 files changed

+37
-22
lines changed

src/pyFAI/gui/widgets/WorkerConfigurator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ def normalizeFiles(filenames):
596596
self.do_oop_range.setChecked(wc.do_oop_range)
597597
self.vertical_integration.setChecked(wc.vertical_integration)
598598
self.do_1d_integration.setChecked(wc.integration_1d)
599-
unit_ip = parse_fiber_unit(**wc.unit_ip)
599+
unit_ip = wc.unit_ip
600600

601601
# In UnitSelector, searching the unit is made with 'is' not '==', not valid for FiberUnit (which are copies)
602602
for index in range(self.ip_unit.count()):
@@ -605,7 +605,7 @@ def normalizeFiles(filenames):
605605
self.ip_unit.setCurrentIndex(index)
606606
break
607607

608-
unit_oop = parse_fiber_unit(**wc.unit_oop)
608+
unit_oop = wc.unit_oop
609609
for index in range(self.oop_unit.count()):
610610
item = self.oop_unit.itemData(index)
611611
if item == unit_oop:

src/pyFAI/io/__init__.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ def init(self, fai_cfg=None, lima_cfg=None):
330330
self.config_grp["type"] = "text/json"
331331
self.config_grp["data"] = json.dumps(self.fai_cfg.as_dict(), indent=2, separators=(",\r\n", ": "))
332332

333-
if isinstance(fai_cfg, WorkerConfig):
333+
if type(fai_cfg) is WorkerConfig:
334334
self._init_azimuthal()
335-
elif isinstance(fai_cfg, WorkerFiberConfig):
335+
elif type(fai_cfg) is WorkerFiberConfig:
336336
self._init_fiber()
337337

338338
def _init_azimuthal(self):
@@ -415,22 +415,31 @@ def _init_fiber(self):
415415
oop_name = oop.space
416416
ip_unit = ip.unit_symbol
417417
oop_unit =oop.unit_symbol
418+
419+
if self.fai_cfg.do_2D:
420+
self.do2D = True
418421

419422
if self.fai_cfg.do_2D or (not self.fai_cfg.do_2D and self.fai_cfg.vertical_integration):
420423
self.outofplane_ds = self.nxdata_grp.require_dataset("out-of-plane", (self.fai_cfg.npt_oop,), numpy.float32)
424+
kw = {
425+
"unit" : oop_unit,
426+
"interpretation" : "scalar",
427+
"name" : oop_name,
428+
"long_name" : f"Diffraction out-of-plane direction {oop_name} ({oop_unit})"
429+
}
421430
self.outofplane_ds.attrs.update({
422431
"unit" : oop_unit,
423432
"interpretation" : "scalar",
424433
"name" : oop_name,
425-
"long_name" : "Diffraction out-of-plane direction %s (%s)" % (oop_name, oop_unit)
434+
"long_name" : f"Diffraction out-of-plane direction {oop_name} ({oop_unit})"
426435
})
427436
if self.fai_cfg.do_2D or (not self.fai_cfg.do_2D and not self.fai_cfg.vertical_integration):
428437
self.inplane_ds = self.nxdata_grp.require_dataset("in-plane", (self.fai_cfg.npt_ip,), numpy.float32)
429438
self.inplane_ds.attrs.update({
430439
"unit" : ip_unit,
431440
"interpretation" : "scalar",
432441
"name" : ip_name,
433-
"long_name" : "Diffraction in-plane direction %s (%s)" % (ip_name, ip_unit)
442+
"long_name" : f"Diffraction out-of-plane direction {ip_name} ({ip_unit})"
434443
})
435444

436445
if self.fai_cfg.do_2D:
@@ -445,26 +454,26 @@ def _init_fiber(self):
445454
if self.fai_cfg.do_2D:
446455
chunk = 1, self.fast_scan_width, self.fai_cfg.npt_oop, self.fai_cfg.npt_ip
447456
self.ndim = 4
448-
axis_definition = [".", "fast", "oop", "ip"]
457+
axis_definition = [".", "fast", "out-of-plane", "in-plane"]
449458
elif self.fai_cfg.vertical_integration:
450459
chunk = 1, self.fast_scan_width, self.fai_cfg.npt_oop
451460
self.ndim = 3
452-
axis_definition = [".", "fast", "oop"]
461+
axis_definition = [".", "fast", "out-of-plane"]
453462
elif not self.fai_cfg.vertical_integration:
454463
chunk = 1, self.fast_scan_width, self.fai_cfg.npt_ip
455464
self.ndim = 3
456-
axis_definition = [".", "fast", "ip"]
465+
axis_definition = [".", "fast", "in-plane"]
457466
else:
458467
if self.fai_cfg.do_2D:
459-
axis_definition = [".", "oop", "ip"]
468+
axis_definition = [".", "out-of-plane", "in-plane"]
460469
chunk = 1, self.fai_cfg.npt_oop, self.fai_cfg.npt_ip
461470
self.ndim = 3
462471
elif self.fai_cfg.vertical_integration:
463-
axis_definition = [".", "ip"]
472+
axis_definition = [".", "in-plane"]
464473
chunk = 1, self.fai_cfg.npt_ip
465474
self.ndim = 2
466475
elif not self.fai_cfg.vertical_integration:
467-
axis_definition = [".", "oop"]
476+
axis_definition = [".", "out-of-plane"]
468477
chunk = 1, self.fai_cfg.npt_oop
469478
self.ndim = 2
470479

src/pyFAI/io/integration_config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
from .. import method_registry
8484
from ..integrator import load_engines as load_integrators
8585
from ..utils import decorators
86-
from ..units import Unit, UnitFiber, parse_fiber_unit
86+
from ..units import Unit, UnitFiber, parse_fiber_unit, get_unit_fiber
8787
_logger = logging.getLogger(__name__)
8888
CURRENT_VERSION = 5
8989

@@ -541,6 +541,8 @@ def from_dict(cls, dico, inplace=False):
541541
else:
542542
_logger.warning(f"Unable to construct class {klass} with input {value} for key {key} in WorkerConfig.from_dict()")
543543
to_init[key] = value
544+
if klass is UnitFiber:
545+
to_init[key] = get_unit_fiber(**value)
544546
else:
545547
to_init[key] = value
546548
self = cls(**to_init)
@@ -808,6 +810,7 @@ class WorkerFiberConfig(WorkerConfig):
808810
"oop_range_min", "oop_range_max",
809811
]
810812
GUESSED: ClassVar[list] = ["do_ip_range", "do_oop_range"]
813+
ENFORCED: ClassVar[list] = ["polarization_description", "poni", "error_model", "unit_ip", "unit_oop"]
811814

812815
@property
813816
def do_ip_range(self):
@@ -886,7 +889,7 @@ def save(self, filename, pop_azimuthal_params:bool=True):
886889
# Serialize fiber units
887890
for key in ("unit_ip", "unit_oop"):
888891
if key in config:
889-
unit = parse_fiber_unit(config[key])
892+
unit = get_unit_fiber(**config[key])
890893
config[key] = unit.get_config()
891894

892895
if pop_azimuthal_params:

src/pyFAI/units.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ def ne_equation(
321321

322322
self.equation = ne_equation
323323
else:
324-
self.equation = self._equation
324+
self._equation_ne = None
325+
self.equation = self._equation_np
325326

326327
def __repr__(self):
327328
incident_angle_degs = numpy.rad2deg(self.incident_angle)
@@ -386,17 +387,19 @@ def get_config(self) -> dict:
386387
"incident_angle" : self._incident_angle,
387388
"tilt_angle" : self._tilt_angle,
388389
"sample_orientation" : self._sample_orientation,
389-
"unit" : self.name,
390+
"name" : self.name,
390391
}
391392
)
392393
return fiberunit_config
394+
395+
as_dict = get_config
393396

394397
def get_config_shared(self) -> dict:
395398
"""Get a config without name, whose parameters can be shared between FiberUnits
396399
:return: dictionary with fiber parameters
397400
"""
398401
config = self.get_config()
399-
config.pop("unit")
402+
config.pop("name")
400403
return config
401404

402405
def set_config(self, config:dict=None, **kwargs) -> None:
@@ -410,7 +413,7 @@ def set_config(self, config:dict=None, **kwargs) -> None:
410413
kwargs = {k:v for k,v in kwargs.items() if k in FIBERUNIT_CONFIG_TEMPLATE}
411414
config = {k:v for k,v in config.items() if k in FIBERUNIT_CONFIG_TEMPLATE}
412415
config.update(kwargs)
413-
if config.get("unit") is not None:
416+
if config.get("name") is not None:
414417
logger.error("The unit itself cannot be set. Create a new UnitFiber instance.")
415418
return
416419

@@ -431,7 +434,7 @@ def set_config(self, config:dict=None, **kwargs) -> None:
431434
"incident_angle" : None,
432435
"tilt_angle" : None,
433436
"sample_orientation" : None,
434-
"unit" : None,
437+
"name" : None,
435438
}
436439

437440

@@ -1805,7 +1808,7 @@ def get_unit_fiber(
18051808

18061809

18071810
def parse_fiber_unit(
1808-
unit, incident_angle=None, tilt_angle=None, sample_orientation=None
1811+
unit, incident_angle=None, tilt_angle=None, sample_orientation=None,
18091812
):
18101813
if isinstance(unit, str):
18111814
unit = get_unit_fiber(name=unit)

src/pyFAI/worker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,8 +922,8 @@ def set_config(self, config:dict | WorkerFiberConfig, consume_keys:bool=False):
922922

923923
self.npt_oop = int(config.npt_oop)
924924
self.npt_ip = int(config.npt_ip)
925-
self.unit_ip = units.parse_fiber_unit(**config.unit_ip.get_config())
926-
self.unit_oop = units.parse_fiber_unit(**config.unit_oop.get_config())
925+
self.unit_ip = config.unit_ip
926+
self.unit_oop = config.unit_oop
927927
config_unit = self.unit_ip.get_config_shared()
928928
self._incident_angle = config_unit["incident_angle"]
929929
self._tilt_angle = config_unit["tilt_angle"]

0 commit comments

Comments
 (0)