reiz.visual

Creating and managing visual stimuli

During import, a basic library will be created. By default, it contains the following set of visual stimuli: post, pre, eo, ec, ready, los, go, imagine, move, count, relax, rating, fixation, logo. These stimuli can be addressed by dot.notation from reiz.visual.library, for example like reiz.visual.library.go

Create complex shapes and murals

class Mural(text='Hello World', font='Times New Roman', fontsize=1, position=(0, 0), color=(1, 1, 1), anchor_x='center', anchor_y='center')[source]

A text on the screen

Parameters
  • text (str) – the text to show

  • font (str) – the font-type (needs to be installed on the system)

  • fontsize (float) – the normalized size of the letters

  • position (XY) – where on the screen the text should be located. Coordinates mark the center of the text

  • color (ColorType) – the desired color

class Image(imgpath, position=(0, 0), scale=0.5)[source]

Show an image loaded from a file

Parameters
  • imgpath (str) – path to the imagefile

  • position (XY) – x-y-coordinate of the center of the image

  • scale (float) – size of the figure relative to the screen size

class Cross(zoom=1, color='white')[source]

A fixation cross in the center of the screen

Parameters
  • zoom (float) – size of the cross

  • color (ColorType) – the desired color

class Circle(zoom=1, color='red', position=(0, 0), opacity=1, stroke=0)[source]

A circle, i.e. the outline of a ball

Parameters
  • zoom (float) – size of the circle

  • color (ColorType) – the desired color

  • position (XY) – position of the center of the circle

  • opacity (float) – how opaque the circle is supposed to be from 0 to 1

  • stroke (float) – thickness of the outline

class Background(color='white')[source]

Fills the whole screen with a single color

Parameters

color (str) – the color to fill the screen. see also reiz.visual.colors.COLORS

class Line(a=(0, 0), b=(0, 0), color='white', linewidth=1)[source]

A line from a to b

Parameters
  • a (XY) – x-y coordinates of the start point

  • b (XY) – x-y coordinates of the end point

  • color (ColorType) – the desired color

  • linewidth (float) –

class Bar(height=0.5, width=0.25, color='white')[source]

A rectangle starting from the bottom centre of the screen

Parameters
  • height (float) – height in normalized units from 0 to 1 (bottom to top of screen)

  • width (float) – width in normalized units from 0 to 1 (nothing to whole screen)

  • color (ColorType) – the desired color

class Polygon(positions=[(0, 0), (0.1, 0.2), (0.3, 0.1)], color='white')[source]

An arbitrary shape defined by the coordinates of its nodes

Parameters
  • positions (List[XY, ]) – a list of x-y-coordinates of each node

  • color (ColorType) – the desired color

class Trapezoid(xpos=(-0.33, -0.25, 0.25, 0.33), ypos=(-0.25, 0.25), color='white')[source]

A trapezoid spanned between four nodes

Parameters
  • xpos (Tuple[float, float, float, float]) – a tuple of x coordinates of the nodes

  • ypos (Tuple[float, float]) – a tuple of y coordinates of the nodes the first entry is the ypos of the first two xpos

  • color (ColorType) – the desired color

class Cylinder(position=(0, 0), angle=0, thickness=0.05, length=0.75, color='brown')[source]

A rectangular shape which can be rotated around its center

Parameters
  • position (XY) – position of the center of the circle

  • angle (float) – rotation angle around its center

  • thickness (float) – width of the cylinder

  • length (float) – length of the cylinder

  • color (ColorType) – the desired color

Library of colors

COLORS = {'black': [0, 0, 0], 'blue': [0, 0, 1], 'bright': [0.75, 0.75, 0.75], 'brown': [0.55, 0.36, 0.24], 'carmine': [0.59, 0.0, 0.09], 'celeste': (0.69, 1, 1), 'crimson': (0.87, 0.08, 0.24), 'dark': [0.125, 0.125, 0.125], 'darkbrown': [0.44, 0.29, 0.2], 'darker': [0.1, 0.1, 0.1], 'darkgreen': (0.0, 0.39, 0.0), 'darkturkis': (0.0, 0.8, 0.82), 'gray': [0.25, 0.25, 0.25], 'green': [0.25, 0.8, 0.25], 'light': [0.5, 0.5, 0.5], 'moss': (0.54, 0.6, 0.36), 'pictorial_carmine': (0.76, 0.04, 0.31), 'pink': [0.9, 0.5, 0.9], 'red': [0.9, 0.1, 0.1], 'turkis': (0.28, 0.82, 0.8), 'white': [1, 1, 1]}

A dictionary of color strings encoding a tuple in RGB

get_color(color='white', opacity=1)[source]

get rgba tuple based on color name

Parameters
  • color (ColorType, i.e. Union[Tuple[float, float, float], str]) – a color name or a tuple of colors, as from reiz.visual.colors.COLORS

  • opacity (float) – the alpha value

Returns

color – a rgba tuple with values between 0 and 1

Return type

RGBA i.e Tuple[float, float, float, float]

Create libraries of visual stimuli

libConf(x)

Dict[str, Dict[str, Any], a dictionary of types and respective keywords arguments

library = namespace(post='Mural', pre='Mural', eo='Mural', ec='Mural', ready='Mural', los='Mural', go='Mural', imagine='Mural', move='Mural', count='Mural', relax='Mural', rating='Mural', fixation='Cross', logo='Image')

a library of visual stimuli

make_library(settings=None, failraise=False)[source]

create a library of visual stimuli from a dictionary of arguments

Parameters
  • settings (Optional[NewType()(libConf, Dict[str, Dict[str, Any]])]) – a dictionary of types with kwargs appropriate to the respective type as dictionary

  • failraise (bool) – raise an exception if a key is not recognized. defaults to False

Returns

a library of instances of stimuli which can be adressed in dot.notation

Return type

library

read_folder(folder=None)[source]

“read image files in a the specified folder into a library

Parameters

folder (str) – the path to the folder with the images

The function selects all files ending in .png and .jpg. It collects them into a SimpleNamespace, so you can use dot notation to select the images. These fields are named based on the filename. Some basic sanitization is performed, but is nonetheless best if the files already have names which could be called safely from python. For example, files should be named ‘image_file.png’ instead of ‘image-file.png’.

Return type

SimpleNamespace