Beispiel #1
0
def read_index(p):
    d = datetime.datetime.now()
    dstr = d.strftime('%Y-%m-%d %H:%M:%S')
    index = configfile.readConfigFile(p)
    print(list(index.keys()))
    for k in list(index.keys()):
        if k in list(changelist.keys()):
            print('index: ', k)
            print('old obj: ', index[k]['objective'])  # pp.pprint(index[k] )
            oldobj = index[k]['objective']
            print('old trans: ', index[k]['transform'])
            print('old devtrans: ', index[k]['deviceTransform'])
            binning = index[k]['binning']
            newobj = changelist[k][1]
            fnewobj = float(newobj)
            index[k]['transform']['scale'] = (binning[0] * refscale[0] /
                                              fnewobj, binning[1] *
                                              refscale[1] / fnewobj, 1.0)
            index[k]['deviceTransform']['scale'] = (binning[0] * refscale[0] /
                                                    fnewobj, binning[1] *
                                                    refscale[1] / fnewobj, 1.0)
            index[k]['objective'] = objlist[newobj]
            index[k][
                'note'] = f'Objective scale corrected from {oldobj:s} to {objlist[newobj]:s} on {dstr:s} by PBM'

    for k in list(index.keys()):
        if k in list(changelist.keys()):
            print('newindex: ', k)
            print('newobj: ', index[k]['objective'])  # pp.pprint(index[k] )
            print('newtrans: ', index[k]['transform'])
            print('newdevtrans: ', index[k]['deviceTransform'])
            print(index[k]['note'])

    return index
Beispiel #2
0
    def loadFile(self, f):
        """Load a log file for display.

          @param str f: path to file that should be laoded.

        f must be able to be read by pyqtgraph configfile.py
        """
        log = configfile.readConfigFile(f)
        self.entries = []
        self.entryArrayBuffer = np.zeros(len(log),
                                         dtype=[('index', 'int32'),
                                                ('importance', 'int32'),
                                                ('msgType', '|S10'),
                                                ('directory', '|S100'),
                                                ('entryId', 'int32')])
        self.entryArray = self.entryArrayBuffer[:]

        i = 0
        for k, v in log.items():
            v['id'] = k[
                9:]  ## record unique ID to facilitate HTML generation (javascript needs this ID)
            self.entries.append(v)
            self.entryArray[i] = np.array(
                [(i, v.get('importance', 5), v.get('msgType', 'status'),
                  v.get('currentDir', ''), v.get('entryId', v['id']))],
                dtype=[('index', 'int32'), ('importance', 'int32'),
                       ('msgType', '|S10'), ('directory', '|S100'),
                       ('entryId', 'int32')])
            i += 1

        self.filterEntries(
        )  ## puts all entries through current filters and displays the ones that pass
Beispiel #3
0
 def loadPreset(self, param, preset):
     if preset == '':
         return
     path = os.path.abspath(os.path.dirname(__file__))
     fn = os.path.join(path, 'presets', preset+".cfg")
     state = configfile.readConfigFile(fn)
     self.loadState(state)
Beispiel #4
0
 def site_info(self):
     if self._site_info is None:
         index = os.path.join(self.path, '.index')
         if not os.path.isfile(index):
             return None
         self._site_info = configfile.readConfigFile(index)['.']
     return self._site_info
Beispiel #5
0
    def _readIndex(self, currdir=''):
        indexFile = os.path.join(self.protocol, currdir, '.index')
#        print self.protocol, currdir, indexFile
        if not os.path.isfile(indexFile):
            raise Exception("Directory '%s' is not managed!" % (self.dataname))
        self._index = configfile.readConfigFile(indexFile)
        return self._index
Beispiel #6
0
 def loadFile(self, fileName=None, startDir=None):
     logger.info('loading file [{0}]'.format(fileName))
     if fileName is None:
         if startDir is None:
             startDir = self.filePath
         if startDir is None:
             startDir = '.'
         fname = QtGui.QFileDialog.getOpenFileName(
             self.parent,
             caption="Load Flowchart",
             directory=startDir,
             filter="Flowchart (*.fc)")[0]
         if fname:
             fileName = fname
         else:
             return
     fileName = unicode(fileName)
     try:
         state = configfile.readConfigFile(fileName)
         self.restoreState(state, clear=True)
     except Exception, err:
         logger.error('Failed to Load file [{0}]'.format(fileName),
                      exc_info=True)
         self.clear()
         ErrorPopupMessagBox(
             self.parent, "Load Flowchart",
             'Cannot load flowchart from file <i>{0}</i>'.format(fileName))
         return
Beispiel #7
0
    def loadAutomation(self, path):
        """ Load automation config into model.

            @param path str: file path
        """
        if os.path.isfile(path):
            configdict = configfile.readConfigFile(path)
            self.model.loadExecTree(configdict)
Beispiel #8
0
 def readDirIndex(self, currdir=''):
     self._dirindex = None
     indexFile = Path(currdir, '.index')
    # print (indexFile)
     if not indexFile.is_file():
         print("Directory '%s' is not managed or '.index' file not found" % (currdir))
         return self._dirindex
     # print('\nindex file found for currdir: ', currdir)
     self._dirindex = configfile.readConfigFile(str(indexFile))
     # print(self._dirindex)
     try:
         self._dirindex = configfile.readConfigFile(str(indexFile))
     except:
         print('Failed to read index file for %s' % currdir)
         print('Probably bad formatting or broken .index file')
         return self._dirindex
     return self._dirindex
Beispiel #9
0
    def loadAutomation(self, path):
        """ Load automation config into model.

            @param path str: file path
        """
        if os.path.isfile(path):
            configdict = configfile.readConfigFile(path)
            self.model.loadExecTree(configdict)
Beispiel #10
0
 def parent_info(self):
     if self._parent_info is None:
         index = os.path.join(self.parent_path, '.index')
         if not os.path.isfile(index):
             raise TypeError(
                 "Cannot find index file (%s) for experiment %s" %
                 (index, self))
         self._parent_info = configfile.readConfigFile(index)['.']
     return self._parent_info
Beispiel #11
0
 def load(self):
     filename = pg.QtWidgets.QFileDialog.getOpenFileName(
         self, "Save State..", "", "Config Files (*.cfg)")
     if isinstance(filename, tuple):
         filename = filename[0]  # Qt4/5 API difference
     if filename == '':
         return
     state = configfile.readConfigFile(str(filename))
     self.loadState(state)
def test_longArrays(tmpdir):
    """
    Test config saving and loading of long arrays.
    """
    arr = np.arange(20)

    tf = tmpdir.join("config.cfg")
    configfile.writeConfigFile({'arr': arr}, tf)
    config = configfile.readConfigFile(tf)
    assert all(config['arr'] == arr)
Beispiel #13
0
 def _readIndex(self, currdir=''):
     self._index = None
     # first try with currdir value, read current protocolSequence directory
     if currdir == '':
         indexFile = Path(self.protocol, '.index')  # use current
     else:
         indexFile = Path(currdir, '.index')
     if not indexFile.is_file():
         print("Directory '%s' is not managed or '.index' file not found" % (str(indexFile)))
         return self._index
     self._index = configfile.readConfigFile(indexFile)
     return self._index
Beispiel #14
0
def test_longArrays():
    """
    Test config saving and loading of long arrays.
    """
    tmp = tempfile.mktemp(".cfg")

    arr = np.arange(20)
    configfile.writeConfigFile({'arr': arr}, tmp)
    config = configfile.readConfigFile(tmp)

    assert all(config['arr'] == arr)

    os.remove(tmp)
def test_multipleParameters(tmpdir):
    """
    Test config saving and loading of multiple parameters.
    """

    par1 = [1, 2, 3]
    par2 = "Test"
    par3 = {'a': 3, 'b': 'c'}

    tf = tmpdir.join("config.cfg")
    configfile.writeConfigFile({'par1': par1, 'par2': par2, 'par3': par3}, tf)
    config = configfile.readConfigFile(tf)

    assert config['par1'] == par1
    assert config['par2'] == par2
    assert config['par3'] == par3
Beispiel #16
0
 def readDirIndex(self, currdir=''):
     self._dirindex = None
     indexFile = os.path.join(currdir, '.index')
     # print (indexFile)
     if not os.path.isfile(indexFile):
         print("Directory '%s' is not managed or '.index' file not found" %
               (currdir))
         print('indexfile: ', indexFile)
         return self._dirindex
     try:
         self._dirindex = configfile.readConfigFile(indexFile)
     except:
         print('Failed to read index file for %s' % currdir)
         print('indexfile should be: ', indexFile)
         print('Probably bad formatting or broken .index file')
         return self._dirindex
     return self._dirindex
Beispiel #17
0
def test_multipleParameters():
    """
    Test config saving and loading of multiple parameters.
    """
    tmp = tempfile.mktemp(".cfg")

    par1 = [1, 2, 3]
    par2 = "Test"
    par3 = {'a': 3, 'b': 'c'}

    configfile.writeConfigFile({'par1': par1, 'par2': par2, 'par3': par3}, tmp)
    config = configfile.readConfigFile(tmp)

    assert config['par1'] == par1
    assert config['par2'] == par2
    assert config['par3'] == par3

    os.remove(tmp)
Beispiel #18
0
def cli(dataset, flowchart):
    app = QtGui.QApplication.instance(
    )  # retrieves the ipython qt application if any
    if app is None:
        app = QtGui.QApplication([])  # create one if standalone execution

    fc = Flowchart(library=LIBRARY, terminals={'dataIn': {'io': 'in'}})
    win = pyviViewerWindow(fc)

    fc.setInput(dataIn=dataset)
    if flowchart:
        fc_state = configfile.readConfigFile(flowchart)
        fc.restoreState(fc_state, clear=False)
        fc.viewBox.autoRange()

    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        app.exec_()
        app.deleteLater()
        sys.exit()
Beispiel #19
0
 def loadFile(self, fileName=None, startDir=None):
     if fileName is None:
         if startDir is None:
             startDir = self.filePath
         if startDir is None:
             startDir = '.'
         self.fileDialog = pg.FileDialog(None, "Load Flowchart..", startDir, "Flowchart (*.fc)")
         #self.fileDialog.setFileMode(QtGui.QFileDialog.AnyFile)
         #self.fileDialog.setAcceptMode(QtGui.QFileDialog.AcceptSave) 
         self.fileDialog.show()
         self.fileDialog.fileSelected.connect(self.loadFile)
         return
         ## NOTE: was previously using a real widget for the file dialog's parent, but this caused weird mouse event bugs..
         #fileName = QtGui.QFileDialog.getOpenFileName(None, "Load Flowchart..", startDir, "Flowchart (*.fc)")
     fileName = str(fileName)
     state = configfile.readConfigFile(fileName)
     self.restoreState(state, clear=True)
     self.viewBox.autoRange()
     #self.emit(QtCore.SIGNAL('fileLoaded'), fileName)
     self.sigFileLoaded.emit(fileName)
Beispiel #20
0
 def loadFile(self, fileName=None, startDir=None):
     if fileName is None:
         if startDir is None:
             startDir = self.filePath
         if startDir is None:
             startDir = '.'
         self.fileDialog = pg.FileDialog(None, "Load Flowchart..", startDir, "Flowchart (*.fc)")
         #self.fileDialog.setFileMode(QtGui.QFileDialog.AnyFile)
         #self.fileDialog.setAcceptMode(QtGui.QFileDialog.AcceptSave) 
         self.fileDialog.show()
         self.fileDialog.fileSelected.connect(self.loadFile)
         return
         ## NOTE: was previously using a real widget for the file dialog's parent, but this caused weird mouse event bugs..
         #fileName = QtGui.QFileDialog.getOpenFileName(None, "Load Flowchart..", startDir, "Flowchart (*.fc)")
     fileName = str(fileName)
     state = configfile.readConfigFile(fileName)
     self.restoreState(state, clear=True)
     self.viewBox.autoRange()
     #self.emit(QtCore.SIGNAL('fileLoaded'), fileName)
     self.sigFileLoaded.emit(fileName)
Beispiel #21
0
 def loadFile(self, fileName=None, startDir=None):
     logger.info('loading file [{0}]'.format(fileName))
     if fileName is None:
         if startDir is None:
             startDir = self.filePath
         if startDir is None:
             startDir = '.'
         fname = QtGui.QFileDialog.getOpenFileName(self.parent, caption="Load Flowchart", directory=startDir, filter="Flowchart (*.fc)")[0]
         if fname:
             fileName = fname
         else:
             return
     fileName = unicode(fileName)
     try:
         state = configfile.readConfigFile(fileName)
         self.restoreState(state, clear=True)
     except Exception, err:
         logger.error('Failed to Load file [{0}]'.format(fileName), exc_info=True)
         self.clear()
         ErrorPopupMessagBox(self.parent, "Load Flowchart", 'Cannot load flowchart from file <i>{0}</i>'.format(fileName))
         return
Beispiel #22
0
    def parse_and_go(self, argsin=None):
        global period
        global binsize
        parser = OptionParser()  # command line options
        ##### parses all of the options inputted at the command line TFR 11/13/2015
        parser.add_option("-u",
                          "--upfile",
                          dest="upfile",
                          metavar='FILE',
                          help="load the up-file")
        parser.add_option("-d",
                          "--downfile",
                          dest="downfile",
                          metavar='FILE',
                          help="load the down-file")
        parser.add_option("-D",
                          "--directory",
                          dest="directory",
                          metavar='FILE',
                          help="Use directory for data")
        parser.add_option("-t",
                          "--test",
                          dest="test",
                          action='store_true',
                          help="Test mode to check calculations",
                          default=False)
        parser.add_option("-p",
                          '--period',
                          dest="period",
                          default=4.25,
                          type="float",
                          help="Stimulus cycle period")
        parser.add_option("-c",
                          '--cycles',
                          dest="cycles",
                          default=0,
                          type="int",
                          help="# cycles to analyze")
        parser.add_option("-b",
                          '--binning',
                          dest="binsize",
                          default=0,
                          type="int",
                          help="bin reduction x,y")
        parser.add_option("-g",
                          '--gfilter',
                          dest="gfilt",
                          default=0,
                          type="float",
                          help="gaussian filter width")
        parser.add_option("-f",
                          '--fdict',
                          dest="fdict",
                          default=0,
                          type="int",
                          help="Use dictionary entry")

        if argsin is not None:
            (options, args) = parser.parse_args(argsin)
        else:
            (options, args) = parser.parse_args()

        if options.test is True:
            print "Running Test Sample"
            period = 8.0  # period and frame sample rate can be different
            framerate = 8.0
            nper = 1
            d = 10.0 * numpy.random.normal(size=(2500, 128,
                                                 128)).astype('float32')
            ds = d.shape
            self.nFrames = d.shape[0]
            self.nPhases = 10
            maxdel = 50
            self.phasex = []
            self.phasey = []
            for i in range(0, self.nPhases):
                dx = i * ds[
                    1] / self.nPhases  # each phase is assigned to a region
                baseline = 0.0
                self.resp = numpy.zeros((self.nFrames, ))
                phaseDelay = 0.25 * period + period * (
                    float(i) / self.nPhases
                )  # phase delay for this region from 0 to nearly the stimulus repeat period
                # print '********phase delay: ', phaseDelay
                for j in range(0, nper):  # for each period
                    tdelay = (float(j) *
                              period) + phaseDelay  # time to phase delay point
                    idelay = int(numpy.floor(
                        tdelay *
                        framerate))  # convert to frame position in frame space
            #     print '     tdel: ', tdelay, '    idel: ', idelay
            #    if idelay < self.nFrames-maxdel:
            #        self.resp[idelay:idelay+maxdel] = (i+1)*numpy.exp(-numpy.linspace(0, 2, maxdel)) # marks amplitudes as well
                self.resp = 1000.0 * numpy.sin(
                    numpy.linspace(
                        0, 2.0 * numpy.pi * self.nFrames /
                        (period * framerate), self.nFrames) +
                    i * numpy.pi / 8.0 - numpy.pi / 2.0)
                d[:, dx:dx + int(ds[1] / self.nPhases),
                  5:int(ds[2] / 2)] += self.resp[:, numpy.newaxis,
                                                 numpy.newaxis]
                self.phasex.append((2 + (dx + int(ds[1] / self.nPhases)) / 2))
                self.phasey.append(
                    (6 + int(ds[2] / 2) / 2)
                )  # make the signal equivalent of digitized one (baseline 3000, signal at 1e-4 of baseline)
            d = (d * 3000.0 * 1e-4
                 ) + 3000.0  # scale and offset to match data scaling coming in
            self.imageData = d.astype(
                'int16')  # reduce to a 16-bit map to match camera data type
            self.times = numpy.arange(0, self.nFrames / framerate,
                                      1.0 / framerate)
            print "Test Image Created"
            getout2 = fac_lift(self.imageData, self.times)
            self.imageData = getout2
            self.Analysis_FourierMap_TFR(period=period,
                                         target=1,
                                         mode=1,
                                         bins=binsize)
            print "Completed Analysis FourierMap"
            self.plotmaps_pg(mode=2, gfilter=0)
            print "Completed plot maps"

        if options.period is not None:
            measuredPeriod = options.period
        if options.cycles is not None:
            self.nCycles = options.cycles
        if options.binsize is not None:
            binsize = options.binsize
        if options.gfilt is not None:
            gfilt = options.gfilt

        print 'DB keys', DB.keys()
        if options.fdict is not None:
            if options.fdict in DB.keys():  # populate options
                options.upfile = DB[options.fdict][0]
                options.downfile = DB[options.fdict][1]
                options.period = DB[options.fdict][4]
            else:
                print "File %d NOT in DBase\n" % options.fdict
                return
        if options.directory is not None:
            self.directory = options.directory

        if options.upfile is not None:
            self.upfile = options.upfile
            target = 1

        if options.downfile is not None:
            self.downfile = options.downfile
            target = 2

        target = 0
        videoupf = None
        videodwnf = None
        audioupf = None
        audiodwnf = None

        if options.upfile is not None:
            videoupf = videobasepath + options.upfile + '.ma'
            audioupf = audiobasepath + options.upfile + '/DaqDevice.ma'
        if options.downfile is not None:
            videodwnf = videobasepath + options.downfile + '.ma'
            audiodwnf = audiobasepath + options.downfile + '/DaqDevice.ma'

        # indexFile = configfile.readConfigFile(basepath+'.index')
        # time = indexFile.__getitem__('video_019.ma')[u'__timestamp__']

        #indexFile = configfile.readConfigFile(basepath+'.index')
        #print 'indexfile', indexfile
        for file in (videoupf, videodwnf):
            #if options.upfile is not None and options.downfile is not None:
            if file is None:
                break
            im = []
            self.imageData = []
            print "loading data from ", file
            try:
                im = MetaArray(file=file,
                               subset=(slice(0, 2), slice(64,
                                                          128), slice(64,
                                                                      128)))
            except:
                print "Error loading upfile: %s\n" % file
                return
            print "data loaded"
            target = target + 1
            # dir = acq4.util.DataManager.getHandle(basepath)
            # time = dir.info()['__timestamp__']
            # print 'time:', time
            #print 'im:', im
            # dir(im)
            rawtimes = []
            rawimageData = []
            rawtimes = im.axisValues('Time').astype('float32')
            #            print 'time', rawtimes
            rawimageData = im.view(np.ndarray).astype('float32')
            #            print 'shape of ra image data:', rawimageData.shape
            ## videobasepath = /......./2016.10.08_000/Intrinsic_Mapping/video_'
            ## indexFile = configFile.readConfigFile('/...../2016.10.08_000/Intrinsic_Mapping/.index') -> a dictionary

            # dir = acq4.util.DataManager.getHandle(videoupf)
            # time = dir.info()['__timestamp__']

            # #timestampup = timestamp[options.fdict][0]
            # audioupstamp = timestamp[options.fdict][1]
            # #timestampdown = timestamp[options.fdict][2]
            # audiodownstamp = timestamp[options.fdict][3]
            # #print 'optioins.dict', options.fdict[0]

            #reads the timestamps from the files
            indexFile = configfile.readConfigFile(basepath + '.index')
            timestampup = indexFile.__getitem__('video_' +
                                                DB[options.fdict][0] +
                                                '.ma')[u'__timestamp__']
            timestampdown = indexFile.__getitem__('video_' +
                                                  DB[options.fdict][1] +
                                                  '.ma')[u'__timestamp__']
            audioupindex = configfile.readConfigFile(audiobasepath +
                                                     DB[options.fdict][0] +
                                                     '/.index')
            # audioupstamp = audioupindex.__getitem__(u'.')[u'__timestamp__']
            audioupstamp = audioupindex.__getitem__(
                'DaqDevice.ma')[u'__timestamp__'] - 13.5
            audiodownindex = configfile.readConfigFile(audiobasepath +
                                                       DB[options.fdict][1] +
                                                       '/.index')
            #audiodownstamp = audiodownindex.__getitem__(u'.')[u'__timestamp__']
            audiodownstamp = audiodownindex.__getitem__(
                'DaqDevice.ma')[u'__timestamp__'] - 13.5

            diffup = audioupstamp - timestampup
            diffdown = audiodownstamp - timestampdown

            if file is videoupf:
                audio = MetaArray(file=audioupf,
                                  subset=(slice(0, 2), slice(64, 128),
                                          slice(64, 128)))
                audiotime = audio.axisValues('Time').astype('float32')
                audiomin = np.min(audiotime) + diffup
                audiomax = np.max(audiotime) + diffup
            elif file is videodwnf:
                audio = MetaArray(file=audiodwnf,
                                  subset=(slice(0, 2), slice(64, 128),
                                          slice(64, 128)))
                audiotime = audio.axisValues('Time').astype('float32')
                audiomin = np.min(audiotime) + diffdown
                audiomax = np.max(audiotime) + diffdown
            else:
                print 'ERROR!  Unable to load audio file'
            print 'audiomin', audiomin
            print 'audiomax', audiomax

            adjustedtime = rawtimes[np.logical_and(rawtimes <= audiomax + 4,
                                                   rawtimes >= audiomin)]

            adjustedimagedata = rawimageData[np.logical_and(
                rawtimes <= audiomax + 4, rawtimes >= audiomin)]
            # print 'adjtime', adjustedtime
            self.times = [x - np.min(adjustedtime) for x in adjustedtime]
            self.imageData = adjustedimagedata
            background = rawimageData[5:25]
            background = np.mean(background, axis=0)
            print 'dimensions of background', np.shape(background)
            pg.image(background, title='mean background')
            subtracted = np.zeros(np.shape(self.imageData), float)
            for i in range(self.imageData.shape[0]):
                subtracted[i, :, :] = (self.imageData[i, :, :] - background)
            subtracted = subtracted / subtracted.mean()
            self.imageData = subtracted
            #print 'self.times:', self.times
            # print 'length of self.times', np.shape(self.times)
            # print 'shape of image data', np.shape(self.imageData)

            #analyze a quarter of the image
            #xcut = (self.imageData.shape[1]+1)/8
            #ycut = (self.imageData.shape[2]+1)/8
            #self.imageData=self.imageData[:,3*xcut-1:7*xcut-1,ycut-1:7*ycut-1]
            im = []
            if file is videoupf:
                upflag = 1
            else:
                upflag = 0
            #print 'target:', target
            measuredPeriod = 4.25
            #self.subtract_Background(diffup=diffup)
            self.Analysis_FourierMap(period=measuredPeriod,
                                     target=target,
                                     bins=binsize,
                                     up=upflag)
        print 'target:', target
        if target > 0:
            self.plotmaps_pg(mode=1, target=target, gfilter=gfilt)

        return
Beispiel #23
0
    def parse_and_go(self, argsin = None):
        global period
        global binsize
        parser=OptionParser() # command line options
        ##### parses all of the options inputted at the command line TFR 11/13/2015
        parser.add_option("-u", "--upfile", dest="upfile", metavar='FILE',
                          help="load the up-file")
        parser.add_option("-d", "--downfile", dest="downfile", metavar='FILE',
                          help="load the down-file")
        parser.add_option("-D", "--directory", dest="directory", metavar='FILE',
                          help="Use directory for data")
        parser.add_option("-t", "--test", dest="test", action='store_true',
                          help="Test mode to check calculations", default=False)
        parser.add_option("-p", '--period', dest = "period", default=4.25, type="float",
                          help = "Stimulus cycle period")
        parser.add_option("-c", '--cycles', dest = "cycles", default=0, type="int",
                          help = "# cycles to analyze")
        parser.add_option("-b", '--binning', dest = "binsize", default=0, type="int",
                          help = "bin reduction x,y")
        parser.add_option("-g", '--gfilter', dest = "gfilt", default=0, type="float",
                          help = "gaussian filter width")
        parser.add_option("-f", '--fdict', dest = "fdict", default=0, type="int",
                          help = "Use dictionary entry")
        
        if argsin is not None:
            (options, args) = parser.parse_args(argsin)
        else:
            (options, args) = parser.parse_args()

        if options.test is True:
            print "Running Test Sample"
            period = 8.0 # period and frame sample rate can be different
            framerate = 8.0
            nper = 1
            d = 10.0*numpy.random.normal(size=(2500,128,128)).astype('float32')
            ds = d.shape
            self.nFrames = d.shape[0]
            self.nPhases = 10
            maxdel = 50
            self.phasex = []
            self.phasey = []
            for i in range(0,self.nPhases):
                dx = i*ds[1]/self.nPhases # each phase is assigned to a region
                baseline = 0.0
                self.resp = numpy.zeros((self.nFrames,))
                phaseDelay = 0.25*period+period*(float(i)/self.nPhases) # phase delay for this region from 0 to nearly the stimulus repeat period
               # print '********phase delay: ', phaseDelay
                for j in range(0, nper): # for each period 
                    tdelay = (float(j) * period) + phaseDelay # time to phase delay point
                    idelay = int(numpy.floor(tdelay*framerate)) # convert to frame position in frame space
               #     print '     tdel: ', tdelay, '    idel: ', idelay
                #    if idelay < self.nFrames-maxdel:
                #        self.resp[idelay:idelay+maxdel] = (i+1)*numpy.exp(-numpy.linspace(0, 2, maxdel)) # marks amplitudes as well
                self.resp = 1000.0*numpy.sin(
                         numpy.linspace(0, 2.0*numpy.pi*self.nFrames/(period*framerate), self.nFrames)+i*numpy.pi/8.0 - numpy.pi/2.0)
                d[:, dx:dx+int(ds[1]/self.nPhases), 5:int(ds[2]/2)] += self.resp[:, numpy.newaxis, numpy.newaxis]
                self.phasex.append( (2+(dx+int(ds[1]/self.nPhases))/2))
                self.phasey.append((6+int(ds[2]/2)/2)) # make the signal equivalent of digitized one (baseline 3000, signal at 1e-4 of baseline)
            d = (d*3000.0*1e-4)+3000.0 # scale and offset to match data scaling coming in
            self.imageData = d.astype('int16') # reduce to a 16-bit map to match camera data type
            self.times = numpy.arange(0, self.nFrames/framerate, 1.0/framerate)
            print "Test Image Created"
            getout2 = fac_lift(self.imageData, self.times)
            self.imageData=getout2
            self.Analysis_FourierMap_TFR(period=period, target = 1, mode=1, bins=binsize)
            print "Completed Analysis FourierMap"
            self.plotmaps_pg(mode = 2, gfilter = 0)
            print "Completed plot maps"

        if options.period is not None:
            measuredPeriod = options.period
        if options.cycles is not None:
            self.nCycles = options.cycles
        if options.binsize is not None:
            binsize = options.binsize
        if options.gfilt is not None:
            gfilt = options.gfilt

        print 'DB keys', DB.keys()
        if options.fdict is not None:
            if options.fdict in DB.keys(): # populate options 
                options.upfile = DB[options.fdict][0]
                options.downfile = DB[options.fdict][1]
                options.period = DB[options.fdict][4]
            else:
               print "File %d NOT in DBase\n" % options.fdict
               return
        if options.directory is not None:
            self.directory = options.directory

        if options.upfile is not None:
            self.upfile = options.upfile
            target = 1
        
        if options.downfile is not None:
            self.downfile = options.downfile
            target = 2

        target = 0
        videoupf = None
        videodwnf = None
        audioupf = None
        audiodwnf = None

        if options.upfile is not None:
            videoupf = videobasepath + options.upfile + '.ma'
            audioupf = audiobasepath + options.upfile + '/DaqDevice.ma'
        if options.downfile is not None:
            videodwnf = videobasepath + options.downfile + '.ma'
            audiodwnf = audiobasepath + options.downfile + '/DaqDevice.ma'

        # indexFile = configfile.readConfigFile(basepath+'.index') 
        # time = indexFile.__getitem__('video_019.ma')[u'__timestamp__'] 

        #indexFile = configfile.readConfigFile(basepath+'.index') 
        #print 'indexfile', indexfile
        for file in (videoupf, videodwnf):
#if options.upfile is not None and options.downfile is not None:
            if file is None:
               break
            im=[]
            self.imageData = []
            print "loading data from ", file
            try:
                im = MetaArray(file = file,  subset=(slice(0,2), slice(64,128), slice(64,128)))
            except:
                print "Error loading upfile: %s\n" % file
                return
            print "data loaded"
            target = target + 1
            # dir = acq4.util.DataManager.getHandle(basepath)
            # time = dir.info()['__timestamp__']
            # print 'time:', time
           #print 'im:', im
            # dir(im)
            rawtimes=[]
            rawimageData=[]
            rawtimes = im.axisValues('Time').astype('float32')
#            print 'time', rawtimes
            rawimageData = im.view(np.ndarray).astype('float32')
#            print 'shape of ra image data:', rawimageData.shape
            ## videobasepath = /......./2016.10.08_000/Intrinsic_Mapping/video_'
            ## indexFile = configFile.readConfigFile('/...../2016.10.08_000/Intrinsic_Mapping/.index') -> a dictionary

            # dir = acq4.util.DataManager.getHandle(videoupf)
            # time = dir.info()['__timestamp__']
            
            # #timestampup = timestamp[options.fdict][0]
            # audioupstamp = timestamp[options.fdict][1]
            # #timestampdown = timestamp[options.fdict][2]
            # audiodownstamp = timestamp[options.fdict][3]
            # #print 'optioins.dict', options.fdict[0]

            #reads the timestamps from the files
            indexFile = configfile.readConfigFile(basepath+'.index') 
            timestampup = indexFile.__getitem__('video_'+DB[options.fdict][0]+'.ma')[u'__timestamp__']
            timestampdown = indexFile.__getitem__('video_'+DB[options.fdict][1]+'.ma')[u'__timestamp__']
            audioupindex = configfile.readConfigFile(audiobasepath+DB[options.fdict][0]+'/.index')
            # audioupstamp = audioupindex.__getitem__(u'.')[u'__timestamp__'] 
            audioupstamp = audioupindex.__getitem__('DaqDevice.ma')[u'__timestamp__'] - 13.5
            audiodownindex = configfile.readConfigFile(audiobasepath+DB[options.fdict][1]+'/.index')
            #audiodownstamp = audiodownindex.__getitem__(u'.')[u'__timestamp__'] 
            audiodownstamp = audiodownindex.__getitem__('DaqDevice.ma')[u'__timestamp__'] -13.5

            diffup = audioupstamp - timestampup
            diffdown = audiodownstamp - timestampdown 

            
            if file is videoupf:
                audio = MetaArray(file = audioupf, subset=(slice(0,2), slice(64,128), slice(64,128)))
                audiotime = audio.axisValues('Time').astype('float32')
                audiomin = np.min(audiotime) + diffup
                audiomax = np.max(audiotime) + diffup
            elif file is videodwnf:
                audio = MetaArray(file = audiodwnf, subset=(slice(0,2), slice(64,128), slice(64,128)))
                audiotime = audio.axisValues('Time').astype('float32')
                audiomin = np.min(audiotime) + diffdown
                audiomax = np.max(audiotime) + diffdown
            else:
                print 'ERROR!  Unable to load audio file'
            print 'audiomin', audiomin
            print 'audiomax', audiomax

            adjustedtime = rawtimes[np.logical_and(rawtimes <= audiomax+4, rawtimes >= audiomin)]
            
            adjustedimagedata = rawimageData[np.logical_and(rawtimes <= audiomax+4, rawtimes >= audiomin)]
            # print 'adjtime', adjustedtime
            self.times = [x-np.min(adjustedtime) for x in adjustedtime]
            self.imageData = adjustedimagedata
            background = rawimageData[5:25]
            background = np.mean(background,axis=0)
            print 'dimensions of background', np.shape(background)
            pg.image(background, title='mean background')
            subtracted = np.zeros(np.shape(self.imageData), float)
            for i in range(self.imageData.shape[0]):
                subtracted[i,:,:] = (self.imageData[i,:,:]-background)
            subtracted=subtracted/subtracted.mean()
            self.imageData = subtracted
            #print 'self.times:', self.times
            # print 'length of self.times', np.shape(self.times)
            # print 'shape of image data', np.shape(self.imageData)

            #analyze a quarter of the image
            #xcut = (self.imageData.shape[1]+1)/8
            #ycut = (self.imageData.shape[2]+1)/8
            #self.imageData=self.imageData[:,3*xcut-1:7*xcut-1,ycut-1:7*ycut-1]
            im=[]
            if file is videoupf:
               upflag = 1
            else:
               upflag = 0
            #print 'target:', target
            measuredPeriod=4.25
            #self.subtract_Background(diffup=diffup)
            self.Analysis_FourierMap(period=measuredPeriod, target = target,  bins=binsize, up=upflag)
        print 'target:', target
        if target > 0:
            self.plotmaps_pg(mode = 1, target = target, gfilter = gfilt)

        return
Beispiel #24
0
    def parse_and_go(self, argsin = None):
        global period
        global binsize
        parser=OptionParser() # command line options
        ##### parses all of the options inputted at the command line TFR 11/13/2015
        parser.add_option("-u", "--upfile", dest="upfile", metavar='FILE',
                          help="load the up-file")
        parser.add_option("-d", "--downfile", dest="downfile", metavar='FILE',
                          help="load the down-file")
        parser.add_option("-D", "--directory", dest="directory", metavar='FILE',
                          help="Use directory for data")
        parser.add_option("-t", "--test", dest="test", action='store_true',
                          help="Test mode to check calculations", default=False)
        parser.add_option("-p", '--period', dest = "period", default=4.25, type="float",
                          help = "Stimulus cycle period")
        parser.add_option("-c", '--cycles', dest = "cycles", default=0, type="int",
                          help = "# cycles to analyze")
        parser.add_option("-b", '--binning', dest = "binsize", default=0, type="int",
                          help = "bin reduction x,y")
        parser.add_option("-g", '--gfilter', dest = "gfilt", default=0, type="float",
                          help = "gaussian filter width")
        parser.add_option("-f", '--fdict', dest = "fdict", default=0, type="int",
                          help = "Use dictionary entry")
        
        if argsin is not None:
            (options, args) = parser.parse_args(argsin)
        else:
            (options, args) = parser.parse_args()

        if options.test is True:
            print "Running Test Sample"
            period = 8.0 # period and frame sample rate can be different
            framerate = 8.0
            nper = 1
            d = 10.0*numpy.random.normal(size=(2500,128,128)).astype('float32')
            ds = d.shape
            self.nFrames = d.shape[0]
            self.nPhases = 10
            maxdel = 50
            self.phasex = []
            self.phasey = []
            for i in range(0,self.nPhases):
                dx = i*ds[1]/self.nPhases # each phase is assigned to a region
                baseline = 0.0
                self.resp = numpy.zeros((self.nFrames,))
                phaseDelay = 0.25*period+period*(float(i)/self.nPhases) # phase delay for this region from 0 to nearly the stimulus repeat period
               # print '********phase delay: ', phaseDelay
                for j in range(0, nper): # for each period 
                    tdelay = (float(j) * period) + phaseDelay # time to phase delay point
                    idelay = int(numpy.floor(tdelay*framerate)) # convert to frame position in frame space
               #     print '     tdel: ', tdelay, '    idel: ', idelay
                #    if idelay < self.nFrames-maxdel:
                #        self.resp[idelay:idelay+maxdel] = (i+1)*numpy.exp(-numpy.linspace(0, 2, maxdel)) # marks amplitudes as well
                self.resp = 1000.0*numpy.sin(
                         numpy.linspace(0, 2.0*numpy.pi*self.nFrames/(period*framerate), self.nFrames)+i*numpy.pi/8.0 - numpy.pi/2.0)
                d[:, dx:dx+int(ds[1]/self.nPhases), 5:int(ds[2]/2)] += self.resp[:, numpy.newaxis, numpy.newaxis]
                self.phasex.append( (2+(dx+int(ds[1]/self.nPhases))/2))
                self.phasey.append((6+int(ds[2]/2)/2)) # make the signal equivalent of digitized one (baseline 3000, signal at 1e-4 of baseline)
            d = (d*3000.0*1e-4)+3000.0 # scale and offset to match data scaling coming in
            self.imageData = d.astype('int16') # reduce to a 16-bit map to match camera data type
            self.times = numpy.arange(0, self.nFrames/framerate, 1.0/framerate)
            print "Test Image Created"
            getout2 = fac_lift(self.imageData, self.times)
            self.imageData=getout2
            self.Analysis_FourierMap_TFR(period=period, target = 1, mode=1, bins=binsize)
            print "Completed Analysis FourierMap"
            self.plotmaps_pg(mode = 2, gfilter = 0)
            print "Completed plot maps"

        if options.period is not None:
            measuredPeriod = options.period
        if options.cycles is not None:
            self.nCycles = options.cycles
        if options.binsize is not None:
            binsize = options.binsize
        if options.gfilt is not None:
            gfilt = options.gfilt
        if options.upfile is not None:
            self.upfile = options.upfile
            target = 1
        
        if options.downfile is not None:
            self.downfile = options.downfile
            target = 2

        target = 0
        videoupf = None
        videodwnf = None
        audioupf = None
        audiodwnf = None

        
        print 'DB keys', DB.keys()
        if options.fdict is not None:
            if options.fdict in DB.keys(): # populate options 
                options.upfile = DB[options.fdict][0]
                options.downfile = DB[options.fdict][1]
                options.period = DB[options.fdict][4]
            else:
               print "File %d NOT in DBase\n" % options.fdict
               return
        if options.directory is not None:
            self.directory = options.directory

        if options.upfile is not None:
            videoupf = videobasepath + options.upfile + '.ma'
            audioupf = audiobasepath + options.upfile + '/DaqDevice.ma'
        if options.downfile is not None:
            videodwnf = videobasepath + options.downfile + '.ma'
            audiodwnf = audiobasepath + options.downfile + '/DaqDevice.ma'

        
        im=[]
        self.imageData = []
        print "loading data from ", videoupf
        try:
            im = MetaArray(file = videoupf,  subset=(slice(0,2), slice(64,128), slice(64,128)))
        except:
            print "Error loading upfile: %s\n" % videoupf
            return
        print "data loaded"
        
         
        rawtimes=[]
        rawimageData=[]
        rawtimes = im.axisValues('Time').astype('float32')

        rawimageData = im.view(np.ndarray).astype('float32')
#  

        #reads the timestamps from the files
        indexFile = configfile.readConfigFile(basepath+'.index') 
        timestampup = indexFile.__getitem__('video_'+DB[options.fdict][0]+'.ma')[u'__timestamp__']
        audioupindex = configfile.readConfigFile(audiobasepath+DB[options.fdict][0]+'/.index')
        audioupstamp = audioupindex.__getitem__(u'.')[u'__timestamp__'] 
 
       
        diffup = audioupstamp - timestampup

        
        
        audio = MetaArray(file = audioupf, subset=(slice(0,2), slice(64,128), slice(64,128)))
        audiotime = audio.axisValues('Time').astype('float32')
        audiomin = np.min(audiotime) + diffup
        audiomax = np.max(audiotime) + diffup
        
        print 'audiomin', audiomin
        print 'audiomax', audiomax

        adjustedtime = rawtimes[np.logical_and(rawtimes <= audiomax+.5, rawtimes >= audiomin)]
        frame_start=np.amin(np.where(rawtimes >= audiomin))
        frame_end=np.amax(np.where(rawtimes <= audiomax+0.5))
        adjustedimagedata = rawimageData[frame_start:frame_end]
        #adjustedimagedata = rawimageData[np.logical_and(rawtimes <= audiomax+.5, rawtimes >= audiomin)]
 
        self.times = [x-np.min(adjustedtime) for x in adjustedtime]
        #self.imageData = adjustedimagedata
        # self.imageData=np.mean(self.imageData, axis=0)
        #self.imageData=np.mean(self.imageData)
        outofbounds = 2*adjustedimagedata.std()

        for i in range(adjustedimagedata.shape[0]):
            for j in range(adjustedimagedata.shape[1]):
                for k in range(adjustedimagedata.shape[2]):
                    
                    if adjustedimagedata[i,j,k]< outofbounds:
                        adjustedimagedata[i,j,k]=1
        pg.image(np.mean(adjustedimagedata,axis=0),title='remove extremes')
        self.imageData = adjustedimagedata
        print 'newmean', adjustedimagedata.mean()
        #############loaded file #1###################
        
        # for background file
        im2=[]
        self.imageData2 = []
        adjustedimagedata = []

        print "loading data from ", videodwnf
        try:
            im2 = MetaArray(file = videodwnf,  subset=(slice(0,2), slice(64,128), slice(64,128)))
        except:
            print "Error loading upfile: %s\n" % videodwnf
            return
        print "data loaded"
        
         
        rawtimes=[]
        rawimageData=[]
        rawtimes = im2.axisValues('Time').astype('float32')

        rawimageData = im2.view(np.ndarray).astype('float32')
#  

        #reads the timestamps from the files
        indexFile = configfile.readConfigFile(basepath+'.index') 
        timestampdwn = indexFile.__getitem__('video_'+DB[options.fdict][1]+'.ma')[u'__timestamp__']
        audiodwnindex = configfile.readConfigFile(audiobasepath+DB[options.fdict][1]+'/.index')
        audiodwnstamp = audiodwnindex.__getitem__(u'.')[u'__timestamp__'] 
 
       
        diffdwn = audiodwnstamp - timestampdwn

        
        
        audio = MetaArray(file = audiodwnf, subset=(slice(0,2), slice(64,128), slice(64,128)))
        audiotime = audio.axisValues('Time').astype('float32')
        audiomin = np.min(audiotime) + diffdwn
        audiomax = np.max(audiotime) + diffdwn
        
        print 'audiomin', audiomin
        print 'audiomax', audiomax

        adjustedtime = rawtimes[np.logical_and(rawtimes <= audiomax+.5, rawtimes >= audiomin)]
        frame_start=np.amin(np.where(rawtimes >= audiomin))
        frame_end=np.amax(np.where(rawtimes <= audiomax+0.5))
        adjustedimagedata = rawimageData[frame_start:frame_end]
 
        self.times = [x-np.min(adjustedtime) for x in adjustedtime]
        outofbounds = 2*adjustedimagedata.std()

        for i in range(adjustedimagedata.shape[0]):
            for j in range(adjustedimagedata.shape[1]):
                for k in range(adjustedimagedata.shape[2]):
                    
                    if adjustedimagedata[i,j,k]< outofbounds:
                        adjustedimagedata[i,j,k]=1
        pg.image(np.mean(adjustedimagedata,axis=0),title='remove extremes')
        self.imageData2 = adjustedimagedata
        print 'newmean', adjustedimagedata.mean()

        # self.imageData2 = adjustedimagedata
        # self.imageData2=np.mean(self.imageData2, axis=0)
        print 'size of imagedata', self.imageData2.shape
        ##############loaded file #2##############

        diffframes = np.mean(self.imageData)/np.mean(self.imageData2)
        print 'mean:', diffframes.mean()
        print 'std:', diffframes.std()
        procimage=diffframes/diffframes.mean()/diffframes.std()

        self.avgframes = pg.image(diffframes, title='Average across frames')
        self.diff_frames = pg.image(procimage, title='Normalized Average across frames')
        
        #self.avgframes = pg.image(procimage, title='Average across frames')
        return
Beispiel #25
0
    def parse_and_go(self, argsin=None):
        global period
        global binsize
        parser = OptionParser()  # command line options
        ##### parses all of the options inputted at the command line TFR 11/13/2015
        parser.add_option("-u",
                          "--upfile",
                          dest="upfile",
                          metavar='FILE',
                          help="load the up-file")
        parser.add_option("-d",
                          "--downfile",
                          dest="downfile",
                          metavar='FILE',
                          help="load the down-file")
        parser.add_option("-D",
                          "--directory",
                          dest="directory",
                          metavar='FILE',
                          help="Use directory for data")
        parser.add_option("-t",
                          "--test",
                          dest="test",
                          action='store_true',
                          help="Test mode to check calculations",
                          default=False)
        parser.add_option("-p",
                          '--period',
                          dest="period",
                          default=4.25,
                          type="float",
                          help="Stimulus cycle period")
        parser.add_option("-c",
                          '--cycles',
                          dest="cycles",
                          default=0,
                          type="int",
                          help="# cycles to analyze")
        parser.add_option("-b",
                          '--binning',
                          dest="binsize",
                          default=0,
                          type="int",
                          help="bin reduction x,y")
        parser.add_option("-g",
                          '--gfilter',
                          dest="gfilt",
                          default=0,
                          type="float",
                          help="gaussian filter width")
        parser.add_option("-f",
                          '--fdict',
                          dest="fdict",
                          default=0,
                          type="int",
                          help="Use dictionary entry")

        if argsin is not None:
            (options, args) = parser.parse_args(argsin)
        else:
            (options, args) = parser.parse_args()

        if options.period is not None:
            measuredPeriod = options.period
        if options.cycles is not None:
            self.nCycles = options.cycles
        if options.binsize is not None:
            binsize = options.binsize
        if options.gfilt is not None:
            gfilt = options.gfilt

        if options.fdict is not None:
            if options.fdict in DB.keys():  # populate options
                options.upfile = DB[options.fdict][0]
                options.downfile = DB[options.fdict][1]
                options.period = DB[options.fdict][4]
            else:
                print "File %d NOT in DBase\n" % options.fdict
                return
        if options.directory is not None:
            self.directory = options.directory

        if options.upfile is not None:
            self.upfile = options.upfile
            target = 1

        if options.downfile is not None:
            self.downfile = options.downfile
            target = 2

        target = 0
        videoupf = None
        videodwnf = None
        audioupf = None
        audiodwnf = None

        if options.upfile is not None:
            videoupf = videobasepath + options.upfile + '.ma'
            audioupf = audiobasepath + options.upfile + '/DaqDevice.ma'
        if options.downfile is not None:
            videodwnf = videobasepath + options.downfile + '.ma'
            audiodwnf = audiobasepath + options.downfile + '/DaqDevice.ma'

        for file in (videoupf, videodwnf):
            #if options.upfile is not None and options.downfile is not None:
            if file is None:
                break
            im = []
            self.imageData = []
            print "loading data from ", file
            try:
                im = MetaArray(file=file,
                               subset=(slice(0, 2), slice(64,
                                                          128), slice(64,
                                                                      128)))

            except:
                print "Error loading upfile: %s\n" % file
                return
            print "data loaded"
            self.times = im.axisValues('Time')
            self.nFrames = numpy.shape(im)[0]
            self.imageData = numpy.array(im).astype(numpy.float32, copy=False)
            print 'min diff', np.amin(np.diff(self.times))
            print 'miax diff', np.amax(np.diff(self.times))
            dt = numpy.mean(numpy.diff(self.times))
            print 'dt:', dt
            target = target + 1
            rawtimes = []
            rawimageData = []
            rawtimes = im.axisValues('Time').astype('float32')
            rawimageData = im.view(np.ndarray).astype('float32')
            print 'size of im', np.shape(rawimageData)
            indexFile = configfile.readConfigFile(basepath + '.index')
            timestampup = indexFile.__getitem__('video_' +
                                                DB[options.fdict][0] +
                                                '.ma')[u'__timestamp__']
            timestampdown = indexFile.__getitem__('video_' +
                                                  DB[options.fdict][1] +
                                                  '.ma')[u'__timestamp__']
            audioupindex = configfile.readConfigFile(audiobasepath +
                                                     DB[options.fdict][0] +
                                                     '/.index')
            audioupstamp = audioupindex.__getitem__(u'.')[u'__timestamp__']
            audiodownindex = configfile.readConfigFile(audiobasepath +
                                                       DB[options.fdict][1] +
                                                       '/.index')
            audiodownstamp = audiodownindex.__getitem__(u'.')[u'__timestamp__']

            diffup = audioupstamp - timestampup
            diffdown = audiodownstamp - timestampdown

            if file is videoupf:
                audio = MetaArray(file=audioupf,
                                  subset=(slice(0, 2), slice(64, 128),
                                          slice(64, 128)))
                audiotime = audio.axisValues('Time').astype('float32')
                audiomin = np.min(audiotime) + diffup
                audiomax = np.max(audiotime) + diffup
            elif file is videodwnf:
                audio = MetaArray(file=audiodwnf,
                                  subset=(slice(0, 2), slice(64, 128),
                                          slice(64, 128)))
                audiotime = audio.axisValues('Time').astype('float32')
                audiomin = np.min(audiotime) + diffdown
                audiomax = np.max(audiotime) + diffdown
            else:
                print 'ERROR!  Unable to load audio file'
            print 'audiomin', audiomin
            print 'audiomax', audiomax

            adjustedtime = rawtimes[np.logical_and(rawtimes <= audiomax + .5,
                                                   rawtimes >= audiomin)]
            frame_start = np.amin(np.where(rawtimes >= audiomin))
            frame_end = np.amax(np.where(rawtimes <= audiomax))

            background = np.mean(rawimageData[10:25, :, :], axis=0)
            print 'size of background', np.shape(background)
            adjustedimagedata = rawimageData[frame_start:frame_end, :, :]
            # print 'adjtime', adjustedtime
            self.times = [x - np.min(adjustedtime) for x in adjustedtime]
            self.imageData = adjustedimagedata
            #print 'self.times:', self.times
            # print 'length of self.times', np.shape(self.times)
            # print 'shape of image data', np.shape(self.imageData)
            print 'size of im', np.shape(self.imageData)
            im = []
            if file is videoupf:
                upflag = 1
            else:
                upflag = 0
            #print 'target:', target

            framerate = 1 / dt
            xsize = self.imageData.shape[1]
            ysize = self.imageData.shape[2]
            nframes = self.imageData.shape[0]
            freq = 4
            frames = self.imageData.reshape(nframes, xsize * ysize)
            print 'seize of frames', np.shape(frames)
            const = np.arange(dt, nframes / framerate, nframes)
            fourvec = []
            for ii in range(const.shape[0]):
                fourvec[ii] = numpy.exp(2 * np.pi * np.complex(0, 1) *
                                        const[ii] * freq)
            print 'size of fourvec', np.shape(fourvec)
            data = frames[:, :] * fourvec
            print 'size of data', np.shape(data)
            data = np.mean(data, axis=0)
            data = data.reshape(xsize, ysize)

            pg.image(data)

            # pg.image(background)
            # diffimage=np.zeros(np.shape(self.imageData))

            # print 'single:', np.shape(self.imageData[4])
            # for i in range(self.imageData.shape[0]):
            #     diffimage[i]=self.imageData[i]/background
            #     #self.imageData[i]/background
            # print 'size of diffimage', np.shape(diffimage)
            # refimage=self.imageData[frame_start]/self.imageData[10]
            # conddiff=np.mean(diffimage,axis=0)-refimage
            # graphme=conddiff/conddiff.mean()/conddiff.std()
            # pg.image(graphme,title='graphme')
            #self.subtract_Background(diffup=diffup)
            #self.Analysis_FourierMap_TFR(period=measuredPeriod, target = target,  bins=binsize, up=upflag)
        print 'target:', target
Beispiel #26
0
 def load(self):
     filename, _ = QtWidgets.QFileDialog.getOpenFileName(self, "Save State..", "", "Config Files (*.cfg)")
     if not filename:
         return
     state = configfile.readConfigFile(filename)
     self.loadState(state)
Beispiel #27
0
 def loadAutomation(self, path):
     if os.path.isfile(path):
         configdict = configfile.readConfigFile(path)
         self.model.loadExecTree(configdict)
Beispiel #28
0
    def parse_and_go(self, argsin = None):
        global period
        global binsize
        parser=OptionParser() # command line options
        ##### parses all of the options inputted at the command line TFR 11/13/2015
        parser.add_option("-u", "--upfile", dest="upfile", metavar='FILE',
                          help="load the up-file")
        parser.add_option("-d", "--downfile", dest="downfile", metavar='FILE',
                          help="load the down-file")
        parser.add_option("-D", "--directory", dest="directory", metavar='FILE',
                          help="Use directory for data")
        parser.add_option("-t", "--test", dest="test", action='store_true',
                          help="Test mode to check calculations", default=False)
        parser.add_option("-p", '--period', dest = "period", default=4.25, type="float",
                          help = "Stimulus cycle period")
        parser.add_option("-c", '--cycles', dest = "cycles", default=0, type="int",
                          help = "# cycles to analyze")
        parser.add_option("-b", '--binning', dest = "binsize", default=0, type="int",
                          help = "bin reduction x,y")
        parser.add_option("-g", '--gfilter', dest = "gfilt", default=0, type="float",
                          help = "gaussian filter width")
        parser.add_option("-f", '--fdict', dest = "fdict", default=0, type="int",
                          help = "Use dictionary entry")
        
        if argsin is not None:
            (options, args) = parser.parse_args(argsin)
        else:
            (options, args) = parser.parse_args()

        if options.period is not None:
            measuredPeriod = options.period
        if options.cycles is not None:
            self.nCycles = options.cycles
        if options.binsize is not None:
            binsize = options.binsize
        if options.gfilt is not None:
            gfilt = options.gfilt

        if options.fdict is not None:
            if options.fdict in DB.keys(): # populate options 
                options.upfile = DB[options.fdict][0]
                options.downfile = DB[options.fdict][1]
                options.period = DB[options.fdict][4]
            else:
               print "File %d NOT in DBase\n" % options.fdict
               return
        if options.directory is not None:
            self.directory = options.directory

        if options.upfile is not None:
            self.upfile = options.upfile
            target = 1
        
        if options.downfile is not None:
            self.downfile = options.downfile
            target = 2

        target = 0
        videoupf = None
        videodwnf = None
        audioupf = None
        audiodwnf = None

        if options.upfile is not None:
            videoupf = videobasepath + options.upfile + '.ma'
            audioupf = audiobasepath + options.upfile + '/DaqDevice.ma'
        if options.downfile is not None:
            videodwnf = videobasepath + options.downfile + '.ma'
            audiodwnf = audiobasepath + options.downfile + '/DaqDevice.ma'

        for file in (videoupf, videodwnf):
#if options.upfile is not None and options.downfile is not None:
            if file is None:
               break
            im=[]
            self.imageData = []
            print "loading data from ", file
            try:
                im = MetaArray(file = file,  subset=(slice(0,2), slice(64,128), slice(64,128)))
                
            except:
                print "Error loading upfile: %s\n" % file
                return
            print "data loaded"
            self.times = im.axisValues('Time')
            self.nFrames = numpy.shape(im)[0]
            self.imageData = numpy.array(im).astype(numpy.float32, copy=False)
            print 'min diff', np.amin(np.diff(self.times))
            print 'miax diff', np.amax(np.diff(self.times))
            dt = numpy.mean(numpy.diff(self.times))
            print 'dt:',dt
            target = target + 1
            rawtimes=[]
            rawimageData=[]
            rawtimes = im.axisValues('Time').astype('float32')
            rawimageData = im.view(np.ndarray).astype('float32')
            print 'size of im', np.shape(rawimageData)
            indexFile = configfile.readConfigFile(basepath+'.index') 
            timestampup = indexFile.__getitem__('video_'+DB[options.fdict][0]+'.ma')[u'__timestamp__']
            timestampdown = indexFile.__getitem__('video_'+DB[options.fdict][1]+'.ma')[u'__timestamp__']
            audioupindex = configfile.readConfigFile(audiobasepath+DB[options.fdict][0]+'/.index')
            audioupstamp = audioupindex.__getitem__(u'.')[u'__timestamp__'] 
            audiodownindex = configfile.readConfigFile(audiobasepath+DB[options.fdict][1]+'/.index')
            audiodownstamp = audiodownindex.__getitem__(u'.')[u'__timestamp__'] 
           
            diffup = audioupstamp - timestampup
            diffdown = audiodownstamp - timestampdown 

            
            if file is videoupf:
                audio = MetaArray(file = audioupf, subset=(slice(0,2), slice(64,128), slice(64,128)))
                audiotime = audio.axisValues('Time').astype('float32')
                audiomin = np.min(audiotime) + diffup
                audiomax = np.max(audiotime) + diffup
            elif file is videodwnf:
                audio = MetaArray(file = audiodwnf, subset=(slice(0,2), slice(64,128), slice(64,128)))
                audiotime = audio.axisValues('Time').astype('float32')
                audiomin = np.min(audiotime) + diffdown
                audiomax = np.max(audiotime) + diffdown
            else:
                print 'ERROR!  Unable to load audio file'
            print 'audiomin', audiomin
            print 'audiomax', audiomax

            adjustedtime = rawtimes[np.logical_and(rawtimes <= audiomax+.5, rawtimes >= audiomin)]
            frame_start=np.amin(np.where(rawtimes >= audiomin))
            frame_end=np.amax(np.where(rawtimes <= audiomax))

            background = np.mean(rawimageData[10:25,:,:], axis=0)
            print 'size of background', np.shape(background)
            adjustedimagedata = rawimageData[frame_start:frame_end,:,:]
            # print 'adjtime', adjustedtime
            self.times = [x-np.min(adjustedtime) for x in adjustedtime]
            self.imageData = adjustedimagedata
            #print 'self.times:', self.times
            # print 'length of self.times', np.shape(self.times)
            # print 'shape of image data', np.shape(self.imageData)
            print 'size of im', np.shape(self.imageData)
            im=[]
            if file is videoupf:
               upflag = 1
            else:
               upflag = 0
            #print 'target:', target

            framerate=1/dt
            xsize=self.imageData.shape[1]
            ysize=self.imageData.shape[2]
            nframes=self.imageData.shape[0]
            freq=4
            frames=self.imageData.reshape(nframes,xsize*ysize)
            print 'seize of frames', np.shape(frames)
            const=np.arange(dt,nframes/framerate,nframes)
            fourvec=[]
            for ii in range(const.shape[0]):
                fourvec[ii]=numpy.exp(2*np.pi*np.complex(0,1)*const[ii]*freq)
            print 'size of fourvec', np.shape(fourvec)
            data=frames[:,:]*fourvec
            print 'size of data', np.shape(data)
            data=np.mean(data,axis=0)
            data=data.reshape(xsize,ysize)
            
            pg.image(data)
            
            # pg.image(background)
            # diffimage=np.zeros(np.shape(self.imageData))

            # print 'single:', np.shape(self.imageData[4])
            # for i in range(self.imageData.shape[0]):
            #     diffimage[i]=self.imageData[i]/background
            #     #self.imageData[i]/background
            # print 'size of diffimage', np.shape(diffimage)
            # refimage=self.imageData[frame_start]/self.imageData[10]
            # conddiff=np.mean(diffimage,axis=0)-refimage
            # graphme=conddiff/conddiff.mean()/conddiff.std()
            # pg.image(graphme,title='graphme')
            #self.subtract_Background(diffup=diffup)
            #self.Analysis_FourierMap_TFR(period=measuredPeriod, target = target,  bins=binsize, up=upflag)
        print 'target:', target