moreniius 0.3.0__py3-none-any.whl → 0.5.0__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
@@ -3,6 +3,7 @@ from dataclasses import dataclass, field
3
3
  from mccode_antlr.instr import Instr
4
4
  from mccode_antlr.common import Expr
5
5
  from nexusformat.nexus import NXfield, NXgroup, NXcollection
6
+ from typing import Union, Any
6
7
 
7
8
 
8
9
  @dataclass
@@ -51,12 +52,11 @@ class NXInstr:
51
52
  # quick and very dirty:
52
53
  return NXfield(str(self.instr))
53
54
 
54
- def expr2nx(self, expr: Expr):
55
+ def expr2nx(self, expr: Union[str, Expr, Any]):
55
56
  from moreniius.utils import link_specifier
56
- if isinstance(expr, list):
57
- return [self.expr2nx(x) for x in expr]
58
- if isinstance(expr, tuple):
59
- return tuple([self.expr2nx(x) for x in expr])
57
+ if not isinstance(expr, str) and hasattr(expr, '__iter__'):
58
+ parts = [self.expr2nx(x) for x in expr]
59
+ return tuple(parts) if isinstance(expr, tuple) else parts
60
60
  if not isinstance(expr, Expr):
61
61
  return expr
62
62
 
@@ -8,17 +8,19 @@ from mccode_antlr.instr import Instr
8
8
 
9
9
  def load_instr(filepath: str | Path) -> Instr:
10
10
  """Loads an Instr object from a .instr file or a HDF5 file"""
11
- from mccode_antlr.loader import load_mcstas_instr
12
- from mccode_antlr.io import load_hdf5
13
-
14
11
  if not isinstance(filepath, Path):
15
12
  filepath = Path(filepath)
16
13
  if not filepath.exists() or not filepath.is_file():
17
14
  raise ValueError('The provided filepath does not exist or is not a file')
18
15
 
19
16
  if filepath.suffix == '.instr':
17
+ from mccode_antlr.loader import load_mcstas_instr
20
18
  return load_mcstas_instr(filepath)
19
+ elif filepath.suffix.lower() == '.json':
20
+ from mccode_antlr.io.json import load_json
21
+ return load_json(filepath)
21
22
 
23
+ from mccode_antlr.io import load_hdf5
22
24
  return load_hdf5(filepath)
23
25
 
24
26
 
@@ -30,9 +32,9 @@ def to_nexus_structure(instr: Instr) -> dict:
30
32
 
31
33
 
32
34
  def convert():
33
- """Convert an Instr (HDF5) or .instr (text) file to an equivalent NeXus Structure JSON string"""
35
+ """Convert an Instr (HDF5|JSON) or .instr (text) file to an equivalent NeXus Structure JSON string"""
34
36
  import argparse
35
- parser = argparse.ArgumentParser(description='Convert an Instr (HDF5) or .instr (text) file to an equivalent NeXus Structure JSON string')
37
+ parser = argparse.ArgumentParser(description='Convert an Instr (HDF5|JSON) or .instr (text) file to an equivalent NeXus Structure JSON string')
36
38
  parser.add_argument('filename', type=str, help='the file to convert')
37
39
  parser.add_argument('--format', type=str, default='json', help='the output format, currently only json')
38
40
  args = parser.parse_args()
moreniius/writer.py CHANGED
@@ -9,10 +9,13 @@ def convert_types(obj, only_nx=True):
9
9
  if np_data_type.name == 'object':
10
10
  if isinstance(obj, ndarray):
11
11
  vl = obj.tolist()
12
- el = vl[0]
13
- for ii in range(1, len(obj.shape)):
14
- el = el[0]
15
- tp = dtype(type(el)).name
12
+ if len(vl):
13
+ el = vl[0]
14
+ for ii in range(1, len(obj.shape)):
15
+ el = el[0]
16
+ tp = dtype(type(el)).name
17
+ else:
18
+ tp = obj.dtype.name
16
19
  elif obj is None:
17
20
  (tp, vl) = ('string', 'None')
18
21
  elif isinstance(obj, NXattr):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: moreniius
3
- Version: 0.3.0
3
+ Version: 0.5.0
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
@@ -14,7 +14,7 @@ Classifier: Programming Language :: Python :: 3.13
14
14
  Description-Content-Type: text/markdown
15
15
  Requires-Dist: zenlog>=1.1
16
16
  Requires-Dist: platformdirs>=3.11
17
- Requires-Dist: mccode-antlr[hdf5]>=0.13.0
17
+ Requires-Dist: mccode-antlr[hdf5]>=0.15.0
18
18
  Requires-Dist: nexusformat>=1.0.6
19
19
 
20
20
  # moreniius
@@ -1,18 +1,18 @@
1
1
  moreniius/__init__.py,sha256=33SUBkXWhH5rog5oaGJr1Kwqjhwz97w4E0Da7rArYi4,154
2
2
  moreniius/additions.py,sha256=6Hhhc4LDUsnBj27Iil-EFFzQm1xd2M45hfcVQYEjxiI,17615
3
3
  moreniius/moreniius.py,sha256=cU3CrfMC1kOnHO77yq5sZfDqRuA38G5kA3RUXFNGP2U,1455
4
- moreniius/nexus_structure.py,sha256=i9CxYwJl4eKP9IIYR80MI3f54Yh0RPDFviZaulE5IOc,1709
4
+ moreniius/nexus_structure.py,sha256=C_ohhilsE6xdfSpFVhsFEK9EC3sBXPGWxCIGk_4UFvI,1853
5
5
  moreniius/nxoff.py,sha256=WHp9wYNn_4Hcx8Nzi9rpX1p8_iwI-AdgTQouSAEG8N4,3288
6
6
  moreniius/utils.py,sha256=R81eHjc0EWjMsP-Z8WI9sZkc_QY357z_aYziflQAUEU,9238
7
- moreniius/writer.py,sha256=rZSOpSmCAiY1KS3YAWKBXZUWTJFLyrkZT-zeZfyENV8,6178
7
+ moreniius/writer.py,sha256=BwAyc2_QCUir-zhELYl9OHItXepF3w7nRPTnbZ73XNU,6272
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=yydYeMGITlZrVWBVYregBWQ0Sd_2A71hgoyCrLLW-Jk,8058
11
- moreniius/mccode/instr.py,sha256=G00MuwhH1QS7gZvABG5BdywFOB2AtqViwbSLyG_u0wk,6104
11
+ moreniius/mccode/instr.py,sha256=D4B3ylD4BMfkiP5t2hx5xop9c7yk7QVSleT1wvpK17E,6161
12
12
  moreniius/mccode/mccode.py,sha256=6NEXovuG-6itzlPgPklNOiZQ-MlldKF20p4TxV8n4BA,3228
13
13
  moreniius/mccode/orientation.py,sha256=khT0jTMXyXkPCoEpDg-eLKulF-J2wIqNhUi1NzFWvto,3907
14
- moreniius-0.3.0.dist-info/METADATA,sha256=UZiXt1i-PnN78u8V7sk0bgHx2FDxzrMX3eifvOZzIsQ,921
15
- moreniius-0.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
- moreniius-0.3.0.dist-info/entry_points.txt,sha256=Ga3k4P4fyBt5_dJ03Oapic2Qlgqv9jufQGdxWiz_j2A,63
17
- moreniius-0.3.0.dist-info/top_level.txt,sha256=RzMo23UfVhgQeuOYeS5P9I0qVbxx4Gbe6Roc29Mr02c,10
18
- moreniius-0.3.0.dist-info/RECORD,,
14
+ moreniius-0.5.0.dist-info/METADATA,sha256=M8vrLMY1YIKnCeJ3upoONyoZ6_hgX_5dfqVFzGa5XkU,921
15
+ moreniius-0.5.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
+ moreniius-0.5.0.dist-info/entry_points.txt,sha256=Ga3k4P4fyBt5_dJ03Oapic2Qlgqv9jufQGdxWiz_j2A,63
17
+ moreniius-0.5.0.dist-info/top_level.txt,sha256=RzMo23UfVhgQeuOYeS5P9I0qVbxx4Gbe6Roc29Mr02c,10
18
+ moreniius-0.5.0.dist-info/RECORD,,