darfix 4.2.0__py3-none-any.whl → 4.3.0__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 (144) hide show
  1. darfix/core/data_selection.py +11 -2
  2. darfix/core/dataset.py +72 -157
  3. darfix/core/grainplot.py +44 -56
  4. darfix/core/{imageStack.py → image_stack.py} +9 -15
  5. darfix/core/moment_types.py +6 -0
  6. darfix/core/{noiseremoval.py → noise_removal.py} +25 -24
  7. darfix/core/noise_removal_type.py +14 -0
  8. darfix/core/positioners.py +6 -0
  9. darfix/core/rocking_curves.py +6 -3
  10. darfix/core/rocking_curves_map.py +1 -1
  11. darfix/core/{shiftcorrection.py → shift_correction.py} +1 -2
  12. darfix/core/state_of_operation.py +7 -46
  13. darfix/core/utils.py +0 -39
  14. darfix/dtypes.py +1 -9
  15. darfix/gui/{binningWidget.py → binning_widget.py} +2 -29
  16. darfix/gui/{blindSourceSeparationWidget.py → blind_source_separation_widget.py} +4 -16
  17. darfix/gui/{chooseDimensions.py → choose_dimensions.py} +1 -1
  18. darfix/gui/concatenate_scans.py +4 -4
  19. darfix/gui/data_selection/{hdf5_data_selection_widgets.py → hdf5_dataset_selection_widget.py} +3 -56
  20. darfix/gui/data_selection/line_edits.py +54 -8
  21. darfix/gui/data_selection/scan_selection_widgets.py +24 -11
  22. darfix/gui/data_selection/utils.py +11 -0
  23. darfix/gui/data_selection/{WorkingDirSelectionWidget.py → working_dir_selection_widget.py} +15 -14
  24. darfix/gui/{dimensionsWidget.py → dimensions_widget.py} +1 -1
  25. darfix/gui/{displayComponentsWidget.py → display_components_widget.py} +1 -1
  26. darfix/gui/{filterByDimension.py → filter_by_dimension.py} +1 -1
  27. darfix/gui/{grainplot/dimensionRangeSlider2D.py → grain_plot/dimension_range_slider_2d.py} +2 -2
  28. darfix/gui/{grainplot/grainPlotWidget.py → grain_plot/grain_plot_widget.py} +1 -1
  29. darfix/gui/{grainplot/mosaicityWidget.py → grain_plot/mosaicity_widget.py} +21 -23
  30. darfix/gui/{magnificationWidget.py → magnification_widget.py} +1 -1
  31. darfix/gui/{noiseremoval → noise_removal}/noise_removal_widget.py +12 -16
  32. darfix/gui/{noiseremoval → noise_removal}/operation_list_widget.py +2 -2
  33. darfix/gui/{noiseremoval → noise_removal}/parameters_widget.py +6 -6
  34. darfix/gui/{PCAWidget.py → pca_widget.py} +2 -4
  35. darfix/gui/{projectionWidget.py → projection_widget.py} +1 -1
  36. darfix/gui/rocking_curves/{rockingCurvesPlot.py → rocking_curves_plot.py} +13 -13
  37. darfix/gui/rocking_curves/{rockingCurvesWidget.py → rocking_curves_widget.py} +10 -18
  38. darfix/gui/{roiSelectionWidget.py → roi_selection_widget.py} +9 -101
  39. darfix/gui/{shiftcorrection/shiftCorrectionWidget.py → shift_correction/shift_correction_widget.py} +4 -7
  40. darfix/gui/utils/data_path_completer.py +7 -7
  41. darfix/gui/utils/data_path_selection.py +4 -4
  42. darfix/gui/utils/{rangeSlider.py → range_slider.py} +1 -1
  43. darfix/gui/{weakBeamWidget.py → weak_beam_widget.py} +13 -28
  44. darfix/gui/{zSumWidget.py → zsum_widget.py} +1 -2
  45. darfix/main.py +19 -3
  46. darfix/processing/rocking_curves.py +12 -13
  47. darfix/tasks/binning.py +6 -17
  48. darfix/tasks/blind_source_separation.py +121 -0
  49. darfix/tasks/blindsourceseparation.py +8 -131
  50. darfix/tasks/copy.py +0 -2
  51. darfix/tasks/data_partition.py +39 -0
  52. darfix/tasks/datapartition.py +8 -50
  53. darfix/tasks/dimension_definition.py +197 -0
  54. darfix/tasks/dimensiondefinition.py +8 -197
  55. darfix/tasks/grain_plot.py +93 -0
  56. darfix/tasks/grainplot.py +8 -103
  57. darfix/tasks/hdf5_data_selection.py +5 -11
  58. darfix/tasks/hdf5_scans_concatenation.py +4 -4
  59. darfix/tasks/noise_removal.py +88 -0
  60. darfix/tasks/noiseremoval.py +8 -86
  61. darfix/tasks/pca.py +1 -3
  62. darfix/tasks/projection.py +1 -6
  63. darfix/tasks/rocking_curves.py +10 -5
  64. darfix/tasks/roi.py +0 -2
  65. darfix/tasks/shift_correction.py +45 -0
  66. darfix/tasks/shiftcorrection.py +8 -43
  67. darfix/tasks/transformation.py +0 -2
  68. darfix/tasks/weak_beam.py +71 -0
  69. darfix/tasks/weakbeam.py +8 -67
  70. darfix/tasks/zsum.py +1 -1
  71. darfix/tests/conftest.py +1 -1
  72. darfix/tests/gui/test_data_path_completer.py +4 -4
  73. darfix/tests/gui/test_dimension_range_slider_2d.py +2 -2
  74. darfix/tests/gui/test_range_slider_with_spinboxes.py +1 -1
  75. darfix/tests/orange/test_ewoks.py +13 -9
  76. darfix/tests/orange/widgets/test_hdf5_data_selection.py +93 -0
  77. darfix/tests/tasks/test_data_copy.py +0 -2
  78. darfix/tests/tasks/{test_dimensiondefinition.py → test_dimension_definition.py} +1 -1
  79. darfix/tests/tasks/test_weak_beam.py +9 -0
  80. darfix/tests/test_components_matching.py +2 -2
  81. darfix/tests/test_dataset.py +2 -28
  82. darfix/tests/test_dimension.py +1 -1
  83. darfix/tests/test_generate_grain_maps_nxdict.py +4 -5
  84. darfix/tests/test_image_operations.py +4 -4
  85. darfix/tests/test_image_registration.py +17 -17
  86. darfix/tests/test_image_stack.py +2 -13
  87. darfix/tests/test_mask.py +1 -1
  88. darfix/tests/test_moments.py +2 -2
  89. darfix/tests/test_rocking_curves.py +1 -3
  90. darfix/tests/test_shift.py +7 -7
  91. darfix/tests/test_workflow.py +4 -4
  92. darfix/tests/test_zsum.py +3 -6
  93. {darfix-4.2.0.dist-info → darfix-4.3.0.dist-info}/METADATA +5 -3
  94. {darfix-4.2.0.dist-info → darfix-4.3.0.dist-info}/RECORD +141 -135
  95. orangecontrib/darfix/widgets/__init__.py +10 -1
  96. orangecontrib/darfix/widgets/binning.py +3 -3
  97. orangecontrib/darfix/widgets/blindsourceseparation.py +4 -6
  98. orangecontrib/darfix/widgets/concatenateHDF5.py +1 -1
  99. orangecontrib/darfix/widgets/datacopy.py +1 -1
  100. orangecontrib/darfix/widgets/datapartition.py +7 -102
  101. orangecontrib/darfix/widgets/{datasetWidgetBase.py → dataset_widget_base.py} +17 -5
  102. orangecontrib/darfix/widgets/dimensions.py +6 -6
  103. orangecontrib/darfix/widgets/grainplot.py +3 -3
  104. orangecontrib/darfix/widgets/hdf5dataselection.py +34 -14
  105. orangecontrib/darfix/widgets/metadata.py +2 -2
  106. orangecontrib/darfix/widgets/noiseremoval.py +4 -4
  107. orangecontrib/darfix/widgets/{operationWidgetBase.py → operation_widget_base.py} +2 -2
  108. orangecontrib/darfix/widgets/pca.py +2 -2
  109. orangecontrib/darfix/widgets/projection.py +2 -2
  110. orangecontrib/darfix/widgets/rockingcurves.py +5 -2
  111. orangecontrib/darfix/widgets/roiselection.py +24 -106
  112. orangecontrib/darfix/widgets/rsmhistogram.py +2 -2
  113. orangecontrib/darfix/widgets/shiftcorrection.py +3 -3
  114. orangecontrib/darfix/widgets/transformation.py +4 -4
  115. orangecontrib/darfix/widgets/weakbeam.py +20 -103
  116. orangecontrib/darfix/widgets/zsum.py +3 -5
  117. darfix/gui/dataPartitionWidget.py +0 -167
  118. darfix/gui/data_selection/DataSelectionBase.py +0 -59
  119. darfix/tests/tasks/test_datapartition.py +0 -52
  120. /darfix/core/{componentsMatching.py → components_matching.py} +0 -0
  121. /darfix/core/{datapathfinder.py → data_path_finder.py} +0 -0
  122. /darfix/core/{imageRegistration.py → image_registration.py} +0 -0
  123. /darfix/gui/{grainplot → grain_plot}/__init__.py +0 -0
  124. /darfix/gui/{grainplot → grain_plot}/_oridist_toolbar_buttons.py +0 -0
  125. /darfix/gui/{grainplot → grain_plot}/flashlight.py +0 -0
  126. /darfix/gui/{grainplot → grain_plot}/flashlight_mode_action.py +0 -0
  127. /darfix/gui/{grainplot → grain_plot}/oridist_toolbar.py +0 -0
  128. /darfix/gui/{grainplot → grain_plot}/utils.py +0 -0
  129. /darfix/gui/{metadataWidget.py → metadata_widget.py} +0 -0
  130. /darfix/gui/{operationProcess.py → parallel/operation_process.py} +0 -0
  131. /darfix/gui/{operationThread.py → parallel/operation_thread.py} +0 -0
  132. /darfix/gui/rocking_curves/{fitComboBox.py → fit_combobox.py} +0 -0
  133. /darfix/gui/{roiLimitsToolbar.py → roi_limits_toolbar.py} +0 -0
  134. /darfix/gui/{rsmHistogramWidget.py → rsm_histogram_widget.py} +0 -0
  135. /darfix/gui/{rsmWidget.py → rsm_widget.py} +0 -0
  136. /darfix/gui/{shiftcorrection → shift_correction}/__init__.py +0 -0
  137. /darfix/gui/{shiftcorrection/shiftInput.py → shift_correction/shift_input.py} +0 -0
  138. /darfix/gui/utils/{standardButtonBox.py → standard_buttonbox.py} +0 -0
  139. /darfix/processing/{imageOperations.py → image_operations.py} +0 -0
  140. /darfix/tests/{test_datapathfinder.py → test_data_path_finder.py} +0 -0
  141. {darfix-4.2.0.dist-info → darfix-4.3.0.dist-info}/WHEEL +0 -0
  142. {darfix-4.2.0.dist-info → darfix-4.3.0.dist-info}/entry_points.txt +0 -0
  143. {darfix-4.2.0.dist-info → darfix-4.3.0.dist-info}/licenses/LICENSE +0 -0
  144. {darfix-4.2.0.dist-info → darfix-4.3.0.dist-info}/top_level.txt +0 -0
@@ -1,7 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import logging
4
- import os.path
5
4
 
6
5
  from ewokscore import Task
7
6
  from ewokscore.missing_data import MISSING_DATA
@@ -12,6 +11,7 @@ from pydantic import Field
12
11
  from silx.io.url import DataUrl
13
12
 
14
13
  from .. import dtypes
14
+ from ..core.data_selection import get_default_output_directory
15
15
  from ..core.data_selection import load_process_data
16
16
 
17
17
  _logger = logging.getLogger(__file__)
@@ -87,15 +87,11 @@ class HDF5DataSelection(
87
87
  bg_data_url = None
88
88
 
89
89
  treated_data_dir = self.get_input_value("treated_data_dir", None)
90
- # Move output folder to 'PROCESSED_DATA' instead of 'RAW_DATA' when possible
91
- # but ONLY if it was not set by the user
92
- if treated_data_dir is None and "RAW_DATA" in raw_data_url.file_path():
93
- treated_data_dir = os.path.dirname(raw_data_url.file_path()).replace(
94
- "RAW_DATA", "PROCESSED_DATA"
95
- )
96
- _logger.warning(f"Treated data will be saved in {treated_data_dir}")
90
+ if treated_data_dir is None:
91
+ treated_data_dir = get_default_output_directory(raw_data_url.file_path())
92
+ _logger.info(f"Output directory is {treated_data_dir}.")
97
93
 
98
- dataset, indices, bg_indices, bg_dataset = load_process_data(
94
+ dataset, bg_dataset = load_process_data(
99
95
  detector_url=raw_data_url.path(),
100
96
  root_dir=treated_data_dir,
101
97
  dark_detector_url=bg_data_url,
@@ -105,7 +101,5 @@ class HDF5DataSelection(
105
101
 
106
102
  self.outputs.dataset = dtypes.Dataset(
107
103
  dataset=dataset,
108
- indices=indices,
109
- bg_indices=bg_indices,
110
104
  bg_dataset=bg_dataset,
111
105
  )
@@ -16,10 +16,10 @@ from pydantic import ConfigDict
16
16
  from pydantic import Field
17
17
  from silx.io.dictdump import dicttoh5
18
18
 
19
- from darfix.core.datapathfinder import DETECTOR_KEYWORD
20
- from darfix.core.datapathfinder import SCAN_KEYWORD
21
- from darfix.core.datapathfinder import DataPathFinder
22
- from darfix.core.datapathfinder import sort_bliss_scan_entries
19
+ from darfix.core.data_path_finder import DETECTOR_KEYWORD
20
+ from darfix.core.data_path_finder import SCAN_KEYWORD
21
+ from darfix.core.data_path_finder import DataPathFinder
22
+ from darfix.core.data_path_finder import sort_bliss_scan_entries
23
23
  from darfix.core.settings import PROCESSED_DATA
24
24
  from darfix.core.settings import RAW_DATA
25
25
 
@@ -0,0 +1,88 @@
1
+ from __future__ import annotations
2
+
3
+ import copy
4
+ import logging
5
+ import threading
6
+ from typing import Any
7
+
8
+ from ewokscore import TaskWithProgress
9
+ from ewokscore.missing_data import MissingData
10
+ from ewokscore.model import BaseInputModel
11
+ from pydantic import ConfigDict
12
+ from pydantic import Field
13
+
14
+ from darfix.core.noise_removal_type import NoiseRemovalType
15
+ from darfix.dtypes import Dataset
16
+
17
+ from ..core.noise_removal import add_background_data_into_operation
18
+ from ..core.noise_removal import apply_noise_removal_operations
19
+
20
+ _logger = logging.getLogger(__name__)
21
+
22
+
23
+ class Inputs(BaseInputModel):
24
+ model_config = ConfigDict(use_attribute_docstrings=True)
25
+ dataset: Dataset
26
+ """ Input dataset containing a stack of images """
27
+ operations: list[dict[str, Any]] | MissingData = Field(
28
+ default=[],
29
+ examples=[
30
+ [
31
+ {"type": "THRESHOLD", "parameters": {"bottom": 10.0, "top": 1000.0}},
32
+ {"type": "HP", "parameters": {"kernel_size": 3}},
33
+ ]
34
+ ],
35
+ description="""List of noise removal operations to apply to the dataset. Empty list if not provided."
36
+
37
+ Available operations :
38
+
39
+ - 'Operation.THRESHOLD': Threshold operation. Parameters: 'bottom' (float) and 'top' (float). Keep value only if it is between bottom and top.
40
+ - 'Operation.HP': Hot Pixel removal using median filter operation. Parameters: 'kernel_size' (int).
41
+ - 'Operation.BS': Background subtraction operation. Parameters: 'method' ("mean" | "median") and 'background_type' ("Data" | "Unused data (after partition)" | "Dark data").
42
+ - 'Operation.MASK': Mask removal operation. Parameters: 'mask' (numpy.ndarray 2D containing 0 and 1 where 0 indicates the pixels to be removed).
43
+ """,
44
+ )
45
+ copy_dataset: bool = False
46
+ """If `True`, operations are applied on a copy of the input dataset. Else, operations are applied directly on the input dataset"""
47
+
48
+
49
+ class NoiseRemoval(
50
+ TaskWithProgress,
51
+ input_model=Inputs,
52
+ output_names=["dataset"],
53
+ ):
54
+ """Apply a list of noise removal operations on a Darfix dataset."""
55
+
56
+ def run(self):
57
+
58
+ self.cancelEvent = threading.Event()
59
+
60
+ inputs = Inputs(**self.get_input_values())
61
+
62
+ input_dataset: Dataset = inputs.dataset
63
+
64
+ if inputs.copy_dataset:
65
+ input_dataset = copy.deepcopy(input_dataset)
66
+
67
+ for operation in inputs.operations:
68
+ if operation["type"] is NoiseRemovalType.BS:
69
+ _logger.info("Computing background...")
70
+ add_background_data_into_operation(input_dataset, operation)
71
+
72
+ apply_noise_removal_operations(
73
+ input_dataset.dataset.as_array3d(),
74
+ inputs.operations,
75
+ self._is_cancelled,
76
+ self._set_progress,
77
+ )
78
+
79
+ self.outputs.dataset = input_dataset
80
+
81
+ def cancel(self) -> None:
82
+ self.cancelEvent.set()
83
+
84
+ def _is_cancelled(self) -> bool:
85
+ return self.cancelEvent.is_set()
86
+
87
+ def _set_progress(self, progress: int):
88
+ self.progress = progress
@@ -1,88 +1,10 @@
1
- from __future__ import annotations
1
+ import warnings
2
2
 
3
- import copy
4
- import logging
5
- import threading
6
- from typing import Any
3
+ from .noise_removal import NoiseRemoval # noqa: F401
7
4
 
8
- from ewokscore import TaskWithProgress
9
- from ewokscore.missing_data import MissingData
10
- from ewokscore.model import BaseInputModel
11
- from pydantic import ConfigDict
12
- from pydantic import Field
13
-
14
- from darfix.core.state_of_operation import Operation
15
- from darfix.dtypes import Dataset
16
-
17
- from ..core.noiseremoval import add_background_data_into_operation
18
- from ..core.noiseremoval import apply_noise_removal_operations
19
-
20
- _logger = logging.getLogger(__name__)
21
-
22
-
23
- class Inputs(BaseInputModel):
24
- model_config = ConfigDict(use_attribute_docstrings=True)
25
- dataset: Dataset
26
- """ Input dataset containing a stack of images """
27
- operations: list[dict[str, Any]] | MissingData = Field(
28
- default=[],
29
- examples=[
30
- [
31
- {"type": "THRESHOLD", "parameters": {"bottom": 10.0, "top": 1000.0}},
32
- {"type": "HP", "parameters": {"kernel_size": 3}},
33
- ]
34
- ],
35
- description="""List of noise removal operations to apply to the dataset. Empty list if not provided."
36
-
37
- Available operations :
38
-
39
- - 'Operation.THRESHOLD': Threshold operation. Parameters: 'bottom' (float) and 'top' (float). Keep value only if it is between bottom and top.
40
- - 'Operation.HP': Hot Pixel removal using median filter operation. Parameters: 'kernel_size' (int).
41
- - 'Operation.BS': Background subtraction operation. Parameters: 'method' ("mean" | "median") and 'background_type' ("Data" | "Unused data (after partition)" | "Dark data").
42
- - 'Operation.MASK': Mask removal operation. Parameters: 'mask' (numpy.ndarray 2D containing 0 and 1 where 0 indicates the pixels to be removed).
43
- """,
44
- )
45
- copy_dataset: bool = False
46
- """If `True`, operations are applied on a copy of the input dataset. Else, operations are applied directly on the input dataset"""
47
-
48
-
49
- class NoiseRemoval(
50
- TaskWithProgress,
51
- input_model=Inputs,
52
- output_names=["dataset"],
53
- ):
54
- """Apply a list of noise removal operations on a Darfix dataset."""
55
-
56
- def run(self):
57
-
58
- self.cancelEvent = threading.Event()
59
-
60
- inputs = Inputs(**self.get_input_values())
61
-
62
- input_dataset: Dataset = inputs.dataset
63
-
64
- if inputs.copy_dataset:
65
- input_dataset = copy.deepcopy(input_dataset)
66
-
67
- for operation in inputs.operations:
68
- if operation["type"] is Operation.BS:
69
- _logger.info("Computing background...")
70
- add_background_data_into_operation(input_dataset, operation)
71
-
72
- apply_noise_removal_operations(
73
- input_dataset.dataset.as_array3d(input_dataset.indices),
74
- inputs.operations,
75
- self._is_cancelled,
76
- self._set_progress,
77
- )
78
-
79
- self.outputs.dataset = input_dataset
80
-
81
- def cancel(self) -> None:
82
- self.cancelEvent.set()
83
-
84
- def _is_cancelled(self) -> bool:
85
- return self.cancelEvent.is_set()
86
-
87
- def _set_progress(self, progress: int):
88
- self.progress = progress
5
+ warnings.warn(
6
+ f"The '{__name__}' module is deprecated and will be removed in a future release. "
7
+ "Please replace module name `noiseremoval` by `noise_removal`",
8
+ DeprecationWarning,
9
+ stacklevel=2,
10
+ )
darfix/tasks/pca.py CHANGED
@@ -35,7 +35,7 @@ class PCA(
35
35
  )
36
36
  num_components = self.get_input_value("num_components")
37
37
 
38
- pca_kwargs = {"return_vals": True, "indices": dataset.indices}
38
+ pca_kwargs = {"return_vals": True}
39
39
  if not is_missing_data(num_components):
40
40
  pca_kwargs["num_components"] = num_components
41
41
 
@@ -44,7 +44,5 @@ class PCA(
44
44
  self.outputs.vals = vals
45
45
  self.outputs.dataset = Dataset(
46
46
  dataset=dataset.dataset,
47
- indices=dataset.indices,
48
47
  bg_dataset=dataset.bg_dataset,
49
- bg_indices=dataset.bg_indices,
50
48
  )
@@ -32,16 +32,11 @@ class Projection(Task, input_model=Inputs, output_names=["dataset"]):
32
32
  raise DatasetTypeError(dataset)
33
33
 
34
34
  darfix_dataset = dataset.dataset
35
- indices = dataset.indices
36
35
  dimension: Sequence[int] = self.inputs.dimension
37
36
 
38
- darfix_dataset = darfix_dataset.project_data(
39
- dimension=dimension, indices=indices
40
- )
37
+ darfix_dataset = darfix_dataset.project_data(dimension=dimension)
41
38
 
42
39
  self.outputs.dataset = Dataset(
43
40
  dataset=darfix_dataset,
44
- indices=indices,
45
- bg_indices=dataset.bg_indices,
46
41
  bg_dataset=dataset.bg_dataset,
47
42
  )
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import os.path
4
+ import threading
4
5
  from pathlib import Path
5
6
  from typing import Literal
6
7
 
@@ -33,6 +34,8 @@ class RockingCurves(Task, input_model=Inputs, output_names=["dataset", "maps"]):
33
34
  """
34
35
 
35
36
  def run(self):
37
+ self.cancelEvent = threading.Event()
38
+
36
39
  inputs = Inputs(**self.get_input_values())
37
40
 
38
41
  output_filename = inputs.output_filename
@@ -43,23 +46,25 @@ class RockingCurves(Task, input_model=Inputs, output_names=["dataset", "maps"]):
43
46
  )
44
47
 
45
48
  dataset = inputs.dataset.dataset
46
- indices = inputs.dataset.indices
47
49
  new_image_dataset, maps = dataset.apply_fit(
48
- indices=indices, int_thresh=inputs.int_thresh, method=inputs.method
50
+ int_thresh=inputs.int_thresh,
51
+ method=inputs.method,
52
+ abort_event=self.cancelEvent,
49
53
  )
50
54
 
51
55
  if output_filename is not None:
52
56
  nxdict = generate_rocking_curves_nxdict(
53
57
  new_image_dataset,
54
58
  maps,
55
- residuals=compute_residuals(new_image_dataset, dataset, indices),
59
+ residuals=compute_residuals(new_image_dataset, dataset),
56
60
  )
57
61
  dicttonx(nxdict, output_filename)
58
62
 
59
63
  self.outputs.dataset = Dataset(
60
64
  dataset=new_image_dataset,
61
- indices=indices,
62
- bg_indices=inputs.dataset.bg_indices,
63
65
  bg_dataset=inputs.dataset.bg_dataset,
64
66
  )
65
67
  self.outputs.maps = maps
68
+
69
+ def cancel(self):
70
+ self.cancelEvent.set()
darfix/tasks/roi.py CHANGED
@@ -58,7 +58,5 @@ class RoiSelection(
58
58
 
59
59
  self.outputs.dataset = Dataset(
60
60
  dataset=dataset,
61
- indices=input_dataset.indices,
62
- bg_indices=input_dataset.bg_indices,
63
61
  bg_dataset=bg_dataset,
64
62
  )
@@ -0,0 +1,45 @@
1
+ from __future__ import annotations
2
+
3
+ import copy
4
+ from typing import Sequence
5
+
6
+ from ewokscore import Task
7
+ from ewokscore.model import BaseInputModel
8
+ from pydantic import ConfigDict
9
+
10
+ from darfix.core.shift_correction import apply_shift
11
+ from darfix.dtypes import Dataset
12
+
13
+
14
+ class Inputs(BaseInputModel):
15
+ model_config = ConfigDict(use_attribute_docstrings=True)
16
+ dataset: Dataset
17
+ """ Input dataset containing a stack of images """
18
+ shift: Sequence[float] | Sequence[Sequence[float]] | None = None
19
+ """Shift to apply to the images. If not provided, dataset will be unchanged."""
20
+ selected_axis: int | None = None
21
+ """Selected dimension axis. If not None. We considere a linear shift along this dimension. Darfix convention is : dimension with axis 0 is the fast motor."""
22
+ copy_dataset: bool = False
23
+ """If `True`, operations are applied on a copy of the input dataset. Else, operations are applied directly on the input dataset"""
24
+
25
+
26
+ class ShiftCorrection(
27
+ Task,
28
+ input_model=Inputs,
29
+ output_names=["dataset"],
30
+ ):
31
+ def run(self):
32
+ inputs = Inputs(**self.get_input_values())
33
+
34
+ if inputs.shift is None:
35
+ self.outputs.dataset = inputs.dataset
36
+ return
37
+
38
+ input_dataset: Dataset = inputs.dataset
39
+
40
+ if inputs.copy_dataset:
41
+ input_dataset = copy.deepcopy(input_dataset)
42
+
43
+ apply_shift(input_dataset, inputs.shift, inputs.selected_axis)
44
+
45
+ self.outputs.dataset = input_dataset
@@ -1,45 +1,10 @@
1
- from __future__ import annotations
1
+ import warnings
2
2
 
3
- import copy
4
- from typing import Sequence
3
+ from .shift_correction import ShiftCorrection # noqa: F401
5
4
 
6
- from ewokscore import Task
7
- from ewokscore.model import BaseInputModel
8
- from pydantic import ConfigDict
9
-
10
- from darfix.core.shiftcorrection import apply_shift
11
- from darfix.dtypes import Dataset
12
-
13
-
14
- class Inputs(BaseInputModel):
15
- model_config = ConfigDict(use_attribute_docstrings=True)
16
- dataset: Dataset
17
- """ Input dataset containing a stack of images """
18
- shift: Sequence[float] | Sequence[Sequence[float]] | None = None
19
- """Shift to apply to the images. If not provided, dataset will be unchanged."""
20
- selected_axis: int | None = None
21
- """Selected dimension axis. If not None. We considere a linear shift along this dimension. Darfix convention is : dimension with axis 0 is the fast motor."""
22
- copy_dataset: bool = False
23
- """If `True`, operations are applied on a copy of the input dataset. Else, operations are applied directly on the input dataset"""
24
-
25
-
26
- class ShiftCorrection(
27
- Task,
28
- input_model=Inputs,
29
- output_names=["dataset"],
30
- ):
31
- def run(self):
32
- inputs = Inputs(**self.get_input_values())
33
-
34
- if inputs.shift is None:
35
- self.outputs.dataset = inputs.dataset
36
- return
37
-
38
- input_dataset: Dataset = inputs.dataset
39
-
40
- if inputs.copy_dataset:
41
- input_dataset = copy.deepcopy(input_dataset)
42
-
43
- apply_shift(input_dataset, inputs.shift, inputs.selected_axis)
44
-
45
- self.outputs.dataset = input_dataset
5
+ warnings.warn(
6
+ f"The '{__name__}' module is deprecated and will be removed in a future release. "
7
+ "Please replace module name `shiftcorrection` by `shift_correction`",
8
+ DeprecationWarning,
9
+ stacklevel=2,
10
+ )
@@ -76,7 +76,5 @@ class TransformationMatrixComputation(
76
76
 
77
77
  self.outputs.dataset = Dataset(
78
78
  dataset=dataset,
79
- indices=input_dataset.indices,
80
- bg_indices=input_dataset.bg_indices,
81
79
  bg_dataset=input_dataset.bg_dataset,
82
80
  )
@@ -0,0 +1,71 @@
1
+ from __future__ import annotations
2
+
3
+ import copy
4
+ import os
5
+ import string
6
+
7
+ import h5py
8
+ import numpy
9
+ from ewokscore import Task
10
+ from ewokscore.missing_data import MISSING_DATA
11
+ from ewokscore.missing_data import MissingData
12
+ from ewokscore.model import BaseInputModel
13
+ from pydantic import ConfigDict
14
+
15
+ from darfix import dtypes
16
+ from darfix.core.moment_types import MomentType
17
+
18
+
19
+ class Inputs(BaseInputModel):
20
+ model_config = ConfigDict(use_attribute_docstrings=True)
21
+ dataset: dtypes.Dataset
22
+ """Input dataset containing a stack of images."""
23
+ nvalue: float | MissingData = MISSING_DATA
24
+ """Increase or decrease the top threshold (threshold = `nvalue` * std)"""
25
+ title: str | MissingData = MISSING_DATA
26
+ """Title for the output file. If not provided, title is empty."""
27
+ copy_dataset: bool = False
28
+ """If `True`, operations are applied on a copy of the input dataset. Else, operations are applied directly on the input dataset"""
29
+
30
+
31
+ class WeakBeam(
32
+ Task,
33
+ input_model=Inputs,
34
+ output_names=["dataset"],
35
+ ):
36
+ """
37
+ Obtain dataset with filtered weak beam and recover its Center of Mass.
38
+ Save file with this COM for further processing.
39
+ """
40
+
41
+ def run(self):
42
+ inputs = Inputs(**self.get_input_values())
43
+
44
+ dataset = inputs.dataset
45
+
46
+ if inputs.copy_dataset:
47
+ dataset = copy.deepcopy(dataset)
48
+
49
+ nvalue = inputs.nvalue
50
+
51
+ img_dataset = dataset.dataset
52
+
53
+ img_dataset.recover_weak_beam(nvalue)
54
+ com = img_dataset.apply_moments()[0][MomentType.COM]
55
+ os.makedirs(img_dataset.dir, exist_ok=True)
56
+ filename = os.path.join(img_dataset.dir, "weakbeam_{}.hdf5".format(nvalue))
57
+
58
+ title = self.get_input_value("title", "")
59
+ # title can be set to None, MISSING_DATA or an empty string. So safer to use the following line
60
+ title = title or self.get_random_title()
61
+ with h5py.File(filename, "a") as _file:
62
+ _file[title] = com
63
+
64
+ self.outputs.dataset = dtypes.Dataset(
65
+ dataset=img_dataset,
66
+ )
67
+
68
+ @staticmethod
69
+ def get_random_title() -> str:
70
+ letters = string.ascii_lowercase
71
+ return "".join(numpy.random.choice(list(letters)) for i in range(6))
darfix/tasks/weakbeam.py CHANGED
@@ -1,69 +1,10 @@
1
- from __future__ import annotations
1
+ import warnings
2
2
 
3
- import os
4
- import string
3
+ from .weak_beam import WeakBeam # noqa: F401
5
4
 
6
- import h5py
7
- import numpy
8
- from ewokscore import Task
9
- from ewokscore.missing_data import MISSING_DATA
10
- from ewokscore.missing_data import MissingData
11
- from ewokscore.model import BaseInputModel
12
- from pydantic import ConfigDict
13
-
14
- from darfix import dtypes
15
-
16
-
17
- class Inputs(BaseInputModel):
18
- model_config = ConfigDict(use_attribute_docstrings=True)
19
- dataset: dtypes.Dataset
20
- """Input dataset containing a stack of images."""
21
- nvalue: float | MissingData = MISSING_DATA
22
- """Increase or decrease the top threshold by this fixed value."""
23
- indices: list[int] | MissingData = MISSING_DATA
24
- """Indices of the images to process. If not provided, all images will be processed."""
25
- title: str | MissingData = MISSING_DATA
26
- """Title for the output file. If not provided, title is empty."""
27
-
28
-
29
- class WeakBeam(
30
- Task,
31
- input_model=Inputs,
32
- output_names=["dataset"],
33
- ):
34
- """
35
- Obtain dataset with filtered weak beam and recover its Center of Mass.
36
- Save file with this COM for further processing.
37
- """
38
-
39
- def run(self):
40
- dataset = self.inputs.dataset
41
- indices = self.get_input_value("indices", None)
42
- if isinstance(dataset, dtypes.Dataset):
43
- dataset = dataset.dataset
44
- if not isinstance(dataset, dtypes.ImageDataset):
45
- raise TypeError("dataset is expected to be an instance")
46
-
47
- nvalue = self.inputs.nvalue
48
- wb_dataset = dataset.recover_weak_beam(nvalue, indices=indices)
49
- com = wb_dataset.apply_moments(indices=indices)[0][0]
50
- os.makedirs(dataset.dir, exist_ok=True)
51
- filename = os.path.join(dataset.dir, "weakbeam_{}.hdf5".format(nvalue))
52
-
53
- title = self.get_input_value("title", "")
54
- # title can be set to None, MISSING_DATA or an empty string. So safer to use the following line
55
- title = title or self.get_random_title()
56
- with h5py.File(filename, "a") as _file:
57
- _file[title] = com
58
-
59
- self.outputs.dataset = dtypes.Dataset(
60
- dataset=dataset,
61
- indices=indices,
62
- bg_indices=self.inputs.dataset.bg_indices,
63
- bg_dataset=self.inputs.dataset.bg_dataset,
64
- )
65
-
66
- @staticmethod
67
- def get_random_title() -> str:
68
- letters = string.ascii_lowercase
69
- return "".join(numpy.random.choice(list(letters)) for i in range(6))
5
+ warnings.warn(
6
+ f"The '{__name__}' module is deprecated and will be removed in a future release. "
7
+ "Please replace module name `weakbeam` by `weak_beam`",
8
+ DeprecationWarning,
9
+ stacklevel=2,
10
+ )
darfix/tasks/zsum.py CHANGED
@@ -21,7 +21,7 @@ class ZSum(
21
21
  input_model=Inputs,
22
22
  output_names=["zsum"],
23
23
  ):
24
- """Sum all images of the dataset or images at specified indices along a given dimension."""
24
+ """Sum all images of the dataset or images along a given dimension."""
25
25
 
26
26
  def run(self):
27
27
  inputs = Inputs(**self.get_input_values())
darfix/tests/conftest.py CHANGED
@@ -33,7 +33,7 @@ def input_dataset(tmp_path, silx_resources):
33
33
  file_path=input_filename, data_path="/2.1/instrument/positioners"
34
34
  )
35
35
 
36
- dataset, _, _, _ = load_process_data(
36
+ dataset, _ = load_process_data(
37
37
  detector_url=detector_url,
38
38
  root_dir=tmp_path,
39
39
  title="input",
@@ -3,10 +3,10 @@ import os
3
3
  import pytest
4
4
  from ewoksorange.tests.conftest import qtapp # noqa F401
5
5
 
6
- from darfix.core.datapathfinder import DETECTOR_KEYWORD
7
- from darfix.core.datapathfinder import FIRST_SCAN_KEYWORD
8
- from darfix.core.datapathfinder import LAST_SCAN_KEYWORD
9
- from darfix.core.datapathfinder import SCAN_KEYWORD
6
+ from darfix.core.data_path_finder import DETECTOR_KEYWORD
7
+ from darfix.core.data_path_finder import FIRST_SCAN_KEYWORD
8
+ from darfix.core.data_path_finder import LAST_SCAN_KEYWORD
9
+ from darfix.core.data_path_finder import SCAN_KEYWORD
10
10
  from darfix.gui.utils.data_path_completer import DataPathLineEditWithCompleter
11
11
  from darfix.gui.utils.data_path_completer import DataPathModel
12
12
  from darfix.tests.utils import create_scans
@@ -7,8 +7,8 @@ from silx.gui.data.test.test_dataviewer import SignalListener
7
7
 
8
8
  from darfix.core.dimension import AcquisitionDims
9
9
  from darfix.core.dimension import Dimension
10
- from darfix.gui.grainplot.dimensionRangeSlider2D import DimensionRangeSlider2D
11
- from darfix.gui.grainplot.dimensionRangeSlider2D import _DimensionRangeSlider
10
+ from darfix.gui.grain_plot.dimension_range_slider_2d import DimensionRangeSlider2D
11
+ from darfix.gui.grain_plot.dimension_range_slider_2d import _DimensionRangeSlider
12
12
 
13
13
 
14
14
  @pytest.fixture
@@ -7,7 +7,7 @@ from silx.gui import qt
7
7
  from silx.gui.data.test.test_dataviewer import SignalListener
8
8
  from silx.gui.widgets.RangeSlider import RangeSlider
9
9
 
10
- from darfix.gui.utils.rangeSlider import RangeSliderWithSpinBox
10
+ from darfix.gui.utils.range_slider import RangeSliderWithSpinBox
11
11
 
12
12
 
13
13
  @pytest.fixture