def test_HSV_RGB(): HSV = numpy.array([ [0, 1, 1], [0, 1, 0.5], #reducing Value reduces intensity of primary gun [0, 0.5, 0.5], #reducing Saturation increases intensity of other guns [30, 1, 1], [60, 1, 1], [90, 1, 1], [120, 1, 1], [150, 1, 1], [180, 1, 1], [210, 1, 1], [240, 1, 1], [270, 1, 1], [300, 1, 1], [330, 1, 1], [360, 1, 1] ]) expectedRGB = numpy.array([[1., -1., -1.], [0., -1., -1.], [0., -0.5, -0.5], [1., 0., -1.], [1., 1., -1.], [0., 1., -1.], [-1., 1., -1.], [-1., 1., 0.], [-1., 1., 1.], [-1., 0., 1.], [-1., -1., 1.], [0., -1., 1.], [1., -1., 1.], [1., -1., 0.], [1., -1., -1.]]) RGB = misc.hsv2rgb(HSV) assert numpy.allclose(RGB, expectedRGB, 0.0001)
def test_HSV_RGB(): HSV=numpy.array([ [ 0, 1, 1], [ 0, 1, 0.5],#reducing Value reduces intensity of primary gun [ 0, 0.5, 0.5],#reducing Saturation increases intensity of other guns [ 30, 1, 1], [ 60, 1, 1], [ 90, 1, 1], [120, 1, 1], [150, 1, 1], [180, 1, 1], [210, 1, 1], [240, 1, 1], [270, 1, 1], [300, 1, 1], [330, 1, 1], [360, 1, 1]]) expectedRGB=numpy.array([ [ 1. , -1. , -1. ], [ 0., -1. , -1. ], [ 0., -0.5, -0.5], [ 1. , 0., -1. ], [ 1. , 1. , -1. ], [ 0., 1. , -1. ], [ -1. , 1. , -1. ], [ -1. , 1. , 0.], [ -1. , 1. , 1. ], [ -1. , 0., 1. ], [ -1. , -1. , 1. ], [ 0., -1. , 1. ], [ 1. , -1. , 1. ], [ 1. , -1. , 0.], [ 1. , -1. , -1. ]]) RGB = misc.hsv2rgb(HSV) assert numpy.allclose(RGB,expectedRGB,0.0001)
def createValue(size): """ Creates the value palette array in HSV and returns as RGB """ # Create array hsv = np.zeros([20, size, 3], dtype=float) # Set value hsv[:, :, 2] = np.linspace(0, 1, size, endpoint=False) # Convert to RGB rgb = misc.hsv2rgb(hsv) # Make in range 0:1 for image stim rgb[:][:][:] = (rgb[:][:][:] + 1) / 2 return rgb
def createPalette(size): """ Creates the color palette array in HSV and returns as RGB """ # Create array hsv = np.ones([size, size, 3], dtype=float) # Set hue hsv[:, :, 0] = np.linspace(0, 360, size, endpoint=False) # Set saturation for i in range(size): hsv[:, i, 1] = np.linspace(0, 1, size, endpoint=False) # Convert to RGB rgb = misc.hsv2rgb(hsv) # Make in range 0:1 for image stim rgb[:][:][:] = (rgb[:][:][:] + 1) / 2 return rgb
def MakeColorWheel(): global color_wheel, color_select, color_dir #Color wheel directions color_dir = visual.TextStim(win, height=0.7, wrapWidth=28, color='black', pos=(-1, 8), text=''' Use the mouse to select the color of the screen at the end of the interval. ''') #Create array of colors in hsv hsv = numpy.ones([256, 256, 3], dtype=float) hsv[:, :, 0] = numpy.linspace(0, 360, 256, endpoint=False) hsv[:, :, 1] = 1 hsv[:, :, 2] = 1 #Create color wheel color_wheel = visual.RadialStim(win, tex=misc.hsv2rgb(hsv), angularCycles=1, interpolate=True, texRes=360, size=(10, 10), pos=(-8, 0)) #Create color selection box color_select = visual.Rect(win, width=10, height=10, pos=(5, 0), lineColor='black', fillColor='white')
SAVE_PATH = os.path.join(HOME_PATH, 'Desktop', 'experiment_data', EXP_NAME) # Path to save experiment results IMAGE_PATH = os.path.join( EXP_PATH, 'images') # Path to store any required experiment images # Note that these RGB values are converted from (0 and 255) to (-1 and 1) BG_color = [0, 0, 0] # Set a background color, currently grey FIX_color = [-1, -1, -1] # Set the fixation color, currently black TEXT_color = [-1, -1, -1] # The text color, currently white textureRes = 64 n_circ = 360 hsv = np.ones([n_circ, 1, 3], dtype=float) hsv[:, :, 0] = np.linspace(0, 360, n_circ, endpoint=False)[:, np.newaxis] rgb = misc.hsv2rgb(hsv) TRIAL_colorS = [ [-1, -1, -1], # Black [-1, -1, 1], # Blue [-1, 1, -1], # Green [-1, 1, 1], # Cyan [1, -1, -1], # Red [1, -1, 1], # Purple [1, 1, -1], # Yellow [1, 0.296, -1] ] # Orange NUM_TYPE = 3 # Number of different trial types NUM_REPS = 50 # Number of repetitions for each different trial type # Note that all sizing is in visual degrees
def __init__(self,expt_design,gui_specs): #basic specs self.subj_name = gui_specs['subj_name'] self.debug = gui_specs['debug'] self.env = gui_specs['env'] self.project_dir = gui_specs['project_dir'] #screen window self.scrcolor = (0,0,0) self.scrunits = 'deg' if self.debug: self.scrfull = False self.scrw = 1200 self.scrh = 1200 else: self.scrfull = True self.scrw = 1440 self.scrh = 900 self.win = visual.Window(size = (self.scrw,self.scrh),monitor=self.env,fullscr = self.scrfull, color=self.scrcolor, units=self.scrunits) #main #fixation dot parameters self.fixrad = .1 self.fixcolor = -1. self.fixlinecolor = 0 self.fix = visual.Circle(self.win,radius=self.fixrad, fillColor=self.fixcolor,lineColor=self.fixlinecolor) # self.circrad = expt_design.positions_rad self.circoffset = .25 self.circlinecolor = None self.circinterp = True self.circedges = 256. self.colors_ind = expt_design.colors_ind self.ncolors = expt_design.ncolors self.colors_rgb = expt_design.colors_rgb #stimulus parameters of squares self.square_size = 1.5 self.square = visual.Rect(self.win, width = self.square_size, height = self.square_size, lineColor=None, fillColor = [1,1,1], fillColorSpace='rgb') self.square_pos = {} for i in range(6): self.square_pos[i] = visual.Rect(self.win, width = self.square_size, height = self.square_size, pos = (expt_design.positions_x[i],expt_design.positions_y[i]), lineColor=[-1,-1,-1], lineWidth=2, fillColor = None, fillColorSpace='rgb') self.wholereportpos = [[-.5,.5],[0,.5],[.5,.5],[-.5,0],[0,0],[.5,0],[-.5,-.5],[0,-.5],[.5,-.5]] self.wholereportsquare = {} for i in range(6): for j in range(9): self.wholereportsquare[i,j] = visual.Rect(self.win, width = self.square_size/3, height = self.square_size/3, pos = self.wholereportpos[i], lineColor=None, fillColor = self.colors_rgb[j], fillColorSpace='rgb') self.wholereportsquare[i,j].pos = (self.wholereportpos[int(j)][0] + expt_design.positions_x[i], self.wholereportpos[int(j)][1] + expt_design.positions_y[i]) self.circle = visual.Circle(self.win, radius = self.square_size/2, edges=32, lineColor=None, fillColor = [1,1,1], fillColorSpace='rgb') #other task parameters self.mouse = event.Mouse(visible=0,win=self.win) #mouse self.stimposrad = 4. #make the colorwheel self.colortextureRes = 512 self.colortexhsv = np.ones([self.colortextureRes,self.colortextureRes,3], dtype=float) self.colortexhsv[:,:,0] = np.linspace(0,self.colortextureRes,self.colortextureRes, endpoint=False) self.colortexhsv[:,:,1] = 1 self.colortexhsv[:,:,2] = 1 rgb = misc.hsv2rgb(self.colortexhsv) rgb = np.tile(expt_design.rgb_circlepts,(self.colortextureRes,1,1)) mask = np.zeros([100,1]) mask[-10:] = 1 # 10% of the radius is 1 (visible) self.colortexrgb = rgb self.colorcirc = visual.RadialStim(self.win, tex=rgb, mask = mask,size=(self.circrad+self.circoffset)*2,ori=0, angularRes=256, angularCycles=1, interpolate=True) #stimuli for drawing the path of the experiment self.start_circle = visual.ShapeStim(self.win,size=1.5,vertices=((-1,-.75),(-1,.75),(1,.75),(1,-.75)),pos=(-6,-6),lineWidth=2,lineColor='black',fillColor='white') self.start_text = visual.TextStim(self.win,text='Start',pos=(-6,-5.75),height=1,color=-1,fontFiles=[self.project_dir +'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.block_outter= visual.Circle(self.win, units = 'deg',radius = .5, pos = (-5,-7.75), lineColor=0,lineWidth=0,fillColor=-1) self.block_inner= visual.Circle(self.win, units = 'deg',radius = .4, pos = (-5,-7.75), lineColor=0,lineWidth=0,fillColor=0) star5vertices = [(-7,2.5),(-3.5,-2),(-5,-7),(-.5,-4.5),(5,-7),(3.5,-2),(7,2.5),(2,2),(-.5,7),(-2,2)] self.finish_star = visual.ShapeStim(self.win,size=.25,vertices=star5vertices,pos=(6,-5.5),lineWidth=2,lineColor='black',fillColor='white') self.finish_text = visual.TextStim(self.win,text='End',pos=(6,-5.75),height=1,color=-1,fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.prog_rect = visual.Rect(self.win, units = 'deg',width = 10, height = 5, pos = (0,0), lineColor=-1,lineWidth=5,fillColor=0) self.prog_bar = visual.Rect(self.win, units = 'deg',width = .1, height = 5, pos = (0,0), lineColor=-1,lineWidth=5,fillColor=-1) #text parameters self.text_welcome = visual.TextStim(self.win, text='Welcome to the magical technicolor shapes adventure!',alignHoriz='center',wrapWidth=20,height=1,pos=(0,7),color=(-1,-1,-.5),fontFiles=[self.project_dir + 'display/fonts/BowlbyOneSC-Regular.ttf'],font=['Bowlby One SC']) self.text_block_start = visual.TextStim(self.win, text='Block i of n',alignHoriz='center',wrapWidth=20,height=1,pos=(0,7),color=(-1,-1,-.5),fontFiles=[self.project_dir + 'display/fonts/BowlbyOneSC-Regular.ttf'],font=['Bowlby One SC']) self.text_instructions5 = visual.TextStim(self.win, text="Now, finally, let's put it all together. We will practice both tasks: Press d for circles, s for squares, and then use your mouse to click at each location",alignHoriz='center',wrapWidth=22,height=.75,pos=(0,7),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_instructions6 = visual.TextStim(self.win, text="If this is confusing, please ask the experimenter any questions that you may have!\n\nOr, press spacebar to start the experiment. Good luck!",alignHoriz='center',wrapWidth=22,height=.75,pos=(0,7),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_feedbackCorrect = visual.TextStim(self.win, text="Correct!",alignHoriz='center',wrapWidth=22,height=.75,pos=(0,1),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_feedbackIncorrect = visual.TextStim(self.win, text="Incorrect",alignHoriz='center',wrapWidth=22,height=.75,pos=(0,1),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_advance = visual.TextStim(self.win, text='Press spacebar to continue',alignHoriz='center',wrapWidth=20,height=.75,pos=(0,-8),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_end_expt = visual.TextStim(self.win, text='All done!\n\nPress spacebar to exit',alignHoriz='center',wrapWidth=20,height=1,pos=(0,3),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_either_key = visual.TextStim(self.win, text='Press either key (s or d) to continue',alignHoriz='center',wrapWidth=20,height=.75,pos=(0,-2.5),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_CDinstructions0 = visual.TextStim(self.win, text="In the last part, colorful blocks like this one will appear on the screen\n\nYour goal will be to remember the color of each block",alignHoriz='center',wrapWidth=22,height=.75,pos=(0,3),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_CDinstructions1 = visual.TextStim(self.win, text="Then, after some time, one block will reappear.\n\nSometimes it will be the same color",alignHoriz='center',wrapWidth=22,height=.75,pos=(0,3),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_CDinstructions2 = visual.TextStim(self.win, text="And sometimes it will reappear in a different color",alignHoriz='center',wrapWidth=22,height=.75,pos=(0,3),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_CDinstructions3 = visual.TextStim(self.win, text="So you'll need to hold in mind the original color of each block\n\nThen, if it reappears in the same color, press the key with a ?\nOr, if it reappears in a different color press the z key",alignHoriz='center',wrapWidth=22,height=.75,pos=(0,3),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_CDinstructions4 = visual.TextStim(self.win, text="Let's practice this now",alignHoriz='center',wrapWidth=22,height=.75,pos=(0,3),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_CDinstructions5 = visual.TextStim(self.win, text="Let's try another, but now 2 blocks will appear at the start\n\nThe computer will randomly test you on one of the blocks",alignHoriz='center',wrapWidth=22,height=.75,pos=(0,3),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_CDinstructions6 = visual.TextStim(self.win, text="In the real game, there will be 6 blocks all at once.\n\nIt may feel challenging, but please try your best!\n\nLet's practice this now",alignHoriz='center',wrapWidth=22,height=.75,pos=(0,3),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_CDinstructions7 = visual.TextStim(self.win, text="Press spacebar to start the main game. Good luck!",alignHoriz='center',wrapWidth=22,height=.75,pos=(0,3),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_CDinstructionsCorrect = visual.TextStim(self.win, text="Correct!",alignHoriz='center',wrapWidth=22,height=.75,pos=(0,3),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_CDinstructionsIncorrect = visual.TextStim(self.win, text="Incorrect\n\nRemember to hold in mind the color of the blocks, and then decide if the color is the same (?) or different (z).\n\nLet's try that again",alignHoriz='center',wrapWidth=22,height=.75,pos=(0,3),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_same = visual.TextStim(self.win, text=u'Press ? if same',alignHoriz='center',wrapWidth=22,height=.75,pos=(4,-6),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato']) self.text_diff = visual.TextStim(self.win, text=u'Press z if different',alignHoriz='center',wrapWidth=22,height=.75,pos=(-4,-6),color=(-1,-1,-1),fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'],font=['Lato'])
def __init__(self, expt_design, gui_specs): #basic specs self.subj_name = gui_specs['subj_name'] self.debug = gui_specs['debug'] self.env = gui_specs['env'] self.project_dir = gui_specs['project_dir'] #screen window self.scrcolor = (0, 0, 0) self.scrunits = 'deg' if self.debug: self.scrfull = False self.scrw = 1200 self.scrh = 1200 else: self.scrfull = True self.scrw = 1440 self.scrh = 900 self.win = visual.Window(size=(self.scrw, self.scrh), monitor=self.env, fullscr=self.scrfull, color=self.scrcolor, units=self.scrunits) #main self.mon = monitors.Monitor(self.env) #fixation dot parameters self.fixrad = .1 self.fixcolor = -1. self.fixlinecolor = 0 self.fix = visual.Circle(self.win, radius=self.fixrad, fillColor=self.fixcolor, lineColor=self.fixlinecolor) #stimuli appear at fixed eccentricity along a circle self.circrad = expt_design.positions_rad self.circoffset = .25 self.circedges = 256. #stimulus parameters of squares self.square_size = 1.5 self.square = visual.Rect(self.win, width=self.square_size, height=self.square_size, lineColor=None, fillColor=[1, 1, 1], fillColorSpace='rgb') self.circle = visual.Circle(self.win, radius=self.square_size / 2, edges=self.circedges, lineColor=None, fillColor=[1, 1, 1], fillColorSpace='rgb') #other task parameters self.mouse = event.Mouse(visible=0, win=self.win) #mouse #make the colorwheel self.colortextureRes = 512 self.colortexhsv = np.ones( [self.colortextureRes, self.colortextureRes, 3], dtype=float) self.colortexhsv[:, :, 0] = np.linspace(0, self.colortextureRes, self.colortextureRes, endpoint=False) self.colortexhsv[:, :, 1] = 1 self.colortexhsv[:, :, 2] = 1 rgb = misc.hsv2rgb(self.colortexhsv) rgb = np.tile(expt_design.rgb_circlepts, (self.colortextureRes, 1, 1)) mask = np.zeros([100, 1]) mask[-10:] = 1 # 10% of the radius is 1 (visible) self.colortexrgb = rgb self.colorcirc = visual.RadialStim( self.win, tex=rgb, mask=mask, size=(self.circrad + self.circoffset) * 2, ori=0, angularRes=256, angularCycles=1, interpolate=True) #stimuli for drawing the path of the experiment self.start_circle = visual.ShapeStim(self.win, size=1.5, vertices=((-1, -.75), (-1, .75), (1, .75), (1, -.75)), pos=(-6, -6), lineWidth=2, lineColor='black', fillColor='white') self.start_text = visual.TextStim( self.win, text='Start', pos=(-6, -5.75), height=1, color=-1, fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'], font=['Lato']) self.block_outter = visual.Circle(self.win, units='deg', radius=.5, pos=(-5, -7.75), lineColor=0, lineWidth=0, fillColor=-1) self.block_inner = visual.Circle(self.win, units='deg', radius=.4, pos=(-5, -7.75), lineColor=0, lineWidth=0, fillColor=0) star5vertices = [(-7, 2.5), (-3.5, -2), (-5, -7), (-.5, -4.5), (5, -7), (3.5, -2), (7, 2.5), (2, 2), (-.5, 7), (-2, 2)] self.finish_star = visual.ShapeStim(self.win, size=.25, vertices=star5vertices, pos=(6, -5.5), lineWidth=2, lineColor='black', fillColor='white') self.finish_text = visual.TextStim( self.win, text='End', pos=(6, -5.75), height=1, color=-1, fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'], font=['Lato']) self.prog_rect = visual.Rect(self.win, units='deg', width=10, height=5, pos=(0, 0), lineColor=-1, lineWidth=5, fillColor=0) self.prog_bar = visual.Rect(self.win, units='deg', width=.1, height=5, pos=(0, 0), lineColor=-1, lineWidth=5, fillColor=-1) #text parameters self.text_welcome = visual.TextStim( self.win, text='Welcome to the magical technicolor shapes adventure!', alignHoriz='center', wrapWidth=20, height=1, pos=(0, 7), color=(-1, -1, -.5), fontFiles=[ self.project_dir + 'display/fonts/BowlbyOneSC-Regular.ttf' ], font=['Bowlby One SC']) self.text_block_start = visual.TextStim( self.win, text='Block i of n', alignHoriz='center', wrapWidth=20, height=1, pos=(0, 7), color=(-1, -1, -.5), fontFiles=[ self.project_dir + 'display/fonts/BowlbyOneSC-Regular.ttf' ], font=['Bowlby One SC']) self.text_advance = visual.TextStim( self.win, text='Press spacebar to continue', alignHoriz='center', wrapWidth=20, height=.75, pos=(0, -8), color=(-1, -1, -1), fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'], font=['Lato']) self.text_end_expt = visual.TextStim( self.win, text='All done!\n\nPress spacebar to exit', alignHoriz='center', wrapWidth=20, height=1, pos=(0, 3), color=(-1, -1, -1), fontFiles=[self.project_dir + 'display/fonts/Lato-Reg.ttf'], font=['Lato'])