moreniius 0.2.1__py3-none-any.whl → 0.2.3__py3-none-any.whl

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.
moreniius/mccode/instr.py CHANGED
@@ -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:
moreniius/utils.py CHANGED
@@ -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,14 +1,14 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: moreniius
3
- Version: 0.2.1
3
+ Version: 0.2.3
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
7
7
  Description-Content-Type: text/markdown
8
- Requires-Dist: zenlog ==1.1
9
- Requires-Dist: platformdirs ==3.11
10
- Requires-Dist: mccode-antlr[hdf5] ==0.7.0
11
- Requires-Dist: nexusformat ==1.0.6
8
+ Requires-Dist: zenlog >=1.1
9
+ Requires-Dist: platformdirs >=3.11
10
+ Requires-Dist: mccode-antlr[hdf5] >=0.7.1
11
+ Requires-Dist: nexusformat >=1.0.6
12
12
  Requires-Dist: importlib-metadata ; python_version < "3.8"
13
13
 
14
14
  # moreniius
@@ -3,16 +3,16 @@ moreniius/additions.py,sha256=6Hhhc4LDUsnBj27Iil-EFFzQm1xd2M45hfcVQYEjxiI,17615
3
3
  moreniius/moreniius.py,sha256=cU3CrfMC1kOnHO77yq5sZfDqRuA38G5kA3RUXFNGP2U,1455
4
4
  moreniius/nexus_structure.py,sha256=i9CxYwJl4eKP9IIYR80MI3f54Yh0RPDFviZaulE5IOc,1709
5
5
  moreniius/nxoff.py,sha256=WHp9wYNn_4Hcx8Nzi9rpX1p8_iwI-AdgTQouSAEG8N4,3288
6
- moreniius/utils.py,sha256=3REIM3nJ3L0PVpIWqu0Kh-znK1ggNNYTCjXatoaAA34,8075
6
+ moreniius/utils.py,sha256=3ix8lLQwzwdx_nm-YEoD17z7s4h4CGda5lzVdD8M8lA,8386
7
7
  moreniius/writer.py,sha256=DOwzpDqoXiDXdtV-hRZVtF5lNBBoYy0UO5_bq89d1lc,6325
8
8
  moreniius/mccode/__init__.py,sha256=1QiZdh90G3gp_WlVpdJB_ZGauoW0GJEQ13Nelaqa5JE,151
9
9
  moreniius/mccode/comp.py,sha256=uR1L5nLfYPHhMKd3XnDbqf5xhkfwfPLRnttREc3jqBg,7382
10
10
  moreniius/mccode/instance.py,sha256=4nqJ3ne6yXCEvsa3FIKUcGDYP_z7cAr46JhakDTB6qs,8055
11
- moreniius/mccode/instr.py,sha256=3BdfYzZnHhCokFQIwp7XUEy9nt6CclqAWunHXfGW228,4363
11
+ moreniius/mccode/instr.py,sha256=8Thl4RuMi2X4ruNtI8-l8S_2OHtW_38F2Pv_FisuImc,4505
12
12
  moreniius/mccode/mccode.py,sha256=6NEXovuG-6itzlPgPklNOiZQ-MlldKF20p4TxV8n4BA,3228
13
- moreniius/mccode/orientation.py,sha256=_jyTtabo3ZHujuXead0elZzcCck_v8UwX5tIMp4dXwI,3199
14
- moreniius-0.2.1.dist-info/METADATA,sha256=IDriQtt4mIeEtG6mTYHH-i860X52N4IGuaO2Y04kGX0,625
15
- moreniius-0.2.1.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
16
- moreniius-0.2.1.dist-info/entry_points.txt,sha256=Ga3k4P4fyBt5_dJ03Oapic2Qlgqv9jufQGdxWiz_j2A,63
17
- moreniius-0.2.1.dist-info/top_level.txt,sha256=RzMo23UfVhgQeuOYeS5P9I0qVbxx4Gbe6Roc29Mr02c,10
18
- moreniius-0.2.1.dist-info/RECORD,,
13
+ moreniius/mccode/orientation.py,sha256=kfOTiHgG68huQdh_ojd2NXxyAxFQoCn6FavwSOulh5E,3923
14
+ moreniius-0.2.3.dist-info/METADATA,sha256=RlDqZin-stzGUdk_yKxBbxIFtYzLmSfnAsm7Rtwimpw,625
15
+ moreniius-0.2.3.dist-info/WHEEL,sha256=uCRv0ZEik_232NlR4YDw4Pv3Ajt5bKvMH13NUU7hFuI,91
16
+ moreniius-0.2.3.dist-info/entry_points.txt,sha256=Ga3k4P4fyBt5_dJ03Oapic2Qlgqv9jufQGdxWiz_j2A,63
17
+ moreniius-0.2.3.dist-info/top_level.txt,sha256=RzMo23UfVhgQeuOYeS5P9I0qVbxx4Gbe6Roc29Mr02c,10
18
+ moreniius-0.2.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (74.0.0)
2
+ Generator: setuptools (74.1.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5