def test_sanitization(rmarker, capsys): assert rmarker out, err = capsys.readouterr() reiz.marker.push("ä ö ü") out, err = capsys.readouterr() assert "Sending ae_oe_ue " in out out, err = capsys.readouterr() reiz.marker.push("ping") out, err = capsys.readouterr() assert 'Sending {"msg": "ping"}' in out out, err = capsys.readouterr() reiz.marker.push("poison-pill") out, err = capsys.readouterr() assert 'Sending {"msg": "poison-pill"}' in out c = reiz.Canvas((10, 10)) reiz.audio.library.beep.volume = 0 cue = reiz.Cue( canvas=c, audiostim=reiz.audio.library.beep, visualstim=reiz.visual.library.go, markerstr="test", ) out, err = capsys.readouterr() cue.show() out, err = capsys.readouterr() assert "Sending test at" in out
def test_canvas_keypress(): canvas = reiz.Canvas() canvas.open() assert canvas.start_run == False canvas.window.dispatch_event("on_key_press", key.F5, 0) canvas.flip() assert canvas.start_run == True canvas.window.dispatch_event("on_key_press", key.P, 0) canvas.flip() assert canvas.paused == True canvas.window.dispatch_event("on_key_press", key.P, 0) canvas.flip() assert canvas.paused == False canvas.window.dispatch_event("on_key_press", key.ESCAPE, 0) canvas.flip() assert canvas.available == False
def test_canvas_properties(capsys): w, h = (1, 1) canvas = reiz.Canvas(size=(w, h)) canvas.open() canvas.clear() canvas.get_diag() canvas.estimate_fps() canvas.set_fullscreen() assert h < canvas.height assert w < canvas.width canvas.set_windowed() assert h == canvas.height assert w == canvas.width canvas.close() canvas.show(reiz.visual.library.fixation) out, err = capsys.readouterr() assert "Window was closed" in out canvas.open()
def test_canvas_available(capsys): canvas = reiz.Canvas(size=(5, 5)) assert canvas.available == False canvas.open() assert canvas.available == True canvas.close() assert canvas.available == False canvas.open() assert canvas.available == True canvas.close() canvas.flip() out, err = capsys.readouterr() assert "Window was closed" in out canvas.open() del canvas.window canvas.flip() out, err = capsys.readouterr() assert "Window was closed" in out
def start(trials=5): canvas = reiz.Canvas() canvas.open() bg = Background(color='red') def countdown(canvas, sek): for i in range(0, sek): cue = reiz.Cue(canvas, visualstim=[ bg, Mural(text=str(sek - i), color=(0.18, 0.18, 0.18)) ]) cue.show(duration=1) pre = reiz.Cue(canvas, visualstim=[bg, reiz.visual.library.pre]) post = reiz.Cue(canvas, visualstim=[bg, reiz.visual.library.post]) f5 = reiz.Cue(canvas, visualstim=[bg, reiz.visual.Mural('Press F5 to start')]) open_eyes = Message('Open eyes') close_eyes = Message('Close eyes') augen_auf = reiz.Cue(canvas, audiostim=reiz.audio.library.beep, visualstim=[bg, reiz.visual.library.fixation], markerstr='augen_auf') augen_zu = reiz.Cue(canvas, audiostim=reiz.audio.library.beep, visualstim=[bg, reiz.visual.library.fixation], markerstr='augen_zu') while not canvas.start_run: f5.show(duration=1) pre.show(duration=3) for trl_num in range(trials): augen_auf.show(duration=30) augen_zu.show(duration=30) post.show(duration=3) canvas.close()
def bmi_main(): import numpy as np import matplotlib.pyplot as plt import time, reiz, liesl from reiz.visual import Mural, Background canvas = reiz.Canvas() canvas.open() def countdown(canvas, sek): for i in range(0, sek): cue = reiz.Cue(canvas, visualstim=[ bg, Mural(text=str(sek - i), color=(0.18, 0.18, 0.18)) ]) cue.show(duration=1) def part2(cuetype, image_lib): if "Nothing" in cuetype: DispImage = image_lib.Nothing elif "Imagine" in cuetype: DispImage = image_lib.Imagine elif "Open" in cuetype: DispImage = image_lib.Open elif "Close" in cuetype: DispImage = image_lib.Close return DispImage bg = Background(color='gray') states = ("Nothing", "Imagine", "Open", "Close") image_lib = reiz.visual.read_folder( r'C:\Users\Messung\Desktop\study-phase-triggered-TMS\phase_triggered_tms\pre_post' ) nBlocks = 3 tiles = np.tile(states, (4)) block_tiles = np.tile(states, (nBlocks, 4)) for i in range(nBlocks): block_tiles[i, :] = np.random.permutation(tiles) canvas.start_run = False start_protocol = reiz.Cue(canvas, visualstim=[ bg, Mural(text='Press F5 to start BMI', color=(0.18, 0.18, 0.18)) ]) while not canvas.start_run: start_protocol.show(duration=0.1) countdown(canvas, 3) reiz.Cue(canvas, visualstim=[ bg, reiz.visual.Mural("BMI Task:", position=[0, 0.5], fontsize=1.5, color=(0.18, 0.18, 0.18)), reiz.visual.Mural("Bitte folgen Sie den Anweisungen", position=[0, -0.25], fontsize=1, color=(0.18, 0.18, 0.18)) ]).show(duration=5) reiz.Cue(canvas, visualstim=[ bg, reiz.visual.Mural("Bilder werden angezeigt.", position=[0, 0.4], fontsize=1, color=(0.18, 0.18, 0.18)), reiz.visual.Mural("Bitte 3 Sekunden lang durchführen", position=[0, -0.4], fontsize=1, color=(0.18, 0.18, 0.18)) ]).show(5) reiz.Cue(canvas, visualstim=[ bg, image_lib.Open, reiz.visual.Mural("Öffnen Ihre rechte Hand", position=[0, 0.7], fontsize=1, color=(0.18, 0.18, 0.18)) ]).show(5) reiz.Cue(canvas, visualstim=[ bg, image_lib.Close, reiz.visual.Mural("Schließe Ihre rechte Hand", position=[0, 0.7], fontsize=1, color=(0.18, 0.18, 0.18)) ]).show(5) reiz.Cue(canvas, visualstim=[ bg, image_lib.Imagine, reiz.visual.Mural( "Stellen sich vor Ihre rechte Hand zu öffnen", position=[0, 0.7], fontsize=0.7, color=(0.18, 0.18, 0.18)) ]).show(5) reiz.Cue(canvas, visualstim=[ bg, image_lib.Nothing, reiz.visual.Mural("Mach nichts", position=[0, 0.7], fontsize=1, color=(0.18, 0.18, 0.18)) ]).show(10) reiz.marker.push('bmi_start') for k in range(nBlocks): canvas.start_run = False start_protocol = reiz.Cue(canvas, visualstim=[ bg, Mural(text="Press F5 to start block " + str(k + 1), color=(0.18, 0.18, 0.18)) ]) while not canvas.start_run: start_protocol.show(duration=0.1) countdown(canvas, 3) for cue in range(np.size(block_tiles, 1)): reiz.marker.push("prepare_" + str(k) + '_' + str(cue)) reiz.Cue(canvas, visualstim=[ bg, reiz.visual.Mural("Bereitmachen", position=[0, 0.4], fontsize=1, color=(0.18, 0.18, 0.18)) ]).show(3) reiz.marker.push( str(block_tiles[k, cue]) + '_' + str(k) + '_' + str(cue)) reiz.Cue(canvas, visualstim=[bg, part2(block_tiles[k, cue], image_lib)]).show(3) reiz.marker.push("relax_" + str(k) + '_' + str(cue)) reiz.Cue(canvas, visualstim=[ bg, reiz.visual.Mural("Entspannen", position=[0, -0.4], fontsize=1, color=(0.18, 0.18, 0.18)) ]).show(5) reiz.marker.push('bmi_end') canvas.close()
def canvas(): c = reiz.Canvas((5, 5), (10, 10)) c.open() yield c c.close()
import reiz # start the MarkerServer which distributes markerstrings over LSL reiz.marker.start() # create a window canvas = reiz.Canvas() # initialize a clock for timing control clock = reiz.Clock() # initialize Cues # each Cue reveices information about # the Window where it will be shown -> canvas # auditory and visual stimuli, e.g. a tone (Hertz) or text (Mural) # and a markerstring to be send via LSL when .show() is called hello = reiz.Cue(canvas, audiostim=reiz.audio.Hertz(frequency=400, duration_in_ms=1000), visualstim=reiz.visual.Mural('Hello World!'), markerstr='hello') # there is also a library of typical auditory and visual stimuli and # we can for example, take the visual "los" and the auditory "beep" stimuli # for convenience, we use the text of the go stimulus as marker message los = reiz.Cue(canvas, audiostim=reiz.audio.library.beep, visualstim=reiz.visual.library.go, markerstr=reiz.visual.library.go.text) # here we show a fixation cross but don't want to play an auditory stimulus. # we can therefore either set it to None or just leave it out (defaults to None)