np-workflows 1.6.89__py3-none-any.whl → 1.6.91__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.
Files changed (76) hide show
  1. np_workflows/__init__.py +3 -5
  2. np_workflows/experiments/dynamic_routing/main.py +20 -41
  3. np_workflows/experiments/dynamic_routing/widgets.py +29 -24
  4. np_workflows/experiments/openscope_P3/P3_workflow_widget.py +11 -19
  5. np_workflows/experiments/openscope_P3/__init__.py +1 -1
  6. np_workflows/experiments/openscope_P3/main_P3_pilot.py +66 -68
  7. np_workflows/experiments/openscope_barcode/__init__.py +1 -1
  8. np_workflows/experiments/openscope_barcode/barcode_workflow_widget.py +14 -20
  9. np_workflows/experiments/openscope_barcode/camstim_scripts/barcode_mapping_script.py +8 -14
  10. np_workflows/experiments/openscope_barcode/camstim_scripts/barcode_opto_script.py +121 -68
  11. np_workflows/experiments/openscope_barcode/main_barcode_pilot.py +69 -69
  12. np_workflows/experiments/openscope_loop/__init__.py +1 -1
  13. np_workflows/experiments/openscope_loop/camstim_scripts/barcode_mapping_script.py +8 -14
  14. np_workflows/experiments/openscope_loop/camstim_scripts/barcode_opto_script.py +121 -68
  15. np_workflows/experiments/openscope_loop/loop_workflow_widget.py +11 -19
  16. np_workflows/experiments/openscope_loop/main_loop_pilot.py +66 -68
  17. np_workflows/experiments/openscope_psycode/__init__.py +1 -1
  18. np_workflows/experiments/openscope_psycode/main_psycode_pilot.py +69 -69
  19. np_workflows/experiments/openscope_psycode/psycode_workflow_widget.py +14 -20
  20. np_workflows/experiments/openscope_v2/__init__.py +1 -1
  21. np_workflows/experiments/openscope_v2/main_v2_pilot.py +66 -68
  22. np_workflows/experiments/openscope_v2/v2_workflow_widget.py +11 -19
  23. np_workflows/experiments/openscope_vippo/__init__.py +1 -1
  24. np_workflows/experiments/openscope_vippo/main_vippo_pilot.py +66 -68
  25. np_workflows/experiments/openscope_vippo/vippo_workflow_widget.py +14 -20
  26. np_workflows/experiments/task_trained_network/__init__.py +1 -1
  27. np_workflows/experiments/task_trained_network/camstim_scripts/make_tt_stims.py +24 -14
  28. np_workflows/experiments/task_trained_network/camstim_scripts/oct22_tt_stim_script.py +54 -41
  29. np_workflows/experiments/task_trained_network/camstim_scripts/ttn_main_script.py +19 -22
  30. np_workflows/experiments/task_trained_network/camstim_scripts/ttn_mapping_script.py +8 -14
  31. np_workflows/experiments/task_trained_network/camstim_scripts/ttn_opto_script.py +121 -68
  32. np_workflows/experiments/task_trained_network/main_ttn_pilot.py +73 -68
  33. np_workflows/experiments/task_trained_network/ttn_session_widget.py +11 -19
  34. np_workflows/experiments/task_trained_network/ttn_stim_config.py +23 -19
  35. np_workflows/experiments/templeton/main.py +18 -41
  36. np_workflows/experiments/templeton/widgets.py +26 -23
  37. np_workflows/shared/__init__.py +1 -1
  38. np_workflows/shared/base_experiments.py +430 -308
  39. np_workflows/shared/npxc.py +85 -53
  40. np_workflows/shared/widgets.py +374 -224
  41. {np_workflows-1.6.89.dist-info → np_workflows-1.6.91.dist-info}/METADATA +7 -21
  42. np_workflows-1.6.91.dist-info/RECORD +48 -0
  43. {np_workflows-1.6.89.dist-info → np_workflows-1.6.91.dist-info}/WHEEL +2 -1
  44. np_workflows-1.6.91.dist-info/entry_points.txt +2 -0
  45. np_workflows-1.6.91.dist-info/top_level.txt +1 -0
  46. np_workflows/assets/images/logo_np_hab.png +0 -0
  47. np_workflows/assets/images/logo_np_vis.png +0 -0
  48. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_00.stim +0 -5
  49. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_01.stim +0 -5
  50. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_02.stim +0 -5
  51. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_03.stim +0 -5
  52. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_04.stim +0 -5
  53. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_05.stim +0 -5
  54. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_06.stim +0 -5
  55. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_07.stim +0 -5
  56. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_08.stim +0 -5
  57. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_09.stim +0 -5
  58. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_10.stim +0 -5
  59. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_11.stim +0 -5
  60. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_12.stim +0 -5
  61. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_13.stim +0 -5
  62. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_14.stim +0 -5
  63. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_15.stim +0 -5
  64. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_16.stim +0 -5
  65. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_17.stim +0 -5
  66. np_workflows/experiments/task_trained_network/camstim_scripts/stims/densely_annotated_18.stim +0 -5
  67. np_workflows/experiments/task_trained_network/camstim_scripts/stims/flash_250ms.stim +0 -20
  68. np_workflows/experiments/task_trained_network/camstim_scripts/stims/gabor_20_deg_250ms.stim +0 -30
  69. np_workflows/experiments/task_trained_network/camstim_scripts/stims/old_stim.stim +0 -5
  70. np_workflows/experiments/task_trained_network/camstim_scripts/stims/shuffle_reversed.stim +0 -5
  71. np_workflows/experiments/task_trained_network/camstim_scripts/stims/shuffle_reversed_1st.stim +0 -5
  72. np_workflows/experiments/task_trained_network/camstim_scripts/stims/shuffle_reversed_2nd.stim +0 -5
  73. np_workflows/shared/camstim_scripts/flash_250ms.stim +0 -20
  74. np_workflows/shared/camstim_scripts/gabor_20_deg_250ms.stim +0 -30
  75. np_workflows-1.6.89.dist-info/RECORD +0 -76
  76. np_workflows-1.6.89.dist-info/entry_points.txt +0 -4
@@ -1,21 +1,22 @@
1
1
  import contextlib
2
2
  import datetime
3
- import inspect
4
3
  import pathlib
5
4
  import shutil
6
5
  import sys
7
6
  import time
8
- from typing import Any, Generator, Sequence, Type
9
7
  import zlib
8
+ from collections.abc import Generator, Sequence
10
9
 
11
10
  import fabric
12
11
  import np_config
13
12
  import np_logging
13
+ import np_services
14
14
  import np_session
15
- from np_services import Initializable, Testable, TestError, Finalizable, Service
16
- from np_services import Sync, VideoMVR, ImageMVR, Cam3d, ScriptCamstim, OpenEphys
17
- import np_services
18
- from np_config import Rig
15
+ from np_services import (
16
+ Finalizable,
17
+ Initializable,
18
+ Service,
19
+ )
19
20
 
20
21
  logger = np_logging.getLogger(__name__)
21
22
 
@@ -36,24 +37,25 @@ CONFIG = RIG.config
36
37
 
37
38
  lims_user_ids: tuple[str, ...] = tuple(
38
39
  sorted(
39
- CONFIG.get('lims_user_ids',
40
+ CONFIG.get(
41
+ "lims_user_ids",
40
42
  [
41
- "hannah.belski",
42
- "hannah.cabasco",
43
- "ryan.gillis",
44
- "henry.loeffler",
45
- "corbettb",
46
- "ben.hardcastle",
47
- "samg",
48
- "ethan.mcbride",
49
- "jackie.kuyat",
50
- "andrew.shelton",
51
- ]
43
+ "hannah.belski",
44
+ "hannah.cabasco",
45
+ "ryan.gillis",
46
+ "henry.loeffler",
47
+ "corbettb",
48
+ "ben.hardcastle",
49
+ "samg",
50
+ "ethan.mcbride",
51
+ "jackie.kuyat",
52
+ "andrew.shelton",
53
+ ],
52
54
  )
53
55
  )
54
56
  )
55
57
 
56
- default_mouse_id: int = int(CONFIG.get('default_mouse_id', 366122))
58
+ default_mouse_id: int = int(CONFIG.get("default_mouse_id", 366122))
57
59
 
58
60
 
59
61
  def get_operators() -> list[str]:
@@ -74,9 +76,10 @@ def print_countdown_timer(seconds: int | float | datetime.timedelta = 0, **kwarg
74
76
  print(f"Waiting {wait} \t{time_remaining()}", end="\r", flush=True)
75
77
  time.sleep(0.1)
76
78
 
79
+
77
80
  def photodoc(img_name: str) -> pathlib.Path:
78
81
  """Capture image with `label` appended to filename, and return the filepath.
79
-
82
+
80
83
  If multiple images are captured, only the last will remain in the Imager.data_files list.
81
84
  """
82
85
  if RIG.idx == 0:
@@ -84,104 +87,133 @@ def photodoc(img_name: str) -> pathlib.Path:
84
87
  else:
85
88
  from np_services import ImageMVR as ImageCamera
86
89
  from np_services import NewScaleCoordinateRecorder
87
-
90
+
88
91
  ImageCamera.label = img_name
89
- if isinstance(ImageCamera, Initializable) and not getattr(ImageCamera, 'initialization', None):
92
+ if isinstance(ImageCamera, Initializable) and not getattr(
93
+ ImageCamera, "initialization", None
94
+ ):
90
95
  ImageCamera.initialize()
91
-
96
+
92
97
  ImageCamera.start()
93
-
98
+
94
99
  if isinstance(ImageCamera, Finalizable):
95
100
  ImageCamera.finalize()
96
-
97
- if isinstance(NewScaleCoordinateRecorder, Initializable) and not getattr(NewScaleCoordinateRecorder, 'initialization', None):
101
+
102
+ if isinstance(NewScaleCoordinateRecorder, Initializable) and not getattr(
103
+ NewScaleCoordinateRecorder, "initialization", None
104
+ ):
98
105
  NewScaleCoordinateRecorder.initialize()
99
106
  NewScaleCoordinateRecorder.label = img_name
100
107
  NewScaleCoordinateRecorder.start()
101
-
108
+
102
109
  # remove all but latest file with the current label
103
110
  if img_name and ImageCamera.data_files:
104
- views = 2 if ImageCamera.__name__ == 'Cam3d' else 1
111
+ views = 2 if ImageCamera.__name__ == "Cam3d" else 1
112
+
105
113
  def files_with_label():
106
114
  return sorted([_ for _ in ImageCamera.data_files if img_name in _.name])
115
+
107
116
  while len(files_with_label()) > views:
108
117
  ImageCamera.data_files.remove(files_with_label()[0])
109
-
118
+
110
119
  return ImageCamera.data_files[-1]
111
120
 
121
+
112
122
  def copy_files(services: Sequence[Service], session_folder: pathlib.Path):
113
123
  """Copy files from raw data storage to session folder for all services."""
114
- password = input(f'Enter password for svc_neuropix:')
124
+ password = input("Enter password for svc_neuropix:")
115
125
  for service in services:
116
126
  match service.__class__.__name__:
117
127
  case "OpenEphys" | "open_ephys":
118
- continue # copy ephys after other files
128
+ continue # copy ephys after other files
119
129
  case _:
120
130
  with contextlib.suppress(AttributeError):
121
- files = service.data_files or service.get_latest_data('*')
131
+ files = service.data_files or service.get_latest_data("*")
122
132
  if not files:
123
133
  continue
124
134
  files = set(files)
125
135
  print(files)
126
136
  for file in files:
127
137
  shutil.copy2(file, session_folder)
128
-
129
- password = np_config.fetch('/logins')['svc_neuropix']['password']
130
- ssh = fabric.Connection(host=np_services.OpenEphys.host, user='svc_neuropix', connect_kwargs=dict(password=password))
138
+
139
+ password = np_config.fetch("/logins")["svc_neuropix"]["password"]
140
+ ssh = fabric.Connection(
141
+ host=np_services.OpenEphys.host,
142
+ user="svc_neuropix",
143
+ connect_kwargs=dict(password=password),
144
+ )
131
145
  for ephys_folder in np_services.OpenEphys.data_files:
132
146
 
133
147
  with contextlib.suppress(Exception):
134
148
  with ssh:
135
149
  ssh.run(
136
- f'robocopy "{ephys_folder}" "{session_folder / ephys_folder.name}" /j /s /xo'
137
- # /j unbuffered, /s incl non-empty subdirs, /xo exclude src files older than dest
150
+ f'robocopy "{ephys_folder}" "{session_folder / ephys_folder.name}" /j /s /xo'
151
+ # /j unbuffered, /s incl non-empty subdirs, /xo exclude src files older than dest
138
152
  )
139
-
140
-
153
+
154
+
141
155
  import warnings
142
156
 
143
- def hide_warning_lines(msg:str,category:str,*args,**kwargs):
144
- print("\n{}: {}\n".format(category.__name__, msg))
157
+
158
+ def hide_warning_lines(msg: str, category: str, *args, **kwargs):
159
+ print(f"\n{category.__name__}: {msg}\n")
160
+
161
+
145
162
  warnings.showwarning = hide_warning_lines
146
163
 
147
164
  import IPython
165
+
166
+
148
167
  def toggle_tracebacks() -> Generator[None, None, None]:
149
168
  if ipython := IPython.get_ipython():
150
169
  show_traceback = ipython.showtraceback
151
-
152
- def hide_traceback(exc_tuple=None, filename=None, tb_offset=None,
153
- exception_only=False, running_compiled_code=False):
170
+
171
+ def hide_traceback(
172
+ exc_tuple=None,
173
+ filename=None,
174
+ tb_offset=None,
175
+ exception_only=False,
176
+ running_compiled_code=False,
177
+ ):
154
178
  etype, value, tb = sys.exc_info()
155
- return ipython._showtraceback(etype, value, ipython.InteractiveTB.get_exception_only(etype, value))
156
-
179
+ return ipython._showtraceback(
180
+ etype, value, ipython.InteractiveTB.get_exception_only(etype, value)
181
+ )
182
+
157
183
  hidden = True
158
184
  while True:
159
185
  ipython.showtraceback = hide_traceback if hidden else show_traceback
160
186
  hidden = yield
161
187
  else:
162
188
  raise RuntimeError("Not in IPython")
163
-
189
+
190
+
164
191
  with contextlib.suppress(RuntimeError):
165
192
  toggle_tb = toggle_tracebacks()
166
193
 
167
194
  toggle_tb.send(None)
195
+
168
196
  def show_tracebacks():
169
197
  toggle_tb.send(False)
198
+
170
199
  def hide_tracebacks():
171
200
  toggle_tb.send(True)
172
-
201
+
202
+
173
203
  def now() -> str:
174
204
  return np_services.utils.normalize_time(time.time())
175
205
 
206
+
176
207
  def validate_or_overwrite(validate: str | pathlib.Path, src: str | pathlib.Path):
177
208
  "Checksum validate against `src`, (over)write `validate` as `src` if different."
178
209
  validate, src = pathlib.Path(validate), pathlib.Path(src)
210
+
179
211
  def copy():
180
212
  logger.debug("Copying %s to %s", src, validate)
181
213
  shutil.copy2(src, validate)
182
- while (
183
- validate.exists() == False
184
- or (v := zlib.crc32(validate.read_bytes())) != (c := zlib.crc32(pathlib.Path(src).read_bytes()))
185
- ):
214
+
215
+ while validate.exists() == False or (v := zlib.crc32(validate.read_bytes())) != (
216
+ c := zlib.crc32(pathlib.Path(src).read_bytes())
217
+ ):
186
218
  copy()
187
- logger.debug("Validated %s CRC32: %08X", validate, (v & 0xFFFFFFFF) )
219
+ logger.debug("Validated %s CRC32: %08X", validate, (v & 0xFFFFFFFF))