--- title: Delays anaylsis format: html: toc: true toc-title: Contents code-block-bg: true code-block-border-left: "#31BAE9" code-line-numbers: true highlight-style: atom-one link-external-icon: true link-external-newwindow: true eqn-number: true --- ### 1. Delays We noticed a delay in the recodings if you were to plot a comparision between the base relacs recording and the new generated open-ephys. ```{python} # | echo: False import pathlib import numpy as np import pandas as pd import plotly.express as px import plotly.graph_objects as go import rlxnix as rlx import scipy.signal as signal from plotly.subplots import make_subplots from rich.progress import track from rich.table import Table from util import calc_lag, plot_line_comparision, trial_plot dataset_path = pathlib.Path("../oephys2nix/test/Test1/2025-10-08-aa-invivo-2-recording.nix") relacs_path = pathlib.Path( "../oephys2nix/test/Test1/2025-10-08-aa-invivo-2_relacs/2025-10-08-aa-invivo-2.nix" ) dataset = rlx.Dataset(str(dataset_path)) relacs = rlx.Dataset(str(relacs_path)) # INFO: Select the first stimulus of the calibration repro repro_d = dataset.repro_runs("FileStimulus_1")[0].stimuli[2] repro_r = relacs.repro_runs("FileStimulus_1")[0].stimuli[2] sinus, t = repro_d.trace_data("sinus") sinus_r, t_r = repro_r.trace_data("V-1") stimulus_oe, t = repro_d.trace_data("stimulus") stimulus_re, t_r = repro_r.trace_data("GlobalEFieldStimulus") local_eod_oe, t = repro_d.trace_data("local-eod") local_eod_re, t_r = repro_r.trace_data("LocalEOD-1") global_eod_oe, t = repro_d.trace_data("global-eod") global_eod_re, t_r = repro_r.trace_data("EOD") ttl, t = repro_d.trace_data("ttl-line") fig = plot_line_comparision( t_r, t, stimulus_re, stimulus_oe - np.mean(stimulus_oe), ["stimulus-relacs", "stimulus-open-ephys"], ) fig.show() ``` ### 2. Look at differnt RePros Currently implemented repros are: - [x] [Baseline](baseline.qmd) - [x] [Calibration](calibration.qmd) - [x] [FI Curve](fi_curve.qmd) - [x] [File Stimulus](filestimulus.qmd) - [ ] Sams - [ ] Chrips - [ ] Beats ### 3. General Delay in detail ```{python} rich_tabel = Table("Repro Run", "Signal", "Lag (samples)") names_lanes = ["sinus", "local-eod", "global-eod", "stimulus"] dataframe = [] for repro_idx, (repro_d, repro_r) in enumerate( zip(dataset.repro_runs(), relacs.repro_runs(), strict=True) ): if not repro_d.stimuli: lags = calc_lag(repro_d, repro_r) for lag, names_lane in zip(lags, names_lanes, strict=True): rich_tabel.add_row(f"{repro_d.name}", f"{names_lane}", f"{lag}") dataframe.append( {"ReproName": repro_d.name, "Line": names_lane, "Lag": lag, "Trial": 0} ) else: lags_lanes = {f"{key}": [] for key in names_lanes} for trial, (stim_oe, stim_re) in enumerate( zip(repro_d.stimuli, repro_r.stimuli, strict=True) ): lags = calc_lag(stim_oe, stim_re) for lag, names_lane in zip(lags, names_lanes): lags_lanes[names_lane].append(lag) dataframe.append( {"ReproName": repro_d.name, "Line": names_lane, "Lag": lag, "Trial": trial} ) for lane in lags_lanes: mean_lag = np.mean(lags_lanes[lane]) std_lag = np.std(lags_lanes[lane]) rich_tabel.add_row(f"{repro_d.name}", f"{lane}", f"{mean_lag:.2f}\u00b1{std_lag:.2f}") rich_tabel ``` ```{python} repros = dataset.repro_runs("Baseline") print(repros) exclude = [] for rep in repros: exclude.append(rep.name) df = pd.DataFrame(dataframe) df = df[~df["ReproName"].isin(exclude)] fig = px.box( df, x="Line", y="Lag", color="Line", title="Lag Distribution Across Different Signals", labels={"Line": "Signal", "Lag": "Lag (samples)"}, ) fig.update_layout(template="plotly_dark") fig.show() fig = px.box( df, x="Line", y="Lag", color="ReproName", title="Lag Distribution by Signal and Repro Run", labels={"Line": "Signal", "Lag": "Lag (samples)"}, ) fig.update_layout(template="plotly_dark") fig.show() ```