jdata 0.9.3__tar.gz → 0.9.5__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.
- {jdata-0.9.3/jdata.egg-info → jdata-0.9.5}/PKG-INFO +38 -14
- {jdata-0.9.3 → jdata-0.9.5}/README.md +1 -1
- jdata-0.9.5/jdata/__init__.py +91 -0
- jdata-0.9.3/jdata/csv.py → jdata-0.9.5/jdata/csvtsv.py +5 -15
- {jdata-0.9.3 → jdata-0.9.5}/jdata/h5.py +20 -54
- {jdata-0.9.3 → jdata-0.9.5}/jdata/jdata.py +446 -76
- jdata-0.9.3/jdata/jdict.py → jdata-0.9.5/jdata/jdictionary.py +12 -26
- {jdata-0.9.3 → jdata-0.9.5}/jdata/jfile.py +386 -125
- {jdata-0.9.3 → jdata-0.9.5}/jdata/jgifti.py +13 -38
- {jdata-0.9.3 → jdata-0.9.5}/jdata/jnifti.py +34 -92
- {jdata-0.9.3 → jdata-0.9.5}/jdata/jpath.py +38 -13
- {jdata-0.9.3 → jdata-0.9.5}/jdata/jschema.py +50 -45
- {jdata-0.9.3 → jdata-0.9.5}/jdata/neurojson.py +40 -81
- {jdata-0.9.3 → jdata-0.9.5}/jdata/njprep.py +29 -60
- {jdata-0.9.3 → jdata-0.9.5/jdata.egg-info}/PKG-INFO +38 -14
- {jdata-0.9.3 → jdata-0.9.5}/jdata.egg-info/SOURCES.txt +4 -2
- jdata-0.9.5/jdata.egg-info/requires.txt +37 -0
- jdata-0.9.5/pyproject.toml +63 -0
- {jdata-0.9.3 → jdata-0.9.5}/setup.cfg +2 -2
- {jdata-0.9.3 → jdata-0.9.5}/setup.py +2 -3
- jdata-0.9.5/test/test_comprehensive.py +1711 -0
- {jdata-0.9.3 → jdata-0.9.5}/test/testgifti.py +3 -9
- {jdata-0.9.3 → jdata-0.9.5}/test/testjd.py +2 -6
- {jdata-0.9.3 → jdata-0.9.5}/test/testjdict.py +9 -25
- {jdata-0.9.3 → jdata-0.9.5}/test/testnifti.py +3 -9
- {jdata-0.9.3 → jdata-0.9.5}/test/testsnirf.py +4 -12
- jdata-0.9.3/jdata/__init__.py +0 -258
- jdata-0.9.3/jdata.egg-info/requires.txt +0 -1
- {jdata-0.9.3 → jdata-0.9.5}/LICENSE.txt +0 -0
- {jdata-0.9.3 → jdata-0.9.5}/MANIFEST.in +0 -0
- {jdata-0.9.3 → jdata-0.9.5}/jdata/__main__.py +0 -0
- {jdata-0.9.3 → jdata-0.9.5}/jdata.egg-info/dependency_links.txt +0 -0
- {jdata-0.9.3 → jdata-0.9.5}/jdata.egg-info/top_level.txt +0 -0
- {jdata-0.9.3 → jdata-0.9.5}/test/testneuroj.py +0 -0
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: jdata
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.5
|
|
4
4
|
Summary: JSON/binary JSON formats for exchanging Python and Numpy data
|
|
5
5
|
Home-page: https://github.com/NeuroJSON/pyjdata
|
|
6
6
|
Author: Qianqian Fang
|
|
7
|
-
Author-email: fangqq@gmail.com
|
|
7
|
+
Author-email: Qianqian Fang <fangqq@gmail.com>
|
|
8
8
|
Maintainer: Qianqian Fang
|
|
9
|
-
|
|
9
|
+
Maintainer-email: Qianqian Fang <fangqq@gmail.com>
|
|
10
|
+
License: Apache-2.0
|
|
11
|
+
Project-URL: Homepage, https://github.com/NeuroJSON/pyjdata
|
|
12
|
+
Project-URL: Documentation, https://github.com/NeuroJSON/pyjdata#readme
|
|
13
|
+
Project-URL: Repository, https://github.com/NeuroJSON/pyjdata
|
|
14
|
+
Project-URL: Issues, https://github.com/NeuroJSON/pyjdata/issues
|
|
10
15
|
Keywords: JSON,JData,UBJSON,BJData,OpenJData,NeuroJSON,JNIfTI,JMesh,Encoder,Decoder
|
|
11
16
|
Platform: any
|
|
12
17
|
Classifier: Development Status :: 4 - Beta
|
|
13
18
|
Classifier: Intended Audience :: Developers
|
|
14
19
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
20
|
Classifier: Programming Language :: Python :: 2.7
|
|
17
21
|
Classifier: Programming Language :: Python :: 3
|
|
18
22
|
Classifier: Programming Language :: Python :: 3.4
|
|
@@ -25,24 +29,44 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
25
29
|
Classifier: Programming Language :: Python :: 3.11
|
|
26
30
|
Classifier: Programming Language :: Python :: 3.12
|
|
27
31
|
Classifier: Programming Language :: Python :: 3.13
|
|
32
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
28
33
|
Classifier: Topic :: Software Development :: Libraries
|
|
29
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
30
34
|
Description-Content-Type: text/markdown
|
|
31
35
|
License-File: LICENSE.txt
|
|
32
36
|
Requires-Dist: numpy>=1.8.0
|
|
37
|
+
Provides-Extra: bjdata
|
|
38
|
+
Requires-Dist: bjdata; extra == "bjdata"
|
|
39
|
+
Provides-Extra: lz4
|
|
40
|
+
Requires-Dist: lz4; extra == "lz4"
|
|
41
|
+
Provides-Extra: hdf5
|
|
42
|
+
Requires-Dist: h5py; extra == "hdf5"
|
|
43
|
+
Provides-Extra: matlab
|
|
44
|
+
Requires-Dist: scipy; extra == "matlab"
|
|
45
|
+
Provides-Extra: msgpack
|
|
46
|
+
Requires-Dist: msgpack; extra == "msgpack"
|
|
47
|
+
Provides-Extra: blosc2
|
|
48
|
+
Requires-Dist: blosc2; extra == "blosc2"
|
|
49
|
+
Provides-Extra: all
|
|
50
|
+
Requires-Dist: bjdata; extra == "all"
|
|
51
|
+
Requires-Dist: lz4; extra == "all"
|
|
52
|
+
Requires-Dist: h5py; extra == "all"
|
|
53
|
+
Requires-Dist: scipy; extra == "all"
|
|
54
|
+
Requires-Dist: msgpack; extra == "all"
|
|
55
|
+
Requires-Dist: blosc2; extra == "all"
|
|
56
|
+
Provides-Extra: dev
|
|
57
|
+
Requires-Dist: bjdata; extra == "dev"
|
|
58
|
+
Requires-Dist: lz4; extra == "dev"
|
|
59
|
+
Requires-Dist: h5py; extra == "dev"
|
|
60
|
+
Requires-Dist: scipy; extra == "dev"
|
|
61
|
+
Requires-Dist: msgpack; extra == "dev"
|
|
62
|
+
Requires-Dist: blosc2; extra == "dev"
|
|
63
|
+
Requires-Dist: black; extra == "dev"
|
|
64
|
+
Requires-Dist: build; extra == "dev"
|
|
33
65
|
Dynamic: author
|
|
34
|
-
Dynamic: author-email
|
|
35
|
-
Dynamic: classifier
|
|
36
|
-
Dynamic: description
|
|
37
|
-
Dynamic: description-content-type
|
|
38
66
|
Dynamic: home-page
|
|
39
|
-
Dynamic: keywords
|
|
40
|
-
Dynamic: license
|
|
41
67
|
Dynamic: license-file
|
|
42
68
|
Dynamic: maintainer
|
|
43
69
|
Dynamic: platform
|
|
44
|
-
Dynamic: requires-dist
|
|
45
|
-
Dynamic: summary
|
|
46
70
|
|
|
47
71
|

|
|
48
72
|
|
|
@@ -50,7 +74,7 @@ Dynamic: summary
|
|
|
50
74
|
|
|
51
75
|
- Copyright: (C) Qianqian Fang (2019-2026) <q.fang at neu.edu>
|
|
52
76
|
- License: Apache License, Version 2.0
|
|
53
|
-
- Version: 0.9.
|
|
77
|
+
- Version: 0.9.4
|
|
54
78
|
- URL: https://github.com/NeuroJSON/pyjdata
|
|
55
79
|
- Acknowledgement: This project is supported by US National Institute of Health (NIH)
|
|
56
80
|
grant [U24-NS124027](https://reporter.nih.gov/project-details/10308329)
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
- Copyright: (C) Qianqian Fang (2019-2026) <q.fang at neu.edu>
|
|
6
6
|
- License: Apache License, Version 2.0
|
|
7
|
-
- Version: 0.9.
|
|
7
|
+
- Version: 0.9.4
|
|
8
8
|
- URL: https://github.com/NeuroJSON/pyjdata
|
|
9
9
|
- Acknowledgement: This project is supported by US National Institute of Health (NIH)
|
|
10
10
|
grant [U24-NS124027](https://reporter.nih.gov/project-details/10308329)
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""pyjdata - encode and decode Python data structrues using portable JData formats
|
|
2
|
+
|
|
3
|
+
This module provides an encoder and a decoder to convert a python/numpy native
|
|
4
|
+
data structure into a JData-compatible structure, or decode JData constructs to
|
|
5
|
+
restore python native data.
|
|
6
|
+
|
|
7
|
+
import jdata as jd
|
|
8
|
+
|
|
9
|
+
jdata = jd.encode(pydata)
|
|
10
|
+
newpydata = jd.decode(jdata)
|
|
11
|
+
|
|
12
|
+
jd.save(jdata,filename)
|
|
13
|
+
jdata=jd.load(filename)
|
|
14
|
+
|
|
15
|
+
The function ``encode`` converts the below python/numpy/pandas data types
|
|
16
|
+
into JData compatible dict-based objects
|
|
17
|
+
|
|
18
|
+
* python dict objects ==> unchanged (JData/JSON objects)
|
|
19
|
+
* python string objects ==> unchanged (JData/JSON strings)
|
|
20
|
+
* python unicode objects ==> unchanged (JData/JSON strings)
|
|
21
|
+
* python numeric objects ==> unchanged (JData/JSON values)
|
|
22
|
+
* python list objects ==> unchanged (JData/JSON arrays)
|
|
23
|
+
* python tuple objects ==> unchanged (JData/JSON arrays)
|
|
24
|
+
* python range objects ==> unchanged (JData/JSON arrays)
|
|
25
|
+
* python bytes/bytearray objects ==> unchanged (JData/JSON bytestream)
|
|
26
|
+
* python set objects ==> unchanged (JData/JSON arrays)
|
|
27
|
+
* python complex numbers and complex arrays ==> JData complex array objects
|
|
28
|
+
* numpy.ndarray objects ==> JData array objects
|
|
29
|
+
* python tables ==> JData table objects
|
|
30
|
+
* pandas.DataFrame objects ==> JData table objects
|
|
31
|
+
|
|
32
|
+
The JData-encoded data object can then be decoded using ``decode``
|
|
33
|
+
to restore the original data types
|
|
34
|
+
|
|
35
|
+
Copyright (c) 2019-2026 Qianqian Fang <q.fang at neu.edu>
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
from . import jdata
|
|
39
|
+
from . import jfile
|
|
40
|
+
from . import jdictionary
|
|
41
|
+
from . import csvtsv
|
|
42
|
+
from . import h5
|
|
43
|
+
from . import jnifti
|
|
44
|
+
from . import jgifti
|
|
45
|
+
from . import jpath
|
|
46
|
+
from . import jschema
|
|
47
|
+
from . import njprep
|
|
48
|
+
from . import neurojson
|
|
49
|
+
|
|
50
|
+
# Re-export all public functions from submodules
|
|
51
|
+
from .jdata import *
|
|
52
|
+
from .jfile import *
|
|
53
|
+
from .jdictionary import *
|
|
54
|
+
from .csvtsv import *
|
|
55
|
+
from .h5 import *
|
|
56
|
+
from .jnifti import *
|
|
57
|
+
from .jgifti import *
|
|
58
|
+
from .jpath import *
|
|
59
|
+
from .jschema import *
|
|
60
|
+
from .njprep import *
|
|
61
|
+
from .neurojson import *
|
|
62
|
+
|
|
63
|
+
__version__ = "0.9.5"
|
|
64
|
+
__all__ = (
|
|
65
|
+
jdata.__all__
|
|
66
|
+
+ jfile.__all__
|
|
67
|
+
+ jdictionary.__all__
|
|
68
|
+
+ csvtsv.__all__
|
|
69
|
+
+ h5.__all__
|
|
70
|
+
+ jnifti.__all__
|
|
71
|
+
+ jgifti.__all__
|
|
72
|
+
+ jpath.__all__
|
|
73
|
+
+ jschema.__all__
|
|
74
|
+
+ njprep.__all__
|
|
75
|
+
+ neurojson.__all__
|
|
76
|
+
+ [
|
|
77
|
+
"jdata",
|
|
78
|
+
"jfile",
|
|
79
|
+
"jdictionary",
|
|
80
|
+
"csvtsv",
|
|
81
|
+
"h5",
|
|
82
|
+
"jnifti",
|
|
83
|
+
"jgifti",
|
|
84
|
+
"jpath",
|
|
85
|
+
"jschema",
|
|
86
|
+
"neurojson",
|
|
87
|
+
"njprep",
|
|
88
|
+
]
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
__license__ = """Apache license 2.0, Copyright (c) 2019-2026 Qianqian Fang"""
|
|
@@ -211,9 +211,7 @@ def group_column(column: List[str]) -> List[Any]:
|
|
|
211
211
|
converted = [tonumbers(value) for value in column]
|
|
212
212
|
|
|
213
213
|
# Check if all non-NaN values are numeric
|
|
214
|
-
numeric_count = sum(
|
|
215
|
-
1 for x in converted if isinstance(x, (int, float)) and not np.isnan(x)
|
|
216
|
-
)
|
|
214
|
+
numeric_count = sum(1 for x in converted if isinstance(x, (int, float)) and not np.isnan(x))
|
|
217
215
|
nan_count = sum(1 for x in converted if isinstance(x, float) and np.isnan(x))
|
|
218
216
|
total_numeric = numeric_count + nan_count
|
|
219
217
|
|
|
@@ -417,9 +415,7 @@ def encode_enum_column(values: List[Any], compress: bool = True) -> Union[List,
|
|
|
417
415
|
]
|
|
418
416
|
)
|
|
419
417
|
|
|
420
|
-
return OrderedDict(
|
|
421
|
-
[("_EnumKey_", list(enum_map.keys())), ("_EnumValue_", enum_value)]
|
|
422
|
-
)
|
|
418
|
+
return OrderedDict([("_EnumKey_", list(enum_map.keys())), ("_EnumValue_", enum_value)])
|
|
423
419
|
|
|
424
420
|
|
|
425
421
|
def decode_enum_column(data: Dict) -> List[Any]:
|
|
@@ -474,9 +470,7 @@ def decode_enum_column(data: Dict) -> List[Any]:
|
|
|
474
470
|
raise ValueError("_EnumValue_ must contain _ArrayZipData_ or _ArrayData_")
|
|
475
471
|
|
|
476
472
|
# Map indices back to values (indices are 1-based)
|
|
477
|
-
result = [
|
|
478
|
-
enum_keys[idx - 1] if 0 < idx <= len(enum_keys) else None for idx in indices
|
|
479
|
-
]
|
|
473
|
+
result = [enum_keys[idx - 1] if 0 < idx <= len(enum_keys) else None for idx in indices]
|
|
480
474
|
|
|
481
475
|
return result
|
|
482
476
|
|
|
@@ -530,9 +524,7 @@ def tsv2json(
|
|
|
530
524
|
for col_name, col_values in data.items():
|
|
531
525
|
# Skip encoding for certain columns
|
|
532
526
|
should_skip = col_name in skip_columns
|
|
533
|
-
if is_participants and any(
|
|
534
|
-
x in col_name.lower() for x in ["age", "sex", "gender"]
|
|
535
|
-
):
|
|
527
|
+
if is_participants and any(x in col_name.lower() for x in ["age", "sex", "gender"]):
|
|
536
528
|
should_skip = True
|
|
537
529
|
|
|
538
530
|
if should_skip:
|
|
@@ -669,9 +661,7 @@ def save_csv_tsv_with_enum(
|
|
|
669
661
|
|
|
670
662
|
for col_name, col_values in data.items():
|
|
671
663
|
should_skip = col_name in skip_columns
|
|
672
|
-
if is_participants and any(
|
|
673
|
-
x in col_name.lower() for x in ["age", "sex", "gender"]
|
|
674
|
-
):
|
|
664
|
+
if is_participants and any(x in col_name.lower() for x in ["age", "sex", "gender"]):
|
|
675
665
|
should_skip = True
|
|
676
666
|
|
|
677
667
|
if should_skip or not compress_enum:
|
|
@@ -231,8 +231,7 @@ def loadh5(filename, *args, **kwargs) -> Union[Dict, Tuple[Dict, Dict]]:
|
|
|
231
231
|
|
|
232
232
|
if opt["complexformat"][1] in data:
|
|
233
233
|
spd[indices] = (
|
|
234
|
-
data[opt["complexformat"][0]]
|
|
235
|
-
+ 1j * data[opt["complexformat"][1]]
|
|
234
|
+
data[opt["complexformat"][0]] + 1j * data[opt["complexformat"][1]]
|
|
236
235
|
)
|
|
237
236
|
else:
|
|
238
237
|
spd[indices] = data[opt["complexformat"][0]]
|
|
@@ -252,9 +251,9 @@ def loadh5(filename, *args, **kwargs) -> Union[Dict, Tuple[Dict, Dict]]:
|
|
|
252
251
|
|
|
253
252
|
for real_key, imag_key in complex_pairs:
|
|
254
253
|
if len(set(fields) & {real_key, imag_key}) == 2:
|
|
255
|
-
if isinstance(
|
|
256
|
-
data.get(
|
|
257
|
-
)
|
|
254
|
+
if isinstance(data.get(real_key), (np.ndarray, int, float)) and isinstance(
|
|
255
|
+
data.get(imag_key), (np.ndarray, int, float)
|
|
256
|
+
):
|
|
258
257
|
data = data[real_key] + 1j * data[imag_key]
|
|
259
258
|
break
|
|
260
259
|
|
|
@@ -262,9 +261,7 @@ def loadh5(filename, *args, **kwargs) -> Union[Dict, Tuple[Dict, Dict]]:
|
|
|
262
261
|
if isinstance(data, (list, np.ndarray)) and len(data) > 0:
|
|
263
262
|
if isinstance(data, np.ndarray) and data.dtype.kind in ["S", "U"]:
|
|
264
263
|
data = data.astype(str)
|
|
265
|
-
elif isinstance(data, list) and all(
|
|
266
|
-
isinstance(x, (str, bytes)) for x in data
|
|
267
|
-
):
|
|
264
|
+
elif isinstance(data, list) and all(isinstance(x, (str, bytes)) for x in data):
|
|
268
265
|
if opt.get("stringarray", 0):
|
|
269
266
|
data = np.array(data, dtype=str)
|
|
270
267
|
|
|
@@ -334,9 +331,7 @@ def loadh5(filename, *args, **kwargs) -> Union[Dict, Tuple[Dict, Dict]]:
|
|
|
334
331
|
if gname in loc:
|
|
335
332
|
rootgid = loc[gname]
|
|
336
333
|
data, meta = {}, {}
|
|
337
|
-
group_iterate(
|
|
338
|
-
rootgid, dname, {"data": data, "meta": meta, "opt": opt}
|
|
339
|
-
)
|
|
334
|
+
group_iterate(rootgid, dname, {"data": data, "meta": meta, "opt": opt})
|
|
340
335
|
else:
|
|
341
336
|
raise KeyError(f"Path {path} not found")
|
|
342
337
|
except Exception:
|
|
@@ -469,9 +464,7 @@ def saveh5(data: Any, fname, *args, **kwargs):
|
|
|
469
464
|
"""
|
|
470
465
|
return obj2h5(f"{name}{idx}", item, handle, level, opt)
|
|
471
466
|
|
|
472
|
-
def cell2h5(
|
|
473
|
-
name: str, item: List, handle: h5py.Group, level: int, opt: Dict
|
|
474
|
-
) -> List:
|
|
467
|
+
def cell2h5(name: str, item: List, handle: h5py.Group, level: int, opt: Dict) -> List:
|
|
475
468
|
"""
|
|
476
469
|
Convert Python list to HDF5 groups/datasets
|
|
477
470
|
|
|
@@ -497,9 +490,7 @@ def saveh5(data: Any, fname, *args, **kwargs):
|
|
|
497
490
|
# Single element
|
|
498
491
|
return [obj2h5(name, item[0], handle, level, opt)] if item else []
|
|
499
492
|
|
|
500
|
-
def struct2h5(
|
|
501
|
-
name: str, item: Dict, handle: h5py.Group, level: int, opt: Dict
|
|
502
|
-
) -> List:
|
|
493
|
+
def struct2h5(name: str, item: Dict, handle: h5py.Group, level: int, opt: Dict) -> List:
|
|
503
494
|
"""
|
|
504
495
|
Convert Python dictionary to HDF5 group
|
|
505
496
|
|
|
@@ -527,9 +518,7 @@ def saveh5(data: Any, fname, *args, **kwargs):
|
|
|
527
518
|
oid = []
|
|
528
519
|
|
|
529
520
|
for field_name in names:
|
|
530
|
-
field_handle = obj2h5(
|
|
531
|
-
field_name, item[field_name], group_handle, level + 1, opt
|
|
532
|
-
)
|
|
521
|
+
field_handle = obj2h5(field_name, item[field_name], group_handle, level + 1, opt)
|
|
533
522
|
oid.append(field_handle)
|
|
534
523
|
|
|
535
524
|
return oid
|
|
@@ -748,9 +737,7 @@ def saveh5(data: Any, fname, *args, **kwargs):
|
|
|
748
737
|
data["Real"] = item_copy["Real"]
|
|
749
738
|
data["Imag"] = item_copy["Imag"]
|
|
750
739
|
else:
|
|
751
|
-
dt = np.dtype(
|
|
752
|
-
[("SparseIndex", idx.dtype), ("Real", item_copy["Real"].dtype)]
|
|
753
|
-
)
|
|
740
|
+
dt = np.dtype([("SparseIndex", idx.dtype), ("Real", item_copy["Real"].dtype)])
|
|
754
741
|
data = np.empty(len(idx), dtype=dt)
|
|
755
742
|
data["SparseIndex"] = idx
|
|
756
743
|
data["Real"] = item_copy["Real"]
|
|
@@ -791,9 +778,7 @@ def saveh5(data: Any, fname, *args, **kwargs):
|
|
|
791
778
|
# Set default options
|
|
792
779
|
opt["compression"] = opt.get("Compression", opt.get("compression", ""))
|
|
793
780
|
opt["compresslevel"] = opt.get("CompressLevel", opt.get("compresslevel", 5))
|
|
794
|
-
opt["compressarraysize"] = opt.get(
|
|
795
|
-
"CompressArraySize", opt.get("compressarraysize", 100)
|
|
796
|
-
)
|
|
781
|
+
opt["compressarraysize"] = opt.get("CompressArraySize", opt.get("compressarraysize", 100))
|
|
797
782
|
opt["unpackhex"] = opt.get("UnpackHex", opt.get("unpackhex", 1))
|
|
798
783
|
opt["dotranspose"] = opt.get("Transpose", opt.get("transpose", 0))
|
|
799
784
|
opt["variablelengthstring"] = opt.get(
|
|
@@ -906,11 +891,7 @@ def regrouph5(root: Union[Dict, Any], *args) -> Dict:
|
|
|
906
891
|
for i, name in enumerate(names):
|
|
907
892
|
# Use regex to match pattern: prefix + digits
|
|
908
893
|
match = re.match(r"^(.*\D)(\d+)$", name)
|
|
909
|
-
if (
|
|
910
|
-
match
|
|
911
|
-
and int(match.group(2)) != 0
|
|
912
|
-
and match.group(1) not in root_list[0]
|
|
913
|
-
):
|
|
894
|
+
if match and int(match.group(2)) != 0 and match.group(1) not in root_list[0]:
|
|
914
895
|
prefix = match.group(1)
|
|
915
896
|
number = int(match.group(2))
|
|
916
897
|
|
|
@@ -977,15 +958,10 @@ def regrouph5(root: Union[Dict, Any], *args) -> Dict:
|
|
|
977
958
|
try:
|
|
978
959
|
# Check if all elements can be converted to numpy array
|
|
979
960
|
first_data = data[0][name]
|
|
980
|
-
if all(
|
|
981
|
-
isinstance(item, (int, float, complex, np.ndarray))
|
|
982
|
-
for item in first_data
|
|
983
|
-
):
|
|
961
|
+
if all(isinstance(item, (int, float, complex, np.ndarray)) for item in first_data):
|
|
984
962
|
# Try to stack arrays
|
|
985
963
|
if all(isinstance(item, np.ndarray) for item in first_data):
|
|
986
|
-
if all(
|
|
987
|
-
item.shape == first_data[0].shape for item in first_data
|
|
988
|
-
):
|
|
964
|
+
if all(item.shape == first_data[0].shape for item in first_data):
|
|
989
965
|
for j in range(len(data)):
|
|
990
966
|
# Use Fortran order (column-major) for flattening/stacking
|
|
991
967
|
data[j][name] = np.stack(data[j][name], axis=0)
|
|
@@ -993,7 +969,7 @@ def regrouph5(root: Union[Dict, Any], *args) -> Dict:
|
|
|
993
969
|
# Convert to numpy array for numeric data
|
|
994
970
|
for j in range(len(data)):
|
|
995
971
|
data[j][name] = np.array(data[j][name], order="F")
|
|
996
|
-
except:
|
|
972
|
+
except Exception:
|
|
997
973
|
# Keep as list if conversion fails
|
|
998
974
|
pass
|
|
999
975
|
|
|
@@ -1076,7 +1052,7 @@ def aos2soa(starray: Union[List[Dict], Dict]) -> Dict:
|
|
|
1076
1052
|
else:
|
|
1077
1053
|
# For scalars and other types, create numpy array or keep as list
|
|
1078
1054
|
st[field_name] = np.array(field_values, order="F")
|
|
1079
|
-
except:
|
|
1055
|
+
except Exception:
|
|
1080
1056
|
# Keep as list if concatenation fails
|
|
1081
1057
|
st[field_name] = field_values
|
|
1082
1058
|
|
|
@@ -1110,8 +1086,7 @@ def soa2aos(starray: Dict) -> List[Dict]:
|
|
|
1110
1086
|
|
|
1111
1087
|
# Get sizes of all fields
|
|
1112
1088
|
allsize = [
|
|
1113
|
-
len(v) if hasattr(v, "__len__") and not isinstance(v, str) else 1
|
|
1114
|
-
for v in starray.values()
|
|
1089
|
+
len(v) if hasattr(v, "__len__") and not isinstance(v, str) else 1 for v in starray.values()
|
|
1115
1090
|
]
|
|
1116
1091
|
|
|
1117
1092
|
# If not all fields have the same size, return original
|
|
@@ -1219,9 +1194,7 @@ def jsnirfcreate(*args, **kwargs) -> Dict:
|
|
|
1219
1194
|
jsn = OrderedDict()
|
|
1220
1195
|
|
|
1221
1196
|
# Return either a SNIRF data structure, or JSNIRF data (enclosed in SNIRFData tag)
|
|
1222
|
-
is_snirf = (
|
|
1223
|
-
len(args) == 1 and isinstance(args[0], str) and args[0].lower() == "snirf"
|
|
1224
|
-
) or (
|
|
1197
|
+
is_snirf = (len(args) == 1 and isinstance(args[0], str) and args[0].lower() == "snirf") or (
|
|
1225
1198
|
"format" in nirsdata
|
|
1226
1199
|
and isinstance(nirsdata["format"], str)
|
|
1227
1200
|
and nirsdata["format"].lower() == "snirf"
|
|
@@ -1309,12 +1282,7 @@ def snirfdecode(root: Dict, *args) -> Dict:
|
|
|
1309
1282
|
if isinstance(args[0], str) and args[0].lower() == "jsnirf":
|
|
1310
1283
|
issnirf = 0
|
|
1311
1284
|
|
|
1312
|
-
if
|
|
1313
|
-
issnirf == 0
|
|
1314
|
-
and "nirs" in data
|
|
1315
|
-
and "formatVersion" in data
|
|
1316
|
-
and "SNIRFData" not in data
|
|
1317
|
-
):
|
|
1285
|
+
if issnirf == 0 and "nirs" in data and "formatVersion" in data and "SNIRFData" not in data:
|
|
1318
1286
|
data["SNIRFData"] = data["nirs"]
|
|
1319
1287
|
|
|
1320
1288
|
# Handle measurementList conversion
|
|
@@ -1332,9 +1300,7 @@ def snirfdecode(root: Dict, *args) -> Dict:
|
|
|
1332
1300
|
for i in range(len(data["nirs"])):
|
|
1333
1301
|
data["SNIRFData"][i]["formatVersion"] = data["formatVersion"]
|
|
1334
1302
|
# Move formatVersion to first position (equivalent to orderfields)
|
|
1335
|
-
data["SNIRFData"][i] = _move_field_to_first(
|
|
1336
|
-
data["SNIRFData"][i], "formatVersion"
|
|
1337
|
-
)
|
|
1303
|
+
data["SNIRFData"][i] = _move_field_to_first(data["SNIRFData"][i], "formatVersion")
|
|
1338
1304
|
else:
|
|
1339
1305
|
data["SNIRFData"]["formatVersion"] = data["formatVersion"]
|
|
1340
1306
|
# Move formatVersion to first position
|