Previous topic

psychopy.logging - control what gets logged

Next topic

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

This Page

Quick links

psychopy.misc - miscellaneous routines for converting units etc

Tools, nothing to do with psychophysics or experiments - just handy things like conversion functions etc...

psychopy.misc.array2image(a)

Takes an array and returns an image object (PIL)

psychopy.misc.cart2pol(x, y, units='deg')

Convert from cartesian to polar coordinates

Usage :theta, radius = pol2cart(x, y, units=’deg’)

units refers to the units (rad or deg) for theta that should be returned

psychopy.misc.cm2deg(cm, monitor)

Convert size in cm to size in degrees for a given Monitor object

psychopy.misc.cm2pix(cm, monitor)

Convert size in degrees to size in pixels for a given Monitor object

psychopy.misc.createXYs(x, y=None)

Create an Nx2 array of XY values including all combinations of the x and y values provided.

>>> createXYs(x=[1,2,3],y=[4,5,6])
array([[1, 4],
   [2, 4],
   [3, 4],
   [1, 5],
   [2, 5],
   [3, 5],
   [1, 6],
   [2, 6],
   [3, 6]])
>>> createXYs(x=[1,2,3])  #assumes y=x
array([[1, 1],
   [2, 1],
   [3, 1],
   [1, 2],
   [2, 2],
   [3, 2],
   [1, 3],
   [2, 3],
   [3, 3]])
psychopy.misc.deg2cm(degrees, monitor)

Convert size in degrees to size in pixels for a given Monitor object

psychopy.misc.deg2pix(degrees, monitor)

Convert size in degrees to size in pixels for a given Monitor object

psychopy.misc.dkl2rgb(dkl_Nx3, conversionMatrix=None)

Convert from DKL color space (cone-opponent space from Derrington, Krauskopf & Lennie) to RGB.

Requires a conversion matrix, which will be generated from generic Sony Trinitron phosphors if not supplied (note that this will not be an accurate representation of the color space unless you supply a conversion matrix).

usage:

rgb(Nx3) = dkl2rgb(dkl_Nx3(el,az,radius), conversionMatrix)
psychopy.misc.dklCart2rgb(LUM, LM, S, conversionMatrix=None)

Like dkl2rgb except that it uses cartesian coords (LM,S,LUM) rather than spherical coords for DKL (elev, azim, contr)

NB: this may return rgb values >1 or <-1

psychopy.misc.extendArr(inArray, newSize)

Takes a numpy array and returns it padded with zeros to the necessary size

>>> misc.extendArr([1,2,3],5)
array([1, 2, 3, 0, 0])
psychopy.misc.float_uint16(inarray)

Converts arrays, lists, tuples and floats ranging -1:1 into an array of Uint16s ranging 0:2^16

psychopy.misc.float_uint8(inarray)

Converts arrays, lists, tuples and floats ranging -1:1 into an array of Uint8s ranging 0:255

>>> float_uint8(-1)
0
>>> float_uint8(0)
128
psychopy.misc.fromFile(filename)

load data (of any sort) from a pickle file

simple wrapper of the cPickle module in core python

psychopy.misc.image2array(im)

Takes an image object (PIL) and returns a numpy array

psychopy.misc.lms2rgb(lms_Nx3, conversionMatrix=None)

Convert from cone space (Long, Medium, Short) to RGB.

Requires a conversion matrix, which will be generated from generic Sony Trinitron phosphors if not supplied (note that you will not get an accurate representation of the color space unless you supply a conversion matrix)

usage:

rgb(Nx3) = lms2rgb(dkl_Nx3(el,az,radius), conversionMatrix)
psychopy.misc.makeImageAuto(inarray)

Combines float_uint8 and image2array operations ie. scales a numeric array from -1:1 to 0:255 and converts to PIL image format

psychopy.misc.mergeFolder(src, dst, pattern=None)

Merge a folder into another.

Existing files in dst with the same name will be overwritten. Non-existent files/folders will be created.

psychopy.misc.pix2cm(pixels, monitor)

Convert size in pixels to size in cm for a given Monitor object

psychopy.misc.pix2deg(pixels, monitor)

Convert size in pixels to size in degrees for a given Monitor object

psychopy.misc.plotFrameIntervals(intervals)

Plot a histogram of the frame intervals.

Where intervals is either a filename to a file, saved by Window.saveFrameIntervals or simply a list (or array) of frame intervals

psychopy.misc.pol2cart(theta, radius, units='deg')

Convert from polar to cartesian coordinates

usage:

x,y = pol2cart(theta, radius, units='deg')
psychopy.misc.radians(degrees)

Convert degrees to radians

>>> radians(180)
3.1415926535897931
>>> degrees(45)
0.78539816339744828
psychopy.misc.ratioRange(start, nSteps=None, stop=None, stepRatio=None, stepdB=None, stepLogUnits=None)

Creates a array where each step is a constant ratio rather than a constant addition.

Specify start and any 2 of, nSteps, stop, stepRatio, stepdB, stepLogUnits

>>> ratioRange(1,nSteps=4,stop=8)
array([ 1.,  2.,  4.,  8.])
>>> ratioRange(1,nSteps=4,stepRatio=2)
array([ 1.,  2.,  4.,  8.])
>>> ratioRange(1,stop=8,stepRatio=2)
array([ 1.,  2.,  4.,  8.])
psychopy.misc.rgb2dklCart(picture, conversionMatrix=None)

Convert an RGB image into Cartesian DKL space

psychopy.misc.shuffleArray(inArray, shuffleAxis=-1, seed=None)

Takes a (flat) num array, list or string and returns a shuffled version as a num array with the same shape. Optional argument ShuffleAxis determines the axis to shuffle along (default=-1 meaning shuffle across entire matrix?)

THIS DOESN’T WORK WITH MATRICES YET - ONLY FLAT ARRAYS - APPEARS TO BE BUG IN EITHER NUMPY.ARGSORT() OR NUMPY.TAKE()

psychopy.misc.sph2cart(*args)

Convert from spherical coordinates (elevation, azimuth, radius) to cartesian (x,y,z)

usage:
array3xN[x,y,z] = sph2cart(array3xN[el,az,rad]) OR x,y,z = sph2cart(elev, azim, radius)
psychopy.misc.toFile(filename, data)

save data (of any sort) as a pickle file

simple wrapper of the cPickle module in core python

psychopy.misc.uint8_float(inarray)

Converts arrays, lists, tuples and UINTs ranging 0:255 into an array of floats ranging -1:1