示例#1
0
def change(param, changes):
    global flatField, interpolation
    print("tree changes:")
    print p
    for param, change, data in changes:
        path = p.childPath(param)
        if path is not None:
            childName = '.'.join(path)
        else:
            childName = param.name()
        print('  parameter: %s' % childName)
        print('  change:    %s' % change)
        print('  data:      %s' % str(data))
        print('  ----------')
        if childName == 'row' or childName == 'col':
            print p['row'], p['col']
            pix = 8 * p['row'] + p['col']
            # retrieve interpolation data
            (xo, yo) = interpolation[pix]
            # calculate phase pattern
            fft_phase = gp.initial_phase_orig(257 - xo, 257 - yo, 512)
            gp.write2file(fft_phase, gp.phasemap, SLMpath, '99')
            shutil.copyfile(
                bobMirrorFileName,
                '/mnt/SLM/Dan/OptimizeSLM/Patterns/OrigSettings/SLM_100.dat')
            send(99)
            print 'From PC: ', wait()
            f = open(settingsFile, 'w')
            f.write('%d' % pix + '\n')
            f.flush()
            f.close()
示例#2
0
文件: guiPIX.py 项目: mallman777/ttag
def change(param, changes):
    global flatField, interpolation
    print("tree changes:")
    print p
    for param, change, data in changes:
        path = p.childPath(param)
        if path is not None:
            childName = '.'.join(path)
        else:
            childName = param.name()
        print('  parameter: %s'% childName)
        print('  change:    %s'% change)
        print('  data:      %s'% str(data))
        print('  ----------')
        if childName=='row' or childName=='col':
          print p['row'], p['col']
          pix = 8*p['row'] + p['col']
          # retrieve interpolation data 
          (xo,yo)=interpolation[pix]
          # calculate phase pattern
          fft_phase = gp.initial_phase_orig(257-xo,257-yo, 512)
          gp.write2file(fft_phase, gp.phasemap, SLMpath, '99')
          shutil.copyfile(bobMirrorFileName, '/mnt/SLM/Dan/OptimizeSLM/Patterns/OrigSettings/SLM_100.dat')
          send(99)
          print 'From PC: ', wait()
          f = open(settingsFile, 'w')
          f.write('%d'%pix + '\n')
          f.flush()
          f.close()        
示例#3
0
def get_Cnts_local(fftphase):
    gp.write2file(fft_phase, gp.phasemap, SLMpath, '99')
    send(99)
    (curr_single,curr_coin) = getcnts(pix, tacq, coincidencewindow,buf)
    f = curr_single[pixel]
    #f = curr_coin[pixel]
    norm = curr_single.sum()
    # norm = curr_coin.sum()
    return f,norm
示例#4
0
        scanparams = np.loadtxt(dataPathInterp+'scanparameters.txt') 
        (xstart, xstop, xstep, ystart, ystop, ystep)=scanparams
        pixel_list = gp.interpolate2SLM(dataPathInterp, xstart, xstep, ystart, ystep)
        #print pixel_list

    cnt = 0
    # Set Bob's SLM to a mirror, only need to do this once
    shutil.copyfile(bobMirrorFileName, '/mnt/SLM/Dan/OptimizeSLM/Patterns/OrigSettings/SLM_100.dat')
    out_fp = open(dataPath+'rasterOptimize.txt','w')
    for pixel in pixel_list:
        (xo,yo)=pixel
        while True:
            fft_phase = gp.initial_phase_orig(257-xo,257-yo, 512)
            #print 'phase_offset',gp.phase_offset
            gp.write2file(fft_phase, gp.phasemap, SLMpath, '99')
            send(99)
            msgin = wait()
            if int(msgin)<0:
                print 'problem talking with loading a file on the SLM'
                break
            #print 'From PC: ',msgin
            prev_single, prev_coin = ttag_wrap.getCnts(Tacq, CoincidenceWindow,gate, heraldChan,buf)

            x_offsetList = np.arange(-2,3)*2            
            y_offsetList = np.arange(-2,3)*2

            cnts = []
            norms = []
            for x_offset in x_offsetList:
              fft_phase = gp.initial_phase_orig(257-(xo+x_offset),257-(yo), 512)
示例#5
0
    infofp.write('#  BOB SLM xshift: %d, yshift: %d\n' % (xshift, yshift))
    infofp.close()

    cnt = 0
    while True:
        for pixel in range(64):
            [xo, yo] = pixel_list[pixel, :]
            print '%2d: %.3f %.3f' % (pixel, xo, yo)
            fft_phase = gp.initial_phase_orig(257 - xo, 257 - yo, 512)
            #print 'phase_offset',gp.phase_offset
            # generate encoding matrix
            seed = cnt + 1
            code = gp.encrypt(seed, 512, 128)
            fft_phase += code
            # send to Alice SLM
            gp.write2file(fft_phase, gp.phasemap, SLMpath, '99')
            # send decoding matrix to Bob SLM
            decode = gp.decrypt(code, xshift, yshift, nrows)
            gp.write2file(decode, gp.phasemap, SLMpath, '100')
            send(99)
            msg = wait()
            time.sleep(0.1)
            if int(msg) < 0:
                print 'Problem with SLM setting'
                break
            # start taking data
            start = buf.datapoints
            time.sleep(Tacq)
            stop = buf.datapoints
            if logtags:
                tup = buf[-(stop -
示例#6
0
    scanparams = np.loadtxt(dataPathInterp+'scanparameters.txt') 
    (xstart,xstop,xstep,ystart,ystop,ystep)=scanparams
    pixel_list = gp.interpolate2SLM(dataPathInterp, xstart, xstep, ystart, ystep)
    
    pixel = 27  # aim for middle of the nanowire array
    [xo,yo]= pixel_list[pixel,:]

    nrows = 512
    cnt = 0
    seed = 1  # use same random pattern all the time
    # compute random phase and set alice
    code = gp.encrypt(seed,512,128) 
    # figure phases to point to pixel
    fft_phase = gp.initial_phase_orig(257-xo,257-yo, 512)
    fft_phase += code
    gp.write2file(fft_phase, gp.phasemap, SLMpath, '99')

    for xshift in range(-10,11):
        for yshift in range(-10,11):
            print 'xshift, yshift: %3d %3d'%(xshift,yshift)
            # send decoding matrix to Bob SLM, vary xshift, yshift
            decode = gp.decrypt(code, xshift, yshift, nrows)
            gp.write2file(decode, gp.phasemap, SLMpath, '100')
            send(99)
            msg = wait()
            if int(msg)<0:
                print 'Problem with SLM setting'
                raise('Problem with SLM setting')
                break
            # start taking data
            start = buf.datapoints
示例#7
0
def write(x, y):
    phase = gp.initial_phase_orig(257. - x, 257. - y, 512)
    gp.write2file(phase, pm, path, filenumber)
    shutil.copyfile(
        bobMirrorFileName,
        '/mnt/SLM/Dan/OptimizeSLM/Patterns/OrigSettings/SLM_100.dat')
示例#8
0
#fft_phase = gp.initial_phase(xo,yo, 512)
fprev = getCnts(pix, Tacq, CoincidenceWindow, buf)
list_phases = [fft_phase]
list_f = [fprev]
nrows = 64
thresh = 0.95
pertPath = "/mnt/SLM/Dan/OptimizeSLM/Patterns/PerturbSettings/"
for loopT in range(n):
    print 'Cycle: %d with Temperature: %.2f f:%f' % (loopT, t, fprev)
    for loop in range(tries_per_cycle):
        times = []
        times.append(time.time())
        rnd = gp.get_rnd(2800, nrows)
        new_phase = np.mod(fft_phase + rnd, 2 * np.pi)
        times.append(time.time())
        gp.write2file(new_phase, phasemap, pertPath, '%d' % pix)
        times.append(time.time())
        send(pix)
        times.append(time.time())
        msg = wait()
        times.append(time.time())
        f = getCnts(pix, Tacq, CoincidenceWindow, buf)
        times.append(time.time())
        print 'loopT: %d inner %d, f@lastT %.3f fprev %.3f, Current f: %f' % (
            loopT, loop, list_f[-1], fprev, f)
        DeltaE = abs(f - fprev)
        # Initialize DeltaE_avg if a worse solution was found
        #   on the first iteration
        if (loopT == 0 and loop == 0): DeltaE_avg = DeltaE
        if f < fprev:
            # instead of minimize in conventional SA, look for maximum
示例#9
0
#fft_phase = gp.initial_phase(xo,yo, 512)
fprev = getCnts(pix, Tacq, CoincidenceWindow,buf) 
list_phases=[fft_phase]
list_f = [fprev]
nrows = 64
thresh = 0.95
pertPath =  "/mnt/SLM/Dan/OptimizeSLM/Patterns/PerturbSettings/"
for loopT in range(n):
    print 'Cycle: %d with Temperature: %.2f f:%f'%(loopT, t, fprev) 
    for loop in range(tries_per_cycle):
        times = []
        times.append(time.time())
        rnd = gp.get_rnd(2800,nrows)
        new_phase = np.mod(fft_phase+rnd, 2*np.pi)
        times.append(time.time())
        gp.write2file(new_phase, phasemap, pertPath, '%d'%pix)
        times.append(time.time())
        send(pix)
        times.append(time.time())
        msg = wait()
        times.append(time.time())
        f = getCnts(pix, Tacq, CoincidenceWindow, buf)
        times.append(time.time())
        print 'loopT: %d inner %d, f@lastT %.3f fprev %.3f, Current f: %f'%(loopT, loop, list_f[-1], fprev, f)
        DeltaE = abs(f-fprev)
        # Initialize DeltaE_avg if a worse solution was found
	      #   on the first iteration
        if (loopT==0 and loop==0): DeltaE_avg = DeltaE
        if f < fprev:
            # instead of minimize in conventional SA, look for maximum
            # objective function is worse