Skip to content

Commit 16f9f14

Browse files
committed
add ability to change sync peak finding algo
1 parent 3bba574 commit 16f9f14

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

packages/cheese3d/cheese3d/synchronize/core.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44
import matplotlib.pyplot as plt
55
from dataclasses import dataclass
6-
from typing import List, Tuple, Dict, Any
6+
from typing import List, Tuple, Dict, Any, Literal
77
from pathlib import Path
88

99
from cheese3d.synchronize.aligners import (BaseAligner,
@@ -19,6 +19,7 @@
1919
class SyncConfig:
2020
pipeline: List[str]
2121
led_threshold: float = 0.9
22+
led_peak_algorithm: Literal["dynamic", "max"] = "dynamic"
2223
max_regression_rmse: float = 1e-2
2324
ref_view: str = "bottomcenter"
2425
ref_crop: str = "default"
@@ -234,12 +235,14 @@ def synchronize_videos(pipeline_cfg: SyncConfig,
234235
ref_reader = VideoSyncReader(source=ref_video,
235236
sample_rate=fps,
236237
threshold=pipeline_cfg.led_threshold,
238+
peak_algorithm=pipeline_cfg.led_peak_algorithm,
237239
crop=ref_crop)
238240
align_params = {"ref": (ref_video, 0, fps)}
239241
for view, (video, crop) in videos.items():
240242
target_reader = VideoSyncReader(source=video,
241243
sample_rate=fps,
242244
threshold=pipeline_cfg.led_threshold,
245+
peak_algorithm=pipeline_cfg.led_peak_algorithm,
243246
crop=crop)
244247
pipeline = SyncPipeline.from_cfg(pipeline_cfg, ref_reader, target_reader)
245248
target_path = pipeline.target.root_path()
@@ -267,6 +270,7 @@ def synchronize_ephys(pipeline_cfg: SyncConfig,
267270
video_reader = VideoSyncReader(source=ref_video,
268271
sample_rate=fps,
269272
threshold=pipeline_cfg.led_threshold,
273+
peak_algorithm=pipeline_cfg.led_peak_algorithm,
270274
crop=ref_crop)
271275
ephys_reader = get_ephys_reader(ephys_path, ephys_params)
272276
pipeline = SyncPipeline.from_cfg(pipeline_cfg, video_reader, ephys_reader)

packages/cheese3d/cheese3d/synchronize/readers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import matplotlib.patches as patches
77
from dataclasses import dataclass, field
88
from pathlib import Path
9-
from typing import Optional, Dict, Any
9+
from typing import Optional, Dict, Any, Literal
1010
from tqdm import tqdm
1111
from open_ephys.analysis import Session as OESession
1212

@@ -50,6 +50,7 @@ class VideoSyncReader(SyncSignalReader):
5050
- `crop`: Tuple of (left, right, top, bottom) coordinates for cropping.
5151
"""
5252
crop: BoundingBox = field(default_factory=lambda: [None, None, None, None])
53+
peak_algorithm: Literal["dynamic", "max"] = "dynamic"
5354

5455
def load_signal(self):
5556
print(self.source)
@@ -65,7 +66,7 @@ def load_signal(self):
6566
min_brightness = bin_edges[np.argmax(hist) + 1]
6667
brightness = brightness - min_brightness
6768
nz_brightness = brightness[brightness > 2]
68-
if len(nz_brightness) > 0:
69+
if (self.peak_algorithm == "dynamic") and (len(nz_brightness) > 0):
6970
mid = np.percentile(nz_brightness, 75)
7071
# q3 = np.percentile(nz_brightness, 75)
7172
# iqr = q3 - q1
@@ -87,6 +88,7 @@ def load_signal(self):
8788

8889
fig, ax = plt.subplots(figsize=(8, 6))
8990
ax.plot(brightness)
91+
ax.axhline(peak_brightness, color='k', linestyle='--')
9092
ax.axhline(led_threshold, color='r', linestyle='--')
9193
ax.set_title("LED BBox Brightness")
9294
fig.savefig(f"{video.path.rstrip('.avi')}-qc-brightness.png", bbox_inches="tight")

0 commit comments

Comments
 (0)