diff --git a/fishbook/reproclasses.py b/fishbook/reproclasses.py index e35bb7a..411f1aa 100644 --- a/fishbook/reproclasses.py +++ b/fishbook/reproclasses.py @@ -435,10 +435,7 @@ class FIData: start_time = stimulus.start_time - delay end_time = stimulus.start_time + stimulus.duration - spikes_da = mtag.references["Spikes-1"] eod_da = mtag.references["LocalEOD-1"] - start_index_spikes = spikes_da.dimensions[0].index_of(start_time) - end_index_spikes = spikes_da.dimensions[0].index_of(end_time) start_index_eod = eod_da.dimensions[0].index_of(start_time) end_index_eod = eod_da.dimensions[0].index_of(end_time) @@ -479,37 +476,51 @@ class FIData: def __do_read_data_block(self, f, l): spikes = [] while len(l.strip()) > 0 and "#" not in l: - spikes.append(float(l.strip())) + spikes.append(float(l.strip())/1000) l = f.readline() return spikes, l def __read_spikes_from_directory(self, repro: RePro): spikes = [] contrasts = [] + times = [] print("Warning! Exact reconstruction of stimulus order not possible for old relacs files!") data_source = os.path.join(self.__dataset.data_source, "fispikes1.dat") + delay = 0.0 + pause = 0.0 + for s in repro.settings.split(", "): + if "pause" in s: + s = s.split(":")[-1].strip() + pause = float(s[:-2])/1000 if "ms" in s else float(s[:-1]) + if "delay" in s: + s = s.split(":")[-1].strip() + delay = float(s[:-2])/1000 if "ms" in s else float(s[:-1]) + t_start = -delay + t_end = pause + delay + time = np.arange(t_start, t_end, 1./repro.dataset.samplerate) if os.path.exists(data_source): with open(data_source, 'r') as f: - l = f.readline() + line = f.readline() fish_intensity = None stim_intensity = None - while l: - l = l.strip().lower() - if "index" in l: + while line: + line = line.strip().lower() + if "index" in line: fish_intensity = None stim_intensity = None - if "intensity = " in l: - if "true intensity = " in l: - fish_intensity = float(l.split("=")[-1].strip()[:-2]) - elif "pre" not in l: - stim_intensity = float(l.split("=")[-1].strip()[:-2]) - if len(l) > 0 and "#" not in l: # data line - sp, l = self.__do_read_data_block(f, l) + if "intensity = " in line: + if "true intensity = " in line: + fish_intensity = float(line.split("=")[-1].strip()[:-2]) + elif "pre" not in line: + stim_intensity = float(line.split("=")[-1].strip()[:-2]) + if len(line) > 0 and "#" not in line: # data line + sp, line = self.__do_read_data_block(f, line) spikes.append(sp) + times.append(time) contrasts.append((stim_intensity/fish_intensity-1)*100) continue - l = f.readline() - return spikes, contrasts, None, None + line = f.readline() + return spikes, contrasts, None, times @property def size(self) -> int: