Home | | News | | Documentation | | Tutorial | | Screen Cast | | Download | |

The following is a complete set of documentation of the py.psy.exp class. You can browse this page to find information on the arguments that each function takes and their function.

py.psy.exp requires: NumPy, Pygame



MouseButton Experiment

class MouseButton

def __init__(self, x, y, w, h)
    Button class based on the template method pattern. The MouseButton class creates a Rect object of w width and h height at (x,y).
def containsPoint(self, x, y)
    Returns True if the point (x,y) is contained in the MouseButton Rect .

    return Boolean

class Experiment

The experiment class is a general purpose class.

def __init__(self, laptop, screenres, experimentname)
    Requires three values to be passed:

    laptop - Boolean. If True, the display created will be windowed. Else, the display will be fullscreen.
    screenres - Two-value tuple or list representing pixel dimensions
    experimentname - String that will be displayed as the title of the new window


def set_filename(self)
    Sets and opens file to be written.

    The filename and datafile opened can be accessed calling self.filename and self.datafile, respectively.


def load_all_resources(self, img_directory, snd_directory="")
    Loads all images and sounds into dictionary self.resources

    img_directory - Path to the folder containing images. Calls load_all_images.

    snd_directory - Path to the folder containing sounds. Empty by default. Calls load_all_sounds if a path is passed.


def load_all_images(self, directory):
    load_all_images goes through directory folder and places all files in a list. The function filters out 'Thumbs.db' files and hidden system files. All images are placed in a dictionary called self.resources.

    All images must be referenced by name, i.e. self.resources['image1.gif'].


def load_all_sounds(self, directory)
    load_all_sounds goes through directory folder and places all files in a list. The function filters out 'Thumbs.db' files and hidden system files. All sounds are placed in a list called self.resources.

    All sounds must be referenced by name, i.e. self.resources['sound1.wav'].play


def load_image(self, fullname, colorkey=None)
    load_image attempts to load an image from the path passed to it in fullname, else an error is generated and the system exits.

    If colorkey is not None, then the color passed will be made transparent. If colorkey = -1, then the RGB value in the top left-most pixel of the image will be set as the colorkey


def get_cond_and_subj_number(self, filename)
    get_cond_and_subj_number reads a text file, filename, that must contain at least 3 values:

    1) Condition current subject will be in (may start at any value from 0 - N (N = # of conditions)
    2) Number of conditions
    3) Current subject number (automatically updated)

    After reading the textfile, the condition number and subject number are automatically updated and written back into the file for subsequent runnings

    return [current condition, # of conditions, subject #]


def get_cond_and_subj_number_ftp(self, host, username, password, filename]
    Similar functionallity to get_cond_and_subj_number. get_cond_and_subj_number_ftp reads data from a remote ftp client in order to set up subject numbers and conditions.

    host - web address of file hosting site
    username - account name on the host site
    password - password for the account

    return [current condition, # of conditions, subject #]


def upload_data(self, host, username, password, filename, netfilename)
    Uploads data to a file storage site.

    host - web address of file hosting site
    username - account name on the host site
    password - password for the account
    filename - file to open and save
    netfilename - file to save to


def update_display(self, mysurf)
    Blits surface mysurf onto the default display screen created by the Experiment class. Then flips it.


def place_text_image(self, mysurf, prompt, size, xoff, yoff, txtcolor, bgcolor)
    Blits a Text object onto the surface passed.

    mysurf - Surface object on which to blit
    prompt - String to be displayed
    size - Text size
    xoff/yoff - Offset from the center of mysurf
    txtcolor - color of the test (RGB)
    bgcolor - color of the background (RGB)


def get_text_image(self, font, message, fontcolor, bg)
    Creates a Surface with anti-aliased text written.

    font - Font object
    message - string to be displayed
    fontcolor - color for text (RGB)
    bg - color for the background

    return Surface


def placing_rect(self, bkgd_surf, inner_surf, xoff, yoff)
    Creates a Rect from Surface inner_surf and centers it on Surface bkgd_surf.

    return Rect


def play_sound(self, sndname, pause)
    Plays a sound file for its length plus pause, in milliseconds. This function works with .wav files only. This pauses the pygame timer as well.

    sndname - String with the sound name (omit the .wav extension)
    pause - time in milliseconds to pause the pygame timer (added to the length of time of the sound file)


def show_centered_image(self, imagename, bgcolor, alpha=None)
    Centers an image in the screen with a given bgcolor (RGB) and alpha


def show_image(self, imagename, bgcolor, xoffset, yoffset, alpha=None)
    Creates Surface object with the dimensions of the display screen. Then blits an image to the center of the Surface plus any offseting x/y values.

    imagename - name of the image to be drawn (i.e. 'image1.jpg')
    bgcolor - color of the background Surface
    x/yoffset - offsets from the center of the Surface
    alpha - alpha value (0-255)

    return Surface


def show_centered_image_add(self, mysurf, imagename, bgcolor, alpha=None)
    Centers an image in the Surface passed with a given bgcolor (RGB) and alpha


def show_image_add(self, mysurf, imagename, xoffset, yoffset, alpha=None)
    Places an image onto a passed Surface with given offsets relative to the center of the Surface. Returns the drawn-on Surface.

    mysurf - Surface to be blitted to
    imagename - name of the image file loaded by load_image (or load_all_images)
    xoffset/offset - offsets relative to the center of the Surface
    alpha - alpha value of the image

    return Surface

    Note: This REQUIRES a Surface object to be passed, whereas show_image creates a Surface to be blitted on


def clear_screen(self, color)
    Creates a Surface with the dimensions of the display screen, fills it with given color, and returns the Surface.

    return Surface



def get_response_and_rt_pq(self, val)
    Monitors keyboard Events for the 'Q' and 'P' keys. Returns the time it took from the call to the function to the end of the function (reaction time; rt) and the response made (res).

    val - list or tuple with coded values, e.g. ['Left', 'Right'] or (0, 1)

    return [response, reaction time]



def get_response(self)
    Monitors keyboard Events. Converts lowercase input into uppercase based on ASCII codes. Pressing the left Shift and Tilde key (~/`) at the same time will call on_exit to exit the program. Functions with alphanumeric keys only.

    return String (key pressed)



def escapable_sleep(self, pause)
    Pauses the program for pause-number of milliseconds. Can be exited at any time by pressing the left Shift and Tilde key (~/`) at the same time


def output_trial(self, myline)
    Writes a line a of data to the file created by set_filename, with each value seperated by a space. myline can be a list or tuple.


def setup_gabor(self, grid_w, grid_h, windowsd)
    Sets up initial values for a gabor patch and its gaussian blur.

    grid_w = Width
    grid_h = Height
    windowsd = Standard deviation


def draw_gabor(self, freq, angle, scale)
    Draws the gabor patch set by setup_gabor

    freq - the frequency of the gabor patch
    angle - value to determine rotation on the patch
    scale - enlarges the gabor patch by a given factor

    * For faster blitting it is recommended to set the grid_w and grid_h in setup_gabor to be smaller than the actual patch desired. To offset this, use the scale value to blow up the image.

    ** Due to the nature of rotating a Surface, the size of the Surface of the gabor patch changes based on the value of the rotation angle. This function re-centers the patch after each rotation, but it should be noted as it will make the area of the Surface larger.

    return Surface



def bivariate_normpdf(self, x, y, sigma_x, sigma_y, mu_x, mu_y, mul)
    Formula used to set the gaussion blur

    x,y - current position in the grid
    sigma_x/y - variance in each plane of the grid
    mu_x/y - mean
    mul - scales by this amplitude factor

    return float



def on_exit(self)
    Clears all data that remains on queue and closes the datafile set in set_filename


Our work is supported by grants from


Copyright 2008-2013 - Todd Gureckis - New York University