nabu 2024.2.4__py3-none-any.whl → 2025.1.0.dev4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. doc/doc_config.py +32 -0
  2. nabu/__init__.py +1 -1
  3. nabu/app/bootstrap_stitching.py +4 -2
  4. nabu/app/cast_volume.py +7 -13
  5. nabu/app/cli_configs.py +0 -5
  6. nabu/app/compare_volumes.py +1 -1
  7. nabu/app/composite_cor.py +2 -4
  8. nabu/app/correct_rot.py +0 -8
  9. nabu/app/diag_to_pix.py +5 -6
  10. nabu/app/diag_to_rot.py +10 -11
  11. nabu/app/multicor.py +1 -1
  12. nabu/app/parse_reconstruction_log.py +1 -0
  13. nabu/app/prepare_weights_double.py +1 -2
  14. nabu/app/reconstruct_helical.py +1 -5
  15. nabu/app/reduce_dark_flat.py +0 -2
  16. nabu/app/rotate.py +3 -1
  17. nabu/app/tests/test_reduce_dark_flat.py +2 -2
  18. nabu/app/validator.py +1 -4
  19. nabu/cuda/convolution.py +1 -1
  20. nabu/cuda/fft.py +1 -1
  21. nabu/cuda/medfilt.py +1 -1
  22. nabu/cuda/padding.py +1 -1
  23. nabu/cuda/src/cone.cu +19 -9
  24. nabu/cuda/src/hierarchical_backproj.cu +16 -0
  25. nabu/cuda/utils.py +2 -2
  26. nabu/estimation/alignment.py +17 -31
  27. nabu/estimation/cor.py +23 -29
  28. nabu/estimation/cor_sino.py +2 -8
  29. nabu/estimation/focus.py +4 -8
  30. nabu/estimation/tests/test_alignment.py +2 -0
  31. nabu/estimation/tests/test_tilt.py +1 -1
  32. nabu/estimation/tilt.py +5 -4
  33. nabu/io/cast_volume.py +5 -5
  34. nabu/io/detector_distortion.py +5 -6
  35. nabu/io/reader.py +3 -3
  36. nabu/io/reader_helical.py +5 -4
  37. nabu/io/tests/test_cast_volume.py +2 -2
  38. nabu/io/tests/test_readers.py +4 -4
  39. nabu/io/tests/test_writers.py +2 -2
  40. nabu/io/utils.py +8 -4
  41. nabu/io/writer.py +1 -2
  42. nabu/misc/fftshift.py +1 -1
  43. nabu/misc/fourier_filters.py +1 -1
  44. nabu/misc/histogram.py +1 -1
  45. nabu/misc/histogram_cuda.py +1 -1
  46. nabu/misc/padding_base.py +1 -1
  47. nabu/misc/rotation.py +1 -1
  48. nabu/misc/rotation_cuda.py +1 -1
  49. nabu/misc/tests/test_binning.py +1 -1
  50. nabu/misc/transpose.py +1 -1
  51. nabu/misc/unsharp.py +1 -1
  52. nabu/misc/unsharp_cuda.py +1 -1
  53. nabu/misc/unsharp_opencl.py +1 -1
  54. nabu/misc/utils.py +1 -1
  55. nabu/opencl/fft.py +1 -1
  56. nabu/opencl/padding.py +1 -1
  57. nabu/opencl/utils.py +8 -8
  58. nabu/pipeline/config.py +2 -2
  59. nabu/pipeline/config_validators.py +4 -3
  60. nabu/pipeline/datadump.py +3 -3
  61. nabu/pipeline/estimators.py +6 -6
  62. nabu/pipeline/fullfield/chunked.py +4 -5
  63. nabu/pipeline/fullfield/dataset_validator.py +0 -1
  64. nabu/pipeline/fullfield/nabu_config.py +2 -1
  65. nabu/pipeline/fullfield/reconstruction.py +9 -8
  66. nabu/pipeline/helical/dataset_validator.py +3 -4
  67. nabu/pipeline/helical/fbp.py +4 -4
  68. nabu/pipeline/helical/filtering.py +5 -4
  69. nabu/pipeline/helical/gridded_accumulator.py +9 -10
  70. nabu/pipeline/helical/helical_chunked_regridded.py +1 -0
  71. nabu/pipeline/helical/helical_reconstruction.py +10 -7
  72. nabu/pipeline/helical/helical_utils.py +1 -2
  73. nabu/pipeline/helical/nabu_config.py +1 -0
  74. nabu/pipeline/helical/span_strategy.py +1 -0
  75. nabu/pipeline/helical/weight_balancer.py +1 -2
  76. nabu/pipeline/tests/__init__.py +0 -0
  77. nabu/pipeline/utils.py +1 -1
  78. nabu/pipeline/writer.py +1 -1
  79. nabu/preproc/alignment.py +0 -10
  80. nabu/preproc/ctf.py +8 -8
  81. nabu/preproc/ctf_cuda.py +1 -1
  82. nabu/preproc/double_flatfield_cuda.py +2 -2
  83. nabu/preproc/double_flatfield_variable_region.py +0 -1
  84. nabu/preproc/flatfield.py +1 -1
  85. nabu/preproc/flatfield_cuda.py +1 -2
  86. nabu/preproc/flatfield_variable_region.py +3 -3
  87. nabu/preproc/phase.py +2 -4
  88. nabu/preproc/phase_cuda.py +2 -2
  89. nabu/preproc/shift_cuda.py +0 -1
  90. nabu/preproc/tests/test_ctf.py +3 -3
  91. nabu/preproc/tests/test_double_flatfield.py +1 -1
  92. nabu/preproc/tests/test_flatfield.py +1 -1
  93. nabu/preproc/tests/test_vshift.py +4 -1
  94. nabu/processing/azim.py +2 -2
  95. nabu/processing/convolution_cuda.py +6 -4
  96. nabu/processing/fft_base.py +1 -1
  97. nabu/processing/fft_cuda.py +19 -8
  98. nabu/processing/fft_opencl.py +9 -4
  99. nabu/processing/fftshift.py +1 -1
  100. nabu/processing/histogram.py +1 -1
  101. nabu/processing/muladd.py +0 -1
  102. nabu/processing/padding_base.py +1 -1
  103. nabu/processing/padding_cuda.py +0 -1
  104. nabu/processing/processing_base.py +1 -1
  105. nabu/processing/tests/test_fft.py +1 -1
  106. nabu/processing/tests/test_fftshift.py +1 -1
  107. nabu/processing/tests/test_medfilt.py +1 -3
  108. nabu/processing/tests/test_padding.py +1 -1
  109. nabu/processing/tests/test_roll.py +1 -1
  110. nabu/processing/unsharp_opencl.py +1 -1
  111. nabu/reconstruction/astra.py +245 -0
  112. nabu/reconstruction/cone.py +9 -4
  113. nabu/reconstruction/fbp_base.py +2 -2
  114. nabu/reconstruction/filtering_cuda.py +1 -1
  115. nabu/reconstruction/hbp.py +16 -3
  116. nabu/reconstruction/mlem.py +0 -1
  117. nabu/reconstruction/projection.py +3 -5
  118. nabu/reconstruction/sinogram.py +1 -1
  119. nabu/reconstruction/sinogram_cuda.py +0 -1
  120. nabu/reconstruction/tests/test_cone.py +76 -3
  121. nabu/reconstruction/tests/test_deringer.py +2 -2
  122. nabu/reconstruction/tests/test_fbp.py +1 -1
  123. nabu/reconstruction/tests/test_halftomo.py +27 -1
  124. nabu/reconstruction/tests/test_mlem.py +3 -2
  125. nabu/reconstruction/tests/test_projector.py +7 -2
  126. nabu/reconstruction/tests/test_sino_normalization.py +0 -1
  127. nabu/resources/dataset_analyzer.py +4 -4
  128. nabu/resources/gpu.py +4 -4
  129. nabu/resources/logger.py +4 -4
  130. nabu/resources/nxflatfield.py +2 -2
  131. nabu/resources/tests/test_nxflatfield.py +4 -4
  132. nabu/stitching/alignment.py +1 -4
  133. nabu/stitching/config.py +19 -16
  134. nabu/stitching/frame_composition.py +8 -10
  135. nabu/stitching/overlap.py +2 -2
  136. nabu/stitching/slurm_utils.py +2 -2
  137. nabu/stitching/stitcher/base.py +2 -0
  138. nabu/stitching/stitcher/dumper/base.py +0 -1
  139. nabu/stitching/stitcher/dumper/postprocessing.py +1 -1
  140. nabu/stitching/stitcher/post_processing.py +6 -6
  141. nabu/stitching/stitcher/pre_processing.py +13 -11
  142. nabu/stitching/stitcher/single_axis.py +3 -4
  143. nabu/stitching/stitcher_2D.py +2 -1
  144. nabu/stitching/tests/test_config.py +7 -8
  145. nabu/stitching/tests/test_sample_normalization.py +1 -1
  146. nabu/stitching/tests/test_slurm_utils.py +1 -2
  147. nabu/stitching/tests/test_z_postprocessing_stitching.py +1 -1
  148. nabu/stitching/tests/test_z_preprocessing_stitching.py +4 -4
  149. nabu/stitching/utils/tests/__init__.py +0 -0
  150. nabu/stitching/utils/tests/test_post-processing.py +1 -0
  151. nabu/stitching/utils/utils.py +10 -12
  152. nabu/tests.py +0 -3
  153. nabu/testutils.py +30 -8
  154. nabu/utils.py +28 -18
  155. {nabu-2024.2.4.dist-info → nabu-2025.1.0.dev4.dist-info}/METADATA +25 -25
  156. nabu-2025.1.0.dev4.dist-info/RECORD +320 -0
  157. {nabu-2024.2.4.dist-info → nabu-2025.1.0.dev4.dist-info}/WHEEL +1 -1
  158. nabu/io/tests/test_detector_distortion.py +0 -178
  159. nabu/resources/tests/test_extract.py +0 -9
  160. nabu-2024.2.4.dist-info/RECORD +0 -318
  161. /nabu/{stitching → app}/tests/__init__.py +0 -0
  162. {nabu-2024.2.4.dist-info → nabu-2025.1.0.dev4.dist-info}/LICENSE +0 -0
  163. {nabu-2024.2.4.dist-info → nabu-2025.1.0.dev4.dist-info}/entry_points.txt +0 -0
  164. {nabu-2024.2.4.dist-info → nabu-2025.1.0.dev4.dist-info}/top_level.txt +0 -0
@@ -9,9 +9,8 @@ def find_mirror_indexes(angles_deg, tolerance_factor=1.0):
9
9
  contains the index of the angles_deg array element which has the value the closest
10
10
  to angles_deg[i] + 180. It is used for padding in halftomo.
11
11
 
12
- Parameters:
12
+ Parameters
13
13
  -----------
14
-
15
14
  angles_deg: a nd.array of floats
16
15
 
17
16
  tolerance: float
@@ -1,3 +1,4 @@
1
+ # ruff: noqa
1
2
  from ..fullfield.nabu_config import *
2
3
  import copy
3
4
 
@@ -1,3 +1,4 @@
1
+ # ruff: noqa
1
2
  import math
2
3
  import numpy as np
3
4
  from ...resources.logger import LoggerOrPrint
@@ -12,8 +12,7 @@ class WeightBalancer:
12
12
  to Nabu, we create this class and follow the scheme initialisation + application.
13
13
 
14
14
  Parameters
15
- ==========
16
-
15
+ ----------
17
16
  rot_center : float
18
17
  the center of rotation in pixel units
19
18
  angles_rad :
File without changes
nabu/pipeline/utils.py CHANGED
@@ -72,7 +72,7 @@ def get_subregion(sub_region, ndim=3):
72
72
  if sub_region is None:
73
73
  res = ((None, None),)
74
74
  elif hasattr(sub_region[0], "__iter__"):
75
- if set(map(len, sub_region)) != set([2]):
75
+ if set(map(len, sub_region)) != {2}:
76
76
  raise ValueError("Expected each tuple to be in the form (start, end)")
77
77
  res = sub_region
78
78
  else:
nabu/pipeline/writer.py CHANGED
@@ -163,7 +163,7 @@ class WriterManager:
163
163
  def _init_histogram_writer(self):
164
164
  if not self.histogram:
165
165
  return
166
- separate_histogram_file = not (self.file_format == "hdf5")
166
+ separate_histogram_file = self.file_format != "hdf5"
167
167
  if separate_histogram_file:
168
168
  fmode = "w"
169
169
  hist_fname = path.join(self.output_dir, "histogram_%05d.hdf5" % self.start_index)
nabu/preproc/alignment.py CHANGED
@@ -1,11 +1 @@
1
1
  # Backward compat.
2
- from ..estimation.alignment import AlignmentBase
3
- from ..estimation.cor import (
4
- CenterOfRotation,
5
- CenterOfRotationAdaptiveSearch,
6
- CenterOfRotationGrowingWindow,
7
- CenterOfRotationSlidingWindow,
8
- )
9
- from ..estimation.translation import DetectorTranslationAlongBeam
10
- from ..estimation.focus import CameraFocus
11
- from ..estimation.tilt import CameraTilt
nabu/preproc/ctf.py CHANGED
@@ -67,7 +67,7 @@ class GeoPars:
67
67
  else:
68
68
  self.M_vh = np.array([1, 1])
69
69
 
70
- self.logger.debug("Magnification : h ({}) ; v ({}) ".format(self.M_vh[1], self.M_vh[0]))
70
+ self.logger.debug(f"Magnification : h ({self.M_vh[1]}) ; v ({self.M_vh[0]}) ")
71
71
 
72
72
  self.length_scale = length_scale
73
73
  self.wavelength = wavelength
@@ -80,17 +80,17 @@ class GeoPars:
80
80
 
81
81
  which_unit = int(np.sum(np.array([self.pix_size_rec > small for small in [1.0e-6, 1.0e-7]]).astype(np.int32)))
82
82
  self.pixelsize_string = [
83
- "{:.1f} nm".format(self.pix_size_rec * 1e9),
84
- "{:.3f} um".format(self.pix_size_rec * 1e6),
85
- "{:.1f} um".format(self.pix_size_rec * 1e6),
83
+ f"{self.pix_size_rec * 1e9:.1f} nm",
84
+ f"{self.pix_size_rec * 1e6:.3f} um",
85
+ f"{self.pix_size_rec * 1e6:.1f} um",
86
86
  ][which_unit]
87
87
 
88
88
  if self.magnification:
89
89
  self.logger.debug(
90
- "All images are resampled to smallest pixelsize: {}".format(self.pixelsize_string),
90
+ f"All images are resampled to smallest pixelsize: {self.pixelsize_string}",
91
91
  )
92
92
  else:
93
- self.logger.debug("Pixelsize images: {}".format(self.pixelsize_string))
93
+ self.logger.debug(f"Pixelsize images: {self.pixelsize_string}")
94
94
 
95
95
 
96
96
  class CTFPhaseRetrieval:
@@ -157,7 +157,7 @@ class CTFPhaseRetrieval:
157
157
  """
158
158
  self.logger = LoggerOrPrint(logger)
159
159
  if not isinstance(geo_pars, GeoPars):
160
- raise ValueError("Expected GeoPars instance for 'geo_pars' parameter")
160
+ raise TypeError("Expected GeoPars instance for 'geo_pars' parameter")
161
161
  self.geo_pars = geo_pars
162
162
  self._calc_shape(shape, padded_shape, padding_mode)
163
163
  self.delta_beta = delta_beta
@@ -292,7 +292,7 @@ class CTFPhaseRetrieval:
292
292
  self.cut_v = math.sqrt(1.0 / 2 / lambda_dist_vh[0]) / fsample_vh[0]
293
293
  self.cut_v = min(self.cut_v, 0.5)
294
294
 
295
- self.logger.debug("Normalized cut-off = {:5.3f}".format(self.cut_v))
295
+ self.logger.debug(f"Normalized cut-off = {self.cut_v:5.3f}")
296
296
 
297
297
  self.r = fourier_filters.get_lowpass_filter(
298
298
  padded_img_shape,
nabu/preproc/ctf_cuda.py CHANGED
@@ -48,7 +48,7 @@ class CudaCTFPhaseRetrieval(CTFPhaseRetrieval):
48
48
  padding_mode: str
49
49
  Padding mode. Default is "reflect".
50
50
 
51
- Other parameters
51
+ Other Parameters
52
52
  -----------------
53
53
  Please refer to CTFPhaseRetrieval documentation.
54
54
  """
@@ -7,7 +7,7 @@ from .ccd_cuda import CudaLog
7
7
 
8
8
  if __has_pycuda__:
9
9
  import pycuda.gpuarray as garray
10
- import pycuda.cumath as cumath
10
+ from pycuda import cumath
11
11
 
12
12
 
13
13
  class CudaDoubleFlatField(DoubleFlatField):
@@ -109,7 +109,7 @@ class CudaDoubleFlatField(DoubleFlatField):
109
109
  Whether to recompute the double flatfield if already computed.
110
110
  """
111
111
  if not (isinstance(radios, garray.GPUArray)): # pylint: disable=E0606
112
- raise ValueError("Expected pycuda.gpuarray.GPUArray for radios")
112
+ raise TypeError("Expected pycuda.gpuarray.GPUArray for radios")
113
113
  if self._computed and not (recompute):
114
114
  return self.doubleflatfield
115
115
  acc = garray.zeros(radios[0].shape, "f")
@@ -1,5 +1,4 @@
1
1
  from .double_flatfield import (
2
- DoubleFlatField,
3
2
  DoubleFlatField,
4
3
  check_shape,
5
4
  get_2D_3D_shape,
nabu/preproc/flatfield.py CHANGED
@@ -91,7 +91,7 @@ class FlatFieldArrays:
91
91
  flatfield_normalization(X') = (X' - D)/(F' - D) = (X - D) / (F - D) * sF/sX
92
92
  So current normalization boils down to a scalar multiplication after flat-field.
93
93
  """
94
- if self._full_shape:
94
+ if self._full_shape: # noqa: SIM102
95
95
  # this is never going to happen in this base class. But in the derived class for helical
96
96
  # which needs to keep the full shape
97
97
  if radios_indices is not None:
@@ -4,7 +4,6 @@ from nabu.cuda.processing import CudaProcessing
4
4
  from ..preproc.flatfield import FlatFieldArrays
5
5
  from ..utils import deprecated_class, get_cuda_srcfile
6
6
  from ..io.reader import load_images_from_dataurl_dict
7
- from ..cuda.utils import __has_pycuda__
8
7
 
9
8
 
10
9
  class CudaFlatFieldArrays(FlatFieldArrays):
@@ -90,7 +89,7 @@ class CudaFlatFieldArrays(FlatFieldArrays):
90
89
  Radios chunk.
91
90
  """
92
91
  if not (isinstance(radios, self.cuda_processing.array_class)):
93
- raise ValueError("Expected a pycuda.gpuarray (got %s)" % str(type(radios)))
92
+ raise TypeError("Expected a pycuda.gpuarray (got %s)" % str(type(radios)))
94
93
  if radios.dtype != np.float32:
95
94
  raise ValueError("radios must be in float32 dtype (got %s)" % str(radios.dtype))
96
95
  if radios.shape != self.radios_shape:
@@ -1,5 +1,5 @@
1
1
  import numpy as np
2
- from .flatfield import FlatFieldArrays, load_images_from_dataurl_dict, check_supported
2
+ from .flatfield import FlatFieldArrays, load_images_from_dataurl_dict
3
3
 
4
4
 
5
5
  class FlatFieldArraysVariableRegion(FlatFieldArrays):
@@ -27,9 +27,9 @@ class FlatFieldArraysVariableRegion(FlatFieldArrays):
27
27
  does not correspond to the length of sub_indexes which is {len(sub_indexes)}
28
28
  """
29
29
  raise ValueError(message)
30
- do_flats_distortion_correction = self.distortion_correction is not None
30
+ # do_flats_distortion_correction = self.distortion_correction is not None
31
31
 
32
- whole_dark = self.get_dark()
32
+ # whole_dark = self.get_dark()
33
33
  for i, (idx, sub_r) in enumerate(zip(sub_indexes, sub_regions_per_radio)):
34
34
  start_x, end_x, start_y, end_y = sub_r
35
35
  slice_x = slice(start_x, end_x)
nabu/preproc/phase.py CHANGED
@@ -5,13 +5,12 @@ from scipy.fft import rfft2, irfft2, fft2, ifft2
5
5
  from ..utils import generate_powers, get_decay, check_supported, get_num_threads, deprecation_warning
6
6
 
7
7
  # COMPAT.
8
- from .ctf import CTFPhaseRetrieval
9
8
 
10
9
  #
11
10
 
12
11
 
13
12
  def lmicron_to_db(Lmicron, energy, distance):
14
- """
13
+ r"""
15
14
  Utility to convert the "Lmicron" parameter of PyHST
16
15
  to a value of delta/beta.
17
16
 
@@ -55,7 +54,7 @@ class PaganinPhaseRetrieval:
55
54
  fftw_num_threads=None,
56
55
  fft_num_threads=None,
57
56
  ):
58
- """
57
+ r"""
59
58
  Paganin Phase Retrieval for an infinitely distant point source.
60
59
  Formula (10) in [1].
61
60
 
@@ -98,7 +97,6 @@ class PaganinPhaseRetrieval:
98
97
 
99
98
  Notes
100
99
  ------
101
-
102
100
  **Padding methods**
103
101
 
104
102
  The phase retrieval is a convolution done in Fourier domain using FFT,
@@ -107,13 +107,13 @@ class CudaPaganinPhaseRetrieval(PaganinPhaseRetrieval):
107
107
  assert data.dtype == np.float32
108
108
  # Rectangular memcopy
109
109
  # TODO profile, and if needed include this copy in the padding kernel
110
- if isinstance(data, np.ndarray) or isinstance(data, self.cuda_processing.array_class):
110
+ if isinstance(data, np.ndarray) or isinstance(data, self.cuda_processing.array_class): # noqa: SIM101
111
111
  self.d_radio_padded[: self.shape[0], : self.shape[1]] = data[:, :]
112
112
  elif isinstance(data, cuda.DeviceAllocation):
113
113
  # TODO manual memcpy2D
114
114
  raise NotImplementedError("pycuda buffers are not supported yet")
115
115
  else:
116
- raise ValueError("Expected either numpy array, pycuda array or pycuda buffer")
116
+ raise TypeError("Expected either numpy array, pycuda array or pycuda buffer")
117
117
 
118
118
  def get_output(self, output):
119
119
  s0, s1 = self.shape
@@ -1,5 +1,4 @@
1
1
  import numpy as np
2
- from ..cuda.utils import __has_pycuda__
3
2
  from ..cuda.processing import CudaProcessing
4
3
  from ..processing.muladd_cuda import CudaMulAdd
5
4
  from .shift import VerticalShift
@@ -10,7 +10,7 @@ from nabu.preproc import ctf
10
10
  from nabu.estimation.distortion import estimate_flat_distortion
11
11
  from nabu.misc.filters import correct_spikes
12
12
  from nabu.preproc.distortion import DistortionCorrection
13
- from nabu.cuda.utils import __has_pycuda__, get_cuda_context
13
+ from nabu.cuda.utils import __has_pycuda__
14
14
 
15
15
  __has_cufft__ = False
16
16
  if __has_pycuda__:
@@ -220,7 +220,7 @@ class TestCtf:
220
220
  # Test multi-core FFT
221
221
  ctf_fft = ctf.CtfFilter(*ctf_args, **ctf_kwargs, use_rfft=True, fft_num_threads=0)
222
222
  if ctf_fft.use_rfft:
223
- phase_fft = ctf_fft.retrieve_phase(img)
223
+ # phase_fft = ctf_fft.retrieve_phase(img)
224
224
  self.check_result(phase_r2c, self.ref_plain, "Something wrong with CtfFilter-FFT")
225
225
 
226
226
  @pytest.mark.skipif(not (__has_pycuda__ and __has_cufft__), reason="pycuda and (scikit-cuda or vkfft)")
@@ -232,7 +232,7 @@ class TestCtf:
232
232
  pix_size_m = 0.1e-6
233
233
 
234
234
  geo_pars = ctf.GeoPars(z2=distance_m, pix_size_det=pix_size_m, wavelength=1.23984199e-9 / energy_kev)
235
- ctx = get_cuda_context()
235
+ # ctx = get_cuda_context()
236
236
 
237
237
  for normalize in [True, False]:
238
238
  ctf_filter = ctf.CTFPhaseRetrieval(
@@ -1,4 +1,4 @@
1
- import os.path as path
1
+ from os import path
2
2
  from math import exp
3
3
  import tempfile
4
4
  import numpy as np
@@ -411,7 +411,7 @@ class FlatFieldTestDataset:
411
411
  self._generate_projections()
412
412
 
413
413
  def get_flat_idx(self, proj_idx):
414
- flats_idx = sorted(list(self.flats.keys()))
414
+ flats_idx = sorted(self.flats.keys())
415
415
  if proj_idx <= flats_idx[0]:
416
416
  return (flats_idx[0],)
417
417
  elif proj_idx > flats_idx[0] and proj_idx < flats_idx[1]:
@@ -70,4 +70,7 @@ class TestVerticalShift:
70
70
  Shifter_neg_cuda = CudaVerticalShift(d_radios.shape, -self.shifts)
71
71
  Shifter_neg_cuda.apply_vertical_shifts(d_radios2, self.indexes)
72
72
  err_max = np.max(np.abs(d_radios2.get() - radios2))
73
- assert err_max < 1e-6, "Something wrong for negative translations: max error = %.2e" % err_max
73
+ #
74
+ # FIXME tolerance was downgraded from 1e-6 to 8e-6 when switching to numpy 2
75
+ #
76
+ assert err_max < 8e-6, "Something wrong for negative translations: max error = %.2e" % err_max
nabu/processing/azim.py CHANGED
@@ -123,11 +123,11 @@ def do_radial_distribution(ip, X0, Y0, mR, nBins=None, use_calibration=False, ca
123
123
  if use_calibration and cal is not None:
124
124
  # Apply calibration if units are provided
125
125
  radii = cal.pixel_width * mR * (np.arange(1, nBins + 1) / nBins)
126
- units = cal.units
126
+ # units = cal.units
127
127
  else:
128
128
  # Use pixel units
129
129
  radii = mR * (np.arange(1, nBins + 1) / nBins)
130
- units = "pixels"
130
+ # units = "pixels"
131
131
 
132
132
  if return_radii:
133
133
  return radii, Accumulator[1]
@@ -159,7 +159,7 @@ class Convolution:
159
159
  self.d_kernel = self.cuda.to_device("d_kernel", self.kernel)
160
160
  else:
161
161
  if not (isinstance(self.kernel, self.cuda.array_class)):
162
- raise ValueError("kernel must be either numpy array or pycuda array")
162
+ raise TypeError("kernel must be either numpy array or pycuda array")
163
163
  self.d_kernel = self.kernel
164
164
  self._old_input_ref = None
165
165
  self._old_output_ref = None
@@ -185,7 +185,7 @@ class Convolution:
185
185
  self._c_conv_mode = mp[self.mode]
186
186
 
187
187
  def _init_kernels(self):
188
- if self.kernel_ndim > 1:
188
+ if self.kernel_ndim > 1: # noqa: SIM102
189
189
  if np.abs(np.diff(self.kernel.shape)).max() > 0:
190
190
  raise NotImplementedError("Non-separable convolution with non-square kernels is not implemented yet")
191
191
  # Compile source module
@@ -290,7 +290,7 @@ class Convolution:
290
290
  return ndim
291
291
 
292
292
  def _check_array(self, arr):
293
- if not (isinstance(arr, self.cuda.array_class) or isinstance(arr, np.ndarray)):
293
+ if not (isinstance(arr, self.cuda.array_class) or isinstance(arr, np.ndarray)): # noqa: SIM101
294
294
  raise TypeError("Expected either pycuda.gpuarray or numpy.ndarray")
295
295
  if arr.dtype != np.float32:
296
296
  raise TypeError("Data must be float32")
@@ -305,7 +305,7 @@ class Convolution:
305
305
  self._old_input_ref = self.data_in
306
306
  self.data_in = array
307
307
  data_in_ref = self.data_in
308
- if output is not None:
308
+ if output is not None: # noqa: SIM102
309
309
  if not (isinstance(output, np.ndarray)):
310
310
  self._old_output_ref = self.data_out
311
311
  self.data_out = output
@@ -324,11 +324,13 @@ class Convolution:
324
324
  cuda_kernel = self.cuda_kernels[axis]
325
325
  cuda_kernel_args = self._configure_kernel_args(self.kernel_args, input_ref, output_ref)
326
326
  ev = cuda_kernel.prepared_call(*cuda_kernel_args)
327
+ return ev
327
328
 
328
329
  def _nd_convolution(self):
329
330
  assert len(self.use_case_kernels) == 1
330
331
  cuda_kernel = self._module.get_function(self.use_case_kernels[0])
331
332
  ev = cuda_kernel.prepared_call(*self.kernel_args)
333
+ return ev
332
334
 
333
335
  def _recover_arrays_references(self):
334
336
  if self._old_input_ref is not None:
@@ -35,7 +35,7 @@ class _BaseFFT:
35
35
  the transform is unitary. Both FFT and IFFT are scaled with 1/sqrt(N).
36
36
  * "none": no normalizatio is done : IFFT(FFT(data)) = data*N
37
37
 
38
- Other parameters
38
+ Other Parameters
39
39
  -----------------
40
40
  backend_options: dict, optional
41
41
  Parameters to pass to CudaProcessing or OpenCLProcessing class.
@@ -25,6 +25,7 @@ def init_skcuda():
25
25
  # This needs to be done here, because scikit-cuda creates a Cuda context at import,
26
26
  # which can mess things up in some cases.
27
27
  # Ugly solution to an ugly problem.
28
+ # ruff: noqa: PLW0603
28
29
  global __has_skcuda__, Plan, cu_fft, cu_ifft
29
30
  try:
30
31
  from skcuda.fft import Plan
@@ -167,7 +168,7 @@ def _has_vkfft(x):
167
168
 
168
169
  if not __has_vkfft__:
169
170
  return False
170
- vk = VKCUFFT((16,), "f")
171
+ _ = VKCUFFT((16,), "f")
171
172
  avail = True
172
173
  except (ImportError, RuntimeError, OSError, NameError):
173
174
  avail = False
@@ -184,9 +185,14 @@ def has_vkfft(safe=True):
184
185
  """
185
186
  if not safe:
186
187
  return _has_vkfft(None)
187
- ctx = get_context("spawn")
188
- with Pool(1, context=ctx) as p:
189
- v = p.map(_has_vkfft, [1])[0]
188
+ try:
189
+ ctx = get_context("spawn")
190
+ with Pool(1, context=ctx) as p:
191
+ v = p.map(_has_vkfft, [1])[0]
192
+ except AssertionError:
193
+ # Can get AssertionError: daemonic processes are not allowed to have children
194
+ # if the calling code is already a subprocess
195
+ return _has_vkfft(None)
190
196
  return v
191
197
 
192
198
 
@@ -195,7 +201,7 @@ def _has_skfft(x):
195
201
  try:
196
202
  from nabu.processing.fft_cuda import SKCUFFT
197
203
 
198
- sk = SKCUFFT((16,), "f")
204
+ _ = SKCUFFT((16,), "f")
199
205
  avail = True
200
206
  except (ImportError, RuntimeError, OSError, NameError):
201
207
  avail = False
@@ -210,9 +216,14 @@ def has_skcuda(safe=True):
210
216
  """
211
217
  if not safe:
212
218
  return _has_skfft(None)
213
- ctx = get_context("spawn")
214
- with Pool(1, context=ctx) as p:
215
- v = p.map(_has_skfft, [1])[0]
219
+ try:
220
+ ctx = get_context("spawn")
221
+ with Pool(1, context=ctx) as p:
222
+ v = p.map(_has_skfft, [1])[0]
223
+ except AssertionError:
224
+ # Can get AssertionError: daemonic processes are not allowed to have children
225
+ # if the calling code is already a subprocess
226
+ return _has_skfft(None)
216
227
  return v
217
228
 
218
229
 
@@ -34,7 +34,7 @@ def _has_vkfft(x):
34
34
 
35
35
  if not __has_vkfft__:
36
36
  return False
37
- vk = VKCLFFT((16,), "f")
37
+ _ = VKCLFFT((16,), "f")
38
38
  avail = True
39
39
  except (RuntimeError, OSError):
40
40
  avail = False
@@ -48,7 +48,12 @@ def has_vkfft(safe=True):
48
48
  """
49
49
  if not safe:
50
50
  return _has_vkfft(None)
51
- ctx = get_context("spawn")
52
- with Pool(1, context=ctx) as p:
53
- v = p.map(_has_vkfft, [1])[0]
51
+ try:
52
+ ctx = get_context("spawn")
53
+ with Pool(1, context=ctx) as p:
54
+ v = p.map(_has_vkfft, [1])[0]
55
+ except AssertionError:
56
+ # Can get AssertionError: daemonic processes are not allowed to have children
57
+ # if the calling code is already a subprocess
58
+ return _has_vkfft(None)
54
59
  return v
@@ -25,7 +25,7 @@ class FFTshiftBase:
25
25
  axes: tuple, optional
26
26
  Axes over which to shift. Default is None, which shifts all axes.
27
27
 
28
- Other parameters
28
+ Other Parameters
29
29
  ----------------
30
30
  backend_options:
31
31
  named arguments to pass to CudaProcessing or OpenCLProcessing
@@ -146,7 +146,7 @@ class PartialHistogram:
146
146
  elif self.bin_width == "uint16":
147
147
  return self._bin_width_u16(dmin, dmax)
148
148
  else:
149
- raise ValueError()
149
+ raise ValueError
150
150
 
151
151
  def _compute_histogram_fixed_bw(self, data, data_range=None):
152
152
  dmin, dmax = data.min(), data.max() if data_range is None else data_range
nabu/processing/muladd.py CHANGED
@@ -1,4 +1,3 @@
1
- import numpy as np
2
1
  from .processing_base import ProcessingBase
3
2
 
4
3
 
@@ -23,7 +23,7 @@ class PaddingBase:
23
23
  mode: str
24
24
  Padding mode
25
25
 
26
- Other parameters
26
+ Other Parameters
27
27
  ----------------
28
28
  constant_values: tuple
29
29
  Tuple containing the values to fill when mode="constant" (as in numpy.pad)
@@ -1,7 +1,6 @@
1
1
  import numpy as np
2
2
  from ..utils import get_cuda_srcfile, updiv
3
3
  from ..cuda.processing import CudaProcessing
4
- from ..cuda.utils import __has_pycuda__
5
4
  from .padding_base import PaddingBase
6
5
 
7
6
 
@@ -88,7 +88,7 @@ class ProcessingBase:
88
88
  self.allocate_array(array_name, array_ref.shape, dtype=dtype)
89
89
  getattr(self, array_name).set(array_ref)
90
90
  else:
91
- raise ValueError("Expected numpy array or pycuda array")
91
+ raise TypeError("Expected numpy array or pycuda array")
92
92
  return getattr(self, array_name)
93
93
 
94
94
  def get_array(self, array_name):
@@ -190,7 +190,7 @@ class TestFFT:
190
190
  pytest.skip("R2C with odd-sized fast dimension is not supported in VKFFT")
191
191
 
192
192
  # FIXME - vkfft + POCL fail for R2C in one dimension
193
- if config["backend"] == "opencl" and r2c and ndim == 1:
193
+ if config["backend"] == "opencl" and r2c and ndim == 1: # noqa: SIM102
194
194
  if self.cl_ctx.devices[0].platform.name.strip().lower() == "portable computing language":
195
195
  pytest.skip("Something wrong with vkfft + pocl for R2C 1D")
196
196
  # ---
@@ -2,7 +2,7 @@ import numpy as np
2
2
  import pytest
3
3
  from nabu.cuda.utils import get_cuda_context, __has_pycuda__
4
4
  from nabu.opencl.utils import __has_pyopencl__, get_opencl_context
5
- from nabu.testutils import get_data, generate_tests_scenarios, __do_long_tests__
5
+ from nabu.testutils import get_data, generate_tests_scenarios
6
6
 
7
7
  if __has_pyopencl__:
8
8
  from nabu.processing.fftshift import OpenCLFFTshift
@@ -34,16 +34,14 @@ def bootstrap(request):
34
34
 
35
35
  @pytest.mark.skipif(not (__has_pycuda__), reason="Need Cuda/pycuda for this test")
36
36
  @pytest.mark.usefixtures("bootstrap")
37
- class TestMedianFilter(object):
37
+ class TestMedianFilter:
38
38
  @classmethod
39
39
  def allocate_numpy_arrays(cls):
40
- shape = cls.data.shape
41
40
  cls.input = cls.data
42
41
  cls.input3d = np.tile(cls.input, (2, 1, 1))
43
42
 
44
43
  @classmethod
45
44
  def allocate_cuda_arrays(cls):
46
- shape = cls.data.shape
47
45
  cls.d_input = garray.to_gpu(cls.input)
48
46
  cls.d_output = garray.zeros_like(cls.d_input)
49
47
  cls.d_input3d = garray.to_gpu(cls.input3d)
@@ -108,7 +108,7 @@ class TestPadding:
108
108
  d_img.set(data)
109
109
  d_out = padding.processing.allocate_array("d_out", padding.padded_shape, dtype="f")
110
110
 
111
- res = padding.pad(d_img, output=d_out)
111
+ padding.pad(d_img, output=d_out)
112
112
 
113
113
  ref = np.roll(np.pad(data, pad_width, mode=mode), (-pad_width[0][0], -pad_width[1][0]), axis=(0, 1))
114
114
 
@@ -2,7 +2,7 @@ import numpy as np
2
2
  import pytest
3
3
  from nabu.cuda.utils import get_cuda_context, __has_pycuda__
4
4
  from nabu.opencl.utils import __has_pyopencl__, get_opencl_context
5
- from nabu.testutils import get_data, generate_tests_scenarios, __do_long_tests__
5
+ from nabu.testutils import get_data, generate_tests_scenarios
6
6
  from nabu.processing.roll_opencl import OpenCLRoll
7
7
 
8
8
  configs_roll = {
@@ -1,5 +1,5 @@
1
1
  try:
2
- import pyopencl.array as parray
2
+ import pyopencl.array as parray # noqa: F401
3
3
  from pyopencl.elementwise import ElementwiseKernel
4
4
  from ..opencl.processing import OpenCLProcessing
5
5