# coding: utf-8

# In[1]:


import os
import sys
import pyqtgraph as pg
import numpy as np


# In[7]:


dir_path = os.path.abspath("")

win = pg.GraphicsWindow()
win.setBackground("w")
p1 = win.addPlot(
    title="Pauser PSTH",
    row=0,
    col=0,
    labels={"bottom": "T (ms)", "left": "# of spikes"},
)
p2 = win.addPlot(
    title="Buildup PSTH",
    row=1,
    col=0,
    labels={"bottom": "T (ms)", "left": "# of spikes"},
)
p3 = win.addPlot(
    title="Wide Chopper PSTH",
    row=2,
    col=0,
    labels={"bottom": "T (ms)", "left": "# of spikes"},
)

# In[ ]:

bins = np.arange(0, 80, 0.5)

PB_spike_data = []
with open("Ad081098_065_PauserBuildup_psth.txt", "r+") as df:
    for x in df:
        x = x.strip("\n").strip()
        x = float(x) * 1e-3
        if x:
            PB_spike_data.append(x)
histogram, binedges = np.histogram(PB_spike_data, bins)
p1.plot(
    binedges,
    histogram,
    stepMode=True,
    fillBrush=(0, 0, 0, 255),
    brush=pg.mkBrush("k"),
    fillLevel=0,
)
B_spike_data = []
with open("Ad041599_062_Buildup_psth.txt", "r+") as df:
    for x in df:
        x = x.strip("\n").strip()
        x = float(x) * 1e-3
        if x:
            B_spike_data.append(x)
histogram, binedges = np.histogram(B_spike_data, bins)
p2.plot(
    binedges,
    histogram,
    stepMode=True,
    fillBrush=(0, 0, 0, 255),
    brush=pg.mkBrush("k"),
    fillLevel=0,
)
C_spike_data = []
with open("Ad081998_199_WideChopper_psth.txt", "r+") as df:
    for x in df:
        x = x.strip("\n").strip()
        x = float(x) * 1e-3
        if x:
            C_spike_data.append(x)
histogram, binedges = np.histogram(C_spike_data, bins)
p3.plot(
    binedges,
    histogram,
    stepMode=True,
    fillBrush=(0, 0, 0, 255),
    brush=pg.mkBrush("k"),
    fillLevel=0,
)
# In[ ]:


win.show()
print("finished")
if sys.flags.interactive == 0:
    pg.QtGui.QApplication.exec_()
