How to use the psychopy.logging.warning function in psychopy

To help you get started, we’ve selected a few psychopy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github psychopy / psychopy / psychopy / visual / windowwarp.py View on Github external
fh.close()
            filetype = int(lines[0])
            rc = map(int, lines[1].split())
            cols, rows = rc[0], rc[1]
            warpdata = np.loadtxt(self.warpfile, skiprows=2)
        except Exception:
            error = 'Unable to read warpfile: ' + self.warpfile
            logging.warning(error)
            print(error)
            return

        if (cols * rows != warpdata.shape[0] or
                warpdata.shape[1] != 5 or
                filetype != 2):
            error = 'warpfile data incorrect: ' + self.warpfile
            logging.warning(error)
            print(error)
            return

        self.xgrid = cols
        self.ygrid = rows

        self.nverts = (self.xgrid - 1) * (self.ygrid - 1) * 4

        # create vertex grid array, and texture coords times 4 for quads
        vertices = np.zeros(
            ((self.xgrid - 1) * (self.ygrid - 1) * 4, 2), dtype='float32')
        tcoords = np.zeros(
            ((self.xgrid - 1) * (self.ygrid - 1) * 4, 2), dtype='float32')
        # opacity is RGBA
        opacity = np.ones(
            ((self.xgrid - 1) * (self.ygrid - 1) * 4, 4), dtype='float32')
github psychopy / psychopy / psychopy / data.py View on Github external
def importTrialTypes(fileName, returnFieldNames=False):
    """importTrialTypes is DEPRECATED (as of v1.70.00)
    Please use `importConditions` for identical functionality.
    """
    logging.warning("importTrialTypes is DEPRECATED (as of v1.70.00). Please use `importConditions` for identical functionality.")
    return importConditions(fileName, returnFieldNames)
github psychopy / psychopy / psychopy / app / pavlovia_ui / menu.py View on Github external
def setUser(self, user):
        if user == PavloviaMenu.currentUser:
            return  # nothing to do here. Move along please.
        PavloviaMenu.currentUser = user
        PavloviaMenu.appData['pavloviaUser'] = user
        if user in pavlovia.knownUsers:
            token = pavlovia.knownUsers[user]['token']
            try:
                pavlovia.getCurrentSession().setToken(token)
            except requests.exceptions.ConnectionError:
                logging.warning("Tried to log in to Pavlovia but no network "
                                "connection")
                return
        else:
            self.onLogInPavlovia()

        if self.searchDlg:
            self.searchDlg.updateUserProjs()
github psychopy / psychopy / psychopy / app / themes / _themes.py View on Github external
# components with theme folders
            # try using the theme name (or 'light' as a default name)
            for themeName in [theme, 'light']:
                thisPath = filename.parent / themeName / filename.name
                if thisPath.exists():
                    return str(thisPath)
            # try in the app icons folder (e.g. for "run.png")
            thisPath = iconsPath / theme / filename
            if thisPath.exists():
                return str(thisPath)
            # and in the root of the app icons
            thisPath = iconsPath / filename
            if thisPath.exists():
                return str(thisPath)
        # still haven't returned nay path. Out of ideas!
        logging.warning("Failed to find icon name={}, theme={}, "
                        "size={}, emblem={}"
                        .format(name, theme, size, emblem))
github psychopy / psychopy / psychopy / visual / window.py View on Github external
def _checkMatchingSizes(self, requested, actual):
        """Checks whether the requested and actual screen sizes differ.
        If not then a warning is output and the window size is set to actual
        """
        if list(requested) != list(actual):
            logging.warning("User requested fullscreen with size %s, "
                            "but screen is actually %s. Using actual size" %
                            (requested, actual))
            self.clientSize = numpy.array(actual)
github psychopy / psychopy / psychopy / microphone.py View on Github external
human speech: 100-8,000 (useful for telephone: 100-3,300)
        Google speech API: 16,000 or 8,000 only
        Nyquist frequency: twice the highest rate, good to oversample a bit

    pyo's downsamp() function can reduce 48,000 to 16,000 in about 0.02s
    (uses integer steps sizes). So recording at 48kHz will generate
    high-quality archival data, and permit easy downsampling.

    outputDevice, bufferSize: set these parameters on the pyoSndServer
        before booting; None means use pyo's default values
    """
    # imports pyo, creates sound.pyoSndServer using sound.initPyo() if not yet
    # created
    t0 = core.getTime()
    if prefs.hardware['audioLib'][0] != 'pyo':
        logging.warning("Starting Microphone but sound lib preference is set to be {}. "
                        "Clashes might occur since 'pyo' is not "
                        "preferred lib but is needed for Microphone"
                        .format(prefs.hardware['audioLib']))
    try:
        global pyo
        import pyo
        global haveMic
        haveMic = True
    except ImportError:  # pragma: no cover
        msg = ('Microphone class not available, needs pyo; '
               'see http://ajaxsoundstudio.com/software/pyo/')
        logging.error(msg)
        raise ImportError(msg)
    if pyo.serverCreated():
        backend_pyo.pyoSndServer.setSamplingRate(sampleRate)
    else:
github psychopy / psychopy / psychopy / visual / textbox2 / fontmanager.py View on Github external
"""
        Returns the list of FontInfo instances that match the provided
        fontName and style information. If no matching fonts are
        found, None is returned.
        """
        if type(fontName) != bytes:
            fontName = bytes(fontName, sys.getfilesystemencoding())
        style_dict = self._available_fontInfo.get(fontName)
        if not style_dict:
            similar = self.getFontNamesSimilar(fontName)
            if len(similar) == 0:
                raise ValueError("Font {} was requested but that font wasn't "
                                 "found. Need to install?"
                                 .format(repr(fontName)))
            elif len(similar) == 1:
                logging.warning("Font {} was requested. Exact match wasn't "
                                "found but we will proceed with {}?"
                                .format(repr(fontName), repr(similar[0])))
                style_dict = self._available_fontInfo.get(similar[0])
            else:  # more than 1 alternatives. Which to use?
                raise ValueError("Font {} was requested. Exact match wasn't "
                                 "found, but maybe one of these was intended:"
                                 "{}?".format(repr(fontName), similar))
            if not style_dict:
                return None
        # check if we have a valid style too
        if fontStyle and fontStyle in style_dict:
            return style_dict[fontStyle]
        for style, fonts in style_dict.items():
            b, i = self.booleansFromStyleName(style)
            if b == bold and i == italic:
                return fonts
github psychopy / psychopy / psychopy / sound / backend_pyo.py View on Github external
maxInputChnls = 0
                duplex = False
        # for other platforms set duplex to True (if microphone is available)
        else:
            audioDriver = prefs.hardware['audioDriver'][0]
            maxInputChnls = pyo.pa_get_input_max_channels(
                pyo.pa_get_default_input())
            maxOutputChnls = pyo.pa_get_output_max_channels(
                pyo.pa_get_default_output())
            duplex = bool(maxInputChnls > 0)

        maxChnls = min(maxInputChnls, maxOutputChnls)
        if maxInputChnls < 1:  # pragma: no cover
            msg = (u'%s.init could not find microphone hardware; '
                   u'recording not available')
            logging.warning(msg % __name__)
            maxChnls = maxOutputChnls
        if maxOutputChnls < 1:  # pragma: no cover
            msg = (u'%s.init could not find speaker hardware; '
                   u'sound not available')
            logging.error(msg % __name__)
            return -1

        # create the instance of the server:
        if sys.platform == 'darwin' or sys.platform.startswith('linux'):
            # for mac/linux we set the backend using the server audio param
            pyoSndServer = Server(sr=rate, nchnls=maxChnls,
                                  buffersize=buffer, audio=audioDriver)
        else:
            # with others we just use portaudio and then set the OutputDevice
            # below
            pyoSndServer = Server(sr=rate, nchnls=maxChnls, buffersize=buffer)
github psychopy / psychopy / psychopy / hardware / bbtk / __init__.py View on Github external
# try to read from port
        self.pause()
        self.com.timeout = 5.0
        nEvents = int(self.com.readline()[:-2])  # last two chars are ;\n
        self.com.readline()[:-2]  # microseconds recorded (ignore)
        self.com.readline()[:-2]  # samples recorded (ignore)
        while True:
            line = self.com.readline()
            if line.startswith(b'EDAT'):  # end of data stream
                break
            events.extend(parseEventsLine(line, lastState))
            lastState = events[-1]['state']
            eventLines.append(line)
        if nEvents != len(eventLines):
            msg = "BBTK reported %i events but told us to expect %i events!!"
            logging.warning(msg % (len(events), nEvents))
        logging.flush()  # we aren't in a time-critical period
        return events
github psychopy / psychopy / psychopy / visual / simpleimage.py View on Github external
# good thing
        self.useShaders = win._haveShaders
        self.pos = pos  # call attributeSetter
        self.image = image  # call attributeSetter
        # check image size against window size
        if (self.size[0] > self.win.size[0] or
                self.size[1] > self.win.size[1]):
            msg = ("Image size (%s, %s)  was larger than window size "
                   "(%s, %s). Will draw black screen.")
            logging.warning(msg % (self.size[0], self.size[1],
                                   self.win.size[0], self.win.size[1]))

        # check position with size, warn if stimuli not fully drawn
        if (self.pos[0] + self.size[0] / 2. > self.win.size[0] / 2. or
                self.pos[0] - self.size[0] / 2. < -self.win.size[0] / 2.):
            logging.warning("The image does not completely fit inside "
                            "the window in the X direction.")
        if (self.pos[1] + self.size[1] / 2. > self.win.size[1] / 2. or
                self.pos[1] - self.size[1] / 2. < -self.win.size[1] / 2.):
            logging.warning("The image does not completely fit inside "
                            "the window in the Y direction.")

        # flip if necessary
        # initially it is false, then so the flip according to arg above
        self.__dict__['flipHoriz'] = False
        self.flipHoriz = flipHoriz  # call attributeSetter
        # initially it is false, then so the flip according to arg above
        self.__dict__['flipVert'] = False
        self.flipVert = flipVert  # call attributeSetter

        self._calcPosRendered()