Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bc13df3
added 3D datatype and added Qz generalizations where obvious
paulneves77 Nov 13, 2025
586995a
added first attempt at ND binner which can take in I(x,y,z,u,v,...) a…
paulneves77 Nov 13, 2025
48842bf
added rebin and sketch of inplied qz for postprocessing
paulneves77 Nov 14, 2025
753355e
updated rebin, added rpm to units, and working on testing readers
paulneves77 Nov 15, 2025
1955691
the ND xubpixel binning appears to be working, and made some updates …
paulneves77 Nov 15, 2025
0b5bc53
corrected errors in qz calculator, cleaned up test_hdf5_reader, impro…
paulneves77 Nov 16, 2025
1a78a94
corrected errors in qz calculator, cleaned up test_hdf5_reader, impro…
paulneves77 Nov 16, 2025
10b9506
started cleaning up for pull request
paulneves77 Nov 17, 2025
a2fa3e7
fixed temp_hdf5_reader to be slightly more compliant with NXcanSAS st…
paulneves77 Nov 17, 2025
63a5e67
fixed apertures and run from none to empty list if missing, and fixed…
paulneves77 Nov 17, 2025
ae30baa
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] Nov 17, 2025
4761ff4
cleaned up code based on Jeff Kryzwon's suggestions and added test ca…
paulneves77 Nov 17, 2025
17c8b3c
removed NDrebin from this branch.
paulneves77 Nov 17, 2025
81126c2
implemented minor cleanups to code
paulneves77 Nov 18, 2025
ebf023d
fixed a few bugs and cleaned up more
paulneves77 Nov 18, 2025
c5f1a0f
added raw back to metadata
paulneves77 Dec 1, 2025
bd677e9
fixed some bugs with importing sasdata/test/sasdataloader/data/simple…
paulneves77 Dec 2, 2025
99b44c7
fixed the collimation cansas_class attribute in the nxcansas_1Dand2D_…
paulneves77 Dec 2, 2025
2134c4c
removed local path references, removed spurious units.py
paulneves77 Dec 3, 2025
6648acd
moved duplicate code in parse_quantity to a call of parse_float, chan…
paulneves77 Dec 3, 2025
462c336
fixed minor error in reference output for nxcansas_1Dand2D_multisasda…
paulneves77 Dec 3, 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
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
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
2 changes: 1 addition & 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
41 changes: 41 additions & 0 deletions sasdata/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

"""

import numpy as np

from sasdata.data import SasData


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

Expand All @@ -14,3 +19,39 @@ def apply_fixes(data: SasData, mantid_unit_error=True):
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

1 change: 1 addition & 0 deletions sasdata/quantities/_build_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
UnitData("Ang", "Å", r"\AA", "angstrom", "angstroms", 1e-10, 1, 0, 0, 0, 0, 0, 0, []),
UnitData("micron", None, None, "micron", "microns", 1e-6, 1, 0, 0, 0, 0, 0, 0, []),
UnitData("min", None, None, "minute", "minutes", 60, 0, 1, 0, 0, 0, 0, 0, []),
UnitData("rpm", None, None, "revolutions per minute", "revolutions per minute", 1/60, 0, -1, 0, 0, 0, 0, 0, []),
UnitData("h", None, None, "hour", "hours", 3600, 0, 1, 0, 0, 0, 0, 0, []),
UnitData("d", None, None, "day", "days", 3600*24, 0, 1, 0, 0, 0, 0, 0, []),
UnitData("y", None, None, "year", "years", 3600*24*365.2425, 0, 1, 0, 0, 0, 0, 0, []),
Expand Down
8 changes: 8 additions & 0 deletions sasdata/quantities/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,14 @@ def attohertz(self) -> T:
else:
return quantity.in_units_of(units.attohertz)

@property
def revolutions_per_minute(self) -> T:
quantity = self.quantity
if quantity is None:
return None
else:
return quantity.in_units_of(units.revolutions_per_minute)



class SpeedAccessor[T](QuantityAccessor[T]):
Expand Down
3 changes: 3 additions & 0 deletions sasdata/quantities/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ def __init__(self, name: str, units: list[NamedUnit]):
angstroms = NamedUnit(1e-10, Dimensions(1, 0, 0, 0, 0, 0, 0),name='angstroms',ascii_symbol='Ang',latex_symbol=r'\AA',symbol='Å')
microns = NamedUnit(1e-06, Dimensions(1, 0, 0, 0, 0, 0, 0),name='microns',ascii_symbol='micron',symbol='micron')
minutes = NamedUnit(60, Dimensions(0, 1, 0, 0, 0, 0, 0),name='minutes',ascii_symbol='min',symbol='min')
revolutions_per_minute = NamedUnit(0.016666666666666666, Dimensions(0, -1, 0, 0, 0, 0, 0),name='revolutions_per_minute',ascii_symbol='rpm',symbol='rpm')
hours = NamedUnit(3600, Dimensions(0, 1, 0, 0, 0, 0, 0),name='hours',ascii_symbol='h',symbol='h')
days = NamedUnit(86400, Dimensions(0, 1, 0, 0, 0, 0, 0),name='days',ascii_symbol='d',symbol='d')
years = NamedUnit(31556952.0, Dimensions(0, 1, 0, 0, 0, 0, 0),name='years',ascii_symbol='y',symbol='y')
Expand Down Expand Up @@ -2047,6 +2048,7 @@ def __init__(self, name: str, units: list[NamedUnit]):
"Å": angstroms,
"micron": microns,
"min": minutes,
"rpm": revolutions_per_minute,
"h": hours,
"d": days,
"y": years,
Expand Down Expand Up @@ -2307,6 +2309,7 @@ def __init__(self, name: str, units: list[NamedUnit]):
picohertz,
femtohertz,
attohertz,
revolutions_per_minute,
])

speed = UnitGroup(
Expand Down
Loading