xarray-behave 0.38.0a2__tar.gz → 0.38.0a3__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 (46) hide show
  1. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/PKG-INFO +1 -1
  2. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/__init__.py +1 -1
  3. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/app.py +20 -5
  4. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/event_widgets.py +6 -2
  5. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/modern_video.py +45 -22
  6. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/views.py +5 -5
  7. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/LICENSE +0 -0
  8. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/README.md +0 -0
  9. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/pyproject.toml +0 -0
  10. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/_dataset_service.py +0 -0
  11. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/annot.py +0 -0
  12. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/api.py +0 -0
  13. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/event_utils.py +0 -0
  14. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/__init__.py +0 -0
  15. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/checkbox_check.svg +0 -0
  16. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/formbuilder.py +0 -0
  17. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/forms/das_make.yaml +0 -0
  18. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/forms/envelope_computation.yaml +0 -0
  19. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/forms/from_dir.yaml +0 -0
  20. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/forms/from_file.yaml +0 -0
  21. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/forms/from_zarr.yaml +0 -0
  22. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/gui_config.py +0 -0
  23. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/icon.png +0 -0
  24. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/media_dialog.py +0 -0
  25. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/project.py +0 -0
  26. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/style_profile.py +0 -0
  27. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/utils.py +0 -0
  28. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/view_dialog.py +0 -0
  29. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/gui/widgets.py +0 -0
  30. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/io/__init__.py +0 -0
  31. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/io/annotations.py +0 -0
  32. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/io/annotations_manual.py +0 -0
  33. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/io/audio.py +0 -0
  34. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/io/balltracks.py +0 -0
  35. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/io/movieparams.py +0 -0
  36. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/io/poses.py +0 -0
  37. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/io/samplestamps/__init__.py +0 -0
  38. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/io/samplestamps/samplestamps.py +0 -0
  39. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/io/samplestamps/utils.py +0 -0
  40. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/io/timestamps.py +0 -0
  41. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/io/tracks.py +0 -0
  42. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/loaders.py +0 -0
  43. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/manifests/default.yaml +0 -0
  44. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/metrics.py +0 -0
  45. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/v1.py +0 -0
  46. {xarray_behave-0.38.0a2 → xarray_behave-0.38.0a3}/src/xarray_behave/xarray_behave.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: xarray-behave
3
- Version: 0.38.0a2
3
+ Version: 0.38.0a3
4
4
  Summary: xarray tools for behavioral data.
5
5
  Author-email: Jan Clemens <clemensjan@googlemail.com>
6
6
  Requires-Python: >=3.10
@@ -1,6 +1,6 @@
1
1
  """xarray tools for behavioral data."""
2
2
 
3
- __version__ = "0.38.0a2"
3
+ __version__ = "0.38.0a3"
4
4
 
5
5
  import os
6
6
 
@@ -1415,7 +1415,7 @@ class PSV(MainWindow):
1415
1415
  threshold_config = viewer_config.get("thresholding", {})
1416
1416
  panel_config = config.get("window", {}).get("panels", {})
1417
1417
  self.setStyleSheet(WINDOW_STYLESHEET)
1418
- pg.setConfigOptions(useOpenGL=False) # appears to be faster that way
1418
+ pg.setConfigOptions(useOpenGL=False) # WaveformPane enables OpenGL independently.
1419
1419
  # build model:
1420
1420
  self.ds = ds
1421
1421
  self.data_source = data_source
@@ -1561,7 +1561,7 @@ class PSV(MainWindow):
1561
1561
  self._is_playing = False
1562
1562
  self._is_slider_scrubbing = False
1563
1563
  self._playback_timer = QtCore.QTimer(self)
1564
- self._playback_timer.setInterval(20)
1564
+ self._playback_timer.setInterval(min(20, max(1, int(1_000 / self.vr.frame_rate))) if self.vr is not None else 20)
1565
1565
  self._playback_timer.timeout.connect(self._on_playback_tick)
1566
1566
  self._playback_clock = QtCore.QElapsedTimer()
1567
1567
  self._playback_anchor_sample = 0.0
@@ -1944,7 +1944,6 @@ class PSV(MainWindow):
1944
1944
  widget.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
1945
1945
  self.preset_panel.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding)
1946
1946
  self._syncing_event_selection = False
1947
- self.slice_view.channel_changed.connect(self._on_audio_selection_changed)
1948
1947
  self.slice_view.audio_settings_changed.connect(self._set_audio_settings)
1949
1948
  self.events_table.window_filter_checkbox.toggled.connect(
1950
1949
  lambda checked: self._refresh_event_widgets(True, force_table=bool(checked))
@@ -2096,6 +2095,7 @@ class PSV(MainWindow):
2096
2095
  self._sync_threshold_mode_ui()
2097
2096
  self._restore_window_geometry()
2098
2097
 
2098
+ self.slice_view.channel_changed.connect(self._on_audio_selection_changed)
2099
2099
  self.show()
2100
2100
  self.update_xy()
2101
2101
  self.update_frame()
@@ -2707,13 +2707,20 @@ class PSV(MainWindow):
2707
2707
  def _sample_seconds(self, sample: float) -> float:
2708
2708
  times = self._audio_time_values()
2709
2709
  if len(times):
2710
- return float(np.interp(float(sample), np.arange(len(times)), times))
2710
+ sample = min(max(float(sample), 0.0), len(times) - 1)
2711
+ index = int(sample)
2712
+ return float(times[index] + (sample - index) * (times[min(index + 1, len(times) - 1)] - times[index]))
2711
2713
  return float(sample) / self.fs_song
2712
2714
 
2713
2715
  def _seconds_sample(self, seconds: float) -> float:
2714
2716
  times = self._audio_time_values()
2715
2717
  if len(times):
2716
- return float(np.interp(float(seconds), times, np.arange(len(times))))
2718
+ index = int(np.searchsorted(times, seconds, side="right"))
2719
+ if index == 0:
2720
+ return 0.0
2721
+ if index == len(times):
2722
+ return float(index - 1)
2723
+ return float(index - 1 + (seconds - times[index - 1]) / (times[index] - times[index - 1]))
2717
2724
  return float(seconds) * self.fs_song
2718
2725
 
2719
2726
  def _apply_active_audio_source(self, *, preserve_seconds: bool = False, old_seconds: float = None) -> None:
@@ -3039,6 +3046,7 @@ class PSV(MainWindow):
3039
3046
  self._stop_window_audio_playhead()
3040
3047
  self._clear_playback_window()
3041
3048
  old_t0 = getattr(self, "_t0", self.tmin)
3049
+ old_frame = self.framenumber if not refresh and self.vr is not None else None
3042
3050
  self._t0 = np.clip(sample, self.tmin, self.tmax_playhead)
3043
3051
  if force_refresh or not np.isclose(self._t0, old_t0, rtol=0.0, atol=1.0e-4):
3044
3052
  self._sync_transport_controls()
@@ -3047,6 +3055,8 @@ class PSV(MainWindow):
3047
3055
  self.update_frame()
3048
3056
  else:
3049
3057
  self._sync_playhead_only()
3058
+ if self.vr is not None and self.framenumber != old_frame:
3059
+ self.update_frame()
3050
3060
  if process_events:
3051
3061
  self.app.processEvents()
3052
3062
 
@@ -4577,6 +4587,7 @@ class PSV(MainWindow):
4577
4587
  self.y,
4578
4588
  y_other=self.y_other,
4579
4589
  scale_y_all=self._audio_settings().scale_y_all,
4590
+ background_step=self.step * 2,
4580
4591
  )
4581
4592
  self.slice_view.set_threshold_data(
4582
4593
  self.x,
@@ -4598,6 +4609,7 @@ class PSV(MainWindow):
4598
4609
  self.y,
4599
4610
  y_other=self.y_other,
4600
4611
  scale_y_all=self._audio_settings().scale_y_all,
4612
+ background_step=self.step * 2,
4601
4613
  )
4602
4614
 
4603
4615
  if "pose_positions_allo" in self.ds:
@@ -5120,6 +5132,9 @@ def main(
5120
5132
  skip_dialog (bool): If True, skips the loading dialog and goes straight to the data view.
5121
5133
  is_das (bool): reduced GUI for audio only data
5122
5134
  """
5135
+ surface_format = QtGui.QSurfaceFormat.defaultFormat()
5136
+ surface_format.setSwapInterval(0) # Avoid a refresh-rate wait on each waveform update.
5137
+ QtGui.QSurfaceFormat.setDefaultFormat(surface_format)
5123
5138
  app = pg.mkQApp()
5124
5139
  config_manager = gui_config.GuiConfigManager(config)
5125
5140
  config_manager.load_for_source(source or None)
@@ -1345,6 +1345,8 @@ class WaveformPane(pg.PlotWidget):
1345
1345
 
1346
1346
  def __init__(self, parent=None, callback=None, region_changed_callback=None, position_changed_callback=None) -> None:
1347
1347
  super().__init__(parent=parent)
1348
+ if QtWidgets.QApplication.platformName() != "offscreen":
1349
+ self.useOpenGL(True)
1348
1350
  self.setMinimumHeight(60)
1349
1351
  self.setBackground(TIMELINE_BACKGROUND)
1350
1352
  self.setMouseEnabled(x=False, y=False)
@@ -1497,6 +1499,7 @@ class WaveformPane(pg.PlotWidget):
1497
1499
  y_other: np.ndarray | None = None,
1498
1500
  scale_y_all: bool = True,
1499
1501
  max_points: int = 6000,
1502
+ background_step: int = 2,
1500
1503
  ) -> None:
1501
1504
  self._clear_other_curves()
1502
1505
  if x is None or y is None or len(x) == 0 or len(y) == 0:
@@ -1517,7 +1520,7 @@ class WaveformPane(pg.PlotWidget):
1517
1520
  curve = pg.PlotCurveItem(pen=pg.mkPen("#4d5968", width=0.9))
1518
1521
  curve.setZValue(-5)
1519
1522
  self.addItem(curve)
1520
- self._set_curve_data(curve, x, y_other[:, channel], max_points=max_points)
1523
+ self._set_curve_data(curve, x[::background_step], y_other[::background_step, channel], max_points=max_points)
1521
1524
  self._other_curves.append(curve)
1522
1525
  self._set_curve_data(self._curve, x, y, max_points=max_points)
1523
1526
  self.setXRange(float(x[0]), float(x[-1]), padding=0)
@@ -1939,9 +1942,10 @@ class EventTimelineWidget(QtWidgets.QWidget):
1939
1942
  y: np.ndarray,
1940
1943
  y_other: np.ndarray | None = None,
1941
1944
  scale_y_all: bool = True,
1945
+ background_step: int = 2,
1942
1946
  ) -> None:
1943
1947
  if self.waveform is not None:
1944
- self.waveform.set_waveform(x, y, y_other=y_other, scale_y_all=scale_y_all)
1948
+ self.waveform.set_waveform(x, y, y_other=y_other, scale_y_all=scale_y_all, background_step=background_step)
1945
1949
  return
1946
1950
  if x is not None and len(x):
1947
1951
  self.events.setXRange(float(x[0]), float(x[-1]), padding=0)
@@ -23,6 +23,7 @@ class PyAVVideoReader:
23
23
  if self._stream is None:
24
24
  self.close()
25
25
  raise RuntimeError(f"No video stream in {self.filename}")
26
+ self._stream.thread_type = "AUTO"
26
27
 
27
28
  self.frame_rate = self._rate_hz(self._stream)
28
29
  self.frame_width = int(getattr(self._stream, "width", 0) or 0)
@@ -32,6 +33,10 @@ class PyAVVideoReader:
32
33
  if self.number_of_frames <= 0:
33
34
  duration = self._duration_seconds()
34
35
  self.number_of_frames = int(np.ceil(max(0.0, duration) * self.frame_rate))
36
+ self._decoder = None
37
+ self._previous_frame = None
38
+ self._current_frame = None
39
+ self._last_target_seconds = None
35
40
 
36
41
  def __getitem__(self, index: int):
37
42
  return self.read(index)[1]
@@ -60,32 +65,50 @@ class PyAVVideoReader:
60
65
 
61
66
  def frame_at_seconds(self, seconds: float):
62
67
  target_seconds = max(0.0, float(seconds))
63
- target_pts = self._seconds_to_pts(target_seconds)
64
- try:
65
- self._container.seek(target_pts, stream=self._stream, backward=True, any_frame=False)
66
- except Exception:
67
- self._container.seek(int(target_seconds * 1_000_000), backward=True)
68
- try:
69
- self._stream.codec_context.flush_buffers()
70
- except Exception:
71
- pass
72
-
73
- best_frame = None
74
- best_distance = None
75
- for frame in self._container.decode(self._stream):
76
- frame_seconds = self._frame_seconds(frame)
77
- distance = abs(frame_seconds - target_seconds)
78
- if best_distance is None or distance <= best_distance:
79
- best_distance = distance
80
- best_frame = frame
81
- if frame_seconds >= target_seconds and best_frame is not None:
82
- break
68
+ # Keep decoding during playback; seek for backwards moves and jumps over a second.
69
+ if (
70
+ self._decoder is None
71
+ or target_seconds < self._last_target_seconds
72
+ or target_seconds - self._last_target_seconds > 1.0
73
+ ):
74
+ self._decoder = None
75
+ target_pts = self._seconds_to_pts(target_seconds)
76
+ try:
77
+ self._container.seek(target_pts, stream=self._stream, backward=True, any_frame=False)
78
+ except Exception:
79
+ self._container.seek(int(target_seconds * 1_000_000), backward=True)
80
+ try:
81
+ self._stream.codec_context.flush_buffers()
82
+ except Exception:
83
+ pass
84
+ self._decoder = self._container.decode(self._stream)
85
+ self._previous_frame = self._current_frame = None
86
+ self._last_target_seconds = target_seconds
83
87
 
84
- if best_frame is None:
88
+ while self._current_frame is None or self._frame_seconds(self._current_frame) < target_seconds:
89
+ frame = next(self._decoder, None)
90
+ if frame is None:
91
+ break
92
+ # Some recordings have non-monotonic PTS; retain the nearest earlier frame.
93
+ if self._current_frame is not None and (
94
+ self._previous_frame is None
95
+ or self._frame_seconds(self._current_frame) >= self._frame_seconds(self._previous_frame)
96
+ ):
97
+ self._previous_frame = self._current_frame
98
+ self._current_frame = frame
99
+
100
+ if self._current_frame is None:
85
101
  return None
86
- return np.ascontiguousarray(best_frame.to_ndarray(format="rgb24"))
102
+ best_frame = self._current_frame
103
+ if self._previous_frame is not None and abs(self._frame_seconds(self._previous_frame) - target_seconds) < abs(
104
+ self._frame_seconds(best_frame) - target_seconds
105
+ ):
106
+ best_frame = self._previous_frame
107
+ return best_frame.to_ndarray(format="rgb24").copy() # Tracking overlays modify the returned image.
87
108
 
88
109
  def close(self):
110
+ self._decoder = None
111
+ self._previous_frame = self._current_frame = None
89
112
  container = getattr(self, "_container", None)
90
113
  self._container = None
91
114
  if container is not None:
@@ -674,13 +674,13 @@ class MovieView(utils.FastImageWidget):
674
674
  else:
675
675
  self.fly_positions.setData(pos=None) # this deletes the graph
676
676
 
677
- x_range, y_range = [0, self.m.vr.frame_height], [0, self.m.vr.frame_width]
677
+ x_range, y_range = [0, self.m.vr.frame_width], [0, self.m.vr.frame_height]
678
678
  if self.m.crop and not self.m.maintain_custom_crop:
679
679
  x_range, y_range = self.crop_frame(frame)
680
680
  # else:
681
- # x_range, y_range = [0, self.m.vr.frame_height], [0, self.m.vr.frame_width]
681
+ # x_range, y_range = [0, self.m.vr.frame_width], [0, self.m.vr.frame_height]
682
682
  else:
683
- x_range, y_range = [0, self.m.vr.frame_height], [0, self.m.vr.frame_width]
683
+ x_range, y_range = [0, self.m.vr.frame_width], [0, self.m.vr.frame_height]
684
684
 
685
685
  # this overrides everything
686
686
  if self.m.maintain_custom_crop:
@@ -739,8 +739,8 @@ class MovieView(utils.FastImageWidget):
739
739
  # makes sure crop does not exceed frame bounds
740
740
  fly_pos[0] = np.clip(fly_pos[0], self.m.box_size, self.m.vr.frame_height - 1 - self.m.box_size)
741
741
  fly_pos[1] = np.clip(fly_pos[1], self.m.box_size, self.m.vr.frame_width - 1 - self.m.box_size)
742
- x_range = (int(fly_pos[0] - self.m.box_size), int(fly_pos[0] + self.m.box_size))
743
- y_range = (int(fly_pos[1] - self.m.box_size), int(fly_pos[1] + self.m.box_size))
742
+ x_range = (int(fly_pos[1] - self.m.box_size), int(fly_pos[1] + self.m.box_size))
743
+ y_range = (int(fly_pos[0] - self.m.box_size), int(fly_pos[0] + self.m.box_size))
744
744
  # frame = frame[slice(*x_range), slice(*y_range), :] # now crop frame around the focal fly
745
745
  # return frame, x_range, y_range
746
746
  return x_range, y_range