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