np-workflows 1.6.86__py3-none-any.whl → 1.6.88__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_workflows/experiments/openscope_v2/__init__.py +2 -0
- np_workflows/experiments/openscope_v2/main_v2_pilot.py +217 -0
- np_workflows/experiments/openscope_v2/v2_workflow_widget.py +83 -0
- np_workflows/shared/base_experiments.py +8 -2
- {np_workflows-1.6.86.dist-info → np_workflows-1.6.88.dist-info}/METADATA +1 -1
- {np_workflows-1.6.86.dist-info → np_workflows-1.6.88.dist-info}/RECORD +8 -5
- {np_workflows-1.6.86.dist-info → np_workflows-1.6.88.dist-info}/WHEEL +1 -1
- {np_workflows-1.6.86.dist-info → np_workflows-1.6.88.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import configparser
|
|
2
|
+
import contextlib
|
|
3
|
+
import copy
|
|
4
|
+
import dataclasses
|
|
5
|
+
import datetime
|
|
6
|
+
import enum
|
|
7
|
+
import functools
|
|
8
|
+
import pathlib
|
|
9
|
+
import platform
|
|
10
|
+
import shutil
|
|
11
|
+
import threading
|
|
12
|
+
import time
|
|
13
|
+
import zlib
|
|
14
|
+
from typing import ClassVar, Literal, NamedTuple, NoReturn, Optional, TypedDict
|
|
15
|
+
|
|
16
|
+
import IPython
|
|
17
|
+
import IPython.display
|
|
18
|
+
import ipywidgets as ipw
|
|
19
|
+
import np_config
|
|
20
|
+
import np_logging
|
|
21
|
+
import np_services
|
|
22
|
+
import np_session
|
|
23
|
+
import np_workflows
|
|
24
|
+
import PIL.Image
|
|
25
|
+
import pydantic
|
|
26
|
+
from pyparsing import Any
|
|
27
|
+
from np_services import (
|
|
28
|
+
Service,
|
|
29
|
+
Finalizable,
|
|
30
|
+
ScriptCamstim, SessionCamstim,
|
|
31
|
+
SessionCamstim,
|
|
32
|
+
OpenEphys,
|
|
33
|
+
Sync,
|
|
34
|
+
VideoMVR,
|
|
35
|
+
NewScaleCoordinateRecorder,
|
|
36
|
+
MouseDirector,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
logger = np_logging.getLogger(__name__)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class V2Session(enum.Enum):
|
|
43
|
+
"""Enum for the different sessions available, each with different param sets."""
|
|
44
|
+
|
|
45
|
+
PRETEST = "pretest"
|
|
46
|
+
HAB = "hab"
|
|
47
|
+
EPHYS = "ephys"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class V2Mixin:
|
|
51
|
+
"""Provides project-specific methods and attributes, mainly related to camstim scripts."""
|
|
52
|
+
|
|
53
|
+
workflow: V2Session
|
|
54
|
+
"""Enum for particular workflow/session, e.g. PRETEST, HAB_60, HAB_90,
|
|
55
|
+
EPHYS."""
|
|
56
|
+
|
|
57
|
+
session: np_session.PipelineSession
|
|
58
|
+
mouse: np_session.Mouse
|
|
59
|
+
user: np_session.User
|
|
60
|
+
platform_json: np_session.PlatformJson
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def recorders(self) -> tuple[Service, ...]:
|
|
64
|
+
"""Services to be started before stimuli run, and stopped after. Session-dependent."""
|
|
65
|
+
match self.workflow:
|
|
66
|
+
case V2Session.PRETEST | V2Session.EPHYS:
|
|
67
|
+
return (Sync, VideoMVR, OpenEphys)
|
|
68
|
+
case V2Session.HAB:
|
|
69
|
+
return (Sync, VideoMVR)
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
def stims(self) -> tuple[Service, ...]:
|
|
73
|
+
return (SessionCamstim, )
|
|
74
|
+
|
|
75
|
+
def initialize_and_test_services(self) -> None:
|
|
76
|
+
"""Configure, initialize (ie. reset), then test all services."""
|
|
77
|
+
|
|
78
|
+
MouseDirector.user = self.user.id
|
|
79
|
+
MouseDirector.mouse = self.mouse.id
|
|
80
|
+
|
|
81
|
+
OpenEphys.folder = self.session.folder
|
|
82
|
+
|
|
83
|
+
NewScaleCoordinateRecorder.log_root = self.session.npexp_path
|
|
84
|
+
NewScaleCoordinateRecorder.log_name = self.platform_json.path.name
|
|
85
|
+
|
|
86
|
+
SessionCamstim.labtracks_mouse_id = self.mouse.id
|
|
87
|
+
SessionCamstim.lims_user_id = self.user.id
|
|
88
|
+
|
|
89
|
+
self.configure_services()
|
|
90
|
+
|
|
91
|
+
super().initialize_and_test_services()
|
|
92
|
+
|
|
93
|
+
def update_state(self) -> None:
|
|
94
|
+
"Store useful but non-essential info."
|
|
95
|
+
self.mouse.state['last_session'] = self.session.id
|
|
96
|
+
self.mouse.state['last_V2_session'] = str(self.workflow)
|
|
97
|
+
if self.mouse == 366122:
|
|
98
|
+
return
|
|
99
|
+
match self.workflow:
|
|
100
|
+
case V2Session.PRETEST:
|
|
101
|
+
return
|
|
102
|
+
case V2Session.HAB:
|
|
103
|
+
self.session.project.state['latest_hab'] = self.session.id
|
|
104
|
+
case V2Session.EPHYS:
|
|
105
|
+
self.session.project.state['latest_ephys'] = self.session.id
|
|
106
|
+
self.session.project.state['sessions'] = self.session.project.state.get('sessions', []) + [self.session.id]
|
|
107
|
+
|
|
108
|
+
def run_stim(self) -> None:
|
|
109
|
+
|
|
110
|
+
self.update_state()
|
|
111
|
+
|
|
112
|
+
if not SessionCamstim.is_ready_to_start():
|
|
113
|
+
raise RuntimeError("SessionCamstim is not ready to start.")
|
|
114
|
+
|
|
115
|
+
np_logging.web(f'V2_{self.workflow.name.lower()}').info(f"Started session {self.mouse.mtrain.stage['name']}")
|
|
116
|
+
SessionCamstim.start()
|
|
117
|
+
|
|
118
|
+
with contextlib.suppress(Exception):
|
|
119
|
+
while not SessionCamstim.is_ready_to_start():
|
|
120
|
+
time.sleep(2.5)
|
|
121
|
+
|
|
122
|
+
if isinstance(SessionCamstim, Finalizable):
|
|
123
|
+
SessionCamstim.finalize()
|
|
124
|
+
|
|
125
|
+
with contextlib.suppress(Exception):
|
|
126
|
+
np_logging.web(f'V2_{self.workflow.name.lower()}').info(f"Finished session {self.mouse.mtrain.stage['name']}")
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def copy_data_files(self) -> None:
|
|
130
|
+
super().copy_data_files()
|
|
131
|
+
|
|
132
|
+
# When all processing completes, camstim Agent class passes data and uuid to
|
|
133
|
+
# /camstim/lims BehaviorSession class, and write_behavior_data() writes a
|
|
134
|
+
# final .pkl with default name YYYYMMDDSSSS_mouseID_foragingID.pkl
|
|
135
|
+
# - if we have a foraging ID, we can search for that
|
|
136
|
+
if None == (stim_pkl := next(self.session.npexp_path.glob(f'{self.session.date:%y%m%d}*_{self.session.mouse}_*.pkl'), None)):
|
|
137
|
+
logger.warning('Did not find stim file on npexp matching the format `YYYYMMDDSSSS_mouseID_foragingID.pkl`')
|
|
138
|
+
return
|
|
139
|
+
assert stim_pkl
|
|
140
|
+
if not self.session.platform_json.foraging_id:
|
|
141
|
+
self.session.platform_json.foraging_id = stim_pkl.stem.split('_')[-1]
|
|
142
|
+
new_stem = f'{self.session.folder}.stim'
|
|
143
|
+
logger.debug(f'Renaming stim file copied to npexp: {stim_pkl} -> {new_stem}')
|
|
144
|
+
stim_pkl = stim_pkl.rename(stim_pkl.with_stem(new_stem))
|
|
145
|
+
|
|
146
|
+
# remove other stim pkl, which is nearly identical, if it was also copied
|
|
147
|
+
for pkl in self.session.npexp_path.glob('*.pkl'):
|
|
148
|
+
if (
|
|
149
|
+
self.session.folder not in pkl.stem
|
|
150
|
+
and
|
|
151
|
+
abs(pkl.stat().st_size - stim_pkl.stat().st_size) < 1e6
|
|
152
|
+
):
|
|
153
|
+
logger.debug(f'Deleting extra stim pkl copied to npexp: {pkl.stem}')
|
|
154
|
+
pkl.unlink()
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def validate_selected_workflow(session: V2Session, mouse: np_session.Mouse) -> None:
|
|
158
|
+
for workflow in ('hab', 'ephys'):
|
|
159
|
+
if (
|
|
160
|
+
workflow in session.value.lower()
|
|
161
|
+
and workflow not in mouse.mtrain.stage['name'].lower()
|
|
162
|
+
) or (
|
|
163
|
+
session.value.lower() == 'ephys' and 'hab' in mouse.mtrain.stage['name'].lower()
|
|
164
|
+
):
|
|
165
|
+
raise ValueError(f"Workflow selected ({session.value}) does not match MTrain stage ({mouse.mtrain.stage['name']}): please check cells above.")
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class Hab(V2Mixin, np_workflows.PipelineHab):
|
|
169
|
+
def __init__(self, *args, **kwargs):
|
|
170
|
+
self.services = (
|
|
171
|
+
MouseDirector,
|
|
172
|
+
Sync,
|
|
173
|
+
VideoMVR,
|
|
174
|
+
self.imager,
|
|
175
|
+
NewScaleCoordinateRecorder,
|
|
176
|
+
SessionCamstim,
|
|
177
|
+
)
|
|
178
|
+
super().__init__(*args, **kwargs)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class Ephys(V2Mixin, np_workflows.PipelineEphys):
|
|
182
|
+
def __init__(self, *args, **kwargs):
|
|
183
|
+
self.services = (
|
|
184
|
+
MouseDirector,
|
|
185
|
+
Sync,
|
|
186
|
+
VideoMVR,
|
|
187
|
+
self.imager,
|
|
188
|
+
NewScaleCoordinateRecorder,
|
|
189
|
+
SessionCamstim,
|
|
190
|
+
OpenEphys,
|
|
191
|
+
)
|
|
192
|
+
super().__init__(*args, **kwargs)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
# --------------------------------------------------------------------------------------
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def new_experiment(
|
|
199
|
+
mouse: int | str | np_session.Mouse,
|
|
200
|
+
user: str | np_session.User,
|
|
201
|
+
workflow: V2Session,
|
|
202
|
+
) -> Ephys | Hab:
|
|
203
|
+
"""Create a new experiment for the given mouse and user."""
|
|
204
|
+
match workflow:
|
|
205
|
+
case V2Session.PRETEST | V2Session.EPHYS:
|
|
206
|
+
experiment = Ephys(mouse, user)
|
|
207
|
+
case V2Session.HAB:
|
|
208
|
+
experiment = Hab(mouse, user)
|
|
209
|
+
case _:
|
|
210
|
+
raise ValueError(f"Invalid workflow type: {workflow}")
|
|
211
|
+
experiment.workflow = workflow
|
|
212
|
+
|
|
213
|
+
with contextlib.suppress(Exception):
|
|
214
|
+
np_logging.web(f'V2_{experiment.workflow.name.lower()}').info(f"{experiment} created")
|
|
215
|
+
|
|
216
|
+
return experiment
|
|
217
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import configparser
|
|
2
|
+
import contextlib
|
|
3
|
+
import copy
|
|
4
|
+
import enum
|
|
5
|
+
import functools
|
|
6
|
+
from typing import ClassVar, Literal, NamedTuple, NoReturn, Optional, TypedDict
|
|
7
|
+
|
|
8
|
+
import IPython.display
|
|
9
|
+
import ipywidgets as ipw
|
|
10
|
+
import np_config
|
|
11
|
+
import np_logging
|
|
12
|
+
import np_session
|
|
13
|
+
import np_workflows
|
|
14
|
+
from pyparsing import Any
|
|
15
|
+
|
|
16
|
+
from np_workflows.experiments.openscope_V2.main_V2_pilot import V2Session
|
|
17
|
+
|
|
18
|
+
global_state = {}
|
|
19
|
+
"""Global variable for persisting widget states."""
|
|
20
|
+
|
|
21
|
+
# for widget, before creating a experiment --------------------------------------------- #
|
|
22
|
+
|
|
23
|
+
class SelectedSession:
|
|
24
|
+
def __init__(self, session: str | V2Session, mouse: str | int | np_session.Mouse):
|
|
25
|
+
if isinstance(session, str):
|
|
26
|
+
session = V2Session(session)
|
|
27
|
+
self.session = session
|
|
28
|
+
self.mouse = str(mouse)
|
|
29
|
+
|
|
30
|
+
def __repr__(self) -> str:
|
|
31
|
+
return f"{self.__class__.__name__}({self.session}, {self.mouse})"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def V2_workflow_widget(
|
|
35
|
+
mouse: str | int | np_session.Mouse,
|
|
36
|
+
) -> SelectedSession:
|
|
37
|
+
"""Select a stimulus session (hab, pretest, ephys) to run.
|
|
38
|
+
|
|
39
|
+
An object with mutable attributes is returned, so the selected session can be
|
|
40
|
+
updated along with the GUI selection. (Preference would be to return an enum
|
|
41
|
+
directly, and change it's value, but that doesn't seem possible.)
|
|
42
|
+
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
selection = SelectedSession(V2Session.PRETEST, mouse)
|
|
46
|
+
|
|
47
|
+
session_dropdown = ipw.Select(
|
|
48
|
+
options=tuple(_.value for _ in V2Session),
|
|
49
|
+
description="Session",
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
def update_selection():
|
|
53
|
+
selection.__init__(str(session_dropdown.value), str(mouse))
|
|
54
|
+
|
|
55
|
+
if (previously_selected_value := global_state.get('selected_session')):
|
|
56
|
+
session_dropdown.value = previously_selected_value
|
|
57
|
+
update_selection()
|
|
58
|
+
|
|
59
|
+
console = ipw.Output()
|
|
60
|
+
with console:
|
|
61
|
+
if last_session := np_session.Mouse(selection.mouse).state.get('last_V2_session'):
|
|
62
|
+
print(f"{mouse} last session: {last_session}")
|
|
63
|
+
print(f"Selected: {selection.session}")
|
|
64
|
+
|
|
65
|
+
def update(change):
|
|
66
|
+
if change["name"] != "value":
|
|
67
|
+
return
|
|
68
|
+
if (options := getattr(change["owner"], "options", None)) and change[
|
|
69
|
+
"new"
|
|
70
|
+
] not in options:
|
|
71
|
+
return
|
|
72
|
+
if change["new"] == change["old"]:
|
|
73
|
+
return
|
|
74
|
+
update_selection()
|
|
75
|
+
with console:
|
|
76
|
+
print(f"Selected: {selection.session}")
|
|
77
|
+
global_state['selected_session'] = selection.session.value
|
|
78
|
+
|
|
79
|
+
session_dropdown.observe(update, names='value')
|
|
80
|
+
|
|
81
|
+
IPython.display.display(ipw.VBox([session_dropdown, console]))
|
|
82
|
+
|
|
83
|
+
return selection
|
|
@@ -8,7 +8,7 @@ import pathlib
|
|
|
8
8
|
import re
|
|
9
9
|
import shutil
|
|
10
10
|
import time
|
|
11
|
-
from typing import Any, ClassVar, Iterable, Literal, Optional, Protocol, Sequence, Type
|
|
11
|
+
from typing import Any, ClassVar, Iterable, Literal, Mapping, Optional, Protocol, Sequence, Type
|
|
12
12
|
|
|
13
13
|
import fabric
|
|
14
14
|
import invoke
|
|
@@ -712,7 +712,13 @@ class DynamicRoutingExperiment(WithSession):
|
|
|
712
712
|
else:
|
|
713
713
|
np_services.ScriptCamstim.script = self.camstim_script.as_posix()
|
|
714
714
|
|
|
715
|
-
|
|
715
|
+
if (script_override_params := getattr(self, 'script_override_params', None)) is not None:
|
|
716
|
+
if not isinstance(script_override_params, Mapping):
|
|
717
|
+
raise TypeError(f"script_override_params must be a dict/Mapping, got {type(script_override_params)}")
|
|
718
|
+
else:
|
|
719
|
+
script_override_params = {}
|
|
720
|
+
|
|
721
|
+
np_services.ScriptCamstim.params = params | script_override_params
|
|
716
722
|
|
|
717
723
|
self.update_state()
|
|
718
724
|
self.log(f"{stim} started")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
np_workflows-1.6.
|
|
2
|
-
np_workflows-1.6.
|
|
3
|
-
np_workflows-1.6.
|
|
1
|
+
np_workflows-1.6.88.dist-info/METADATA,sha256=IhX7bzLQy2osL9vRBRVOZ2piKwCVCtitJPIkfQQ5jmw,3991
|
|
2
|
+
np_workflows-1.6.88.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
|
|
3
|
+
np_workflows-1.6.88.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
|
4
4
|
np_workflows/__init__.py,sha256=QWnSRZ3THmQPF6HO8rFC4EkcjGd5ypap7BssqKqva64,232
|
|
5
5
|
np_workflows/assets/images/logo_np_hab.png,sha256=N1skdSq4lQv0liucargHoulzfE-zeTYoud-wAePD2VY,10071
|
|
6
6
|
np_workflows/assets/images/logo_np_vis.png,sha256=yDaQ3dQcX1OXPN8Rsne9SvaevUlgvVRcw_tWs02cyTU,19349
|
|
@@ -21,6 +21,9 @@ np_workflows/experiments/openscope_loop/main_loop_pilot.py,sha256=ye9qPdZPy5_Em7
|
|
|
21
21
|
np_workflows/experiments/openscope_psycode/__init__.py,sha256=FYX6cNbpueIFqKU5g2l3IeFAgXv8Ikzuv6dC0SMpusQ,148
|
|
22
22
|
np_workflows/experiments/openscope_psycode/main_psycode_pilot.py,sha256=gpYAw4JKU71iveRIu4O_L3gAw4KodCVYcPGhW7lHrCg,7404
|
|
23
23
|
np_workflows/experiments/openscope_psycode/psycode_workflow_widget.py,sha256=LZPRfi3H0z4_zbVezmAPhVUfInpZyaKBKx0tEqkPx4I,2654
|
|
24
|
+
np_workflows/experiments/openscope_v2/__init__.py,sha256=Tmzui2YozeY_a1fiB8dYnlWZdpK_1gEV7MaVtwprP-0,133
|
|
25
|
+
np_workflows/experiments/openscope_v2/main_v2_pilot.py,sha256=O0LThYX8ahKLTgKKcW0rkaqM9bmQkXaDi6l13Wzh-t0,7304
|
|
26
|
+
np_workflows/experiments/openscope_v2/v2_workflow_widget.py,sha256=VI3gohtX5lWXG08x5Xf1a98o-QXXWV25TQpADIlVc2I,2609
|
|
24
27
|
np_workflows/experiments/openscope_vippo/__init__.py,sha256=LTrsyImW6JjUFsu6qoIjdb3aM7YTkQovyLEDHWFv2aA,142
|
|
25
28
|
np_workflows/experiments/openscope_vippo/main_vippo_pilot.py,sha256=q859hjqaFqlMUl6phmOH8PnVYg6iCyG6H67o_HAvDMA,7364
|
|
26
29
|
np_workflows/experiments/openscope_vippo/vippo_workflow_widget.py,sha256=B5kiU-kXypoA7lSonaS7OWZecV4HdmgOdPZq9INbpHE,2636
|
|
@@ -62,9 +65,9 @@ np_workflows/experiments/templeton/__init__.py,sha256=LrTnP6DnkTSB-sdadvSOJvLZMZ
|
|
|
62
65
|
np_workflows/experiments/templeton/main.py,sha256=5JDBN4fQbBy2PfiUh6OQr0NVZo-h58la3C-mgfLsU3Y,2906
|
|
63
66
|
np_workflows/experiments/templeton/widgets.py,sha256=e0t7zhD0N-i6Q5_8EWW4lYrESuAb7hIz_BEL4NPaywo,2884
|
|
64
67
|
np_workflows/shared/__init__.py,sha256=L9h5R3dioT8m0KcwjlQV5_eoEFoneJHEzDTGaH4_ySg,131
|
|
65
|
-
np_workflows/shared/base_experiments.py,sha256=
|
|
68
|
+
np_workflows/shared/base_experiments.py,sha256=K0G4XSMkpP2s6c9XZAtxaj9niRd8GLpZQ6FVX3YDPuA,34500
|
|
66
69
|
np_workflows/shared/camstim_scripts/flash_250ms.stim,sha256=ARwNQPJRRQwEaD_k0oXR1lafdafWlf_Kvfbq6TVEkDU,408
|
|
67
70
|
np_workflows/shared/camstim_scripts/gabor_20_deg_250ms.stim,sha256=xvuRMORZiN9IuOLWZbNTWuxmhfHefGnZtIpeYcsQXpE,718
|
|
68
71
|
np_workflows/shared/npxc.py,sha256=NWi826e14EEt3vKlsLwsQ2wYcsLk9Ea_Hrb8hn2iA3Y,6689
|
|
69
72
|
np_workflows/shared/widgets.py,sha256=aehptvxluwfyRs7Sa4ZSvCMhOwGCxhUM7STBR4wFG5k,26880
|
|
70
|
-
np_workflows-1.6.
|
|
73
|
+
np_workflows-1.6.88.dist-info/RECORD,,
|
|
File without changes
|