[database] fix repro run counter ...

sometimes repros do not  put out stimuli for whatever reason.
They are noted in the stimuli.dat but not e.g. in the stimspikes.dat.
This leads to conflicts when fetching the data...
This commit is contained in:
Jan Grewe 2020-08-14 17:19:02 +02:00
parent 34f0044749
commit 6e2bfde2dc

View File

@ -453,7 +453,9 @@ def scan_nix_file_for_repros(dataset):
def scan_folder_for_repros(dataset):
print("\t\tNo nix-file, scanning directory!")
repro_settings, stim_indices = read_stimuli_file(dataset["data_source"])
repro_counts = {}
repro_counts = {} # internal counter for repro runs, for cases in which the repro does not have a run counter
repros_skipped = {} # internal counter to correct the run counter for repro runs in which no stimulus was put out, needed to align e.g. with stimspikes file
repros_without_stims = ["baselineactivity"]
cell_id = (Cells * CellDatasetMap * (Datasets & "dataset_id = '%s'" % dataset["dataset_id"])).fetch("cell_id", limit=1)[0]
for rs, si in zip(repro_settings, stim_indices):
rp = Repros.get_template_tuple()
@ -463,20 +465,26 @@ def scan_folder_for_repros(dataset):
find_key_recursive(rs, "RePro", path)
rp["repro_name"] = deep_get(rs, path, "None")
if rp["repro_name"] not in repros_skipped.keys():
repros_skipped[rp["repro_name"]] = 0
if rp["repro_name"].lower() not in repros_without_stims and len(si) == 0:
repros_skipped[rp["repro_name"]] += 1
continue
path = []
if rp["repro_name"] in repro_counts.keys():
repro_counts[rp["repro_name"]] += 1
else:
repro_counts[rp["repro_name"]] = 0
path = []
if not find_key_recursive(rs, "run", path):
find_key_recursive(rs, "Run", path)
if len(path) > 0:
rp["run"] = deep_get(rs, path, 0)
rp["run"] = int(deep_get(rs, path, 0)) - repros_skipped[rp["repro_name"]]
else: # the run information is not there and needs to be fixed!
rp["run"] = repro_counts[rp["repro_name"]]
rp["run"] = repro_counts[rp["repro_name"]] - repros_skipped[rp["repro_name"]]
rp["cell_id"] = cell_id
rp["repro_id"] = rp["repro_name"] + str(repro_counts[rp["repro_name"]])
rp["start"] = 0.
@ -501,8 +509,10 @@ def scan_folder_for_repros(dataset):
find_key_recursive(rs, "Duration", path)
if len(path) > 0 :
stim_duration = deep_get(rs, path, None)
if "ms" in stim_duration:
stim_duration = float(stim_duration[:stim_duration.index("ms")])
if "sec" in stim_duration:
stim_duration = float(stim_duration[:stim_duration.index("sec")])
elif "ms" in stim_duration:
stim_duration = float(stim_duration[:stim_duration.index("ms")]) / 1000
else:
stim_duration = float(stim_duration[:stim_duration.index("s")])
else: