示例#1
0
def main():
    wdth = 1024
    hght = 768
    flds = ['Intensity','Luminance']
    args = prsr.parse_args()
    flnm = 'results/' + args.flnm

    hrl = HRL(wdth,hght,0,coords=(0,1,0,1),flipcoords=False,dpx=True,ocal=True,rfl=flnm,rhds=flds,fs=True)
    # Initializations

    ptch = hrl.newTexture(np.array([[args.lm]]))
    pwdth,phght = wdth*args.sz,hght*args.sz
    ppos = ((wdth - pwdth)/2,(hght - phght)/2)

    if args.rnd: rnd = round
    else: rnd = lambda x: x

    nitss = int(args.tmprs/args.bfrq)
    itss = [ args.bamp * rnd((1 + np.sin(2*np.pi*x)) / 2) + ((1-args.bamp)/2)
            for x in np.linspace(0,1,nitss) ]
    tsts = [ n % (nitss / args.sfrq) == 0 for n in range(nitss) ]
    cycl = zip(itss,tsts)
    slptm = int(1000.0 / args.tmprs)

    def opticalRead(its):
        print 'Current Intensity:', its
        lm = hrl.readLuminance(1,0)
        hrl.rmtx['Intensity'] = its
        hrl.rmtx['Luminance'] = lm
        hrl.writeResultLine()

    for (its,tst) in cycl * args.ncyc:

        hrl.changeBackground(its)
        ptch.draw(ppos,(pwdth,phght))
        hrl.flip()

        pg.time.wait(slptm)

        if tst:
            prcs = Process(target=opticalRead,args=(its,))
            prcs.start()

        if hrl.checkEscape(): break

    # Experiment is over!
    hrl.close
示例#2
0
文件: shiftsin.py 项目: TUBvision/hrl
def main():
    wdth = 1024
    hght = 768
    args = prsr.parse_args()

    # Initializations

    hrl = HRL(wdth,hght,0,dpx=True,ocal=True,fs=True)
    hrl = HRL(wdth,hght,0,coords=(0,1,0,1),flipcoords=False,dpx=True,ocal=True,fs=True)

    pwdth,phght = int(wdth*args.sz),int(hght*args.sz)
    ppos = ((wdth - pwdth)/2,(hght - phght)/2)

    wv1 = np.array([ [round((np.sin(x*np.pi*2) + 1)/2)] for x in
                       np.linspace(0,args.scyc,phght) ])

    wv2 = np.array([ [round((np.sin(x*np.pi*2 + np.pi) + 1)/2)] for x in
                       np.linspace(0,args.scyc,phght) ])

    ptch1 = hrl.newTexture(wv1)
    ptch2 = hrl.newTexture(wv2)

    slptm = int(1000.0 / args.tfrq)

    for i in range(args.ncyc):

        ptch1.draw(ppos,(pwdth,phght))
        hrl.flip()

        pg.time.wait(slptm)

        ptch2.draw(ppos,(pwdth,phght))
        hrl.flip()

        pg.time.wait(slptm)

        if hrl.checkEscape(): break

# Experiment is over!
    hrl.close()
示例#3
0
def main():

    # Parse args
    args = prsr.parse_args()

    # HRL parameters
    wdth = 1024
    hght = 768

    # Section the screen - used by Core Loop
    wqtr = wdth/4.0
    
    # IO Stuff
    dpxBool = False
    dfl = 'design.csv'
    rfl = 'results/' + args.sbj + '.csv'
    flds = ['TrialTime','SelectedLuminance']
    btns = ['Yellow','Red','Blue','Green','White']

    # Central Coordinates (the origin of the graphics buffers is at the centre of the
    # screen. Change this if you don't want a central coordinate system. If you delete
    # this part the default will be a matrix style coordinate system.
    coords = (-0.5,0.5,-0.5,0.5)
    flipcoords = False

    # Pass this to HRL if we want to use gamma correction.
    lut = 'LUT.txt'
    # If fs is true, we must provide a way to exit with e.g. checkEscape().
    fs = False

    # Step sizes for luminance changes
    smlstp = 0.01
    bgstp = 0.1

    # HRL Init
    hrl = HRL(wdth,hght,dpx=dpxBool,dfl=dfl,rfl=rfl,rhds=flds
              ,btns=btns,fs=fs,coords=coords,flipcoords=flipcoords)

    # Core Loop
    for dsgn in hrl.dmtx:

        # Load Trial
        mnl = float(dsgn['MinLuminance'])
        mxl = float(dsgn['MaxLuminance'])
        rds = float(dsgn['Radius'])

        # Create Patches
        mnptch = hrl.newTexture(np.array([[mnl]]),'circle')
        mxptch = hrl.newTexture(np.array([[mxl]]),'circle')
        cntrllm = uniform(0.0,1.0)
        cntrlptch = hrl.newTexture(np.array([[cntrllm]]),'circle')

        # Draw Patches
        mnptch.draw((-wqtr,0),(2*rds,2*rds))
        mxptch.draw((wqtr,0),(2*rds,2*rds))
        cntrlptch.draw((0,0),(2*rds,2*rds))
        # Draw but don't clear the back buffer
        hrl.flip(clr=False)

        # Prepare Core Loop logic
        btn = None
        t = 0.0
        escp = False

        # Adjust central patch
        while ((btn != 'White') & (escp != True)):
            
            (btn,t1) = hrl.readButton()
            t += t1

            if btn == 'Yellow':
                cntrllm += smlstp
            elif btn == 'Red':
                cntrllm += bgstp
            elif btn == 'Blue':
                cntrllm -= smlstp
            elif btn == 'Green':
                cntrllm -= bgstp

            # Bound Checking
            if cntrllm > 1: cntrllm = 1
            if cntrllm < 0: cntrllm = 0

            # Update display
            cntrlptch = hrl.newTexture(np.array([[cntrllm]]),'circle')
            cntrlptch.draw((0,0),(2*rds,2*rds))
            hrl.flip(clr=False)

            if hrl.checkEscape(): escp = True

        # Save results of trial
        hrl.rmtx['TrialTime'] = t
        hrl.rmtx['SelectedLuminance'] = cntrllm
        hrl.writeResultLine()
        
        # Check if escape has been pressed
        if escp: break

    # Experiment is over!
    hrl.close()