moreniius 0.2.3__py3-none-any.whl → 0.2.5__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 +27 -5
- moreniius/mccode/orientation.py +1 -2
- moreniius/utils.py +19 -2
- moreniius/writer.py +0 -2
- {moreniius-0.2.3.dist-info → moreniius-0.2.5.dist-info}/METADATA +7 -7
- {moreniius-0.2.3.dist-info → moreniius-0.2.5.dist-info}/RECORD +9 -9
- {moreniius-0.2.3.dist-info → moreniius-0.2.5.dist-info}/WHEEL +1 -1
- {moreniius-0.2.3.dist-info → moreniius-0.2.5.dist-info}/entry_points.txt +0 -0
- {moreniius-0.2.3.dist-info → moreniius-0.2.5.dist-info}/top_level.txt +0 -0
moreniius/mccode/instr.py
CHANGED
|
@@ -2,7 +2,7 @@ from zenlog import log
|
|
|
2
2
|
from dataclasses import dataclass, field
|
|
3
3
|
from mccode_antlr.instr import Instr
|
|
4
4
|
from mccode_antlr.common import Expr
|
|
5
|
-
from nexusformat.nexus import NXfield, NXcollection
|
|
5
|
+
from nexusformat.nexus import NXfield, NXgroup, NXcollection
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
@dataclass
|
|
@@ -15,7 +15,8 @@ class NXInstr:
|
|
|
15
15
|
"""Start the C translation to ensure McCode-oddities are handled before any C-code parsing."""
|
|
16
16
|
from mccode_antlr.common import ShapeType, DataType, Value
|
|
17
17
|
from mccode_antlr.translators.target import MCSTAS_GENERATOR
|
|
18
|
-
from mccode_antlr.translators.c import CTargetVisitor
|
|
18
|
+
from mccode_antlr.translators.c import CTargetVisitor
|
|
19
|
+
from mccode_antlr.translators.c_listener import CDeclarator
|
|
19
20
|
from mccode_antlr.translators.c_listener import evaluate_c_defined_expressions
|
|
20
21
|
config = dict(default_main=True, enable_trace=False, portable=False, include_runtime=True,
|
|
21
22
|
embed_instrument_file=False, verbose=False, output=None)
|
|
@@ -25,9 +26,9 @@ class NXInstr:
|
|
|
25
26
|
# translator.component_uservars is a dictionary of lists for each component type of `CDeclaration` objects.
|
|
26
27
|
|
|
27
28
|
# only worry about instrument level variables for the moment, and convert the CDeclarations into Expr objects
|
|
28
|
-
def c_declaration_to_expr(dec:
|
|
29
|
+
def c_declaration_to_expr(dec: CDeclarator) -> Expr:
|
|
29
30
|
expr = Expr(Value(None)) if dec.init is None else Expr.parse(dec.init)
|
|
30
|
-
expr.data_type = DataType.from_name(dec.
|
|
31
|
+
expr.data_type = DataType.from_name(dec.dtype)
|
|
31
32
|
if dec.is_pointer or dec.is_array:
|
|
32
33
|
expr.shape_type = ShapeType.vector
|
|
33
34
|
return expr
|
|
@@ -83,8 +84,29 @@ class NXInstr:
|
|
|
83
84
|
'expression' in nx_args[0]:
|
|
84
85
|
not_expr = [x for x in nx_args[0] if x != 'expression']
|
|
85
86
|
if len(not_expr) == 1:
|
|
87
|
+
not_expr_arg = nx_args[0][not_expr[0]]
|
|
88
|
+
# if isinstance(not_expr_arg, NXfield):
|
|
89
|
+
# # We have and want an NXfield, but it might be missing attributes specified in the nx_kwargs
|
|
90
|
+
# # Passing the keywords to the NXfield constructor versus this method is not identical,
|
|
91
|
+
# # since some keyword arguments are reserved (and only some of which are noted)
|
|
92
|
+
# # Explicit keywords, used in the constructor:
|
|
93
|
+
# # value, name, shape, dtype, group, attrs
|
|
94
|
+
# # Keywords extracted from the kwargs dict, if present (and all controlling HDF5 file attributes?):
|
|
95
|
+
# # chunks, compression, compression_opts, fillvalue, fletcher32, maxshape, scaleoffset, shuffle
|
|
96
|
+
# # For now, just assume all keywords provided here are _actually_ attributes for the NXfield
|
|
97
|
+
# # which is an extension of a dict, but can *not* use the update method, since the __setitem__
|
|
98
|
+
# # method is overridden to wrap inputs in NXattr objects :/
|
|
99
|
+
# for k, v in nx_kwargs.items():
|
|
100
|
+
# not_expr_arg.attrs[k] = v
|
|
101
|
+
# return not_expr_arg
|
|
102
|
+
|
|
86
103
|
# TODO make this return an nx_class once we're sure that nx_kwargs is parseable (no mccode_antlr.Expr)
|
|
87
|
-
|
|
104
|
+
if all(x in not_expr_arg for x in ('module', 'config')):
|
|
105
|
+
# This is a file-writer stream directive? So make a group
|
|
106
|
+
return NXgroup(entries={not_expr[0]: not_expr_arg}, **nx_kwargs)
|
|
107
|
+
print('!!')
|
|
108
|
+
print(not_expr_arg)
|
|
109
|
+
return nx_class(not_expr_arg, **nx_kwargs)
|
|
88
110
|
else:
|
|
89
111
|
raise RuntimeError('Not sure what I should do here')
|
|
90
112
|
return nx_class(*nx_args, **nx_kwargs)
|
moreniius/mccode/orientation.py
CHANGED
|
@@ -18,6 +18,7 @@ class NXPart:
|
|
|
18
18
|
return self.instr.make_nx(nx_class, *args, **kwargs)
|
|
19
19
|
|
|
20
20
|
def make_translation(self, norm, vec, dep):
|
|
21
|
+
# if `norm` is a link or NXlog, we should make a group not an NXfield
|
|
21
22
|
return self.make_nx(NXfield, norm, vector=vec, depends_on=dep, transformation_type='translation', units='m')
|
|
22
23
|
|
|
23
24
|
def translations(self, dep: str, name: str) -> list[tuple[str, NXfield]]:
|
|
@@ -28,7 +29,6 @@ class NXPart:
|
|
|
28
29
|
pos = self.o.position()
|
|
29
30
|
if any(isinstance(c, (Expr, Value)) for c in (pos.x, pos.y, pos.z)):
|
|
30
31
|
translations = []
|
|
31
|
-
print(f'{pos.x=} {pos.y=} {pos.z=}')
|
|
32
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
33
|
if c != Expr.parse('0'):
|
|
34
34
|
next_name = f'{name}_{n}'
|
|
@@ -51,7 +51,6 @@ class NXPart:
|
|
|
51
51
|
print(repr(self.o))
|
|
52
52
|
raise NotImplementedError()
|
|
53
53
|
|
|
54
|
-
# print(f'rotation {axis}, {angle}')
|
|
55
54
|
# handle the case where angle is not a constant?
|
|
56
55
|
return self.make_nx(NXfield, angle, vector=axis, depends_on=dep, transformation_type='rotation', units=angle_unit)
|
|
57
56
|
|
moreniius/utils.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from mccode_antlr.instr import Instance
|
|
2
|
-
from nexusformat.nexus import NXevent_data
|
|
2
|
+
from nexusformat.nexus import NXevent_data, NXfield
|
|
3
3
|
|
|
4
4
|
class NotNXdict:
|
|
5
5
|
"""Wrapper class to prevent NXfield-parsing of the held dictionary"""
|
|
@@ -12,6 +12,10 @@ class NotNXdict:
|
|
|
12
12
|
def __repr__(self):
|
|
13
13
|
return f"NotNXdict<{self.value}>"
|
|
14
14
|
|
|
15
|
+
def __str__(self):
|
|
16
|
+
from json import dumps
|
|
17
|
+
return dumps(self.value)
|
|
18
|
+
|
|
15
19
|
|
|
16
20
|
def outer_transform_dependency(transformations):
|
|
17
21
|
"""For a NXtransformations group, find the most-dependent transformation name
|
|
@@ -36,7 +40,20 @@ def outer_transform_dependency(transformations):
|
|
|
36
40
|
obj = getattr(transformations, name)
|
|
37
41
|
if not hasattr(obj, 'depends_on'):
|
|
38
42
|
raise ValueError(f'{name} in {names} dependency chain missing "depends_on" attribute')
|
|
39
|
-
|
|
43
|
+
if isinstance(obj.depends_on, NXfield):
|
|
44
|
+
# obj.depends_on is an NXfield object; which has a number of properties
|
|
45
|
+
# nxgroup - the parent group
|
|
46
|
+
# dtype - string or numpy dtype
|
|
47
|
+
# shape - list or tuple of ints
|
|
48
|
+
# attrs - dict of attributes
|
|
49
|
+
# nxdata - a scalar or numpy array or string
|
|
50
|
+
# nxpath - string, where this object is in the tree
|
|
51
|
+
# nxroot - the root NXgroup object containing this object
|
|
52
|
+
# I _think_ we *always* want the data stored in this object
|
|
53
|
+
return obj.depends_on.nxdata
|
|
54
|
+
elif isinstance(obj.depends_on, str):
|
|
55
|
+
return obj.depends_on
|
|
56
|
+
raise ValueError(f"depends_on attribute of {name} is not an NXfield or str")
|
|
40
57
|
|
|
41
58
|
# depends = {name: getattr(transformations, name).depends_on for name in names}
|
|
42
59
|
depends = {name: depends_on_per(name) for name in names}
|
moreniius/writer.py
CHANGED
|
@@ -113,7 +113,6 @@ class Writer:
|
|
|
113
113
|
if absolute_depends_on and 'depends_on' == name and not obj.nxdata.startswith('/'):
|
|
114
114
|
obj.nxdata = _to_absolute(top_obj.nxpath, obj.nxdata)
|
|
115
115
|
if obj.nxclass == 'NXfield':
|
|
116
|
-
# print(f'to_json_dict for NXfield {name=}')
|
|
117
116
|
typ, val = convert_types(obj.nxdata, only_nx)
|
|
118
117
|
# typ is None if obj.nxdata is a NotNXdict (such that val _is_ the contained dict)
|
|
119
118
|
entry = dict(module='dataset', config=dict(name=name, values=val, type=typ)) if typ else val
|
|
@@ -123,7 +122,6 @@ class Writer:
|
|
|
123
122
|
if len(list(obj)):
|
|
124
123
|
entry['children'] = self._to_json_dict(obj, only_nx=only_nx, absolute_depends_on=absolute_depends_on)
|
|
125
124
|
for n, v in obj.attrs.items():
|
|
126
|
-
# print(f'to_json_dict for attribute of {name=}, named {n=}')
|
|
127
125
|
typ, val = convert_types(v, only_nx)
|
|
128
126
|
if absolute_depends_on and n == 'depends_on' and '/' != val[0]:
|
|
129
127
|
val = _to_absolute(top_obj.nxpath, val)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: moreniius
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.5
|
|
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
|
|
9
|
-
Requires-Dist: platformdirs
|
|
10
|
-
Requires-Dist:
|
|
11
|
-
Requires-Dist:
|
|
12
|
-
Requires-Dist:
|
|
8
|
+
Requires-Dist: zenlog>=1.1
|
|
9
|
+
Requires-Dist: platformdirs>=3.11
|
|
10
|
+
Requires-Dist: importlib_metadata; python_version < "3.8"
|
|
11
|
+
Requires-Dist: mccode-antlr[hdf5]>=0.9.2
|
|
12
|
+
Requires-Dist: nexusformat>=1.0.6
|
|
13
13
|
|
|
14
14
|
# moreniius
|
|
15
15
|
A project to contain custom components required to use `eniius` to produce `NeXus Structure` `JSON` from `mccode-antlr` simulated instruments.
|
|
@@ -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=
|
|
7
|
-
moreniius/writer.py,sha256=
|
|
6
|
+
moreniius/utils.py,sha256=R81eHjc0EWjMsP-Z8WI9sZkc_QY357z_aYziflQAUEU,9238
|
|
7
|
+
moreniius/writer.py,sha256=rZSOpSmCAiY1KS3YAWKBXZUWTJFLyrkZT-zeZfyENV8,6178
|
|
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=
|
|
11
|
+
moreniius/mccode/instr.py,sha256=q0NS2hH7eWaHu4xzdcPRRx4M-9WHA2IcElgO__PXjiQ,6138
|
|
12
12
|
moreniius/mccode/mccode.py,sha256=6NEXovuG-6itzlPgPklNOiZQ-MlldKF20p4TxV8n4BA,3228
|
|
13
|
-
moreniius/mccode/orientation.py,sha256=
|
|
14
|
-
moreniius-0.2.
|
|
15
|
-
moreniius-0.2.
|
|
16
|
-
moreniius-0.2.
|
|
17
|
-
moreniius-0.2.
|
|
18
|
-
moreniius-0.2.
|
|
13
|
+
moreniius/mccode/orientation.py,sha256=khT0jTMXyXkPCoEpDg-eLKulF-J2wIqNhUi1NzFWvto,3907
|
|
14
|
+
moreniius-0.2.5.dist-info/METADATA,sha256=9d8qeZuOv6YNkojoOPY41lTdhv7tVycA2m5XM6ytqdk,620
|
|
15
|
+
moreniius-0.2.5.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
16
|
+
moreniius-0.2.5.dist-info/entry_points.txt,sha256=Ga3k4P4fyBt5_dJ03Oapic2Qlgqv9jufQGdxWiz_j2A,63
|
|
17
|
+
moreniius-0.2.5.dist-info/top_level.txt,sha256=RzMo23UfVhgQeuOYeS5P9I0qVbxx4Gbe6Roc29Mr02c,10
|
|
18
|
+
moreniius-0.2.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|