Skip to content

Commit 4ace65f

Browse files
committed
fix tests, refactor a bit
1 parent 6803448 commit 4ace65f

5 files changed

Lines changed: 27 additions & 25 deletions

File tree

src/easyreflectometry/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from importlib import metadata
22

3-
from .orso_utils import LoadOrso
4-
from .orso_utils import load_data_from_orso_file
53
from .project import Project
64

75
try:
@@ -12,6 +10,4 @@
1210
__all__ = [
1311
Project,
1412
__version__,
15-
LoadOrso,
16-
load_data_from_orso_file,
1713
]

src/easyreflectometry/calculators/calculator_base.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
from __future__ import annotations
22

33
from abc import ABCMeta
4-
from typing import TYPE_CHECKING
54
from typing import Callable
65

76
import numpy as np
87
from easyscience.Objects.core import ComponentSerializer
98
from easyscience.Objects.Inferface import ItemContainer
109

10+
#if TYPE_CHECKING:
11+
from easyreflectometry.model import Model
12+
from easyreflectometry.sample import BaseAssembly
13+
from easyreflectometry.sample import Layer
14+
from easyreflectometry.sample import Material
15+
from easyreflectometry.sample import MaterialMixture
16+
from easyreflectometry.sample import Multilayer
17+
1118
from .wrapper_base import WrapperBase
1219

13-
if TYPE_CHECKING:
14-
from easyreflectometry.model import Model
15-
from easyreflectometry.sample import BaseAssembly
16-
from easyreflectometry.sample import Layer
17-
from easyreflectometry.sample import Material
18-
from easyreflectometry.sample import MaterialMixture
19-
from easyreflectometry.sample import Multilayer
20+
2021
class CalculatorBase(ComponentSerializer, metaclass=ABCMeta):
2122
"""
2223
This class is a template and defines all properties that a calculator should have.

src/easyreflectometry/orso_utils.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,16 @@ def load_orso_data(orso_str: str) -> DataSet1D:
116116
)
117117
attrs[f'R_{name}'] = {'orso_header': sc.scalar(Header.asdict(o.info))}
118118
data_group = sc.DataGroup(data=data, coords=coords, attrs=attrs)
119-
dataset = DataSet1D(
120-
x=data_group['coords']['Qz_0'].values,
121-
y=data_group['data']['R_0'].values,
122-
ye=data_group['data']['R_0'].variances,
123-
xe=data_group['coords']['Qz_0'].variances,
124-
)
125-
return dataset
119+
return data_group
120+
# if 'Qz_spin_up' in data_group['coords']:
121+
# component = 'spin_up'
122+
# else:
123+
# component = '0'
124+
# dataset = DataSet1D(
125+
# x=data_group['coords'][f'Qz_{component}'].values,
126+
# y=data_group['data'][f'R_{component}'].values,
127+
# ye=data_group['data'][f'R_{component}'].variances,
128+
# xe=data_group['coords'][f'Qz_{component}'].variances,
129+
# )
130+
# return dataset
126131

src/easyreflectometry/project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def get_index_d2o(self) -> int:
242242

243243
def load_orso_file(self, path: Union[Path, str]) -> None:
244244
"""Load an ORSO file and optionally create a model and a data from it."""
245-
from easyreflectometry import LoadOrso
245+
from easyreflectometry.orso_utils import LoadOrso
246246

247247
model, data = LoadOrso(path)
248248
if model is not None:

tests/test_data.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from orsopy.fileio import load_orso
1111

1212
import easyreflectometry
13-
from easyreflectometry.data.measurement import _load_orso
1413
from easyreflectometry.data.measurement import _load_txt
1514
from easyreflectometry.data.measurement import load
15+
from easyreflectometry.orso_utils import load_data_from_orso_file
1616

1717
PATH_STATIC = os.path.join(os.path.dirname(easyreflectometry.__file__), '..', '..', 'tests', '_static')
1818

@@ -47,7 +47,7 @@ def test_load_with_txt_commas(self):
4747

4848
def test_orso1(self):
4949
fpath = os.path.join(PATH_STATIC, 'test_example1.ort')
50-
er_data = _load_orso(fpath)
50+
er_data = load_data_from_orso_file(fpath)
5151
o_data = load_orso(fpath)
5252
assert er_data['attrs']['R_spin_up']['orso_header'].value == Header.asdict(o_data[0].info)
5353
assert_almost_equal(er_data['data']['R_spin_up'].values, o_data[0].data[:, 1])
@@ -57,7 +57,7 @@ def test_orso1(self):
5757

5858
def test_orso2(self):
5959
fpath = os.path.join(PATH_STATIC, 'test_example2.ort')
60-
er_data = _load_orso(fpath)
60+
er_data = load_data_from_orso_file(fpath)
6161
o_data = load_orso(fpath)
6262
for i, o in enumerate(list(reversed(o_data))):
6363
assert er_data['attrs'][f'R_{o.info.data_set}']['orso_header'].value == Header.asdict(o.info)
@@ -68,7 +68,7 @@ def test_orso2(self):
6868

6969
def test_orso3(self):
7070
fpath = os.path.join(PATH_STATIC, 'test_example3.ort')
71-
er_data = _load_orso(fpath)
71+
er_data = load_data_from_orso_file(fpath)
7272
o_data = load_orso(fpath)
7373
for i, o in enumerate(o_data):
7474
assert er_data['attrs'][f'R_{o.info.data_set}']['orso_header'].value == Header.asdict(o.info)
@@ -79,7 +79,7 @@ def test_orso3(self):
7979

8080
def test_orso4(self):
8181
fpath = os.path.join(PATH_STATIC, 'test_example4.ort')
82-
er_data = _load_orso(fpath)
82+
er_data = load_data_from_orso_file(fpath)
8383
o_data = load_orso(fpath)
8484
for i, o in enumerate(o_data):
8585
print(list(er_data.keys()))

0 commit comments

Comments
 (0)