reload(dataloader)

from jaratoolbox.test.nick.database import cellDB
reload(cellDB)

from jaratoolbox.test.nick.database import dataplotter
from jaratoolbox import spikesorting
from jaratoolbox.test.nick import clustercutting

from pylab import *


loader = dataloader.DataLoader('offline', experimenter='nick')

dbFn = '/home/nick/data/database/nick_thalamus_cells.json'
db = cellDB.CellDB()
db.load_from_json(dbFn)


c = db[0]
spikeData, eventData, behavData = loader.get_cluster_data(c, 'tc_heatmap')

spikeTimes = spikeData.timestamps
eventOnsetTimes = loader.get_event_onset_times(eventData)
currentFreq = behavData['currentFreq']
currentIntensity = behavData['currentIntensity']
trialsToPlot = currentIntensity==70
eventOnsetTimes=eventOnsetTimes[trialsToPlot]
currentFreq = currentFreq[trialsToPlot]

dataplotter.plot_raster(spikeTimes, eventOnsetTimes, sortArray=currentFreq)
 def setUp(self):
     self.database = cellDB.CellDB()
d2site1.add_session('11-15-56', None, sessionTypes['nb'])
d2site1.add_session('11-18-36', None, sessionTypes['lp'])
d2site1.add_session('11-21-26', None, sessionTypes['lt'])
d2site1.add_session('11-25-58', 'a', sessionTypes['tc'])
d2site1.add_session('11-39-46', None, sessionTypes['bf'])
d2site1.add_session('11-42-37', None, sessionTypes['3p'])
d2site1.add_session('11-45-22', None, sessionTypes['1p'])

d2site1.add_clusters({3: [2, 3, 5], 6: [3, 7]})

# ----------------------
##Initializing the database and adding clusters
# ----------------------

db = cellDB.CellDB()
db.add_clusters(d1site1.clusterList)
db.add_clusters(d2site1.clusterList)

# ----------------------
##Saving and loading databases
# ----------------------

#Writing currently overwrites the file. The proper way is to load the database,
#append new clusters to it, and then rewrite the file with the new contents added
#However, I am currently asking for confirmation unless you pass force=True.
dbfile = '/tmp/allcells.json'
db.write_to_json(dbfile)

db2 = cellDB.CellDB()
db2.load_from_json(dbfile)
from jaratoolbox.test.nick.database import cellDB

dbFn = '/home/nick/data/database/nick_thalamus_cells.json'
db = cellDB.CellDB()
db.load_from_json(dbFn)

figuredb = cellDB.CellDB()
figuredb.append(db[0])
figuredb.append(db[8])
figuredb.append(db[10])
figuredb.append(db[1])

figuredb[0].comments = 'B/C/D Option -  site 1 T6c3 (Thalamus)'

figuredb[
    1].comments = 'B/C/D (our favorite so far), also possibly J - site 6 T6c3 (Thalamus)'

figuredb[2].comments = 'J - site4 T3c10 (Thalamus)'

figuredb[3].comments = 'K - site1 T6c6 (Thalamus)'

cortexFn = '/home/nick/Desktop/cortexdb.json'
cortexdb = cellDB.CellDB()
cortexdb.load_from_json(cortexFn)

for cell in cortexdb:
    figuredb.append(cell)

amdbFn = '/home/nick/Desktop/amdatabase.json'
amdb = cellDB.CellDB()
amdb.load_from_json(amdbFn)