np_codeocean 0.3.5__py3-none-any.whl → 0.3.6__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.
- np_codeocean/__init__.py +1 -1
- np_codeocean/metadata/__init__.py +1 -1
- np_codeocean/metadata/common.py +1 -3
- np_codeocean/metadata/core.py +333 -331
- np_codeocean/metadata/dynamic_routing_task_etl.py +1 -1
- np_codeocean/metadata/model_templates/behavior_box.py +115 -115
- np_codeocean/metadata/model_templates/neuropixels_rig.py +544 -544
- np_codeocean/metadata/np.py +1 -1
- np_codeocean/metadata/rigs.py +1 -1
- np_codeocean/metadata/storage.py +78 -78
- np_codeocean/metadata/update.py +1 -2
- np_codeocean/metadata/utils.py +1 -1
- np_codeocean/np_session_utils.py +462 -385
- np_codeocean/scripts/upload_dynamic_routing_behavior.py +483 -413
- np_codeocean/scripts/upload_dynamic_routing_ecephys.py +279 -217
- np_codeocean/scripts/upload_split_recordings_example.py +39 -33
- np_codeocean/utils.py +671 -563
- {np_codeocean-0.3.5.dist-info → np_codeocean-0.3.6.dist-info}/METADATA +13 -6
- np_codeocean-0.3.6.dist-info/RECORD +23 -0
- {np_codeocean-0.3.5.dist-info → np_codeocean-0.3.6.dist-info}/WHEEL +2 -1
- {np_codeocean-0.3.5.dist-info → np_codeocean-0.3.6.dist-info}/entry_points.txt +0 -3
- np_codeocean-0.3.6.dist-info/top_level.txt +1 -0
- np_codeocean-0.3.5.dist-info/RECORD +0 -22
np_codeocean/metadata/np.py
CHANGED
np_codeocean/metadata/rigs.py
CHANGED
np_codeocean/metadata/storage.py
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
"""Stores a history of object changes in local storage. Simple updater and
|
|
2
|
-
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
import datetime
|
|
6
|
-
import json
|
|
7
|
-
import logging
|
|
8
|
-
import pathlib
|
|
9
|
-
import shutil
|
|
10
|
-
|
|
11
|
-
logger = logging.getLogger(__name__)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def _generate_item_filename(
|
|
15
|
-
*tags: str,
|
|
16
|
-
) -> str:
|
|
17
|
-
return "_".join(str(tag) for tag in tags) + "_rig.json"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
TIMESTAMP_FORMAT = "%Y-%m-%d-%H-%M-%S"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def _item_path_sorter(path: pathlib.Path) -> datetime.datetime:
|
|
24
|
-
mtime_str = path.stem.replace("_rig", "").split("_")[-1]
|
|
25
|
-
return datetime.datetime.strptime(mtime_str, TIMESTAMP_FORMAT)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def get_item(
|
|
29
|
-
storage_directory: pathlib.Path,
|
|
30
|
-
timestamp: datetime.datetime,
|
|
31
|
-
*_tags: str,
|
|
32
|
-
) -> pathlib.Path | None:
|
|
33
|
-
"""Gets latest item before or equal to timestamp."""
|
|
34
|
-
search_pattern = _generate_item_filename(*_tags, "*")
|
|
35
|
-
logger.info("Search pattern: %s" % search_pattern)
|
|
36
|
-
items = list(storage_directory.glob(search_pattern))
|
|
37
|
-
if not items:
|
|
38
|
-
logger.debug("No item found for tags: %s" % json.dumps(_tags))
|
|
39
|
-
return None
|
|
40
|
-
|
|
41
|
-
sorted_items = sorted(items, key=_item_path_sorter)
|
|
42
|
-
logger.debug("Fetched items: %s" % sorted_items)
|
|
43
|
-
logger.debug([_item_path_sorter(item) for item in sorted_items])
|
|
44
|
-
filtered = list(
|
|
45
|
-
filter(
|
|
46
|
-
lambda item: _item_path_sorter(item) <= timestamp,
|
|
47
|
-
sorted_items,
|
|
48
|
-
)
|
|
49
|
-
)
|
|
50
|
-
logger.debug("Filtered items: %s" % filtered)
|
|
51
|
-
if not filtered:
|
|
52
|
-
return None
|
|
53
|
-
return filtered[-1]
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def update_item(
|
|
57
|
-
storage_directory: pathlib.Path,
|
|
58
|
-
filepath: pathlib.Path,
|
|
59
|
-
timestamp: datetime.datetime,
|
|
60
|
-
*_tags: str,
|
|
61
|
-
) -> pathlib.Path:
|
|
62
|
-
"""
|
|
63
|
-
Notes
|
|
64
|
-
-----
|
|
65
|
-
- Also used to initialize a new base rig in local storage.
|
|
66
|
-
- If a rig with the same name doest not exist, a new rig will be created.
|
|
67
|
-
"""
|
|
68
|
-
filename = _generate_item_filename(
|
|
69
|
-
*_tags,
|
|
70
|
-
timestamp.strftime(TIMESTAMP_FORMAT),
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
return pathlib.Path(
|
|
74
|
-
shutil.copy2(
|
|
75
|
-
filepath,
|
|
76
|
-
storage_directory / filename,
|
|
77
|
-
)
|
|
78
|
-
)
|
|
1
|
+
"""Stores a history of object changes in local storage. Simple updater and
|
|
2
|
+
getter for iterations of a file.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import datetime
|
|
6
|
+
import json
|
|
7
|
+
import logging
|
|
8
|
+
import pathlib
|
|
9
|
+
import shutil
|
|
10
|
+
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _generate_item_filename(
|
|
15
|
+
*tags: str,
|
|
16
|
+
) -> str:
|
|
17
|
+
return "_".join(str(tag) for tag in tags) + "_rig.json"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
TIMESTAMP_FORMAT = "%Y-%m-%d-%H-%M-%S"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _item_path_sorter(path: pathlib.Path) -> datetime.datetime:
|
|
24
|
+
mtime_str = path.stem.replace("_rig", "").split("_")[-1]
|
|
25
|
+
return datetime.datetime.strptime(mtime_str, TIMESTAMP_FORMAT)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_item(
|
|
29
|
+
storage_directory: pathlib.Path,
|
|
30
|
+
timestamp: datetime.datetime,
|
|
31
|
+
*_tags: str,
|
|
32
|
+
) -> pathlib.Path | None:
|
|
33
|
+
"""Gets latest item before or equal to timestamp."""
|
|
34
|
+
search_pattern = _generate_item_filename(*_tags, "*")
|
|
35
|
+
logger.info("Search pattern: %s" % search_pattern)
|
|
36
|
+
items = list(storage_directory.glob(search_pattern))
|
|
37
|
+
if not items:
|
|
38
|
+
logger.debug("No item found for tags: %s" % json.dumps(_tags))
|
|
39
|
+
return None
|
|
40
|
+
|
|
41
|
+
sorted_items = sorted(items, key=_item_path_sorter)
|
|
42
|
+
logger.debug("Fetched items: %s" % sorted_items)
|
|
43
|
+
logger.debug([_item_path_sorter(item) for item in sorted_items])
|
|
44
|
+
filtered = list(
|
|
45
|
+
filter(
|
|
46
|
+
lambda item: _item_path_sorter(item) <= timestamp,
|
|
47
|
+
sorted_items,
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
logger.debug("Filtered items: %s" % filtered)
|
|
51
|
+
if not filtered:
|
|
52
|
+
return None
|
|
53
|
+
return filtered[-1]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def update_item(
|
|
57
|
+
storage_directory: pathlib.Path,
|
|
58
|
+
filepath: pathlib.Path,
|
|
59
|
+
timestamp: datetime.datetime,
|
|
60
|
+
*_tags: str,
|
|
61
|
+
) -> pathlib.Path:
|
|
62
|
+
"""
|
|
63
|
+
Notes
|
|
64
|
+
-----
|
|
65
|
+
- Also used to initialize a new base rig in local storage.
|
|
66
|
+
- If a rig with the same name doest not exist, a new rig will be created.
|
|
67
|
+
"""
|
|
68
|
+
filename = _generate_item_filename(
|
|
69
|
+
*_tags,
|
|
70
|
+
timestamp.strftime(TIMESTAMP_FORMAT),
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
return pathlib.Path(
|
|
74
|
+
shutil.copy2(
|
|
75
|
+
filepath,
|
|
76
|
+
storage_directory / filename,
|
|
77
|
+
)
|
|
78
|
+
)
|
np_codeocean/metadata/update.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import datetime
|
|
3
2
|
import logging
|
|
4
3
|
import pathlib
|
|
@@ -153,4 +152,4 @@ def update_rig(
|
|
|
153
152
|
else:
|
|
154
153
|
update_rig_modification_date(build_source, datetime.date.today())
|
|
155
154
|
|
|
156
|
-
return pathlib.Path(shutil.copy2(build_source, output_path))
|
|
155
|
+
return pathlib.Path(shutil.copy2(build_source, output_path))
|
np_codeocean/metadata/utils.py
CHANGED