当前位置: 首页>>代码示例>>Python>>正文


Python logging.data函数代码示例

本文整理汇总了Python中psychopy.logging.data函数的典型用法代码示例。如果您正苦于以下问题:Python data函数的具体用法?Python data怎么用?Python data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: waitKeys

def waitKeys(maxWait=float('inf'), keyList=None, timeStamped=False):
    """
    Same as `~psychopy.event.getKeys`, but halts everything (including drawing) while awaiting
    input from keyboard. Implicitly clears keyboard, so any preceding keypresses will be lost.

    :Parameters:
        maxWait : any numeric value.
            Maximum number of seconds period and which keys to wait for.
            Default is float('inf') which simply waits forever.

    Returns None if times out.
    """

    #NB pygame.event does have a wait() function that will
    #do this and maybe leave more cpu idle time?
    key = None
    clearEvents('keyboard')  # So that we only take presses from here onwards.

    # Check for keypresses until maxWait is exceeded
    timer = psychopy.core.Clock()
    while key == None and timer.getTime() < maxWait:
        # Pump events on pyglet windows if they exist
        if havePyglet:
            wins = pyglet.window.get_platform().get_default_display().get_windows()
            for win in wins: win.dispatch_events()

        # Get keypresses and return if anything is pressed
        keys = getKeys(keyList=keyList, timeStamped=timeStamped)
        if len(keys):
            return keys

    # If maxWait is exceeded (exits while-loop), return None
    logging.data("No keypress (maxWait exceeded)")
    return None
开发者ID:JasonLocklin,项目名称:psychopy,代码行数:34,代码来源:event.py

示例2: _record

    def _record(self, sec, filename='', block=True):
        while self.recorder.running:
            pass
        self.duration = float(sec)
        self.onset = core.getTime()  # for duration estimation, high precision
        self.fileOnset = core.getAbsTime()  # for log and filename, 1 sec precision
        logging.data('%s: Record: onset %d, capture %.3fs' %
                     (self.loggingId, self.fileOnset, self.duration) )
        if not file:
            onsettime = '-%d' % self.fileOnset
            self.savedFile = onsettime.join(os.path.splitext(self.wavOutFilename))
        else:
            self.savedFile = os.path.abspath(filename).strip('.wav') + '.wav'

        t0 = core.getTime()
        self.recorder.run(self.savedFile, self.duration, **self.options)

        self.rate = sound.pyoSndServer.getSamplingRate()
        if block:
            core.wait(self.duration, 0)
            logging.exp('%s: Record: stop. %.3f, capture %.3fs (est)' %
                     (self.loggingId, core.getTime(), core.getTime() - t0) )
            while self.recorder.running:
                core.wait(.001, 0)
        else:
            logging.exp('%s: Record: return immediately, no blocking' %
                     (self.loggingId) )

        return self.savedFile
开发者ID:DiogoamCoutinho,项目名称:stimulus.py,代码行数:29,代码来源:microphone.py

示例3: record

    def record(self, sec, file='', block=True):
        """Capture sound input for duration <sec>, save to a file.

        Return the path/name to the new file. Uses onset time (epoch) as
        a meaningful identifier for filename and log.
        """
        while self.recorder.running:
            pass
        self.duration = float(sec)
        self.onset = core.getTime() # note: report onset time in log, and use in filename
        logging.data('%s: Record: onset %.3f, capture %.3fs' %
                     (self.loggingId, self.onset, self.duration) )
        if not file:
            onsettime = '-%.3f' % self.onset
            self.savedFile = onsettime.join(os.path.splitext(self.wavOutFilename))
        else:
            self.savedFile = os.path.abspath(file).strip('.wav') + '.wav'

        t0 = core.getTime()
        self.recorder.run(self.savedFile, self.duration, self.sampletype)
        self.rate = sound.pyoSndServer.getSamplingRate()

        if block:
            core.wait(self.duration - .0008) # .0008 fudge factor for better reporting
                # actual timing is done by Clean_objects
            logging.exp('%s: Record: stop. %.3f, capture %.3fs (est)' %
                     (self.loggingId, core.getTime(), core.getTime() - t0) )
        else:
            logging.exp('%s: Record: return immediately, no blocking' %
                     (self.loggingId) )

        return self.savedFile
开发者ID:RainyJupiter,项目名称:psychopy,代码行数:32,代码来源:microphone.py

示例4: _record

    def _record(self, sec, filename="", block=True, log=True):
        while self.recorder.running:
            pass
        self.duration = float(sec)
        self.onset = core.getTime()  # for duration estimation, high precision
        self.fileOnset = core.getAbsTime()  # for log and filename, 1 sec precision
        ms = "%.3f" % (core.getTime() - int(core.getTime()))
        if log and self.autoLog:
            logging.data("%s: Record: onset %d, capture %.3fs" % (self.loggingId, self.fileOnset, self.duration))
        if not filename:
            onsettime = "-%d" % self.fileOnset + ms[1:]
            self.savedFile = onsettime.join(os.path.splitext(self.wavOutFilename))
        else:
            self.savedFile = os.path.abspath(filename).strip(".wav") + ".wav"

        t0 = core.getTime()
        self.recorder.run(self.savedFile, self.duration, **self.options)

        self.rate = sound.pyoSndServer.getSamplingRate()
        if block:
            core.wait(self.duration, 0)
            if log and self.autoLog:
                logging.exp(
                    "%s: Record: stop. %.3f, capture %.3fs (est)"
                    % (self.loggingId, core.getTime(), core.getTime() - t0)
                )
            while self.recorder.running:
                core.wait(0.001, 0)
        else:
            if log and self.autoLog:
                logging.exp("%s: Record: return immediately, no blocking" % (self.loggingId))

        return self.savedFile
开发者ID:rpbaxter,项目名称:psychopy,代码行数:33,代码来源:microphone.py

示例5: _onPygletKey

def _onPygletKey(symbol, modifiers, emulated=False):
    """handler for on_key_press pyglet events, or call directly to emulate a key press

    Appends a tuple with (keyname, timepressed) into the global _keyBuffer. The
    _keyBuffer can then be accessed as normal using event.getKeys(), .waitKeys(),
    clearBuffer(), etc.

    J Gray 2012: Emulated means add a key (symbol) to the buffer virtually.
    This is useful for fMRI_launchScan, and for unit testing (in testTheApp)
    Logging distinguished EmulatedKey events from real Keypress events.
    For emulation, the key added to the buffer is unicode(symbol), instead of
    pyglet.window.key.symbol_string(symbol)

    S Mathot 2012: Implement fallback to _onPygletText
    """

    global useText
    keyTime=psychopy.core.getTime() #capture when the key was pressed
    if emulated:
        thisKey = unicode(symbol)
        keySource = 'EmulatedKey'
    else:
        thisKey = pyglet.window.key.symbol_string(symbol).lower() #convert symbol into key string
        #convert pyglet symbols to pygame forms ( '_1'='1', 'NUM_1'='[1]')
        # 'user_key' indicates that Pyglet has been unable to make sense out of
        # the keypress. In that case, we fall back to _onPygletText to handle
        # the input.
        if 'user_key' in thisKey:
            useText = True
            return
        useText = False
        thisKey = thisKey.lstrip('_').lstrip('NUM_')
        keySource = 'Keypress'
    _keyBuffer.append( (thisKey,keyTime) ) # tuple
    logging.data("%s: %s" % (keySource, thisKey))
开发者ID:BrainTech,项目名称:psychopy,代码行数:35,代码来源:event.py

示例6: _onGLFWKey

def _onGLFWKey(*args, **kwargs):
    """Callback for key/character events for the GLFW backend.

    :return:
    """
    keyTime = psychopy.core.getTime()  # get timestamp

    # TODO - support for key emulation
    win_ptr, key, scancode, action, modifiers = args
    global useText
    
    if key == glfw.KEY_UNKNOWN:
        useText = True
        return
    useText = False

    # get the printable name, always make lowercase
    key_name = glfw.get_key_name(key, scancode)

    # if there is no localized key name or space
    if key_name is None or key_name == ' ':
        try:
            key_name = _glfw_keycodes_[key]
        except KeyError:
            pass
    else:
        key_name = key_name.lower()

    # TODO - modifier integration
    keySource = 'Keypress'
    _keyBuffer.append((key_name, modifiers, keyTime))  # tuple
    logging.data("%s: %s" % (keySource, key_name))
开发者ID:mmagnuski,项目名称:psychopy,代码行数:32,代码来源:event.py

示例7: record

    def record(self, sec, block=True):
        """Capture sound input for duration <sec>, save to a file.
        
        Return the path/name to the new file. Uses onset time (epoch) as
        a meaningful identifier for filename and log.
        """
        RECORD_SECONDS = float(sec)
        self.onset = time.time() # note: report onset time in log, and use in filename
        logging.data('%s: Record: onset %.3f, capture %.3fs' %
                     (self.loggingId, self.onset, RECORD_SECONDS) )
        
        self.savedFile = self.wavOutFilename.replace(ONSET_TIME_HERE, '-%.3f' % self.onset)
        inputter = Input(chnl=0, mul=1) # chnl=[0,1] for stereo input
        t0 = time.time()
        # launch the recording, saving to file:
        recorder = Record(inputter,
                        self.savedFile,
                        chnls=2,
                        fileformat=0, # .wav format
                        sampletype=0,
                        buffering=4) # 4 is default
        # launch recording, block as needed, and clean up:
        clean = Clean_objects(RECORD_SECONDS, recorder) # set up to stop recording
        clean.start() # the timer starts now, ends automatically whether block or not
        if block:
            time.sleep(RECORD_SECONDS - 0.0008) # Clean_objects() set-up takes ~0.0008s, for me
            logging.exp('%s: Record: stop. %.3f, capture %.3fs (est)' %
                     (self.loggingId, time.time(), time.time() - t0) )
        else:
            logging.exp('%s: Record: return immediately, no blocking' %
                     (self.loggingId) )
        
        self.duration = RECORD_SECONDS # used in playback()

        return self.savedFile # filename, or None
开发者ID:jsalva,项目名称:psychopy,代码行数:35,代码来源:microphone.py

示例8: _onPygletText

def _onPygletText(text, emulated=False):
    """handler for on_text pyglet events, or call directly to emulate a text
    event.

    S Mathot 2012: This function only acts when the key that is pressed
    corresponds to a non-ASCII text character (Greek, Arabic, Hebrew, etc.).
    In that case the symbol that is passed to _onPygletKey() is translated
    into a useless 'user_key()' string. If this happens, _onPygletText takes
    over the role of capturing the key. Unfortunately, _onPygletText()
    cannot solely handle all input, because it does not respond to spacebar
    presses, etc.
    """

    global useText
    if not useText:  # _onPygletKey has handled the input
        return
    # This is needed because sometimes the execution
    # sequence is messed up (somehow)
    useText = False
    # capture when the key was pressed:
    keyTime = psychopy.core.getTime()
    if emulated:
        keySource = 'EmulatedKey'
    else:
        keySource = 'KeyPress'
    _keyBuffer.append((text.lower(), lastModifiers, keyTime))
    logging.data("%s: %s" % (keySource, text))
开发者ID:hoechenberger,项目名称:psychopy,代码行数:27,代码来源:event.py

示例9: _onGLFWMouseScroll

def _onGLFWMouseScroll(*args, **kwargs):
    """Callback for mouse scrolling events. For most computer mice with scroll
    wheels, only the vertical (Y-offset) is relevant.

    """
    window_ptr, x_offset, y_offset = args
    global mouseWheelRel
    mouseWheelRel = mouseWheelRel + numpy.array([x_offset, y_offset])
    msg = "Mouse: wheel shift=(%i,%i)"
    logging.data(msg % (x_offset, y_offset))
开发者ID:mmagnuski,项目名称:psychopy,代码行数:10,代码来源:event.py

示例10: _onPygletMouseRelease

def _onPygletMouseRelease(x,y, button, modifiers):
    global mouseButtons
    if button == pyglet.window.mouse.LEFT:
        mouseButtons[0]=0
        label='Left'
    if button == pyglet.window.mouse.MIDDLE:
        mouseButtons[1]=0
        label='Middle'
    if button == pyglet.window.mouse.RIGHT:
        mouseButtons[2]=0
        label='Right'
    logging.data("Mouse: %s button up, pos=(%i,%i)" %(label, x,y))
开发者ID:BrainTech,项目名称:psychopy,代码行数:12,代码来源:event.py

示例11: _onPygletKey

def _onPygletKey(symbol, modifiers, emulated=False):
    """handler for on_key_press pyglet events; call directly to emulate a
    key press

    Appends a tuple with (keyname, timepressed) into the global _keyBuffer.
    The _keyBuffer can then be accessed as normal using event.getKeys(),
    .waitKeys(), clearBuffer(), etc.

    J Gray 2012: Emulated means add a key (symbol) to the buffer virtually.
    This is useful for fMRI_launchScan, and for unit testing (in testTheApp)
    Logging distinguishes EmulatedKey events from real Keypress events.
    For emulation, the key added to the buffer is unicode(symbol), instead of
    pyglet.window.key.symbol_string(symbol).

    S Mathot 2012: Implement fallback to _onPygletText

    5AM Solutions 2016: Add the keyboard modifier flags to the key buffer.

    M Cutone 2018: Added GLFW backend support.

    """
    global useText, lastModifiers

    keyTime = psychopy.core.getTime()  # capture when the key was pressed
    if emulated:
        if not isinstance(modifiers, int):
            msg = 'Modifiers must be passed as an integer value.'
            raise ValueError(msg)

        thisKey = str(symbol)
        keySource = 'EmulatedKey'
    else:
        thisKey = pyglet.window.key.symbol_string(
            symbol).lower()  # convert symbol into key string
        # convert pyglet symbols to pygame forms ( '_1'='1', 'NUM_1'='[1]')
        # 'user_key' indicates that Pyglet has been unable to make sense
        # out of the keypress. In that case, we fall back to _onPygletText
        # to handle the input.
        if 'user_key' in thisKey:
            useText = True
            lastModifiers = modifiers
            return
        useText = False
        thisKey = thisKey.lstrip('_').lstrip('NUM_')
        # Pyglet 1.3.0 returns 'enter' when Return key (0xFF0D) is pressed 
        # in Windows Python3. So we have to replace 'enter' with 'return'.
        if thisKey == 'enter':
            thisKey = 'return'
        keySource = 'Keypress'
    _keyBuffer.append((thisKey, modifiers, keyTime))  # tuple
    logging.data("%s: %s" % (keySource, thisKey))
    _process_global_event_key(thisKey, modifiers)
开发者ID:hoechenberger,项目名称:psychopy,代码行数:52,代码来源:event.py

示例12: stop

    def stop(self):
        """Interrupt a recording that is in progress; close & keep the file.

        Ends the recording before the duration that was initially specified. The
        same file name is retained, with the same onset time but a shorter duration.

        The same recording cannot be resumed after a stop (it is not a pause),
        but you can start a new one.
        """
        if not self.recorder.running:
            logging.exp('%s: Stop requested, but no record() in progress' % self.loggingId )
            return
        self.duration = core.getTime() - self.onset  # new shorter duration
        self.recorder.stop()
        logging.data('%s: Record stopped early, new duration %.3fs' % (self.loggingId, self.duration))
开发者ID:RainyJupiter,项目名称:psychopy,代码行数:15,代码来源:microphone.py

示例13: _onPygletMousePress

def _onPygletMousePress(x,y, button, modifiers):
    global mouseButtons, mouseClick, mouseTimes
    if button == pyglet.window.mouse.LEFT:
        mouseButtons[0]=1
        mouseTimes[0]= psychopy.clock.getTime()-mouseClick[0].getLastResetTime()
        label='Left'
    if button == pyglet.window.mouse.MIDDLE:
        mouseButtons[1]=1
        mouseTimes[1]= psychopy.clock.getTime()-mouseClick[1].getLastResetTime()
        label='Middle'
    if button == pyglet.window.mouse.RIGHT:
        mouseButtons[2]=1
        mouseTimes[2]= psychopy.clock.getTime()-mouseClick[2].getLastResetTime()
        label='Right'
    logging.data("Mouse: %s button down, pos=(%i,%i)" %(label, x,y))
开发者ID:BrainTech,项目名称:psychopy,代码行数:15,代码来源:event.py

示例14: _onPygletMouseRelease

def _onPygletMouseRelease(x, y, button, modifiers, emulated=False):
    global mouseButtons
    if emulated:
        label = 'Emulated'
    else:
        label = ''
    if button & LEFT:
        mouseButtons[0] = 0
        label += ' Left'
    if button & MIDDLE:
        mouseButtons[1] = 0
        label += ' Middle'
    if button & RIGHT:
        mouseButtons[2] = 0
        label += ' Right'
    logging.data("Mouse: %s button up, pos=(%i,%i)" % (label, x, y))
开发者ID:mmagnuski,项目名称:psychopy,代码行数:16,代码来源:event.py

示例15: _onGLFWText

def _onGLFWText(*args, **kwargs):
    """Handle unicode character events if _onGLFWKey() cannot.

    :return:
    """
    keyTime = psychopy.core.getTime()  # get timestamp



    # TODO - support for key emulation
    win_ptr, codepoint, modifiers = args
    # win = glfw.get_window_user_pointer(win_ptr)
    text = chr(codepoint)  # convert to unicode character (Python 3.0)
    global useText
    if not useText:  # _onPygletKey has handled the input
        return
    keySource = 'KeyPress'
    _keyBuffer.append((text, keyTime))
    logging.data("%s: %s" % (keySource, text))
开发者ID:mmagnuski,项目名称:psychopy,代码行数:19,代码来源:event.py


注:本文中的psychopy.logging.data函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。