<commit_before>
from PyQt4 import QtGui, QtCore
from collections import OrderedDict
from acq4.analysis.AnalysisModule import AnalysisModule
import STDPControlTemplate, STDPPlotsTemplate
import acq4.pyqtgraph as pg
import numpy as np
from acq4.util.functions import measureResistance
from acq4.util.DatabaseGui.DatabaseGui import DatabaseGui
import STDPFileLoader

class STDPAnalyzer(AnalysisModule):

    dbIdentity = "STDPAnalyzer"

    def __init__(self, host):
        AnalysisModule.__init__(self, host)

        self.ctrlWidget = QtGui.QWidget()
        self.ctrl = STDPControlTemplate.Ui_Form()
        self.ctrl.setupUi(self.ctrlWidget)

        tables = OrderedDict([
            (self.dbIdentity+'.trials', 'STDP_Trials'),
            (self.dbIdentity+'.cell', 'STDP_Cell')
        ])
        self.dbGui = DatabaseGui(dm=self.dataManager(), tables=tables)

       
        self.plotsWidget = QtGui.QWidget()
        self.plots = STDPPlotsTemplate.Ui_Form()
        self.plots.setupUi(self.plotsWidget)

        self.pairingPlot = pg.PlotWidget()

        self.fileLoader = STDPFileLoader.STDPFileLoader(self.dataManager(), host=self, showFileTree=True)


        # ### Plots accessible through self.plots - defined above:
        #     exptPlot - displays the time when traces were recorded. Used to choose which traces are displayed in tracesPlot
        #     tracesPlot - displays data traces
        #     plasticityPlot - displays a measure of synaptic plasticity over the course of the experimetn
        #     RMP_plot - displays the resting membrane potential (or holding current) over the course of the Experiment
        #     RI_plot - displays the input resistance over the course of the experiment
        #     HoldingPlot -- displays the amount of slow holding current used over the course of the experiment

        self._elements_ = OrderedDict([
            ('File Loader', {'type':'ctrl', 'object': self.fileLoader, 'size': (100, 100)}),
            ('Control Panel', {'type':'ctrl', 'object': self.ctrlWidget, 'pos':('below', 'File Loader'),'size': (100, 400)}),
            ('Database', {'type':'ctrl', 'object': self.dbGui, 'pos':('below', 'Control Panel'), 'size':(100,100)}),
            ('EPSP Plots', {'type': 'ctrl', 'object': self.plotsWidget, 'pos': ('right', 'File Loader'), 'size': (400, 700)}),
            ('Pairing Plots', {'type': 'ctrl', 'object': self.pairingPlot, 'pos':('below', 'EPSP Plots')})
        ])
        self.initializeElements()
           
        
        ## Set labels/titles on plots  -- takes a lot of space
        # self.plots.exptPlot.setTitle('Experiment Timecourse')
        # self.plots.tracesPlot.setLabel('left', "Voltage") ### TODO: check whether traces are in VC or IC
        # self.plots.tracesPlot.setTitle("Data")
        self.plots.plasticityPlot.setLabel('left', 'Slope', units='V/s')
        # self.plots.plasticityPlot.setTitle('Plasticity')
        # self.plots.RMP_plot.setTitle('Resting Membrane Potential')
        self.plots.RMP_plot.setLabel('left', text='RMP', units='V')
        self.plots.RI_plot.setLabel('left', text='Input R', units='Ohm')
        self.plots.holdingPlot.setLabel('left', "Holding Current", units='A')
        # self.plots.RI_plot.setTitle('Input Resistance')

        for p in [self.plots.exptPlot, self.plots.tracesPlot, self.plots.plasticityPlot,
                 self.plots.RMP_plot, self.plots.RI_plot, self.plots.holdingPlot]:
            p.setLabel('bottom', 'Time', units='s')

        ## Set up measurement regions in plots
        self.traceSelectRgn = pg.LinearRegionItem()
        self.traceSelectRgn.setRegion([0, 300])
        self.plots.exptPlot.addItem(self.traceSelectRgn)
        self.traceSelectRgn.sigRegionChanged.connect(self.updateTracesPlot)

        self.plasticityRgn = pg.LinearRegionItem(movable=False)
        self.plasticityRgn.setRegion([27*60, 47*60])
        self.plots.exptPlot.addItem(self.plasticityRgn)

        self.baselineRgn = pg.LinearRegionItem(brush=(0,150,0,50))
        self.plots.tracesPlot.addItem(self.baselineRgn)
        
        self.pspRgn = pg.LinearRegionItem(brush=(150,0,0,50))
        self.plots.tracesPlot.addItem(self.pspRgn)

        self.healthRgn = pg.LinearRegionItem(brush=(0,0,150,50))
        self.plots.tracesPlot.addItem(self.healthRgn)

        self.pspLine = pg.InfiniteLine(pos=0.055, pen='b', movable=True)
        self.pairingPlot.addItem(self.pspLine)
        self.spikeLine = pg.InfiniteLine(pos=0.065, pen='r', movable=True)
        self.pairingPlot.addItem(self.spikeLine)
        self.ctrl.pspStartTimeSpin.setOpts(suffix='s', siPrefix=True, dec=True, value=0.055, step=0.1)
        self.ctrl.spikePeakSpin.setOpts(suffix='s', siPrefix=True, dec=True, value=0.065, step=0.1)
        self.pspLine.sigPositionChanged.connect(self.pspLineChanged)
        self.spikeLine.sigPositionChanged.connect(self.spikeLineChanged)
        self.ctrl.pspStartTimeSpin.valueChanged.connect(self.pspStartSpinChanged)
        self.ctrl.spikePeakSpin.valueChanged.connect(self.spikePeakSpinChanged)

        ### Connect control panel
        self.averageCtrl = pg.WidgetGroup(self.ctrl.traceDisplayGroup) ##TODO: save state when we save data
        self.ctrl.averageCheck.setChecked(True)
        self.ctrl.averageTimeSpin.setOpts(suffix='s', siPrefix=True, dec=True, value=60, step=1)
        self.ctrl.averageNumberSpin.setOpts(step=1, dec=True)
        self.ctrl.startExcludeAPsSpin.setOpts(suffix='s', siPrefix=True, dec=True, value=0, step=1, minstep=0.001)
        self.ctrl.endExcludeAPsSpin.setOpts(suffix='s', siPrefix=True, dec=True, value=0.25, step=1, minstep=0.001)
        self.averageCtrl.sigChanged.connect(self.averageCtrlChanged)

        self.analysisCtrl = pg.WidgetGroup(self.ctrl.analysisGroup)
        self.ctrl.baselineCheck.toggled.connect(self.regionDisplayToggled)
        self.ctrl.pspCheck.toggled.connect(self.regionDisplayToggled)
        self.ctrl.healthCheck.toggled.connect(self.regionDisplayToggled)

        self.ctrl.baselineStartSpin.setOpts(suffix='s', siPrefix=True, dec=True, step=1, minStep=0.001)
        self.ctrl.baselineEndSpin.setOpts(suffix='s', siPrefix=True, dec=True, step=1, minStep=0.001)
        self.ctrl.baselineStartSpin.valueChanged.connect(self.baselineSpinChanged)
        self.ctrl.baselineEndSpin.valueChanged.connect(self.baselineSpinChanged)
        self.baselineRgn.sigRegionChangeFinished.connect(self.baselineRgnChanged)

        self.ctrl.pspStartSpin.setOpts(suffix='s', siPrefix=True, dec=True, step=1, minStep=0.001)
        self.ctrl.pspEndSpin.setOpts(suffix='s', siPrefix=True, dec=True, step=1, minStep=0.001)
        self.ctrl.pspStartSpin.valueChanged.connect(self.pspSpinChanged)
        self.ctrl.pspEndSpin.valueChanged.connect(self.pspSpinChanged)
        self.pspRgn.sigRegionChangeFinished.connect(self.pspRgnChanged)

        self.ctrl.healthStartSpin.setOpts(suffix='s', siPrefix=True, dec=True, step=1, minStep=0.001)
        self.ctrl.healthEndSpin.setOpts(suffix='s', siPrefix=True, dec=True, step=1, minStep=0.001)
        self.ctrl.healthStartSpin.valueChanged.connect(self.healthSpinChanged)
        self.ctrl.healthEndSpin.valueChanged.connect(self.healthSpinChanged)
        self.healthRgn.sigRegionChangeFinished.connect(self.healthRgnChanged)

        self.ctrl.analyzeBtn.clicked.connect(self.analyze)
        self.ctrl.storeToDBBtn.clicked.connect(self.storeToDB)
        self.ctrl.createSummaryBtn.clicked.connect(self.summarySheetRequested)
        self.ctrl.createBlindSummaryBtn.clicked.connect(self.blindSummarySheetRequested)
        self.ctrl.defaultRgnBtn.clicked.connect(self.defaultBtnClicked)

        self.baselineRgn.setRegion((0,0.05))
        self.pspRgn.setRegion((0.052,0.067))
        self.healthRgn.setRegion((0.24,0.34))

        #self.ctrl.measureAvgSpin.setOpts(step=1, dec=True)
        self.ctrl.measureModeCombo.addItems(['Slope (max)', 'Amplitude (max)'])<commit_msg>disabled measurement of PSP amplitudes<commit_after>
from PyQt4 import QtGui, QtCore
from collections import OrderedDict
from acq4.analysis.AnalysisModule import AnalysisModule
import STDPControlTemplate, STDPPlotsTemplate
import acq4.pyqtgraph as pg
import numpy as np
from acq4.util.functions import measureResistance
from acq4.util.DatabaseGui.DatabaseGui import DatabaseGui
import STDPFileLoader

class STDPAnalyzer(AnalysisModule):

    dbIdentity = "STDPAnalyzer"

    def __init__(self, host):
        AnalysisModule.__init__(self, host)

        self.ctrlWidget = QtGui.QWidget()
        self.ctrl = STDPControlTemplate.Ui_Form()
        self.ctrl.setupUi(self.ctrlWidget)

        tables = OrderedDict([
            (self.dbIdentity+'.trials', 'STDP_Trials'),
            (self.dbIdentity+'.cell', 'STDP_Cell')
        ])
        self.dbGui = DatabaseGui(dm=self.dataManager(), tables=tables)

       
        self.plotsWidget = QtGui.QWidget()
        self.plots = STDPPlotsTemplate.Ui_Form()
        self.plots.setupUi(self.plotsWidget)

        self.pairingPlot = pg.PlotWidget()

        self.fileLoader = STDPFileLoader.STDPFileLoader(self.dataManager(), host=self, showFileTree=True)


        # ### Plots accessible through self.plots - defined above:
        #     exptPlot - displays the time when traces were recorded. Used to choose which traces are displayed in tracesPlot
        #     tracesPlot - displays data traces
        #     plasticityPlot - displays a measure of synaptic plasticity over the course of the experimetn
        #     RMP_plot - displays the resting membrane potential (or holding current) over the course of the Experiment
        #     RI_plot - displays the input resistance over the course of the experiment
        #     HoldingPlot -- displays the amount of slow holding current used over the course of the experiment

        self._elements_ = OrderedDict([
            ('File Loader', {'type':'ctrl', 'object': self.fileLoader, 'size': (100, 100)}),
            ('Control Panel', {'type':'ctrl', 'object': self.ctrlWidget, 'pos':('below', 'File Loader'),'size': (100, 400)}),
            ('Database', {'type':'ctrl', 'object': self.dbGui, 'pos':('below', 'Control Panel'), 'size':(100,100)}),
            ('EPSP Plots', {'type': 'ctrl', 'object': self.plotsWidget, 'pos': ('right', 'File Loader'), 'size': (400, 700)}),
            ('Pairing Plots', {'type': 'ctrl', 'object': self.pairingPlot, 'pos':('below', 'EPSP Plots')})
        ])
        self.initializeElements()
           
        
        ## Set labels/titles on plots  -- takes a lot of space
        # self.plots.exptPlot.setTitle('Experiment Timecourse')
        # self.plots.tracesPlot.setLabel('left', "Voltage") ### TODO: check whether traces are in VC or IC
        # self.plots.tracesPlot.setTitle("Data")
        self.plots.plasticityPlot.setLabel('left', 'Slope', units='V/s')
        # self.plots.plasticityPlot.setTitle('Plasticity')
        # self.plots.RMP_plot.setTitle('Resting Membrane Potential')
        self.plots.RMP_plot.setLabel('left', text='RMP', units='V')
        self.plots.RI_plot.setLabel('left', text='Input R', units='Ohm')
        self.plots.holdingPlot.setLabel('left', "Holding Current", units='A')
        # self.plots.RI_plot.setTitle('Input Resistance')

        for p in [self.plots.exptPlot, self.plots.tracesPlot, self.plots.plasticityPlot,
                 self.plots.RMP_plot, self.plots.RI_plot, self.plots.holdingPlot]:
            p.setLabel('bottom', 'Time', units='s')

        ## Set up measurement regions in plots
        self.traceSelectRgn = pg.LinearRegionItem()
        self.traceSelectRgn.setRegion([0, 300])
        self.plots.exptPlot.addItem(self.traceSelectRgn)
        self.traceSelectRgn.sigRegionChanged.connect(self.updateTracesPlot)

        self.plasticityRgn = pg.LinearRegionItem(movable=False)
        self.plasticityRgn.setRegion([27*60, 47*60])
        self.plots.exptPlot.addItem(self.plasticityRgn)

        self.baselineRgn = pg.LinearRegionItem(brush=(0,150,0,50))
        self.plots.tracesPlot.addItem(self.baselineRgn)
        
        self.pspRgn = pg.LinearRegionItem(brush=(150,0,0,50))
        self.plots.tracesPlot.addItem(self.pspRgn)

        self.healthRgn = pg.LinearRegionItem(brush=(0,0,150,50))
        self.plots.tracesPlot.addItem(self.healthRgn)

        self.pspLine = pg.InfiniteLine(pos=0.055, pen='b', movable=True)
        self.pairingPlot.addItem(self.pspLine)
        self.spikeLine = pg.InfiniteLine(pos=0.065, pen='r', movable=True)
        self.pairingPlot.addItem(self.spikeLine)
        self.ctrl.pspStartTimeSpin.setOpts(suffix='s', siPrefix=True, dec=True, value=0.055, step=0.1)
        self.ctrl.spikePeakSpin.setOpts(suffix='s', siPrefix=True, dec=True, value=0.065, step=0.1)
        self.pspLine.sigPositionChanged.connect(self.pspLineChanged)
        self.spikeLine.sigPositionChanged.connect(self.spikeLineChanged)
        self.ctrl.pspStartTimeSpin.valueChanged.connect(self.pspStartSpinChanged)
        self.ctrl.spikePeakSpin.valueChanged.connect(self.spikePeakSpinChanged)

        ### Connect control panel
        self.averageCtrl = pg.WidgetGroup(self.ctrl.traceDisplayGroup) ##TODO: save state when we save data
        self.ctrl.averageCheck.setChecked(True)
        self.ctrl.averageTimeSpin.setOpts(suffix='s', siPrefix=True, dec=True, value=60, step=1)
        self.ctrl.averageNumberSpin.setOpts(step=1, dec=True)
        self.ctrl.startExcludeAPsSpin.setOpts(suffix='s', siPrefix=True, dec=True, value=0, step=1, minstep=0.001)
        self.ctrl.endExcludeAPsSpin.setOpts(suffix='s', siPrefix=True, dec=True, value=0.25, step=1, minstep=0.001)
        self.averageCtrl.sigChanged.connect(self.averageCtrlChanged)

        self.analysisCtrl = pg.WidgetGroup(self.ctrl.analysisGroup)
        self.ctrl.baselineCheck.toggled.connect(self.regionDisplayToggled)
        self.ctrl.pspCheck.toggled.connect(self.regionDisplayToggled)
        self.ctrl.healthCheck.toggled.connect(self.regionDisplayToggled)

        self.ctrl.baselineStartSpin.setOpts(suffix='s', siPrefix=True, dec=True, step=1, minStep=0.001)
        self.ctrl.baselineEndSpin.setOpts(suffix='s', siPrefix=True, dec=True, step=1, minStep=0.001)
        self.ctrl.baselineStartSpin.valueChanged.connect(self.baselineSpinChanged)
        self.ctrl.baselineEndSpin.valueChanged.connect(self.baselineSpinChanged)
        self.baselineRgn.sigRegionChangeFinished.connect(self.baselineRgnChanged)

        self.ctrl.pspStartSpin.setOpts(suffix='s', siPrefix=True, dec=True, step=1, minStep=0.001)
        self.ctrl.pspEndSpin.setOpts(suffix='s', siPrefix=True, dec=True, step=1, minStep=0.001)
        self.ctrl.pspStartSpin.valueChanged.connect(self.pspSpinChanged)
        self.ctrl.pspEndSpin.valueChanged.connect(self.pspSpinChanged)
        self.pspRgn.sigRegionChangeFinished.connect(self.pspRgnChanged)

        self.ctrl.healthStartSpin.setOpts(suffix='s', siPrefix=True, dec=True, step=1, minStep=0.001)
        self.ctrl.healthEndSpin.setOpts(suffix='s', siPrefix=True, dec=True, step=1, minStep=0.001)
        self.ctrl.healthStartSpin.valueChanged.connect(self.healthSpinChanged)
        self.ctrl.healthEndSpin.valueChanged.connect(self.healthSpinChanged)
        self.healthRgn.sigRegionChangeFinished.connect(self.healthRgnChanged)

        self.ctrl.analyzeBtn.clicked.connect(self.analyze)
        self.ctrl.storeToDBBtn.clicked.connect(self.storeToDB)
        self.ctrl.createSummaryBtn.clicked.connect(self.summarySheetRequested)
        self.ctrl.createBlindSummaryBtn.clicked.connect(self.blindSummarySheetRequested)
        self.ctrl.defaultRgnBtn.clicked.connect(self.defaultBtnClicked)

        self.baselineRgn.setRegion((0,0.05))
        self.pspRgn.setRegion((0.052,0.067))
        self.healthRgn.setRegion((0.24,0.34))

        #self.ctrl.measureAvgSpin.setOpts(step=1, dec=True)
        self.ctrl.measureModeCombo.addItems(['Slope (max)'])
{'fraction_non_alphanumeric': 0.12689940977018713, 'fraction_numerical': 0.018711540876554064, 'mean_word_length': 3.570157819225251, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4257826', 'n_tokens_mistral': 5446, 'n_tokens_neox': 5002, 'n_words': 795}