From 0b1750ea243bf222a41411559c7b80ad2906200b Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Wed, 8 Oct 2025 16:03:36 +0200 Subject: [PATCH] [recreation] addning test sinus --- oephys2nix/stimulus_recreation.py | 52 ++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/oephys2nix/stimulus_recreation.py b/oephys2nix/stimulus_recreation.py index 956d0bf..8652d89 100644 --- a/oephys2nix/stimulus_recreation.py +++ b/oephys2nix/stimulus_recreation.py @@ -25,6 +25,9 @@ console = Console() class StimulusToNix: def __init__(self, open_ephys_path: pathlib.Path, relacs_nix_path: str, nix_file: str): + self.relacs_nix_path = relacs_nix_path + self.nix_file_path = nix_file + self.dataset = rlx.Dataset(relacs_nix_path) self.relacs_nix_file = nixio.File.open(relacs_nix_path, nixio.FileMode.ReadOnly) @@ -34,7 +37,6 @@ class StimulusToNix: self.neo_data = OpenEphysBinaryIO(open_ephys_path).read(lazy=True) self.fs = self.neo_data[0].segments[0].analogsignals[0].sampling_rate.magnitude - self.nix_file_path = nix_file self.nix_file = nixio.File(nix_file, nixio.FileMode.ReadWrite) self.block = self.nix_file.blocks[0] @@ -450,11 +452,8 @@ class StimulusToNix: for repro_r, repro_n in zip(self.dataset.repro_runs(), nix_data_set.repro_runs()): if repro_n.name.split("_")[0] not in important_repros: continue - if "SAM" in repro_n.name: - embed() - exit() - else: - continue + embed() + exit() if "FileStimulus" in repro_n.name: repro_n.stimulus_folder = "/home/alexander/stimuli/whitenoise/" @@ -464,10 +463,38 @@ class StimulusToNix: stim = repro_n.stimuli[0] stim_r = repro_r.stimuli[0] - v, t = stim.trace_data("local-eod") - v_r, t_r = stim_r.trace_data("LocalEOD-1") - plt.plot(t_r, v_r, "o--", color="tab:blue", label="relacs") - plt.plot(t, v, "o--", color="tab:red", label="open-ephys") + + # stim = repro_n + # stim_r = repro_r + sinus, t = stim.trace_data("sinus") + sinus_r, t_r = stim_r.trace_data("V-1") + + stimulus_oe, t = stim.trace_data("stimulus") + stimulus_re, t_r = stim_r.trace_data("GlobalEFieldStimulus") + + local_eod_oe, t = stim.trace_data("local-eod") + local_eod_re, t_r = stim_r.trace_data("LocalEOD-1") + + global_eod_oe, t = stim.trace_data("global-eod") + global_eod_re, t_r = stim_r.trace_data("EOD") + + ttl, t = stim.trace_data("ttl-line") + + fig, ax = plt.subplots(4, sharex=True) + ax[0].plot(t_r, stimulus_re, color="tab:blue", label="relacs") + ax[0].plot(t, stimulus_oe - np.mean(stimulus_oe), color="tab:red", label="open-ephys") + ax[0].plot(t, ttl, color="black") + + ax[1].plot(t_r, local_eod_re, color="tab:blue", label="relacs") + ax[1].plot(t, local_eod_oe, color="tab:red", label="open-ephys") + + ax[2].plot(t_r, global_eod_re, color="tab:blue", label="relacs") + ax[2].plot(t, global_eod_oe, color="tab:red", label="open-ephys") + + ax[3].plot(t_r, sinus_r, color="tab:blue", label="relacs") + ax[3].plot(t, sinus, color="tab:red", label="open-ephys") + + plt.legend(loc="upper right") # plt.plot(stimulus_time, white_noise, "o--", color="tab:orange", label="stimulus") # plt.plot(new_t, new_v, "go--", label="resampled") for i, (s, r) in enumerate(zip(repro_n.stimuli, repro_r.stimuli)): @@ -475,7 +502,6 @@ class StimulusToNix: v_r, t_r = r.trace_data("LocalEOD-1") plt.plot(t_r + (i * r.duration), v_r) plt.plot(t + (i * s.duration), v) - plt.legend(loc="upper right") plt.show() am = extract_am(v, 30_000) @@ -490,7 +516,9 @@ class StimulusToNix: ttl_oeph = self.block.data_arrays["ttl-line"][:] time_index = np.arange(len(ttl_oeph)) - peaks_ttl = time_index[(np.roll(ttl_oeph, 1) < 2) & (ttl_oeph > 2)] + peaks_ttl = time_index[ + (np.roll(ttl_oeph, 1) < self.threshold) & (ttl_oeph > self.threshold) + ] stimulus_oeph = self.block.data_arrays["stimulus"] stimulus = self.relacs_block.data_arrays["GlobalEFieldStimulus"]