Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
968 commits
Select commit Hold shift + click to select a range
b4d2c73
Start parsing SESANS sample metadata
rprospero May 6, 2025
f46d235
Include SESANS angle metadata
rprospero May 6, 2025
a5661ac
Multiple SESANS files in reader test
rprospero May 6, 2025
3cd6dac
Parse actual data from SES files
rprospero May 6, 2025
8d4555c
Add Raw SESANS Node Data
rprospero May 7, 2025
e75cdeb
Update XML test references to include apertures
rprospero May 7, 2025
fa2e3ae
SESANS metadata as a process, not an aperture
rprospero May 7, 2025
91d111c
Fixup lint
rprospero May 7, 2025
67e0ccd
Make changes suggested in PR review
rprospero May 19, 2025
dfc37d7
Fix simple typos from rebase
rprospero Jun 3, 2025
bd055b6
Add equality testing for quantities
rprospero Jun 10, 2025
3143ec0
More tests for quantities
rprospero Jun 10, 2025
a1ced95
Fix meshmerge calculation
rprospero Jun 17, 2025
391d583
Ruff format.
jamescrake-merani Jun 23, 2025
c6c14f9
This comment was repetitive.
jamescrake-merani Jun 23, 2025
44c8738
Ruff format.
jamescrake-merani Jun 24, 2025
2099b76
Function to guess the dataset type.
jamescrake-merani Jun 24, 2025
ae8bb53
Function for loading a file with default params.
jamescrake-merani Jun 24, 2025
ee9a634
Ruff format.
jamescrake-merani Jun 24, 2025
7a9d77d
Remove imports ruff is complaining aren't used.
jamescrake-merani Jun 24, 2025
51b1c61
Added a test to make sure 2d data gets read right.
jamescrake-merani Jun 24, 2025
a60f0d3
Makes sure the dataset type gets guessed.
jamescrake-merani Jun 24, 2025
e88c44b
Use basename for sasdata ascii name.
jamescrake-merani Jun 25, 2025
e6114b8
Be consistent with how basename is called.
jamescrake-merani Jul 4, 2025
bbed817
Move comment to avoid odd Ruff format.
jamescrake-merani Jul 4, 2025
4503c6d
Move comment again.
jamescrake-merani Jul 4, 2025
1d2d748
Fixed test.
jamescrake-merani Jul 4, 2025
0677885
Created an import metadata function.
jamescrake-merani Jul 7, 2025
ff5657e
Remove the old function.
jamescrake-merani Jul 7, 2025
cd63965
Use the new import function.
jamescrake-merani Jul 7, 2025
7197027
Remove these imports.
jamescrake-merani Jul 7, 2025
a74f9e0
Need to use keywords for this dataclass.
jamescrake-merani Jul 7, 2025
840c790
Added a case for mumag data.
jamescrake-merani Jul 7, 2025
418d374
Added test for loading ascii data with metadata.
jamescrake-merani Jul 7, 2025
b5a5610
Use params filenames not just filenames.
jamescrake-merani Jul 7, 2025
83bf8ae
Fixed column parameters.
jamescrake-merani Jul 7, 2025
333ba2e
Doh. Missing commas on filename list.
jamescrake-merani Jul 7, 2025
52720b3
Roll the raw metadata into the metadata object.
jamescrake-merani Jul 7, 2025
5e0eaba
Need to fill in all the parameters.
jamescrake-merani Jul 7, 2025
df88cca
Forgot process :P
jamescrake-merani Jul 7, 2025
09c284c
Consider both of these.
jamescrake-merani Jul 7, 2025
a72ba6e
Combine both metadata so we go through all of them
jamescrake-merani Jul 7, 2025
3be78d4
Raw metadata is in lists.
jamescrake-merani Jul 7, 2025
76f3857
I don't know what these decimals were.
jamescrake-merani Jul 7, 2025
7d85443
Start implementing ModellingRequirements
rprospero Jun 18, 2025
313ad0e
Start testing modelling requirements
rprospero Jun 18, 2025
ed4daad
Start adding better tests for ModellingRequirements
rprospero Jun 18, 2025
9188c5a
Flip order of parameters on compose
rprospero Jun 18, 2025
0d6aab3
Don't assume that Sesans includes smear
rprospero Jun 18, 2025
8d4ea66
Enable left composition by null model
rprospero Jun 18, 2025
5267142
support right addition of NullModel
rprospero Jun 18, 2025
61039b3
Allow preprocess and postprocess steps
rprospero Jun 18, 2025
893feb7
Start performing Hankel transform for SESANS
rprospero Jun 18, 2025
ecf3ea1
Ignore slit smearing before SESANS
rprospero Jun 20, 2025
346d638
Pull sesans metadata from file
rprospero Jun 20, 2025
33b2c1a
Add unit test for Hankel transform
rprospero Jun 20, 2025
3e15fea
Fix units with error calculation
rprospero Jun 20, 2025
12717cc
χ² squared based test
rprospero Jun 20, 2025
9b63768
Code Review Suggestions
rprospero Jun 20, 2025
cf7ba78
Fix up rename in compose
rprospero Jun 20, 2025
f651a62
Fix uncertainty in SESANS parser
rprospero Jul 1, 2025
313f30e
Update SESANS units in unit_kinds
rprospero Jul 14, 2025
4618e37
Applies auto fixes for ruff rule F401
DrPaulSharp Jul 17, 2025
8ff17a6
Applies auto fixes for ruff rule E714
DrPaulSharp Jul 17, 2025
8d7211e
Applies auto fixes for ruff rule F541
DrPaulSharp Jul 17, 2025
dd7b408
Test should fail when there's no data.
Jul 18, 2025
f2e7af3
Added a get default unit function.
Jul 18, 2025
2475986
Use the new get default unit function.
Jul 18, 2025
03e4902
Pass in the unit group as well.
Jul 18, 2025
8be653d
Return value if it isn't None.
Jul 18, 2025
ed94d80
Set the dataset type properly.
Jul 18, 2025
2bfd363
Expect 2D test to fail.
Jul 18, 2025
807bd95
Use Quantity in models
rprospero Jul 14, 2025
31cca50
Don't use a quantity for model post processing
rprospero Jul 14, 2025
55d4393
Basic Pinhole model
rprospero Jul 14, 2025
3d2faf0
Refactor pinhole tests
rprospero Jul 15, 2025
6d1999b
Fix radius bug in smearing
rprospero Jul 17, 2025
93a496d
More realisting δq
rprospero Jul 18, 2025
a653077
Combine Smearing and Sesans tests
rprospero Jul 17, 2025
f8c7926
Define model metadata in constructor
rprospero Jul 18, 2025
b0aa9a9
Better testing range for pinhole
rprospero Jul 18, 2025
f945e2f
Add slit smearing
rprospero Jul 18, 2025
3d960b6
Remove old commented code
rprospero Jul 18, 2025
1b13e34
Vectorise slit calculation
rprospero Jul 21, 2025
e97c47c
Check combination of slit models
rprospero Jul 21, 2025
92a67fa
Decrease logical depth of linear_extrapolation
rprospero Jul 31, 2025
00014f7
Decrease logical depth of slit_resolution
rprospero Jul 31, 2025
80d35a7
Decrease logical depth of geometric_extrapolation
rprospero Jul 31, 2025
b1316dc
Apply PR changes
rprospero Jul 31, 2025
11d3429
Fixes ruff linting errors (#140)
DrPaulSharp Aug 1, 2025
18a3a68
Adds Pyupgrade (UP) ruleset and rules SIM118 & SIM300 to ruff linter …
DrPaulSharp Aug 6, 2025
3dc412f
Applies fixes for isort (I) ruff ruleset (#146)
DrPaulSharp Aug 7, 2025
a923378
Fixes whitespace errors
DrPaulSharp Aug 6, 2025
ff2387d
Fix hours, days, and years
rprospero Aug 1, 2025
f0a7b27
Add command for explicitly formatting quantity units
rprospero Aug 1, 2025
10cda0b
Add test harness for serialisation
rprospero Jun 3, 2025
fa91d56
Add first real json property
rprospero Aug 1, 2025
b06d8b4
Export data type
rprospero Aug 1, 2025
1560324
Add mask and model requirements
rprospero Aug 1, 2025
2699d65
Start exporting metadata
rprospero Aug 1, 2025
eef33dd
Start adding sample details
rprospero Aug 1, 2025
8c5e3c3
Export process metadata
rprospero Aug 1, 2025
b18bbd1
Export Instrument and Raw metadata
rprospero Aug 1, 2025
4cddb02
Support exporting Quantities
rprospero Aug 1, 2025
a333960
Remove unneeded default calls
rprospero Aug 1, 2025
5c3fc88
Start writing decoder
rprospero Aug 1, 2025
a9b204c
Correctly export sample temperature
rprospero Aug 1, 2025
d3c7c32
Fix notes nodes type
rprospero Aug 1, 2025
36da56d
Decode metadata from json
rprospero Aug 1, 2025
900dc8b
Use proper bytes for numpy serialisation
rprospero Aug 11, 2025
f4730c2
Fix historical unit errors
rprospero Aug 1, 2025
ebd6e24
Parse MetaNode
rprospero Aug 1, 2025
cabcbf0
Use .json extension for JSON files
rprospero Aug 11, 2025
ea2c2c3
Fix formatting
rprospero Aug 12, 2025
efe542a
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] Aug 12, 2025
21ec9d9
Adds main check to "transforms.py"
DrPaulSharp Aug 13, 2025
78079b3
Start descending
rprospero Aug 12, 2025
bb6a534
Convert tail call recursion to loop
rprospero Aug 13, 2025
955f4c9
Enumerate keys for access
rprospero Aug 13, 2025
1dca594
Descend into dicts
rprospero Aug 13, 2025
c39d2d9
Fix access to dict items
rprospero Aug 13, 2025
27f4b64
Fix formatting and doctstrings
rprospero Aug 13, 2025
7e9bc21
Enable tag collection
rprospero Aug 13, 2025
5bf82f4
Fix PR Comments
rprospero Aug 13, 2025
25b4bec
Formatting fixes
rprospero Aug 14, 2025
1838cad
Start encoding
rprospero Aug 15, 2025
fff15bf
Test saving with XML files
rprospero Sep 8, 2025
627faca
More tests for sample metadata
rprospero Sep 8, 2025
dd22120
Switch to safe asserts
rprospero Sep 8, 2025
9aef3f3
Start serialising process
rprospero Sep 9, 2025
f6ce026
Start serialising process
rprospero Sep 9, 2025
b5a8509
Write instrument tests
rprospero Sep 9, 2025
47b15c6
Start testing g5 round trip
rprospero Sep 10, 2025
315e557
Fix *most* of the round trip issues
rprospero Sep 10, 2025
0f71502
Everything passes if we ignore raw
rprospero Sep 10, 2025
e9774f1
Start trying to serialise raw data
rprospero Sep 10, 2025
e325f40
Simplify test setup
rprospero Sep 10, 2025
8ee754c
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] Sep 12, 2025
de42969
Attach metadata to every entry
rprospero Sep 11, 2025
38cd8fe
Add comments to as_h5
rprospero Sep 11, 2025
fa2b942
Fix up file handling of test
rprospero Sep 11, 2025
de1fec6
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] Sep 12, 2025
9ebeee9
Remove debugging print
rprospero Sep 12, 2025
8c2a32f
Respond to PR suggestions
rprospero Sep 24, 2025
2d70662
Adds local pre-commit hook for ruff linting auto fixes
DrPaulSharp Sep 29, 2025
1fa76c6
Handle bytes type object in units parser
rprospero Sep 24, 2025
7ae0d2f
Fix underline length in metadata export
rprospero Sep 24, 2025
50812b6
Fix import of actual sasdata
rprospero Sep 24, 2025
7cb7c4d
Tweak json handling
rprospero Sep 24, 2025
15d5d79
Fix most of HDF file loading
rprospero Sep 24, 2025
bf1e2fa
Properly save multidimensional data
rprospero Sep 26, 2025
19ea320
Fix parsing of exception in test
rprospero Sep 26, 2025
0d4feb2
Perform serialisation test on ALL example data
rprospero Sep 26, 2025
8d0b267
Export json
rprospero Sep 26, 2025
99c58d9
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] Sep 26, 2025
56400cc
Fix json export of data objects
rprospero Sep 26, 2025
191d566
Fixes to json export
rprospero Sep 26, 2025
c1213b3
Respond to PR suggestions
rprospero Oct 7, 2025
5469e0f
Use file name as file id
rprospero Oct 7, 2025
db91baf
157 refactor design documentation (#158)
lucas-wilkins Oct 21, 2025
5493a20
Redesign tests (#155)
jamescrake-merani Oct 22, 2025
1a671b0
Mark dataload test for faster turnaround
rprospero Oct 22, 2025
9177a4f
Ruff code formatting
rprospero Oct 22, 2025
2ac58b1
Fix up HDF Test case
rprospero Oct 22, 2025
9ad4cb4
Start moving HDF tests into James test framework
rprospero Oct 22, 2025
7e6b200
Start moving XML into James test framework
rprospero Oct 22, 2025
851ae29
Move round trip testing into main framework
rprospero Oct 22, 2025
c89c55c
Move json testing into test framework
rprospero Oct 22, 2025
f6f4202
Eliminate old testing detritus
rprospero Oct 22, 2025
135416c
Start on Sesans testing
rprospero Oct 22, 2025
7a3ff08
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] Oct 22, 2025
9a345ee
added rpms and ran to rebuild tables
paulneves77 Nov 17, 2025
4581c99
ran ruff fixes
paulneves77 Nov 17, 2025
cdaa3af
added 3D datatype and added Qz generalizations where obvious
paulneves77 Nov 13, 2025
866ed24
added first attempt at ND binner which can take in I(x,y,z,u,v,...) a…
paulneves77 Nov 13, 2025
baaf1fc
added rebin and sketch of inplied qz for postprocessing
paulneves77 Nov 14, 2025
59905b5
updated rebin, added rpm to units, and working on testing readers
paulneves77 Nov 15, 2025
f6fd6e0
the ND xubpixel binning appears to be working, and made some updates …
paulneves77 Nov 15, 2025
88521ee
corrected errors in qz calculator, cleaned up test_hdf5_reader, impro…
paulneves77 Nov 16, 2025
04ed7ba
corrected errors in qz calculator, cleaned up test_hdf5_reader, impro…
paulneves77 Nov 16, 2025
3dbad92
started cleaning up for pull request
paulneves77 Nov 17, 2025
9d5ab7b
fixed temp_hdf5_reader to be slightly more compliant with NXcanSAS st…
paulneves77 Nov 17, 2025
a9fbd0b
fixed apertures and run from none to empty list if missing, and fixed…
paulneves77 Nov 17, 2025
5b1dcbb
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] Nov 17, 2025
42ba593
cleaned up code based on Jeff Kryzwon's suggestions and added test ca…
paulneves77 Nov 17, 2025
4497343
implemented minor cleanups to code
paulneves77 Nov 18, 2025
163b16f
fixed a few bugs and cleaned up more
paulneves77 Nov 18, 2025
cdc9bd4
added raw back to metadata
paulneves77 Dec 1, 2025
e7779ee
fixed some bugs with importing sasdata/test/sasdataloader/data/simple…
paulneves77 Dec 2, 2025
a5d948b
fixed the collimation cansas_class attribute in the nxcansas_1Dand2D_…
paulneves77 Dec 2, 2025
49136d9
removed local path references, removed spurious units.py
paulneves77 Dec 3, 2025
508969f
moved duplicate code in parse_quantity to a call of parse_float, chan…
paulneves77 Dec 3, 2025
23e1e28
fixed minor error in reference output for nxcansas_1Dand2D_multisasda…
paulneves77 Dec 3, 2025
8477c9a
brought over NDrebin from refactor_24_3D branch
paulneves77 Nov 16, 2025
b620e68
updated NDrebin a bunch and also added NDrebin testing
paulneves77 Nov 17, 2025
ad9c24f
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] Nov 17, 2025
7a8bfc0
added note on using NDrebin for M dimensional integration
paulneves77 Nov 17, 2025
b351ed5
first pass at rebasing NDrebin to a class
paulneves77 Nov 18, 2025
957f389
second pass at cleaning up NDrebin class
paulneves77 Nov 18, 2025
efdc2eb
NDrebin class ready for testing
paulneves77 Nov 18, 2025
8d69367
added unit testing for NDrebin
paulneves77 Nov 18, 2025
353a0f3
removed temporary testing from NDrebin.py
paulneves77 Nov 18, 2025
e2894f6
cleaned up NDrebin, removed old function, added documentation
paulneves77 Nov 18, 2025
52f04a7
refactor NDRebin._build_limits to pass codescene review. vectorized a…
paulneves77 Dec 1, 2025
3d4a426
fixed bug in _build_limits
paulneves77 Dec 1, 2025
51b5981
indented code block, clarified non-vector comment, fixed typo, remove…
paulneves77 Dec 3, 2025
abe2029
indented code block, clarified non-vector comment, fixed typo, remove…
paulneves77 Dec 3, 2025
9db83ff
Update date format in refactor roadmap
DrPaulSharp Dec 15, 2025
056fd79
Basic test harness for names
rprospero Jan 20, 2026
28bc837
Base 62 encode the hash for shorter names
rprospero Jan 20, 2026
aabaeb9
Name info in unique id for NamedQuantity
rprospero Jan 20, 2026
ec1ed08
Ruff formatting
rprospero Jan 20, 2026
d893995
Properly attach run title and number to quantity information
rprospero Jan 20, 2026
8a1263a
Make the name a part of all quantities
rprospero Jan 21, 2026
f9f2a9f
Ensure that xml imports also include a proper name unique id
rprospero Jan 21, 2026
9410ff8
Ensure ASCII reader generates unique_id for data quantities
rprospero Jan 21, 2026
901172e
Refactor our id_header
rprospero Jan 21, 2026
b9d94c0
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] Jan 21, 2026
6edfa75
Minor formatting fixes
rprospero Jan 21, 2026
da94560
Remove debugging print statements
rprospero Jan 23, 2026
a9fa674
Refactor operations (#184)
DrPaulSharp Jan 23, 2026
2a6d3d6
Update refactor roadmap
DrPaulSharp Feb 6, 2026
f6db2fe
Adds trig and exp operations (#186)
DrPaulSharp Feb 17, 2026
52c09ab
Implement ArbitraryUnit class
rprospero Feb 19, 2026
be90b84
Refactor utest_units.py
rprospero Feb 19, 2026
1c06f7f
Add multiplication support for arbitrary units
rprospero Feb 19, 2026
50ca307
Add power support for arbitrary units
rprospero Feb 19, 2026
c55c3ad
Refactor arbitrary unit representations
rprospero Feb 19, 2026
a161c2a
Enable arbitrary division
rprospero Feb 19, 2026
dd9205b
Rework display of arbitrary units
rprospero Feb 19, 2026
93ca044
Properly reduce terms and add rdiv for arbitrary units
rprospero Feb 19, 2026
8606a90
Remove unneeded function stubs
rprospero Feb 20, 2026
94be372
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] Feb 20, 2026
c42da8c
Fix windows unicode printing issue in test
rprospero Feb 20, 2026
fa06b73
Switch name to UnknownUnit
rprospero Mar 3, 2026
70c963b
Minor format cleanup of _units_base.py
rprospero Mar 3, 2026
6615ec1
Check for invalid characters in UnknownUnit
rprospero Mar 3, 2026
9563d57
Add parentheses around denominator of UnknownUnits
rprospero Mar 3, 2026
273bacc
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] Mar 3, 2026
9ab8f14
Simplify division and serialisation of UnknownUnits
rprospero Mar 3, 2026
f96972d
Mypy fixup of sasdata/quantities/units.py
rprospero Mar 6, 2026
2f11cae
Rename test_unit_names to test_unit_operations
rprospero Mar 9, 2026
db761aa
Add default case for __eq__ in UnknownUnit
rprospero Mar 17, 2026
7ca5bf0
Fix return types for division of UnknownUnit
rprospero Mar 17, 2026
bae2947
Add trace and determinant to quantity operations
DrPaulSharp Mar 16, 2026
4b53e30
Adds matrix inverse operation
DrPaulSharp Mar 17, 2026
9d241f0
Adds norm operations
DrPaulSharp Mar 19, 2026
f65c67d
Removes determinant and sympy dependency
DrPaulSharp Mar 20, 2026
d27abec
199 remove autogen code (#201)
rprospero May 1, 2026
dd691e0
Removes print statements
DrPaulSharp May 1, 2026
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ venv
tests.log
/.pytest_cache

# Unit test / coverage reports
htmlcov/
.coverage
.cache/

# Installer files
/installers/build
/installers/dist
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default_install_hook_types: [pre-commit, pre-push]

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.1
rev: v0.12.9
hooks:
# Run the linter, applying any available fixes
- id: ruff-check
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ html5lib

# Other stuff
matplotlib
pre-commit
pre-commit
2 changes: 1 addition & 1 deletion sasdata/ascii_reader_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
T = TypeVar('T')

# TODO: There may be a better place for this.
pairings = {'I': 'dI', 'Q': 'dQ', 'Qx': 'dQx', 'Qy': 'dQy'}
pairings = {'I': 'dI', 'Q': 'dQ', 'Qx': 'dQx', 'Qy': 'dQy', 'Qz': 'dQz'}
pairing_error = {value: key for key, value in pairings.items()}
# Allows this to be bidirectional.
bidirectional_pairings = pairings | pairing_error
Expand Down
3 changes: 3 additions & 0 deletions sasdata/checklist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Things to check once everything is in place:

1) Do any centigrade fields read in incorrectly?
2 changes: 1 addition & 1 deletion sasdata/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def abscissae(self) -> Quantity:
# TODO: Won't work when there's errors involved. On reflection, we
# probably want to avoid creating a new Quantity but at the moment I
# can't see a way around it.
return Quantity(data_contents, reference_data_content.units)
return Quantity(data_contents, reference_data_content.units, name=self._data_contents["Qx"].name, id_header=self._data_contents["Qx"]._id_header)
case dataset_types.sesans:
return self._data_contents["SpinEchoLength"]
case _:
Expand Down
2 changes: 1 addition & 1 deletion sasdata/data_backing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def summary(self, indent_amount: int = 0, indent: str = " ") -> str:
s += f"{indent*(indent_amount+1)}{shorten_string(str(self.data))}\n"
for key in self.attributes:
value = self.attributes[key]
if isinstance(value, (Group | Dataset)):
if isinstance(value, (Group, Dataset)):
value_string = value.summary(indent_amount+1, indent)
else:
value_string = f"{indent * (indent_amount+1)}{key}: {shorten_string(repr(value))}\n"
Expand Down
17 changes: 17 additions & 0 deletions sasdata/data_util/manipulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@
"sasdata.data_util.averaging.", DeprecationWarning, stacklevel=2)


def deduce_qz(qx: float, qy: float, wavelength: float) -> float:
"""
If you know qx, qy, and the wavelength, you can derive qz

:param qx: qx [inverse length]
:param dy: qy [inverse length]
:param wavelength: neutron wavelength [length]

:return: qz
"""

k0 = 2*np.pi/wavelength
twotheta = np.arcsin((qx**2 + qy**2) / k0)
qz = (1 - np.cos(twotheta)) * k0
return qz


def position_and_wavelength_to_q(dx: float, dy: float, detector_distance: float, wavelength: float) -> float:
"""
:param dx: x-distance from beam center [mm]
Expand Down
18 changes: 9 additions & 9 deletions sasdata/data_util/nxsunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
__all__ = ['Converter', 'standardize_units']
T = TypeVar('T')
ConversionType = float | tuple[float, float]
DIMENSIONS = {} # type: Dict[str, Dict[str, ConversionType]]
AMBIGUITIES = {} # type: Dict[str, str]
DIMENSIONS: dict[str, dict[str, ConversionType]] = {}
AMBIGUITIES: dict[str, str] = {}
PREFIX = dict(peta=1e15, tera=1e12, giga=1e9, mega=1e6, kilo=1e3, deci=1e-1, centi=1e-2, milli=1e-3, mili=1e-3,
micro=1e-6, nano=1e-9, pico=1e-12, femto=1e-15)
SHORT_PREFIX = dict(P=1e15, T=1e12, G=1e9, M=1e6, k=1e3, d=1e-1, c=1e-2, m=1e-3, u=1e-6, n=1e-9, p=1e-12, f=1e-15)
Expand Down Expand Up @@ -258,7 +258,7 @@ def _build_all_units():
# APS files may be using 'a.u.' for 'arbitrary units'. Other
# facilities are leaving the units blank, using ??? or not even
# writing the units attributes.
unknown = {} # type: Dict[str, ConversionType]
unknown: dict[str, ConversionType] = {}
unknown.update(
{'None': 1, '???': 1, '': 1, 'A.U.': 1, 'a.u.': 1, 'arbitrary': 1, 'arbitrary units': 1,
'Counts': 1, 'counts': 1, 'Cts': 1, 'cts': 1, 'unitless': 1, 'unknown': 1, 'Unknown': 1, 'Unk': 1}
Expand Down Expand Up @@ -356,15 +356,15 @@ class Converter:
value name.
"""
#: Name of the source units (km, Ang, us, ...)
_units = None # type: List[str]
_units: list[str] = None
#: Type of the source units (distance, time, frequency, ...)
dimension = None # type: List[str]
dimension: list[str] = None
#: Scale converter, mapping unit name to scale factor or (scale, offset)
#: for temperature units.
scalemap = None # type: List[Dict[str, ConversionType]]
scalemap: list[dict[str, ConversionType]] = None
#: Scale base for the source units
scalebase = None # type: float
scaleoffset = None # type: float
scalebase: float = None
scaleoffset: float = None

@property
def units(self) -> str:
Expand All @@ -375,7 +375,7 @@ def units(self, unit: str):
self._units = standardize_units(unit)

def __init__(self, units: str | None = None, dimension: list[str] | None = None):
self.units = units if units is not None else 'a.u.' # type: str
self.units: str = units if units is not None else 'a.u.'

# Lookup dimension if not given
if dimension:
Expand Down
2 changes: 1 addition & 1 deletion sasdata/dataloader/data_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ def is_slit_smeared(self):
:return: True is slit smearing info is present, False otherwise
"""
def _check(v):
return (isinstance(v.__class__ == list | np.ndarray)
return (isinstance(v.__class__, list | np.ndarray)
and len(v) > 0 and min(v) > 0)
return _check(self.dxl) or _check(self.dxw)

Expand Down
1 change: 0 additions & 1 deletion sasdata/dataloader/readers/red2d_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def get_file_contents(self):

wavelength = None
distance = None
transmission = None

pixel_x = None
pixel_y = None
Expand Down
11 changes: 10 additions & 1 deletion sasdata/dataset_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ class DatasetType:
two_dim = DatasetType(
name="2D I vs Q",
required=["Qx", "Qy", "I"],
optional=["dQx", "dQy", "dI", "Qz", "ShadowFactor", "mask"],
optional=["dQx", "dQy", "dQz", "dI", "Qz", "ShadowFactor", "mask"],
expected_orders=[
["Qx", "Qy", "I"],
["Qx", "Qy", "I", "dI"],
["Qx", "Qy", "dQx", "dQy", "I", "dI"]])

three_dim = DatasetType(
name="3D I vs Q",
required=["Qx", "Qy", "Qz", "I"],
optional=["dQx", "dQy", "dQz", "dI", "ShadowFactor", "mask"],
expected_orders=[
["Qx", "Qy", "Qz", "I"],
["Qx", "Qy", "Qz", "I", "dI"],
["Qx", "Qy", "Qz", "dQx", "dQy", "dQz", "I", "dI"]])

sesans = DatasetType(
name="SESANS",
required=["SpinEchoLength", "Depolarisation", "Wavelength"],
Expand Down
11 changes: 11 additions & 0 deletions sasdata/distributions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


class DistributionModel:


@property
def is_density(self) -> bool:
return False

def standard_deviation(self) -> Quantity:
return NotImplementedError("Variance not implemented yet")
Empty file.
43 changes: 43 additions & 0 deletions sasdata/manual_tests/interpolation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import matplotlib.pyplot as plt
import numpy as np

from sasdata.quantities import units
from sasdata.quantities.plotting import quantity_plot
from sasdata.quantities.quantity import NamedQuantity
from sasdata.transforms.rebinning import InterpolationOptions, calculate_interpolation_matrix_1d


def linear_interpolation_check():

for from_bins in [(-10, 10, 10),
(-10, 10, 1000),
(-15, 5, 10),
(15,5, 10)]:
for to_bins in [
(-15, 0, 10),
(-15, 15, 10),
(0, 20, 100)]:

plt.figure()

x = NamedQuantity("x", np.linspace(*from_bins), units=units.meters)
y = x**2

quantity_plot(x, y)

new_x = NamedQuantity("x_new", np.linspace(*to_bins), units=units.meters)

rebin_mat = calculate_interpolation_matrix_1d(x, new_x, order=InterpolationOptions.LINEAR)

new_y = y @ rebin_mat

quantity_plot(new_x, new_y)

print(new_y.history.summary())

plt.show()




linear_interpolation_check()
10 changes: 9 additions & 1 deletion sasdata/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ class Metadata:
process: list[Process]
sample: Sample | None
instrument: Instrument | None
raw: MetaNode
raw: MetaNode | None

def summary(self):
run_string = str(self.run[0] if len(self.run) == 1 else self.run)
Expand Down Expand Up @@ -567,6 +567,14 @@ def from_json(obj):
raw=MetaNode.from_json(obj["raw"]),
)

@property
def id_header(self):
"""Generate a header for used in the unique_id for datasets"""
title = ""
if self.title is not None:
title = self.title
return f"{title}:{",".join(self.run)}"

def as_h5(self, f: h5py.Group):
"""Export data onto an HDF5 group"""
for idx, run in enumerate(self.run):
Expand Down
57 changes: 57 additions & 0 deletions sasdata/postprocess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""

Post processing for loaded files

"""

import numpy as np

from sasdata.data import SasData


def fix_mantid_units_error(data: SasData) -> SasData:
pass



def apply_fixes(data: SasData, mantid_unit_error=True):
if mantid_unit_error:
data = fix_mantid_units_error(data)

return data


def deduce_qz(data: SasData):
"""Calculates and appends Qz to SasData if Qx, Qy, and wavelength are all present"""
# if Qz is not already in the dataset, but Qx and Qy are
if 'Qz' not in data._data_contents and 'Qx' in data._data_contents and 'Qy' in data._data_contents:
# we start by making the approximation that qz=0
data._data_contents['Qz'] = 0*data._data_contents['Qx']

# now check if metadata has wavelength information
wavelength = getattr(
getattr(
getattr(
getattr(data, "metadata", None),
"instrument",
None
),
"source",
None
),
"wavelength",
None
)

if wavelength is not None:
# we can deduce the value of qz from qx and qy
# if we have the wavelength
qx = data._data_contents['Qx']
qy = data._data_contents['Qy']

# this is how you convert qx, qy, and wavelength to qz
k0 = 2*np.pi/wavelength
qz = k0-(k0**2-qx**2-qy**2)**(0.5)

data._data_contents['Qz'] = qz

Loading
Loading