-
Notifications
You must be signed in to change notification settings - Fork 271
Expand file tree
/
Copy pathserialize_objects.py
More file actions
46 lines (37 loc) · 1.78 KB
/
Copy pathserialize_objects.py
File metadata and controls
46 lines (37 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
"""
Generate cross-version serialization fixtures with the *installed* spikeinterface.
Run this under an OLD spikeinterface release to produce the fixtures that the current
code then loads (see src/spikeinterface/core/tests/test_cross_version_serialization.py):
python serialize_objects.py [output_dir]
If output_dir is omitted, fixtures are written to ./serialization_fixtures.
The CI workflow cross_version_serialization.yml does this automatically.
"""
import sys
from pathlib import Path
import spikeinterface
sys.path.insert(0, str(Path(__file__).parent))
from objects import OBJECTS, FIXTURE_SUFFIX # noqa: E402
out_dir = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("serialization_fixtures")
out_dir.mkdir(parents=True, exist_ok=True) # do not rmtree an arbitrary path; overwrite in place
print(f"Generating serialization fixtures with spikeinterface {spikeinterface.__version__}")
for entry in OBJECTS:
obj = entry["build"]()
for fmt in entry["formats"]:
dest = out_dir / f"{entry['id']}{FIXTURE_SUFFIX[fmt]}"
if fmt == "json":
obj.dump_to_json(dest)
elif fmt == "pickle":
obj.dump_to_pickle(dest)
elif fmt == "binary":
obj.save(folder=dest, format="binary", overwrite=True)
elif fmt == "binary_parallel":
obj.save(folder=dest, format="binary", overwrite=True, n_jobs=2)
elif fmt == "numpy_folder":
obj.save(folder=dest, format="numpy_folder", overwrite=True)
elif fmt == "zarr":
obj.save(folder=dest, format="zarr", overwrite=True)
elif fmt == "zarr_parallel":
obj.save(folder=dest, format="zarr", overwrite=True, n_jobs=2)
print(f" wrote {dest.name} ({fmt})")
print(f"Fixtures written to: {out_dir.resolve()}")