Table Of Contents

Previous topic

psychopy.misc - miscellaneous routines for converting units etc

Next topic

psychopy.parallel - functions for interacting with the parallel port

This Page

Quick links

psychopy.monitors - for those that don’t like Monitor Center

Most users won’t need to use the code here. In general the Monitor Centre interface is sufficient and monitors setup that way can be passed as strings to Window s. If there is some aspect of the normal calibration that you wish to override. eg:

from psychopy import visual, monitors
mon = monitors.Monitor('SonyG55')#fetch the most recent calib for this monitor
mon.setDistance(114)#further away than normal?
win = visual.Window(size=[1024,768], monitor=mon)

You might also want to fetch the Photometer class for conducting your own calibrations

Monitor

class psychopy.monitors.Monitor(name, width=None, distance=None, gamma=None, notes=None, useBits=None, verbose=True, currentCalib=None, autoLog=True)

Creates a monitor object for storing calibration details. This will be loaded automatically from disk if the monitor name is already defined (see methods).

Many settings from the stored monitor can easilly be overridden either by adding them as arguments during the initial call.

arguments:

  • width, distance, gamma are details about the calibration

  • notes is a text field to store any useful info

  • useBits True, False, None

  • verbose True, False, None

  • currentCalib is a dictionary object containing various

    fields for a calibration. Use with caution since the dictionary may not contain all the necessary fields that a monitor object expects to find.

eg:

myMon = Monitor('sony500', distance=114) Fetches the info on the sony500 and overrides its usual distance to be 114cm for this experiment.

These can be saved to the monitor file using saveMon() or not (in which case the changes will be lost)

copyCalib(calibName=None)

Stores the settings for the current calibration settings as new monitor.

delCalib(calibName)

Remove a specific calibration from the current monitor. Won’t be finalised unless monitor is saved

gammaIsDefault()

Determine whether we’re using the default gamma values

getCalibDate()

As a python date object (convert to string using calibTools.strFromDate

getDKL_RGB(RECOMPUTE=False)

Returns the DKL->RGB conversion matrix. If one has been saved this will be returned. Otherwise, if power spectra are available for the monitor a matrix will be calculated.

getDistance()

Returns distance from viewer to the screen in cm, or None if not known

getGamma()

Returns just the gamma value (not the whole grid)

getGammaGrid()

Gets the min,max,gamma values for the each gun

getLMS_RGB(recompute=False)

Returns the LMS->RGB conversion matrix. If one has been saved this will be returned. Otherwise (if power spectra are available for the monitor) a matrix will be calculated.

getLevelsPost()

Gets the measured luminance values from last calibration TEST

getLevelsPre()

Gets the measured luminance values from last calibration

getLinearizeMethod()

Gets the method that this monitor is using to linearize the guns

getLumsPost()

Gets the measured luminance values from last calibration TEST

getLumsPre()

Gets the measured luminance values from last calibration

getMeanLum()

Returns the mean luminance of the screen if explicitly stored

getNotes()

Notes about the calibration

getPsychopyVersion()

Returns the version of PsychoPy that was used to create this calibration

getSizePix()

Returns the size of the current calibration in pixels, or None if not defined

getSpectra()

Gets the wavelength values from the last spectrometer measurement (if available)

usage:
  • nm, power = monitor.getSpectra()
getUseBits()

Was this calibration carried out witha a bits++ box

getWidth()

Of the viewable screen in cm, or None if not known

lineariseLums(desiredLums, newInterpolators=False, overrideGamma=None)

lums should be uncalibrated luminance values (e.g. a linear ramp) ranging 0:1

newCalib(calibName=None, width=None, distance=None, gamma=None, notes=None, useBits=False, verbose=True)

create a new (empty) calibration for this monitor and makes this the current calibration

saveMon()

Saves the current dictionary of calibrations as a json file

setCalibDate(date=None)

Sets the current calibration to have a date/time or to the current date/time if none given. (Also returns the date as set)

setCurrent(calibration=-1)

Sets the current calibration for this monitor. Note that a single file can hold multiple calibrations each stored under a different key (the date it was taken)

The argument is either a string (naming the calib) or an integer eg:

myMon.setCurrent('mainCalib') fetches the calibration named mainCalib. You can name calibrations what you want but PsychoPy will give them names of date/time by default. In Monitor Center you can ‘copy...’ a calibration and give it a new name to keep a second version.

calibName = myMon.setCurrent(0) fetches the first calibration (alphabetically) for this monitor

calibName = myMon.setCurrent(-1) fetches the last alphabetical calibration for this monitor (this is default). If default names are used for calibrations (ie date/time stamp) then this will import the most recent.

setDKL_RGB(dkl_rgb)

Sets the DKL->RGB conversion matrix for a chromatically calibrated monitor (matrix is a 3x3 num array).

setDistance(distance)

To the screen (cm)

setGamma(gamma)

Sets the gamma value(s) for the monitor. This only uses a single gamma value for the three guns, which is fairly approximate. Better to use setGammaGrid (which uses one gamma value for each gun)

setGammaGrid(gammaGrid)

Sets the min,max,gamma values for the each gun

setLMS_RGB(lms_rgb)

Sets the LMS->RGB conversion matrix for a chromatically calibrated monitor (matrix is a 3x3 num array).

setLevelsPost(levels)

Sets the last set of luminance values measured AFTER calibration

setLevelsPre(levels)

Sets the last set of luminance values measured during calibration

setLineariseMethod(method)

Sets the method for linearising 0 uses y=a+(bx)^gamma 1 uses y=(a+bx)^gamma 2 uses linear interpolation over the curve

setLumsPost(lums)

Sets the last set of luminance values measured AFTER calibration

setLumsPre(lums)

Sets the last set of luminance values measured during calibration

setMeanLum(meanLum)

Records the mean luminance (for reference only)

setNotes(notes)

For you to store notes about the calibration

setPsychopyVersion(version)

To store the version of PsychoPy that this calibration used

setSizePix(pixels)

Set the size of the screen in pixels x,y

setSpectra(nm, rgb)

Sets the phosphor spectra measured by the spectrometer

setUseBits(usebits)

DEPRECATED: Use the new hardware classes to control these devices

setWidth(width)

Of the viewable screen (cm)


GammaCalculator

class psychopy.monitors.GammaCalculator(inputs=(), lums=(), gamma=None, bitsIN=8, bitsOUT=8, eq=1)

Class for managing gamma tables

Parameters:

  • inputs (required)= values at which you measured screen luminance either

    in range 0.0:1.0, or range 0:255. Should include the min and max of the monitor

Then give EITHER “lums” or “gamma”:

  • lums = measured luminance at given input levels
  • gamma = your own gamma value (single float)
  • bitsIN = number of values in your lookup table
  • bitsOUT = number of bits in the DACs

myTable.gammaModel myTable.gamma

fitGammaErrFun(params, x, y, minLum, maxLum)

Provides an error function for fitting gamma function

(used by fitGammaFun)

fitGammaFun(x, y)

Fits a gamma function to the monitor calibration data.

Parameters:
-xVals are the monitor look-up-table vals, either 0-255 or 0.0-1.0 -yVals are the measured luminances from a photometer/spectrometer

getAllMonitors()

psychopy.monitors.getAllMonitors()

Find the names of all monitors for which calibration files exist

findPR650()

psychopy.monitors.findPR650(ports=None)

DEPRECATED (as of v.1.60.01). Use psychopy.hardware.findPhotometer() instead, which finds a wider range of devices

getLumSeriesPR650()

psychopy.monitors.getLumSeriesPR650(lumLevels=8, winSize=(800, 600), monitor=None, gamma=1.0, allGuns=True, useBits=False, autoMode='auto', stimSize=0.3, photometer='COM1')

DEPRECATED (since v1.60.01): Use psychopy.monitors.getLumSeries() instead

getRGBspectra()

psychopy.monitors.getRGBspectra(stimSize=0.3, winSize=(800, 600), photometer='COM1')
usage:
getRGBspectra(stimSize=0.3, winSize=(800,600), photometer=’COM1’)
Params:
  • ‘photometer’ could be a photometer object or a serial port

name on which a photometer might be found (not recommended)

gammaFun()

psychopy.monitors.gammaFun(xx, minLum, maxLum, gamma, eq=1, a=None, b=None, k=None)

Returns gamma-transformed luminance values. y = gammaFun(x, minLum, maxLum, gamma)

a and b are calculated directly from minLum, maxLum, gamma

Parameters:

  • xx are the input values (range 0-255 or 0.0-1.0)
  • minLum = the minimum luminance of your monitor
  • maxLum = the maximum luminance of your monitor (for this gun)
  • gamma = the value of gamma (for this gun)

gammaInvFun()

psychopy.monitors.gammaInvFun(yy, minLum, maxLum, gamma, b=None, eq=1)

Returns inverse gamma function for desired luminance values. x = gammaInvFun(y, minLum, maxLum, gamma)

a and b are calculated directly from minLum, maxLum, gamma Parameters:

  • xx are the input values (range 0-255 or 0.0-1.0)

  • minLum = the minimum luminance of your monitor

  • maxLum = the maximum luminance of your monitor (for this gun)

  • gamma = the value of gamma (for this gun)

  • eq determines the gamma equation used;

    eq==1[default]: yy = a + (b * xx)**gamma eq==2: yy = (a + b*xx)**gamma

makeDKL2RGB()

psychopy.monitors.makeDKL2RGB(nm, powerRGB)

Creates a 3x3 DKL->RGB conversion matrix from the spectral input powers

makeLMS2RGB()

psychopy.monitors.makeLMS2RGB(nm, powerRGB)

Creates a 3x3 LMS->RGB conversion matrix from the spectral input powers