forked from jgrewe/fishbook
[database] Stimului included
This commit is contained in:
parent
ed1974980c
commit
ec38f2db12
45
database.py
45
database.py
@ -4,6 +4,7 @@ import nixio as nix
|
||||
import os
|
||||
import glob
|
||||
import util as ut
|
||||
import uuid
|
||||
|
||||
from IPython import embed
|
||||
|
||||
@ -181,7 +182,7 @@ class Repro(dj.Manual):
|
||||
def get_template_tuple(repro_id=None):
|
||||
tup = dict(repro_id=None, dataset_id=None, run=0, repro_name="", settings=None, start=None, duration=None)
|
||||
if repro_id is not None:
|
||||
d = dict((RePro() & {"repro_id": repro_id}).fetch1())
|
||||
d = dict((Repro() & {"repro_id": repro_id}).fetch1())
|
||||
return d
|
||||
return tup
|
||||
|
||||
@ -189,14 +190,25 @@ class Repro(dj.Manual):
|
||||
@schema
|
||||
class Stimulus(dj.Manual):
|
||||
definition = """
|
||||
stimulus_id : int
|
||||
-> Repro
|
||||
stimulus_id : varchar(50)
|
||||
-> Repro
|
||||
---
|
||||
settings : varchar(3000)
|
||||
stimulus_index : int
|
||||
stimulus_name : varchar(512)
|
||||
start : float
|
||||
duration : float
|
||||
settings : varchar(3000)
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def get_template_tuple(stimulus_id=None):
|
||||
if stimulus_id is not None:
|
||||
tup = dict((Stimulus & {"stimulus_id": stimulus_id}).fetch1())
|
||||
else:
|
||||
tup = dict(stimulus_id=None, stimulus_index=None, stimulus_name="", start=0.0, duration=0.0, settings=None)
|
||||
return tup
|
||||
|
||||
|
||||
def populate_datasets(data_path):
|
||||
print("Importing dataset %s" % data_path)
|
||||
if not os.path.exists(data_path):
|
||||
@ -341,6 +353,31 @@ def populate_repros(data_path):
|
||||
rp["start"] = t.position[0]
|
||||
rp["duration"] = t.extent[0]
|
||||
Repro.insert1(rp, skip_duplicates=True)
|
||||
repro = dict((Repro & dict(repro_id="BaselineActivity_2", dataset_id="2018-11-20-ae-invivo-1")).fetch1())
|
||||
repro.pop("settings")
|
||||
repro.pop("repro_name")
|
||||
repro.pop("start")
|
||||
repro.pop("duration")
|
||||
# import Stimuli
|
||||
mtags = ut.find_mtags_for_tag(b, t)
|
||||
stim_index = 0
|
||||
for mt in mtags:
|
||||
mt_positions = np.atleast_2d(mt.positions[:]).T
|
||||
mt_extents = np.atleast_2d(mt.extents[:]).T
|
||||
for i in range(mt.positions.shape[0]):
|
||||
settings = ut.mtag_settings_to_yaml(mt, i)
|
||||
stim_start = mt_positions[i, 0]
|
||||
stim_duration = mt_extents[i, 0]
|
||||
|
||||
stim = Stimulus.get_template_tuple()
|
||||
stim["stimulus_id"] = str(uuid.uuid1())
|
||||
stim["stimulus_index"] = stim_index
|
||||
stim["start"] = stim_start
|
||||
stim["duration"] = stim_duration
|
||||
stim["settings"] = settings
|
||||
stim.update(repro)
|
||||
Stimulus.insert1(stim, skip_duplicates=True)
|
||||
stim_index += 1
|
||||
f.close()
|
||||
f = None
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user