Skip to content

Commit 7d1cbd6

Browse files
committed
Abscissa basics
1 parent dcb3fb3 commit 7d1cbd6

3 files changed

Lines changed: 140 additions & 0 deletions

File tree

sasdata/abscissa.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from abc import ABC, abstractmethod
2+
3+
import numpy as np
4+
from numpy._typing import ArrayLike
5+
6+
from quantities.quantity import Quantity
7+
8+
9+
class Abscissa(ABC):
10+
11+
def __init__(self, axes: list[Quantity]):
12+
self._axes = axes
13+
self._dimensionality = len(axes)
14+
@property
15+
def dimensionality(self) -> int:
16+
""" Dimensionality of this data """
17+
return self._dimensionality
18+
19+
@property
20+
@abstractmethod
21+
def is_grid(self) -> bool:
22+
""" Are these coordinates using a grid representation
23+
( as opposed to a general list representation)
24+
25+
is_grid = True: implies that the corresponding ordinate is n-dimensional tensor
26+
is_grid = False: implies that the corresponding ordinate is a 1D list
27+
28+
If the data is one dimensional, is_grid=True
29+
30+
"""
31+
32+
33+
@property
34+
def axes(self) -> list[Quantity]:
35+
""" Axes of the data:
36+
37+
If it's an (n1-by-n2-by-n3...) grid (is_grid=True): give the values for each axis, returning a list like
38+
[Quantity(length n1), Quantity(length n2), Quantity(length n3) ... ]
39+
40+
If it is not grid data (is_grid=False), but n points on a general mesh, give one array for each dimension
41+
[Quantity(length n), Quantity(length n), Quantity(length n) ... ]
42+
43+
"""
44+
45+
return self._axes
46+
47+
@staticmethod
48+
def determine(axes_data: list[Quantity[ArrayLike]], ordinate_data: Quantity[ArrayLike]) -> "Abscissa":
49+
""" Get an Abscissa object that fits the combination of axes and data"""
50+
51+
# Different possibilites:
52+
# 1: axes_data[i].shape == axes_data[j].shape == ordinate_data.shape
53+
# 1a: axis_data[i] is 1D =>
54+
# 1a-i: len(axes_data) == 1 => Grid type (trivially)
55+
# 1a-ii: len(axes_data) != 1 => Mesh type
56+
# 1b: axis_data[i] dimensionality matches len(axis_data) => Grid type
57+
# 1c: other => Error
58+
# 2: (len(axes_data[0]), len(axes_data[1])... ) == ordinate_data.shape => Grid type
59+
# 3: None of the above => Error
60+
61+
ordinate_shape = np.array(ordinate_data.value).shape
62+
63+
if len(ordinate_shape) == 1 and all([np.array(axis.value).shape == ordinate_shape for axis in axes_data]):
64+
return ScatterAbscissa(axes_data)
65+
66+
elif
67+
class GridAbscissa(Abscissa):
68+
69+
@property
70+
def is_grid(self):
71+
return True
72+
73+
class ScatterAbscissa(Abscissa):
74+
75+
@property
76+
def is_grid(self):
77+
return False
78+

sasdata/data.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,65 @@
77

88

99
class SasData:
10+
""" General object containing data in the SasView ecosystem"""
11+
12+
def __init__(self,
13+
name: str,
14+
ordinate: Quantity,
15+
mask: Quantity,
16+
abscissae: list[Quantity],
17+
dependents: list["SasData"]):
18+
19+
self._ordinate = ordinate
20+
self._abscissae = abscissae
21+
self._mask = mask
22+
23+
@property
24+
def ordinate(self) -> Quantity:
25+
return self._ordinate
26+
27+
@property
28+
def abscissae(self) -> list[Quantity]:
29+
return self._abscissae
30+
31+
@property
32+
def mask(self) -> Quantity:
33+
return self._mask
34+
35+
def scatter_data(self):
36+
""" Return data in the coordinate/value form [(x1, x2, x3, y)...]"""
37+
38+
39+
class SasDerivedMeasurement(SasData):
40+
""" General object sas measurement that has not come directly from a file,
41+
for example, the difference between two datasets"""
42+
43+
44+
def __init__(self,
45+
name: str,
46+
ordinate: Quantity,
47+
abscissae: list[Quantity],
48+
dependents: list["SasData"],
49+
metadata: DerivedMetadata):
50+
51+
super().__init__(
52+
name=name,
53+
ordinate=ordinate,
54+
abscissae=abscissae,
55+
dependents=dependents)
56+
57+
self.metadata = metadata
58+
59+
60+
61+
62+
class SasMeasurement(SasData):
63+
def __init__(self, name: str,
64+
data_contents: dict[str, Quantity],
65+
dataset_type: DatasetType,
66+
metadata: Metadata,
67+
verbose: bool=False):
68+
1069
def __init__(
1170
self,
1271
name: str,

sasdata/metadata.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,3 +537,6 @@ def default(self, obj):
537537
}
538538
case _:
539539
return super().default(obj)
540+
541+
class DerivedMetadata(Metadata):
542+
pass

0 commit comments

Comments
 (0)