moreniius 0.2.1__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {moreniius-0.2.1/src/moreniius.egg-info → moreniius-0.2.2}/PKG-INFO +1 -1
  2. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius/mccode/instr.py +2 -1
  3. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius/mccode/orientation.py +21 -7
  4. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius/utils.py +8 -1
  5. {moreniius-0.2.1 → moreniius-0.2.2/src/moreniius.egg-info}/PKG-INFO +1 -1
  6. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius.egg-info/SOURCES.txt +1 -0
  7. moreniius-0.2.2/tests/test_motorized_positions.py +24 -0
  8. {moreniius-0.2.1 → moreniius-0.2.2}/.github/workflows/pip.yml +0 -0
  9. {moreniius-0.2.1 → moreniius-0.2.2}/.github/workflows/wheels.yml +0 -0
  10. {moreniius-0.2.1 → moreniius-0.2.2}/.gitignore +0 -0
  11. {moreniius-0.2.1 → moreniius-0.2.2}/README.md +0 -0
  12. {moreniius-0.2.1 → moreniius-0.2.2}/pyproject.toml +0 -0
  13. {moreniius-0.2.1 → moreniius-0.2.2}/setup.cfg +0 -0
  14. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius/__init__.py +0 -0
  15. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius/additions.py +0 -0
  16. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius/mccode/__init__.py +0 -0
  17. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius/mccode/comp.py +0 -0
  18. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius/mccode/instance.py +0 -0
  19. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius/mccode/mccode.py +0 -0
  20. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius/moreniius.py +0 -0
  21. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius/nexus_structure.py +0 -0
  22. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius/nxoff.py +0 -0
  23. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius/writer.py +0 -0
  24. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius.egg-info/dependency_links.txt +0 -0
  25. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius.egg-info/entry_points.txt +0 -0
  26. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius.egg-info/requires.txt +0 -0
  27. {moreniius-0.2.1 → moreniius-0.2.2}/src/moreniius.egg-info/top_level.txt +0 -0
  28. {moreniius-0.2.1 → moreniius-0.2.2}/tests/test_nexus_structure.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: moreniius
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Author-email: Gregory Tucker <gregory.tucker@ess.eu>
5
5
  Classifier: License :: OSI Approved :: BSD License
6
6
  Classifier: Development Status :: 2 - Pre-Alpha
@@ -83,7 +83,8 @@ class NXInstr:
83
83
  'expression' in nx_args[0]:
84
84
  not_expr = [x for x in nx_args[0] if x != 'expression']
85
85
  if len(not_expr) == 1:
86
- return nx_args[0][not_expr[0]]
86
+ # TODO make this return an nx_class once we're sure that nx_kwargs is parseable (no mccode_antlr.Expr)
87
+ return nx_class(nx_args[0][not_expr[0]], **nx_kwargs)
87
88
  else:
88
89
  raise RuntimeError('Not sure what I should do here')
89
90
  return nx_class(*nx_args, **nx_kwargs)
@@ -17,14 +17,28 @@ class NXPart:
17
17
  def make_nx(self, nx_class, *args, **kwargs):
18
18
  return self.instr.make_nx(nx_class, *args, **kwargs)
19
19
 
20
- def translation(self, dep: str) -> NXfield:
20
+ def make_translation(self, norm, vec, dep):
21
+ return self.make_nx(NXfield, norm, vector=vec, depends_on=dep, transformation_type='translation', units='m')
22
+
23
+ def translations(self, dep: str, name: str) -> list[tuple[str, NXfield]]:
21
24
  from mccode_antlr.instr import RotationPart
25
+ from mccode_antlr.common import Expr, Value
22
26
  if isinstance(self.o, RotationPart):
23
27
  raise RuntimeError('Part is a rotation!')
24
28
  pos = self.o.position()
29
+ if any(isinstance(c, (Expr, Value)) for c in (pos.x, pos.y, pos.z)):
30
+ translations = []
31
+ print(f'{pos.x=} {pos.y=} {pos.z=}')
32
+ for n, c, v in (('x', pos.x, [1, 0, 0]), ('y', pos.y, [0, 1, 0]), ('z', pos.z, [0, 0, 1])):
33
+ if c != Expr.parse('0'):
34
+ next_name = f'{name}_{n}'
35
+ translations.append((next_name, self.make_translation(c, v, dep)))
36
+ dep = next_name
37
+ return translations
38
+ # vector is all constants, hopefully
25
39
  norm = pos.length()
26
- vec = pos if norm.is_zero else pos / norm
27
- return self.make_nx(NXfield, norm, vector=vec, depends_on=dep, transformation_type='translation', units='m')
40
+ vec = pos if norm.is_zero else pos/norm
41
+ return [(name, self.make_translation(norm, vec, dep))]
28
42
 
29
43
  def rotation(self, dep: str) -> NXfield:
30
44
  from mccode_antlr.instr import TranslationPart
@@ -43,11 +57,11 @@ class NXPart:
43
57
 
44
58
  def transformations(self, name: str, dep: str | None = None) -> list[tuple[str, NXfield]]:
45
59
  if self.o.is_translation and self.o.is_rotation:
46
- trans = self.translation(dep)
47
- rot = self.rotation(f'{name}_t')
48
- return [(f'{name}_t', trans), (f'{name}_r', rot)]
60
+ ops = self.translations(dep, name)
61
+ rot = self.rotation(ops[-1][0])
62
+ return [*ops, (f'{name}_r', rot)]
49
63
  elif self.o.is_translation:
50
- return [(name, self.translation(dep))]
64
+ return self.translations(dep, name)
51
65
  elif self.o.is_rotation:
52
66
  return [(name, self.rotation(dep))]
53
67
  else:
@@ -32,7 +32,14 @@ def outer_transform_dependency(transformations):
32
32
  names = list(transformations)
33
33
  if len(names) == 1:
34
34
  return names[0]
35
- depends = {name: getattr(transformations, name).depends_on for name in names}
35
+ def depends_on_per(name):
36
+ obj = getattr(transformations, name)
37
+ if not hasattr(obj, 'depends_on'):
38
+ raise ValueError(f'{name} in {names} dependency chain missing "depends_on" attribute')
39
+ return obj.depends_on
40
+
41
+ # depends = {name: getattr(transformations, name).depends_on for name in names}
42
+ depends = {name: depends_on_per(name) for name in names}
36
43
  externals = [v for k, v in depends.items() if v not in depends]
37
44
  if len(externals) != 1:
38
45
  raise RuntimeError(f"Dependency chain {depends} should have one absolute dependency, found {externals} instead")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: moreniius
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Author-email: Gregory Tucker <gregory.tucker@ess.eu>
5
5
  Classifier: License :: OSI Approved :: BSD License
6
6
  Classifier: Development Status :: 2 - Pre-Alpha
@@ -22,4 +22,5 @@ src/moreniius/mccode/instance.py
22
22
  src/moreniius/mccode/instr.py
23
23
  src/moreniius/mccode/mccode.py
24
24
  src/moreniius/mccode/orientation.py
25
+ tests/test_motorized_positions.py
25
26
  tests/test_nexus_structure.py
@@ -0,0 +1,24 @@
1
+
2
+ def make_motorized_instrument():
3
+ from mccode_antlr.assembler import Assembler
4
+ from mccode_antlr.reader import MCSTAS_REGISTRY, LocalRegistry
5
+ from mccode_to_kafka.writer import da00_dataarray_config, da00_variable_config
6
+
7
+ inst = Assembler('inst', registries=[MCSTAS_REGISTRY])
8
+ inst.parameter('double ex/"m"=0')
9
+ inst.parameter('double phi/"degree"=0')
10
+
11
+ inst.component('origin', 'Arm', at=(0, 0, 0))
12
+ inst.component('source', 'Source_simple', at=[(0, 0, 0), 'origin'])
13
+ inst.component('xpos', 'Arm', at=[('ex', 0, 0), 'source'])
14
+ inst.component('zrot', 'Arm', at=[(0, 0, 0), 'xpos'], rotate=[(0, 0, 'phi'), 'xpos'])
15
+
16
+ return inst.instrument
17
+
18
+
19
+ def test_motorized_instrument():
20
+ import moreniius
21
+ motorized = make_motorized_instrument()
22
+ nx = moreniius.MorEniius.from_mccode(motorized, origin='origin', only_nx=False, absolute_depends_on=True)
23
+ assert nx is not None
24
+ #TODO add actual tests for the contents of, e.g., the dumped NeXus Structure
File without changes
File without changes
File without changes
File without changes