Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e20b6f0
Added file with unit tests for slicer averagers based on constructed …
ehewins Aug 23, 2023
2743ffb
Initial version of averagers with cartesian ROI, and made correspondi…
ehewins Aug 31, 2023
aacf1d7
Changed the binning/weighting process for _Slab to make the fractiona…
ehewins Sep 1, 2023
62e85b4
Refactoring to test SlabX, SlabY, SectorQ and SectorPhi rather than t…
ehewins Sep 4, 2023
a0f365c
Restructured ROI classes and added DirectionalAverage class, which of…
ehewins Sep 7, 2023
7b6188a
Updated the unit tests to suit the new_manipulations.py implementation.
ehewins Sep 7, 2023
acc2bc7
Added dedicated WedgeQ and WedgePhi classes, plus corresponding unit …
ehewins Sep 8, 2023
204bc63
Added documentation to new manipulations module
ehewins Sep 17, 2023
6dccdeb
Replaced python logical_and with numpy logical_and for speed
ehewins Sep 17, 2023
adff0d2
Removed some superfluous logical_and checks. Both arrays should have …
ehewins Sep 17, 2023
078b2dd
Forgot to remove 'angles + np.pi' from SectorQ call, no longer needed…
ehewins Sep 18, 2023
85cd0ef
Added unit tests for DirectionalAverage class
ehewins Sep 22, 2023
31eae90
Move averaging tests from data loader to manipulations folder
krzywon Oct 16, 2023
3469460
Move files used in averaging tests
krzywon Oct 16, 2023
dbacebd
Create and apply interval type enum to remove hard-coded strings
krzywon Oct 16, 2023
9941521
Allow for non-linear bin spacings in the directional averaging
krzywon Oct 16, 2023
8eba5a9
Update unit tests to account for new bin widths
krzywon Oct 16, 2023
53965a4
Rename manipulations_new to averaging and update internal references …
krzywon Oct 16, 2023
bb66e0a
Add deprecation warning that is triggered on import of manipulations.py
krzywon Oct 16, 2023
82af368
Use Enum instead of StrEnum to ensure backwards compatibility with py…
krzywon Oct 16, 2023
953a89b
Move 2D data restructure function to data_info where it is more seman…
krzywon Oct 24, 2023
053c3af
Grammar
lucas-wilkins Oct 24, 2023
5ea8793
Revert removal of reader2d_converter from manipulations
krzywon Oct 25, 2023
0296c49
Update deprecation messages
krzywon Oct 25, 2023
db3147b
Port RingCut from manipulations to averaging
krzywon Oct 25, 2023
044b1e6
Port Boxcut from manipulations to averaging
krzywon Oct 25, 2023
4900864
Update documentation in manipulations to point to new test location
krzywon Oct 25, 2023
7aa9bf3
Move Sectorcut to averaging from manipulations
krzywon Oct 25, 2023
2d2874b
Use unmasked data for masking purposes
krzywon Oct 25, 2023
14a8f12
Fix issue where sector cut only masked one half of region
krzywon Oct 26, 2023
07f4bed
Type hinting
lucas-wilkins Dec 6, 2023
cc05ea7
Fix for first bug
lucas-wilkins Dec 7, 2023
91da04a
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] Oct 27, 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
1,037 changes: 1,037 additions & 0 deletions sasdata/data_util/averaging.py

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions sasdata/data_util/manipulations.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""
Data manipulations for 2D data sets.
Using the meta data information, various types of averaging
are performed in Q-space
Using the meta data information, various types of averaging are performed in Q-space

To test this module use:
```
cd test
PYTHONPATH=../src/ python2 -m sasdataloader.test.utest_averaging DataInfoTests.test_sectorphi_quarter
PYTHONPATH=../src/ python2 -m sasmanipulations.test.utest_averaging DataInfoTests.test_sectorphi_quarter
```
"""
#####################################################################
Expand All @@ -20,11 +19,15 @@

# TODO: copy the meta data from the 2D object to the resulting 1D object
import math
from warnings import warn

import numpy as np

from sasdata.dataloader.data_info import Data1D, Data2D

warn("sasdata.data_util.manipulations is deprecated. Unless otherwise noted, update your import to "
"sasdata.data_util.averaging.", DeprecationWarning, stacklevel=2)


def position_and_wavelength_to_q(dx: float, dy: float, detector_distance: float, wavelength: float) -> float:
"""
Expand Down Expand Up @@ -196,7 +199,7 @@ def get_dq_data(data2d: Data2D) -> np.array:
Get the dq for resolution averaging
The pinholes and det. pix contribution present
in both direction of the 2D which must be subtracted when
converting to 1D: dq_overlap should calculated ideally at
converting to 1D: dq_overlap should be calculated ideally at
q = 0. Note This method works on only pinhole geometry.
Extrapolate dqx(r) and dqy(phi) at q = 0, and take an average.
'''
Expand Down Expand Up @@ -245,6 +248,8 @@ def reader2D_converter(data2d: Data2D | None = None) -> Data2D:
:return: 1d arrays of Data2D object

"""
warn("reader2D_converter should be imported in the future sasdata.dataloader.data_info.",
DeprecationWarning, stacklevel=2)
if data2d.data is None or data2d.x_bins is None or data2d.y_bins is None:
raise ValueError("Can't convert this data: data=None...")
new_x = np.tile(data2d.x_bins, (len(data2d.y_bins), 1))
Expand Down
37 changes: 37 additions & 0 deletions sasdata/dataloader/data_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,43 @@ def _perform_union(self, other):
return result


def reader2D_converter(data2d: Data2D | None = None) -> Data2D:
"""
convert old 2d format opened by IhorReader or danse_reader
to new Data2D format
This is mainly used by the Readers

:param data2d: 2d array of Data2D object
:return: 1d arrays of Data2D object

"""
if data2d.data is None or data2d.x_bins is None or data2d.y_bins is None:
raise ValueError("Can't convert this data: data=None...")
new_x = np.tile(data2d.x_bins, (len(data2d.y_bins), 1))
new_y = np.tile(data2d.y_bins, (len(data2d.x_bins), 1))
new_y = new_y.swapaxes(0, 1)

new_data = data2d.data.flatten()
qx_data = new_x.flatten()
qy_data = new_y.flatten()
q_data = np.sqrt(qx_data * qx_data + qy_data * qy_data)
if data2d.err_data is None or np.any(data2d.err_data <= 0):
new_err_data = np.sqrt(np.abs(new_data))
else:
new_err_data = data2d.err_data.flatten()
mask = np.ones(len(new_data), dtype=bool)

output = data2d
output.data = new_data
output.err_data = new_err_data
output.qx_data = qx_data
output.qy_data = qy_data
output.q_data = q_data
output.mask = mask

return output


def combine_data_info_with_plottable(data, datainfo):
"""
A function that combines the DataInfo data in self.current_datainto with a
Expand Down
Binary file added test/sasmanipulations/data/MAR07232_rest.h5
Binary file not shown.
21 changes: 21 additions & 0 deletions test/sasmanipulations/data/avg_testdata.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
0.00019987186878 -0.01196215 0.148605728355
0.000453772721237 0.02091606 0.23372601
0.000750492390439 -0.01337855 0.17169562
0.00103996394336 0.03062 0.13136407
0.0013420198959 0.0811008333333 0.10681163
0.001652061869 0.167022288372 0.10098903
0.00196086470492 27.5554711176 0.7350533
0.00226262401224 105.031578947 1.35744586624
0.00256734439716 82.1791776119 1.10749938588
0.0028637128388 54.714657971 0.890486416264
0.00315257408712 36.8455584416 0.691746880003
0.00344644126616 24.8938701149 0.534917225468
0.00374248202229 16.5905619565 0.424655384023
0.00404393067437 11.4714217925 0.328969543128
0.004346317814 8.05405805556 0.273083524998
0.00465162170627 5.5823291129 0.21217630209
0.00495449803049 4.2574845082 0.186808495528
0.00525641407066 3.30448963768 0.154743584955
0.00555735057365 2.6995389781 0.140373302568
0.00585577429002 2.03298512 0.116418358232

Loading
Loading