Compare commits

...

3 Commits

3 changed files with 50 additions and 19 deletions

View File

@ -35,6 +35,13 @@ def main(
log.info(f"Selected data_path is {data_path}")
open_ephys_data_paths = list(Path(data_path).rglob("*open-ephys"))
relacs_data_paths = list(Path(data_path).rglob("*relacs/*.nix"))
if not open_ephys_data_paths:
log.error("Did not find any open-ephys data")
raise typer.Exit()
if not relacs_data_paths:
log.error("Did not find any relacs data")
raise typer.Exit()
if len(open_ephys_data_paths) != len(relacs_data_paths):
log.error(

View File

@ -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
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"]

View File

@ -35,23 +35,19 @@ class RawToNix:
self.block.metadata = sec
def append_fish_lines(self):
efishs = [
"ttl-line",
"global-eod",
"stimulus",
"local-eod",
]
efishs = ["ttl-line", "global-eod", "stimulus", "local-eod", "sinus"]
efish_types = [
"open-ephys.data.sampled",
"open-ephys.data.sampled",
"open-ephys.data.sampled",
"open-ephys.data.sampled",
"open-ephys.data.sampled",
]
efish_group = self.block.create_group("efish", "open-ephys.sampled")
efish_neo_data = self.neo_data[0].segments[0].analogsignals[1].load()
efish_neo_data = self.neo_data[0].segments[0].analogsignals[2].load()
for i in np.arange(len(efishs)):
log.debug(f"Appending efish traces {efishs[i]}")