import from old-style relacs directory works

This commit is contained in:
Jan Grewe 2019-09-09 14:31:37 +02:00
parent 7ba7db5f63
commit fb7f856953

View File

@ -5,6 +5,7 @@ import os
import glob
import util as ut
import uuid
import yaml
import pyrelacs
from IPython import embed
@ -175,7 +176,6 @@ class Repro(dj.Manual):
----
repro_name : varchar(512)
settings : varchar(3000)
run : int
start : float
duration : float
"""
@ -371,7 +371,7 @@ def scan_nix_file_for_repros(dataset):
stim["stimulus_id"] = str(uuid.uuid1())
stim["stimulus_index"] = p
stim["start"] = stim_start
stim["start_index"] = -1;
stim["start_index"] = -1
stim["duration"] = stim_duration
stim["settings"] = settings
stim["mtag_id"] = mt.id
@ -384,22 +384,63 @@ def scan_nix_file_for_repros(dataset):
def scan_folder_for_repros(dataset):
print("No nix-file, scanning directory!")
repro_settings = ut.read_stimuli_file(dataset["data_source"])
for i, rs in enumerate(repro_settings):
repro_settings, stim_indices = ut.read_stimuli_file(dataset["data_source"])
repro_counts = {}
for i, (rs, si) in enumerate(zip(repro_settings, stim_indices)):
rp = Repro.get_template_tuple()
rp["run"] = rs["Run"]
rp["repro_name"] = rs["RePro"]
rp["dataset_id"] = dataset["dataset_id"]
rp["repro_id"] = t.name
settings = t.metadata.find_sections(lambda x: "settings" in x.type)
if len(settings) > 0:
rp["settings"] = ut.nix_metadata_to_yaml(settings[0])
path = []
if not ut.find_key_recursive(rs, "run", path):
ut.find_key_recursive(rs, "Run", path)
print(ut.deep_get(rs, path, 0))
rp["run"] = ut.deep_get(rs, path, 0)
path = []
if not ut.find_key_recursive(rs, "repro", path):
ut.find_key_recursive(rs, "RePro", path)
print(ut.deep_get(rs, path, "None"))
rp["repro_name"] = ut.deep_get(rs, path, "None")
path = []
if rp["repro_name"] in repro_counts.keys():
repro_counts[rp["repro_name"]] += 1
else:
rp["settings"] = ut.nix_metadata_to_yaml(t.metadata)
rp["start"] = t.position[0]
rp["duration"] = t.extent[0]
repro_counts[rp["repro_name"]] = 1
rp["dataset_id"] = dataset["dataset_id"]
rp["repro_id"] = rp["repro_name"] + str(repro_counts[rp["repro_name"]])
rp["start"] = 0.
rp["duration"] = 0.
rp["settings"] = yaml.dump(rs)
Repro.insert1(rp, skip_duplicates=True)
pass
# import stimuli
repro = dict((Repro & dict(repro_id=rp["repro_id"], dataset_id=rp["dataset_id"])).fetch1())
repro.pop("settings")
repro.pop("repro_name")
repro.pop("start")
repro.pop("duration")
for j, s in enumerate(si):
stim_start = 0.
path = []
if not ut.find_key_recursive(rs, "duration", path):
ut.find_key_recursive(rs, "Duration", path)
if len(path) > 0 :
stim_duration = ut.deep_get(rs, path, None)
stim_duration = float(stim_duration[:-2])
else:
stim_duration = 0.0
stim = Stimulus.get_template_tuple()
stim["stimulus_id"] = str(uuid.uuid1())
stim["stimulus_index"] = j
stim["start"] = stim_start
stim["start_index"] = s
stim["duration"] = stim_duration
stim["settings"] = yaml.dump(rs)
stim["mtag_id"] = ""
stim["stimulus_name"] = ""
stim.update(repro)
Stimulus.insert1(stim, skip_duplicates=True)
def populate_repros(data_path):
@ -436,7 +477,7 @@ def populate(datasets):
if __name__ == "__main__":
data_dir = "/data/apteronotus"
# data_dir = "../high_freq_chirps/data"
datasets = glob.glob(os.path.join(data_dir, '2018-03-22-ak-*'))
# drop_tables()
datasets = glob.glob(os.path.join(data_dir, '2012-03-23-ad*'))
populate(datasets)