viewephys 1.3.0__tar.gz → 1.4.0__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.
Files changed (33) hide show
  1. {viewephys-1.3.0 → viewephys-1.4.0}/PKG-INFO +15 -3
  2. {viewephys-1.3.0 → viewephys-1.4.0}/README.md +11 -2
  3. {viewephys-1.3.0 → viewephys-1.4.0}/pyproject.toml +6 -1
  4. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/command_line.py +41 -0
  5. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/data_model.py +47 -13
  6. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/gui.py +524 -127
  7. viewephys-1.4.0/src/viewephys/noise.py +328 -0
  8. viewephys-1.4.0/src/viewephys/replay.py +75 -0
  9. viewephys-1.4.0/src/viewephys/tests/conftest.py +21 -0
  10. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/tests/test_data_model.py +44 -16
  11. viewephys-1.4.0/src/viewephys/tests/test_replay.py +69 -0
  12. viewephys-1.4.0/src/viewephys/tests/test_spikeinterface.py +132 -0
  13. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/tests/test_viewer_gui.py +313 -1
  14. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/viewer/gui.py +90 -16
  15. viewephys-1.3.0/src/viewephys/tests/test_spikeinterface.py +0 -64
  16. {viewephys-1.3.0 → viewephys-1.4.0}/LICENSE +0 -0
  17. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/__init__.py +0 -0
  18. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/nav_file.ui +0 -0
  19. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/raster.py +0 -0
  20. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/raster.ui +0 -0
  21. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/tests/__init__.py +0 -0
  22. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/tests/mock_data/meta_file.meta +0 -0
  23. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/tests/test_model.py +0 -0
  24. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/tests/test_pick.py +0 -0
  25. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/tests/test_viewer_helpers.py +0 -0
  26. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/tests/test_viewer_model.py +0 -0
  27. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/tests/test_viewer_pgtools.py +0 -0
  28. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/viewephys.svg +0 -0
  29. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/viewer/__init__.py +0 -0
  30. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/viewer/pgtools.py +0 -0
  31. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/viewer/qt.py +0 -0
  32. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/viewer/spectrogram.ui +0 -0
  33. {viewephys-1.3.0 → viewephys-1.4.0}/src/viewephys/viewer/view.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: viewephys
3
- Version: 1.3.0
3
+ Version: 1.4.0
4
4
  Summary: Neuropixel raw data viewer
5
5
  Author: Olivier Winter
6
6
  License: MIT
@@ -15,6 +15,7 @@ Requires-Dist: ibllib
15
15
  Requires-Dist: iblutil>=1.6.0
16
16
  Requires-Dist: numpy
17
17
  Requires-Dist: pandas
18
+ Requires-Dist: probeinterface
18
19
  Requires-Dist: pyqtgraph>=0.13.1
19
20
  Requires-Dist: qtpy
20
21
  Requires-Dist: scipy
@@ -22,6 +23,8 @@ Requires-Dist: spikeinterface
22
23
  Provides-Extra: lfpack
23
24
  Requires-Dist: lfpack; extra == "lfpack"
24
25
  Requires-Dist: iblatlas; extra == "lfpack"
26
+ Provides-Extra: nwb
27
+ Requires-Dist: h5py; extra == "nwb"
25
28
  Provides-Extra: dev
26
29
  Requires-Dist: pytest; extra == "dev"
27
30
  Requires-Dist: pytest-qt; extra == "dev"
@@ -81,16 +84,25 @@ When the picking mode is enabled (menu pick)
81
84
 
82
85
  ## Examples
83
86
 
84
- ### Visualize raw binary file through the command line
85
- Activate your environment and type `viewephys`, you can then load a neuropixel binary file using the file menu.
87
+ ### Visualize raw data through the GUI
88
+ Activate your environment and type `viewephys`. Use `File > open > SpikeGLX` to load a neuropixel binary file, or `File > open > Open Ephys` to select an Open Ephys folder (containing `structure.oebin`). The GUI will prompt you to select a specific recording and data stream if multiple exist. `File > open > NWB` loads an NWB file containing an electrical series. If the file holds several electrical series you are prompted to select one. If the optional `lfpack` dependency is installed (`pip install viewephys[lfpack]`), `File > open > LFPack (HDF5)` is also available and loads HDF5-packed LFP archives (`.h5`/`.hdf5`); if the file holds several recordings you can switch between them with the recording selector.
89
+
90
+ For recordings without probe information, `Probe > Load from probeinterface library` allows for attaching probe geometries of different manufacturers and models from the probeinterface library (fetched online) to recordings. Channels are then shown at their positions on the probe, and can be spatially sorted.
86
91
 
87
92
  ![alt text](./docs/raw_bin_viewer_destripe.png "Ephys viewer ")
88
93
 
94
+ ### Visualize raw binary file through the command line
89
95
  Alternatively you can point the viewer to a specific file using the command line:
90
96
  ```shell
91
97
  viewphys -f /path/to/raw.bin
92
98
  ```
93
99
 
100
+ You can also "replay" `.bin` or `.cbin` files using the `viewephys-replay` command. This will rewrite the specified file to a new location in chunks (a `replay` subfolder next to the source unless `-o` is given) and allow you to open it with `File > open live recording` in the viewephys GUI.
101
+
102
+ ```shell
103
+ viewephys-replay /path/to/raw.bin -o /path/to/replay/directory --speed 0.25
104
+ ```
105
+
94
106
  ### Load in a numpy array or slice
95
107
 
96
108
  `viewephys` can be used through the Python console or iPython, allowing you to create
@@ -36,16 +36,25 @@ When the picking mode is enabled (menu pick)
36
36
 
37
37
  ## Examples
38
38
 
39
- ### Visualize raw binary file through the command line
40
- Activate your environment and type `viewephys`, you can then load a neuropixel binary file using the file menu.
39
+ ### Visualize raw data through the GUI
40
+ Activate your environment and type `viewephys`. Use `File > open > SpikeGLX` to load a neuropixel binary file, or `File > open > Open Ephys` to select an Open Ephys folder (containing `structure.oebin`). The GUI will prompt you to select a specific recording and data stream if multiple exist. `File > open > NWB` loads an NWB file containing an electrical series. If the file holds several electrical series you are prompted to select one. If the optional `lfpack` dependency is installed (`pip install viewephys[lfpack]`), `File > open > LFPack (HDF5)` is also available and loads HDF5-packed LFP archives (`.h5`/`.hdf5`); if the file holds several recordings you can switch between them with the recording selector.
41
+
42
+ For recordings without probe information, `Probe > Load from probeinterface library` allows for attaching probe geometries of different manufacturers and models from the probeinterface library (fetched online) to recordings. Channels are then shown at their positions on the probe, and can be spatially sorted.
41
43
 
42
44
  ![alt text](./docs/raw_bin_viewer_destripe.png "Ephys viewer ")
43
45
 
46
+ ### Visualize raw binary file through the command line
44
47
  Alternatively you can point the viewer to a specific file using the command line:
45
48
  ```shell
46
49
  viewphys -f /path/to/raw.bin
47
50
  ```
48
51
 
52
+ You can also "replay" `.bin` or `.cbin` files using the `viewephys-replay` command. This will rewrite the specified file to a new location in chunks (a `replay` subfolder next to the source unless `-o` is given) and allow you to open it with `File > open live recording` in the viewephys GUI.
53
+
54
+ ```shell
55
+ viewephys-replay /path/to/raw.bin -o /path/to/replay/directory --speed 0.25
56
+ ```
57
+
49
58
  ### Load in a numpy array or slice
50
59
 
51
60
  `viewephys` can be used through the Python console or iPython, allowing you to create
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "viewephys"
3
- version = "1.3.0"
3
+ version = "1.4.0"
4
4
  description = "Neuropixel raw data viewer"
5
5
  authors = [
6
6
  { name = "Olivier Winter" },
@@ -17,6 +17,7 @@ dependencies = [
17
17
  "iblutil>=1.6.0",
18
18
  "numpy",
19
19
  "pandas",
20
+ "probeinterface",
20
21
  "pyqtgraph>=0.13.1",
21
22
  "qtpy",
22
23
  "scipy",
@@ -35,6 +36,9 @@ lfpack = [
35
36
  "lfpack",
36
37
  "iblatlas",
37
38
  ]
39
+ nwb = [
40
+ "h5py",
41
+ ]
38
42
  dev = [
39
43
  "pytest",
40
44
  "pytest-qt",
@@ -67,6 +71,7 @@ Homepage = "https://github.com/int-brain-lab/viewephys"
67
71
 
68
72
  [project.scripts]
69
73
  viewephys = "viewephys.command_line:viewephys"
74
+ viewephys-replay = "viewephys.command_line:replay"
70
75
 
71
76
  [tool.pdm]
72
77
  package-dir = "src"
@@ -50,5 +50,46 @@ def viewephys():
50
50
  sys.exit(app.exec())
51
51
 
52
52
 
53
+ def replay():
54
+ """Replay a SpikeGLX recording into a growing file the GUI can follow."""
55
+ parser = argparse.ArgumentParser(
56
+ description="Replay a SpikeGLX recording as if it were being acquired live"
57
+ )
58
+ parser.add_argument("source", help="path to the .bin or .cbin file to replay")
59
+ parser.add_argument(
60
+ "-o",
61
+ "--out",
62
+ default=None,
63
+ help="destination directory (default: a `replay` subfolder next to the source)",
64
+ )
65
+ parser.add_argument(
66
+ "--speed",
67
+ type=float,
68
+ default=1.0,
69
+ help="speed multiplier; 0 writes as fast as possible",
70
+ )
71
+ parser.add_argument(
72
+ "--chunk-s", type=float, default=0.25, help="seconds of data written per chunk"
73
+ )
74
+ args = parser.parse_args()
75
+
76
+ from pathlib import Path
77
+
78
+ from viewephys.replay import replay_path, write_replay
79
+
80
+ source = Path(args.source).resolve()
81
+ if not source.exists():
82
+ parser.error(f"no such file: {source}")
83
+ print(f"replaying {source}")
84
+ print("open this file in the GUI with File > open live recording:")
85
+ print(f" {replay_path(source, args.out)}")
86
+ try:
87
+ write_replay(source, args.out, speed=args.speed, chunk_s=args.chunk_s)
88
+ except KeyboardInterrupt:
89
+ print("\nreplay interrupted")
90
+ return
91
+ print("replay finished")
92
+
93
+
53
94
  if __name__ == "__main__":
54
95
  viewephys()
@@ -56,6 +56,24 @@ class AbstractDataModel(abc.ABC):
56
56
  """
57
57
  return None
58
58
 
59
+ def get_t0(self) -> float:
60
+ """Time in seconds of sample 0, i.e. the recording's clock origin.
61
+
62
+ Defaults to zero; backends whose clock does not start at zero
63
+ (e.g. a SpikeInterface recording shifted with ``set_times``) override
64
+ this. Sampling is assumed linear from this origin: drift within the
65
+ recording is not modeled.
66
+ """
67
+ return 0.0
68
+
69
+ def get_time_from_sample(self, sample: int) -> float:
70
+ """Time in seconds of a sample index, assuming a linear clock."""
71
+ return self.get_t0() + sample / self.get_sampling_frequency()
72
+
73
+ def get_sample_from_time(self, time: float) -> int:
74
+ """Sample index of a time in seconds, assuming a linear clock."""
75
+ return int(round((time - self.get_t0()) * self.get_sampling_frequency()))
76
+
59
77
 
60
78
  class SpikeGLXDataModel(AbstractDataModel):
61
79
  """Data model wrapping ``spikeglx.Reader``."""
@@ -193,16 +211,17 @@ class LFPackDataModel(SpikeGLXDataModel):
193
211
  """Data model for lfpack HDF5-packed LFP files.
194
212
 
195
213
  Wraps an ``lfpack.LFPackReader`` (a drop-in ``spikeglx.Reader``). The data
196
- is already decompressed and denoised, so the steps are the ``"raw"`` signal
197
- and its current-source density (``"csd"``). Most methods are inherited from
198
- :class:`SpikeGLXDataModel`; only those relying on SpikeGLX metadata absent
199
- from compressed files, or specific to lfpack, are overridden.
214
+ is already decompressed and denoised, so the steps are the ``"raw"`` signal,
215
+ its bipolar reference (``"bpr"``) and its current-source density (``"csd"``).
216
+ Most methods are inherited from :class:`SpikeGLXDataModel`; only those
217
+ relying on SpikeGLX metadata absent from compressed files, or specific to
218
+ lfpack, are overridden.
200
219
  """
201
220
 
202
221
  @override
203
222
  def get_steps(self) -> list[str]:
204
- """Denoised signal and its current-source density."""
205
- return ["raw", "csd"]
223
+ """Denoised signal, its bipolar reference and current-source density."""
224
+ return ["raw", "bpr", "csd"]
206
225
 
207
226
  @override
208
227
  def get_data(
@@ -212,17 +231,27 @@ class LFPackDataModel(SpikeGLXDataModel):
212
231
  step: str,
213
232
  raw: np.ndarray | None = None,
214
233
  ) -> np.ndarray:
215
- """Return the raw signal or its current-source density.
216
-
217
- The ``"csd"`` step computes the CSD via
218
- :func:`ibldsp.voltage.current_source_density`; other steps defer to the
219
- inherited (raw pass-through) implementation.
234
+ """Return the raw signal, its bipolar reference or its CSD.
235
+
236
+ ``"bpr"`` and ``"csd"`` are spatial derivatives of the raw signal via
237
+ :func:`ibldsp.voltage.current_source_density`: first difference with
238
+ sigma=1 for the bipolar reference, second difference with sigma=-1/3
239
+ (tissue conductivity, with the physical minus sign) for the CSD. Both
240
+ are rescaled to the raw window's RMS, as they are display-only steps:
241
+ flipping between processing domains needs no gain change. Other steps
242
+ defer to the inherited (raw pass-through) implementation.
220
243
  """
221
- if step != "csd":
244
+ if step not in ("bpr", "csd"):
222
245
  return super().get_data(start_sample, end_sample, step, raw=raw)
223
246
  if raw is None:
224
247
  raw = self.get_raw(start_sample, end_sample)
225
- return voltage.current_source_density(raw, h=self.get_header())
248
+ n, sigma = (1, 1.0) if step == "bpr" else (2, -1 / 3)
249
+ out = voltage.current_source_density(raw, h=self.get_header(), n=n, sigma=sigma)
250
+ rms_raw = np.sqrt(np.mean(raw.astype(np.float64) ** 2))
251
+ rms_out = np.sqrt(np.nanmean(out.astype(np.float64) ** 2))
252
+ if rms_out > 0:
253
+ out = out * (rms_raw / rms_out)
254
+ return out
226
255
 
227
256
  @override
228
257
  def get_probe_information(self) -> str:
@@ -412,6 +441,11 @@ class SpikeInterfaceDataModel(AbstractDataModel):
412
441
  def get_sampling_frequency(self) -> float:
413
442
  return self.first_recording.get_sampling_frequency()
414
443
 
444
+ @override
445
+ def get_t0(self) -> float:
446
+ """Time in seconds of sample 0 on the SpikeInterface recording's clock."""
447
+ return self.first_recording.sample_index_to_time(0, segment_index=0)
448
+
415
449
  @override
416
450
  def get_recording_length(self) -> float:
417
451
  """