Skip to content

Commit

Permalink
Implement the workier configuration as a dataclass
Browse files Browse the repository at this point in the history
  • Loading branch information
kif committed Dec 20, 2024
1 parent cac4b80 commit 1c6f537
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 47 deletions.
7 changes: 6 additions & 1 deletion src/pyFAI/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@
__contact__ = "[email protected]"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "19/11/2024"
__date__ = "20/12/2024"
__status__ = "development"

from collections import namedtuple
from enum import IntEnum
from .utils.decorators import deprecated_warning

PolarizationArray = namedtuple("PolarizationArray",
["array", "checksum"])
PolarizationDescription = namedtuple("PolarizationDescription",
["polarization_factor", "axis_offset"])

Integrate1dtpl = namedtuple("Integrate1dtpl", "position intensity sigma signal variance normalization count std sem norm_sq", defaults=(None,) * 3)
Integrate2dtpl = namedtuple("Integrate2dtpl", "radial azimuthal intensity sigma signal variance normalization count std sem norm_sq", defaults=(None,) * 3)

Expand Down
32 changes: 15 additions & 17 deletions src/pyFAI/geometry/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@
__contact__ = "[email protected]"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "10/10/2024"
__date__ = "20/12/2024"
__status__ = "production"
__docformat__ = 'restructuredtext'

import copy
import logging
from math import pi
twopi = 2 * pi
from numpy import arccos, arctan2, sin, cos, sqrt
import numpy
import os
import threading
import json
import gc
from collections import namedtuple, OrderedDict
from collections import OrderedDict
from ..containers import PolarizationArray, PolarizationDescription
from .fit2d import convert_to_Fit2d, convert_from_Fit2d
from .imaged11 import convert_from_ImageD11, convert_to_ImageD11
from .. import detectors
Expand All @@ -64,6 +64,7 @@
from .. import utils
from ..io import ponifile, integration_config
from ..units import CONST_hc, to_unit, UnitFiber
TWO_PI = 2 * pi

logger = logging.getLogger(__name__)

Expand All @@ -85,9 +86,6 @@
logger.debug("Backtrace", exc_info=True)
bilinear = None

PolarizationArray = namedtuple("PolarizationArray", ["array", "checksum"])
PolarizationDescription = namedtuple("PolarizationDescription",
["polarization_factor", "axis_offset"])


class Geometry(object):
Expand Down Expand Up @@ -263,7 +261,7 @@ def normalize_azimuth_range(self, azimuth_range):
return
azimuth_range = tuple(deg2rad(azimuth_range[i], self.chiDiscAtPi) for i in (0, -1))
if azimuth_range[1] <= azimuth_range[0]:
azimuth_range = (azimuth_range[0], azimuth_range[1] + twopi)
azimuth_range = (azimuth_range[0], azimuth_range[1] + TWO_PI)
self.check_chi_disc(azimuth_range)
return azimuth_range

Expand Down Expand Up @@ -558,7 +556,7 @@ def rd2Array(self, shape=None):
if self._cached_array.get("d*2_center") is None:
with self._sem:
if self._cached_array.get("d*2_center") is None:
self._cached_array["d*2_center"] = (qArray / (twopi)) ** 2
self._cached_array["d*2_center"] = (qArray / (TWO_PI)) ** 2
return self._cached_array["d*2_center"]

@deprecated
Expand Down Expand Up @@ -638,7 +636,7 @@ def chi(self, d1, d2, path="cython"):
_, t1, t2 = self.calc_pos_zyx(d0=None, d1=d1, d2=d2, corners=False, use_cython=True, do_parallax=True)
chi = numpy.arctan2(t1, t2)
if not self.chiDiscAtPi:
numpy.mod(chi, (twopi), out=chi)
numpy.mod(chi, (TWO_PI), out=chi)
return chi

def chi_corner(self, d1, d2):
Expand Down Expand Up @@ -675,7 +673,7 @@ def chiArray(self, shape=None):
chia = numpy.fromfunction(self.chi, shape,
dtype=numpy.float32)
if not self.chiDiscAtPi:
chia = chia % (twopi)
chia = chia % (TWO_PI)
self._cached_array["chi_center"] = chia
return self._cached_array["chi_center"]

Expand Down Expand Up @@ -821,10 +819,10 @@ def corner_array(self, shape=None, unit=None, use_cython=True, scale=True):
# numpy path
chi = numpy.arctan2(y, x)
if not self.chiDiscAtPi:
numpy.mod(chi, (twopi), out=chi)
numpy.mod(chi, (TWO_PI), out=chi)
else:
# numexpr path
chi = numexpr.evaluate("arctan2(y, x)") if self.chiDiscAtPi else numexpr.evaluate("arctan2(y, x)%twopi")
chi = numexpr.evaluate("arctan2(y, x)") if self.chiDiscAtPi else numexpr.evaluate("arctan2(y, x)%TWO_PI")
corners = numpy.zeros((shape[0], shape[1], nb_corners, 2),
dtype=numpy.float32)
if chi.shape[:2] == shape:
Expand Down Expand Up @@ -945,7 +943,7 @@ def center_array(self, shape=None, unit="2th_deg", scale=True):
ary = unit.equation(x, y, z, self.wavelength)

if unit.space == "chi" and not self.chiDiscAtPi:
numpy.mod(ary, twopi, out=ary)
numpy.mod(ary, TWO_PI, out=ary)
self._cached_array[key] = ary
if scale and unit:
return ary * unit.scale
Expand Down Expand Up @@ -983,9 +981,9 @@ def delta_array(self, shape=None, unit="2th_deg", scale=False):
delta = abs(corners[..., 0] - numpy.atleast_3d(center))
if space == "chi_delta":
if numexpr:
delta = numexpr.evaluate("where(delta<twopi-delta, delta, twopi-delta)")
delta = numexpr.evaluate("where(delta<TWO_PI-delta, delta, TWO_PI-delta)")
else:
numpy.minimum(delta, twopi - delta, out=delta)
numpy.minimum(delta, TWO_PI - delta, out=delta)

ary = delta.max(axis=-1)
self._cached_array[space] = ary
Expand Down Expand Up @@ -1021,8 +1019,8 @@ def deltaChi(self, shape=None, use_cython=True):
self._cached_array[key] = delta
else:
center = numpy.atleast_3d(center)
delta = numpy.minimum(((corner[:,:,:, 1] - center) % twopi),
((center - corner[:,:,:, 1]) % twopi))
delta = numpy.minimum(((corner[:,:,:, 1] - center) % TWO_PI),
((center - corner[:,:,:, 1]) % TWO_PI))
self._cached_array[key] = delta.max(axis=-1)
return self._cached_array[key]

Expand Down
Loading

0 comments on commit 1c6f537

Please sign in to comment.