Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dataclass for worker config #2363

Merged
merged 34 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1f6a889
Attempt for a dataclass to handle the worker config
kif Dec 19, 2024
cac4b80
a couple of stupid bugs
kif Dec 19, 2024
1c6f537
Implement the workier configuration as a dataclass
kif Dec 20, 2024
d9d23c1
Implement some basic tests
kif Dec 20, 2024
7577969
Update some tests
kif Dec 20, 2024
39b59b4
Polish tests
kif Dec 20, 2024
e534235
Polish a bit further ...
kif Dec 20, 2024
cf56acf
Update src/pyFAI/worker.py
kif Jan 6, 2025
53d4d8b
Update src/pyFAI/io/integration_config.py
kif Jan 6, 2025
e50f0a4
Update src/pyFAI/io/integration_config.py
kif Jan 6, 2025
d3080f4
Update src/pyFAI/io/integration_config.py
kif Jan 6, 2025
18ea926
Remove compilation warning
kif Jan 6, 2025
2118755
Fix the worker class to use WorkerConfig instance
kif Jan 6, 2025
c11cb6f
This is WIP around issue #2230
kif Jan 6, 2025
e040169
Fix tests
kif Jan 7, 2025
b6c36bf
Merge remote-tracking branch 'upstream/main' into 2360_dataclass_for_…
kif Jan 7, 2025
dacd265
Merge branch '2360_worker_config_stage2' into 2360_dataclass_for_work…
kif Jan 7, 2025
59f28da
Fix unconsistencies between dim of the integrator and the method
kif Jan 7, 2025
f88de33
Update changelog
kif Jan 7, 2025
cd65431
Simplify the API, add an extra (compatibility) method
kif Jan 7, 2025
65eab9b
Update src/pyFAI/io/integration_config.py
kif Jan 7, 2025
8ac55c0
Typo
kif Jan 7, 2025
e2d8a92
Merge remote-tracking branch 'origin/2360_dataclass_for_worker_config…
kif Jan 7, 2025
0c4615d
Define default values to prevent a few compiler warnings
kif Jan 7, 2025
0a95c79
Flake8 dislikes this kind of typing.
kif Jan 7, 2025
4d01e99
Fix compiler warninig about -Wmaybe-uninitialized
kif Jan 7, 2025
3b8a66c
fix test in test_integrate_config.py
kif Jan 7, 2025
8b5c0a7
Run pylint on worker
kif Jan 8, 2025
37c5562
Merge remote-tracking branch 'origin/2360_dataclass_for_worker_config…
kif Jan 8, 2025
bd3f5bf
pylint the file
kif Jan 8, 2025
cbd86f9
update spelling dict
kif Jan 8, 2025
6f72eed
Merge branch 'main' into 2360_dataclass_for_worker_config
kif Jan 8, 2025
35547aa
Simplify worker
kif Jan 10, 2025
cba8e79
Merge remote-tracking branch 'origin/2360_dataclass_for_worker_config…
kif Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions ci/private-dictionary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
acc
ai
asdict
azimuthal
bbox
bool
config
cpu
csr
cython
dataclass
dataclasses
dtype
gpu
inplace
io
Jérôme
json
Kieffer
kwargs
lima
lut
numpy
opencl
os
PathLike
poissonian
poni
rtype
solidangle
str
sublicense
synchrotron
1 change: 1 addition & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Change-log of versions
Next Version: 2025
------------------
- Refactoring of the integrator classes
- New dataclass `pyFAI.io.integration_config.WorkerConfig` which is in charge of the serialization of worker configuration.
- Tool to rebin 2d-result into 1d-result (`pyFAI.containers.rebin1d`)

2024.09 12/09/2024
Expand Down
5 changes: 5 additions & 0 deletions src/pyFAI/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
from .utils.decorators import deprecated_warning
import numpy

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
6 changes: 3 additions & 3 deletions src/pyFAI/ext/_convolution.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ algorithm.

__authors__ = ["Pierre Paleo", "Jérôme Kieffer"]
__contact__ = "[email protected]"
__date__ = "03/03/2023"
__date__ = "06/01/2025"
__status__ = "stable"
__license__ = "MIT"

Expand All @@ -63,7 +63,7 @@ def horizontal_convolution(float[:, ::1] img,
int FILTER_SIZE, HALF_FILTER_SIZE
int IMAGE_H, IMAGE_W
int x, y, fIndex, newpos
double acc
double acc=0.0
float[:, ::1] output

FILTER_SIZE = filter.shape[0]
Expand Down Expand Up @@ -104,7 +104,7 @@ def vertical_convolution(float[:, ::1] img, float[::1] filter):
int FILTER_SIZE, HALF_FILTER_SIZE
int IMAGE_H, IMAGE_W
int x, y, fIndex, newpos
double acc
double acc=0.0
float[:, ::1] output

FILTER_SIZE = filter.shape[0]
Expand Down
4 changes: 2 additions & 2 deletions src/pyFAI/ext/_distortion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Distortion correction are correction are applied by look-up table (or CSR)

__author__ = "Jerome Kieffer"
__license__ = "MIT"
__date__ = "09/03/2023"
__date__ = "07/01/2025"
__copyright__ = "2011-2021, ESRF"
__contact__ = "[email protected]"

Expand Down Expand Up @@ -170,7 +170,7 @@ def calc_size(floating[:, :, :, ::1] pos not None,
cdef:
int i, j, k, l, shape_out0, shape_out1, shape_in0, shape_in1, min0, min1, max0, max1
int32_t[:, ::1] lut_size = numpy.zeros(shape, dtype=numpy.int32)
float A0, A1, B0, B1, C0, C1, D0, D1, offset0, offset1
float A0, A1, B0, B1, C0, C1, D0, D1, offset0=0.0, offset1=0.0
bint do_mask = mask is not None
int8_t[:, ::1] cmask
shape_in0, shape_in1 = pos.shape[0], pos.shape[1]
Expand Down
4 changes: 2 additions & 2 deletions src/pyFAI/ext/_geometry.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ coordinates.

__author__ = "Jerome Kieffer"
__license__ = "MIT"
__date__ = "04/12/2023"
__date__ = "07/01/2025"
__copyright__ = "2011-2020, ESRF"
__contact__ = "[email protected]"

Expand Down Expand Up @@ -635,7 +635,7 @@ def calc_rad_azim(double L,
double[::1] c2 = numpy.ascontiguousarray(pos2.ravel(), dtype=numpy.float64)
double[::1] c3
float[:, ::1] out = numpy.empty((size, 2), dtype=numpy.float32)
double t1, t2, t3, fwavelength, chi
double t1, t2, t3, chi, fwavelength=0.0

if space == "2th":
cspace = 1
Expand Down
6 changes: 3 additions & 3 deletions src/pyFAI/ext/inpainting.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# https://github.com/silx-kit/pyFAI
#
#
# Copyright (C) 2017-2022 European Synchrotron Radiation Facility, Grenoble, France
# Copyright (C) 2017-2025 European Synchrotron Radiation Facility, Grenoble, France
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -32,7 +32,7 @@
Cython module for doing inpaining of images.
"""
__author__ = "Jérôme Kieffer"
__date__ = "12/11/2024"
__date__ = "07/01/2025"
__contact__ = "[email protected]"
__license__ = "MIT"

Expand Down Expand Up @@ -142,7 +142,7 @@ def polar_inpaint(floating[:, :] img not None,
int row, col, npt_radial, npt_azim, idx_col, idx_row, tar_row, radius, dist
float[:, ::1] res
bint do_dummy = empty is not None
float value, dummy
float value, dummy=0.0
double sum, cnt, weight
list values

Expand Down
4 changes: 2 additions & 2 deletions src/pyFAI/ext/reconstruct.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ image (masked) to be able to use more common algorithms.

__author__ = "Jerome Kieffer"
__contact__ = "[email protected]"
__date__ = "12/11/2024"
__date__ = "07/01/2025"
__status__ = "stable"
__license__ = "MIT"

Expand Down Expand Up @@ -131,7 +131,7 @@ def reconstruct(data,
float[:, ::1] cdata
int8_t[:, ::1] cmask
bint is_masked, do_dummy
float cdummy, cddummy, value
float cdummy=0.0, cddummy=0.0, value
float[:, ::1] out = numpy.zeros_like(data)

cdata = numpy.ascontiguousarray(data, dtype=numpy.float32)
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 @@ -266,7 +264,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 @@ -561,7 +559,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 @@ -641,7 +639,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 @@ -678,7 +676,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 @@ -824,10 +822,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 @@ -948,7 +946,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 @@ -986,9 +984,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 @@ -1024,8 +1022,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
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
Loading
Loading