标签:
图片:16张
呈现时间:2种,2秒和0.2秒
处理类型:2种,处理前和处理后
8个量表项目的评分(1~7)
图片和量表项目为完全被试内设计。由于每张图片不可以被被试看两次,因此,呈现时间和处理类型为不完全被试内设计
下面表格展示了被试可能碰到的4种情况的图片序列。
图片编号 | 1~4 | 5~8 | 9~12 | 13~16 |
S1 | 处理过,0.2s | 未处理,2s | 处理过,2s | 未处理,0.2s |
S2 | 未处理,2s | 处理过,2s | 未处理,0.2s | 处理过,0.2s |
S3 | 处理过,2s | 未处理,0.2s | 处理过,0.2s | 未处理,2s |
S4 | 未处理,0.2s | 处理过,0.2s | 未处理,2s | 处理过,2s |
被试ID、参加实验组别(1~4)、实验序号、呈现图片、是否处理、呈现时间、项目评分
根据实验选取的组别,把图片与呈现时间、是否处理进行绑定,生成Stim实例,然后打乱示例顺序,分别呈现,最后储存数据。
# -*- coding: utf-8 -*- """ Created on Sun Apr 19 16:50:21 2015 @author: zbg """ from psychopy.visual import Window, ImageStim, TextStim from psychopy import core, event, gui import random #================在这里设置各种基本参数================== picNames=[‘1.png‘, ‘2.png‘, ‘3.png‘, ‘4.png‘, ‘5.png‘, ‘6.png‘, ‘7.png‘, ‘8.png‘, ‘9.png‘, ‘10.png‘, ‘11.png‘, ‘12.png‘, ‘13.png‘, ‘14.png‘, ‘15.png‘, ‘16.png‘] processTypes = [‘initial\\‘, ‘processed\\‘] times = [0.2, 2] scales = [ (‘Meaningful1‘, u"我能理解这幅画的意义"), (‘Meaningful2‘, u"我能理解这幅画的主题"), (‘Unity‘, u"这幅画的构图是和谐统一的"), (‘Complexity‘, u"这幅画的构图是复杂的"), (‘Variety‘, u"这幅画构图是多样的"), (‘Liking‘, u"我喜欢这幅画"), (‘Pleasing‘, u"这幅画使我感到愉悦"), (‘Interesting‘, u"这幅画能引起我的兴趣。"), ] timeCursor = 0.25 #====================其他生成变量 stims = [] results = [] ‘‘‘ results = [(stim, result), ...] result = {label: 2; ...} ‘‘‘ trailOrder = range(16) random.shuffle(trailOrder) #================绑定相关 if len(picNames) != 16: raise ‘error‘ bindTypes = [] for i in range(4): bindTypes.append([processTypes[i%2], times[i/2]]) class Stim: def __init__(self, name, bindType): global bindTypes self.process = bindTypes[bindType][0] self.time = bindTypes[bindType][1] self.name = name def __repr__(self): return self.process + ‘\t‘ + self.name + ‘\t‘ + str(self.time) + ‘\n‘ #=================程序使用的各种函数=================== def GetSubject(): myDlg = gui.Dlg(title="Subject Information") myDlg.addText("-------------Subject-----------") myDlg.addField(‘ID:‘) myDlg.addField(‘Type:‘, choices=[1, 2, 3, 4]) myDlg.show() if myDlg.OK: thisInfo = myDlg.data else: exit(0) subject={} subject[‘ID‘]=thisInfo[0] subject[‘Type‘]=thisInfo[1] return subject def PicBind(t): global stims, picNames for i in range(4): for j in range(4): index = i * 4 + j stim = Stim(picNames[index], (t + i - 1) % 4) stims.append(stim) def ShowIntro(win): introduce =u""" 啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦 按[空格键]继续 """ t =TextStim(win, introduce ,pos=(0,-0.0)) t.draw() win.flip() keys=[] while ‘space‘ not in keys: keys=event.getKeys() def ShowStim(win, stim): global timeCursor t =TextStim(win, ‘+‘ ,pos=(0,-0.0)) t.draw() win.flip() core.wait(timeCursor) image = ImageStim(win, stim.process + stim.name) image.draw() win.flip() core.wait(stim.time) def ShowScale(text): def GetMyKey(): keys=[] while True: while len(keys) == 0: core.wait(0.1) keys=event.getKeys() if keys[0] in [‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘, ‘7‘]: return keys[0] if ‘m‘ in keys: exit(0) keys = [] t =TextStim(win, text ,pos=(0,-0.0)) t.draw() t =TextStim(win, u‘1不同意------------------------------7非常同意‘,pos=(0,-0.2)) t.draw() win.flip() key = GetMyKey() t =TextStim(win, u‘你按下了‘ + key,pos=(0,-0.2),color = (0 ,1.,0)) t.draw() win.flip() core.wait(0.1) return key #=================程序开始的地方======================== sub = GetSubject() PicBind(int(sub[‘Type‘])) win = Window() ShowIntro(win) for trail in trailOrder: #呈现图画 stim = stims[trail] ShowStim(win, stim) #收集量表数据 event.getKeys() #清空键盘缓存3 result = {} for label, text in scales: key = ShowScale(text) result[label] = key #把图画属性和量表数据存起来 results.append((stim, result)) win.close() #把数据保存进文件里 fp = open(sub[‘ID‘] + ‘.txt‘,‘w‘) fp.write("ID\tType\tnum\tpic\tprocess\ttime") for label, text in scales: fp.write("\t" + label) fp.write(‘\n‘) i = 1 for stim, result in results: fp.write(sub[‘ID‘] + ‘\t‘ + sub[‘Type‘] + ‘\t‘ + str(i)) i = i + 1 fp.write(‘\t‘ + stim.name) fp.write(‘\t‘ + stim.process) fp.write(‘\t‘ + str(stim.time)) for label, text in scales: fp.write(‘\t‘ + result[label]) fp.write(‘\n‘) fp.close()
完整程序下载(包括图片等文件):http://download.csdn.net/detail/zhanghao9547/8618453
标签:
原文地址:http://my.oschina.net/u/1387924/blog/404787