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

Finishing the manipulatons.py Rewrite #47

Open
wants to merge 37 commits into
base: release_0.9.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9573f92
Added file with unit tests for slicer averagers based on constructed …
ehewins Aug 23, 2023
a5cb0a4
Initial version of averagers with cartesian ROI, and made correspondi…
ehewins Aug 31, 2023
b8423ba
Changed the binning/weighting process for _Slab to make the fractiona…
ehewins Sep 1, 2023
b10edd3
Refactoring to test SlabX, SlabY, SectorQ and SectorPhi rather than t…
ehewins Sep 4, 2023
7670d2b
Restructured ROI classes and added DirectionalAverage class, which of…
ehewins Sep 7, 2023
b3829a4
Updated the unit tests to suit the new_manipulations.py implementation.
ehewins Sep 7, 2023
2503d81
Added dedicated WedgeQ and WedgePhi classes, plus corresponding unit …
ehewins Sep 8, 2023
c2ee6bd
Added documentation to new manipulations module
ehewins Sep 17, 2023
fb0da1a
Replaced python logical_and with numpy logical_and for speed
ehewins Sep 17, 2023
1bcd84f
Removed some superfluous logical_and checks. Both arrays should have …
ehewins Sep 17, 2023
78df64b
Added scipy to dependencies
lucas-wilkins Sep 18, 2023
66a29a0
Merge branch 'master' into 46-manipulations-dot-py-rewrite
lucas-wilkins Sep 22, 2023
980fafe
Forgot to remove 'angles + np.pi' from SectorQ call, no longer needed…
ehewins Sep 18, 2023
cb27521
Added unit tests for DirectionalAverage class
ehewins Sep 22, 2023
f13fad4
Move averaging tests from data loader to manipulations folder
krzywon Oct 16, 2023
7b46314
Move files used in averaging tests
krzywon Oct 16, 2023
f7950c4
Create and apply interval type enum to remove hard-coded strings
krzywon Oct 16, 2023
17bb08c
Allow for non-linear bin spacings in the directional averaging
krzywon Oct 16, 2023
a95eee0
Update unit tests to account for new bin widths
krzywon Oct 16, 2023
b41b7f6
Rename manipulations_new to averaging and update internal references …
krzywon Oct 16, 2023
d7996ef
Add deprecation warning that is triggered on import of manipulations.py
krzywon Oct 16, 2023
06da060
Use Enum instead of StrEnum to ensure backwards compatibility with py…
krzywon Oct 16, 2023
bda0ec8
Merge branch 'master' into 46-manipulations-dot-py-rewrite
krzywon Oct 16, 2023
715a8d6
Grammar
lucas-wilkins Oct 24, 2023
71560b9
Move 2D data restructure function to data_info where it is more seman…
krzywon Oct 24, 2023
fc5a712
Merge remote-tracking branch 'origin/46-manipulations-dot-py-rewrite'…
krzywon Oct 24, 2023
4020cef
Revert removal of reader2d_converter from manipulations
krzywon Oct 25, 2023
31ed62a
Update deprecation messages
krzywon Oct 25, 2023
85842d7
Port RingCut from manipulations to averaging
krzywon Oct 25, 2023
b92576c
Port Boxcut from manipulations to averaging
krzywon Oct 25, 2023
3e81f2d
Update documentation in manipulations to point to new test location
krzywon Oct 25, 2023
01f4daa
Move Sectorcut to averaging from manipulations
krzywon Oct 25, 2023
f8d7cbf
Use unmasked data for masking purposes
krzywon Oct 25, 2023
f657a53
Fix issue where sector cut only masked one half of region
krzywon Oct 26, 2023
8edf310
Type hinting
lucas-wilkins Dec 6, 2023
30f8bf0
Fix for first bug
lucas-wilkins Dec 7, 2023
03c45b5
Merge branch 'release_0.9.0' into 46-manipulations-dot-py-rewrite
wpotrzebowski Oct 27, 2024
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,038 changes: 1,038 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 @@ -22,9 +21,13 @@
import math
import numpy as np
from typing import Optional, Union
from warnings import warn

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: Optional[Data2D] = 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
38 changes: 38 additions & 0 deletions sasdata/dataloader/data_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import math
from math import fabs
import copy
from typing import Optional

import numpy as np

Expand Down Expand Up @@ -1235,6 +1236,43 @@ def _perform_union(self, other):
return result


def reader2D_converter(data2d: Optional[Data2D] = 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