コード例 #1
0
def surface_control_yvar(file, surface_num, val):
    link = pyz.createLink()
    link.zLoadFile(file)
    link.zSetSurfaceParameter(surface_num, 4, val)
    link.zSetSurfaceParameter(surface_num + 4, 4, -val)
    link.zSaveFile(file)
    pyz.closeLink()
コード例 #2
0
ファイル: fc.py プロジェクト: shuaixue/slacecodes
def standard_var(low_angle, high_angle, file):
    link = pyz.createLink()
    link.zLoadFile(file)
    
    angles= np.arange(low_angle, high_angle+0.01, 0.01)
    beam_x = []
    beam_y = []
    
    #extract at surface 11
    for i in angles:
        #input in zemax system 
        link.zSetSurfaceParameter(4,3,i)
        link.zSetSurfaceParameter(8,3,-i)
        
        link.zSetSurfaceParameter(4,4,i)
        link.zSetSurfaceParameter(8,4,-i)
        link.zSaveFile(file) 
        #get output in surf 12
        offsetx = link.zOperandValue('POPD', 11, 1, 0, 11)
        offsety = link.zOperandValue('POPD', 11, 1, 0, 12)  
        beam_x.append(offsetx)
        beam_y.append(offsety)
    pyz.closeLink()
    np.savetxt(r'C:\Users\pwfa-facet2\Desktop\slacecodes\raytracing\xyvar_400_700'+'.csv',  list(zip(angles, beam_x, beam_y)))
    print('done')
コード例 #3
0
def ccd_screens(file):
    link = pyz.createLink()
    link.zLoadFile(file)
    ccd1x = link.zOperandValue('POPD', 10, 1, 0, 11)
    ccd1y = link.zOperandValue('POPD', 10, 1, 0, 12)

    ccd2x = link.zOperandValue('POPD', 19, 1, 0, 11)
    ccd2y = link.zOperandValue('POPD', 19, 1, 0, 12)

    ccd3x = link.zOperandValue('POPD', 28, 1, 0, 11)
    ccd3y = link.zOperandValue('POPD', 28, 1, 0, 12)

    ccd4x = link.zOperandValue('POPD', 37, 1, 0, 11)
    ccd4y = link.zOperandValue('POPD', 37, 1, 0, 12)

    ccd5x = link.zOperandValue('POPD', 46, 1, 0, 11)
    ccd5y = link.zOperandValue('POPD', 46, 1, 0, 12)

    ccd6x = link.zOperandValue('POPD', 55, 1, 0, 11)
    ccd6y = link.zOperandValue('POPD', 55, 1, 0, 12)

    beam_pos_vec = np.matrix([[ccd1x], [ccd1y], [ccd2x], [ccd2y], [ccd3x],
                              [ccd3y], [ccd4x], [ccd4y], [ccd5x], [ccd5y],
                              [ccd6x], [ccd6y]])
    pyz.closeLink()
    return (beam_pos_vec)
コード例 #4
0
ファイル: f-method1.py プロジェクト: shuaixue/slacecodes
def algo_var(file, low_angle, high_angle, x_dmax, y_dmax):
    link = pyz.createLink()
    link.zLoadFile(file)
    alpha1_x = np.random.uniform(low_angle, high_angle)
    alpha1_y = np.random.uniform(low_angle, high_angle)
    x_decenter, y_decenter = np.random.uniform(-x_dmax,
                                               x_dmax), np.random.uniform(
                                                   -y_dmax, y_dmax)
    print("random input var:", alpha1_x, alpha1_y)
    print("random decenter var:", x_decenter, y_decenter)
    #insert variations
    link.zSetSurfaceParameter(4, 3, alpha1_x)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(4, 4, alpha1_y)
    link.zSetSurfaceParameter(4, 5, 0)

    link.zSetSurfaceParameter(8, 3, -alpha1_x)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(8, 4, -alpha1_y)
    link.zSetSurfaceParameter(8, 5, 0)
    link.zSetSurfaceParameter(16, 1, x_decenter)  #decenter x,y : 1,2
    link.zSetSurfaceParameter(21, 1, -x_decenter)
    link.zSetSurfaceParameter(16, 2, y_decenter)  #decenter x,y : 1,2
    link.zSetSurfaceParameter(21, 2, -y_decenter)
    link.zSaveFile(file)
    # print("random input variations:",alpha1_x, alpha1_y, alpha2_x, alpha2_y)
    #print('config set for fixing!')
    img_str = str(
        r'C:\Users\pwfa-facet2\Desktop\slacecodes\raytracing\varinput-norm.csv'
    )
    print(img_str)
    link.zGetTextFile(textFileName=img_str, analysisType='Pop')
    pyz.closeLink()
    return (alpha1_x, alpha1_y)
コード例 #5
0
def facet_chief_ray_tracker(file_name, surface_tbvariated, surface_pos_list, wavenum,  angle_variation):
    
    link = pyz.createLink()
    link.zLoadFile(file_name)
    wavelength = wavenum /1000
    link.zSetWave(1, wavelength, 1) 
    
    link.zSetSurfaceParameter(4, 3, 0) #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(6, 3, 0)
    link.zSetSurfaceParameter(4, 4, 0)
    link.zSetSurfaceParameter(6, 4, 0)

    link.zSaveFile(file)
    
    offset_x =[]
    offset_y = []
    
    #modify entries 
    link.zSetSurfaceParameter(surface_tbvariated, 3, angle_variation)
    link.zSetSurfaceParameter(surface_tbvariated+2, 3, -angle_variation)
    link.zSaveFile(file_name)
    
    for curr_surface in surface_pos_list:
        t_ccdx = link.zOperandValue('POPD', curr_surface, 1, 0, 11)
        t_ccdy = link.zOperandValue('POPD', curr_surface, 1, 0, 12)
       #print(t_ccdx, t_ccdy)
        offset_x.append(t_ccdx)
        offset_y.append(t_ccdy)
    
    pyz.closeLink()
    return(offset_x, offset_y)
コード例 #6
0
ファイル: algo.py プロジェクト: shuaixue/slacecodes
def algo_var(file, low_angle, high_angle):
    link = pyz.createLink()
    link.zLoadFile(file)
    alpha1_x = np.random.uniform(low_angle, high_angle)
    alpha1_y = np.random.uniform(low_angle, high_angle)
    alpha2_x = np.random.uniform(low_angle, high_angle)
    alpha2_y = np.random.uniform(low_angle, high_angle)

    #insert variations
    link.zSetSurfaceParameter(4, 3, alpha1_x)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(4, 4, alpha1_y)
    link.zSetSurfaceParameter(4, 5, 0)

    link.zSetSurfaceParameter(8, 3, -alpha1_x)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(8, 4, -alpha1_y)
    link.zSetSurfaceParameter(8, 5, 0)

    link.zSetSurfaceParameter(20, 3, alpha2_x)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(20, 4, alpha2_y)
    link.zSetSurfaceParameter(20, 5, 0)

    link.zSetSurfaceParameter(24, 3, -alpha2_x)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(24, 4, -alpha2_y)
    link.zSetSurfaceParameter(24, 5, 0)
    link.zSaveFile(file)
    # print("random input variations:",alpha1_x, alpha1_y, alpha2_x, alpha2_y)
    #print('config set for fixing!')
    pyz.closeLink()
    return (alpha1_x, alpha1_y, alpha2_x, alpha2_y)
コード例 #7
0
ファイル: test-lim.py プロジェクト: shuaixue/slacecodes
def algo_var_test(file, low_angle, high_angle, sample_size):
    link = pyz.createLink()
    link.zLoadFile(file)
    ccd1x_arr = []
    ccd1y_arr = []
    ccd2x_arr = []
    ccd2y_arr = []
    angle1_xarr = []
    angle1_yarr = []
    angle2_xarr = []
    angle2_yarr = []
    for i in range(0, sample_size):
        alpha1_x = np.random.uniform(low_angle, high_angle)
        alpha1_y = np.random.uniform(low_angle, high_angle)
        alpha2_x = np.random.uniform(low_angle, high_angle)
        alpha2_y = np.random.uniform(low_angle, high_angle)
        angle1_xarr.append(alpha1_x)
        angle1_yarr.append(alpha1_y)
        angle2_xarr.append(alpha2_x)
        angle2_yarr.append(alpha2_y)
        #insert variations
        link.zSetSurfaceParameter(4, 3, alpha1_x)  #3 = x-tilt, 4=y-tilt
        link.zSetSurfaceParameter(4, 4, alpha1_y)
        link.zSetSurfaceParameter(4, 5, 0)

        link.zSetSurfaceParameter(8, 3, -alpha1_x)  #3 = x-tilt, 4=y-tilt
        link.zSetSurfaceParameter(8, 4, -alpha1_y)
        link.zSetSurfaceParameter(8, 5, 0)

        link.zSetSurfaceParameter(20, 3, alpha2_x)  #3 = x-tilt, 4=y-tilt
        link.zSetSurfaceParameter(20, 4, alpha2_y)
        link.zSetSurfaceParameter(20, 5, 0)

        link.zSetSurfaceParameter(24, 3, -alpha2_x)  #3 = x-tilt, 4=y-tilt
        link.zSetSurfaceParameter(24, 4, -alpha2_y)
        link.zSetSurfaceParameter(24, 5, 0)
        link.zSaveFile(file)
        #print("random input variations:",alpha1_x, alpha1_y, alpha2_x, alpha2_y)
        #print('config set for fixing!')
        #extract offsets:
        ccd1_offsetx = link.zOperandValue('POPD', 30, 1, 0, 11)
        ccd1_offsety = link.zOperandValue('POPD', 30, 1, 0, 12)

        ccd2_x = link.zOperandValue('POPD', 32, 1, 0, 11)
        ccd2_y = link.zOperandValue('POPD', 32, 1, 0, 12)
        #make offsets vector

        ccd1x_arr.append(ccd1_offsetx)
        ccd1y_arr.append(ccd1_offsety)
        ccd2x_arr.append(ccd2_x)
        ccd2y_arr.append(ccd2_y)
    pyz.closeLink()
    np.savetxt(
        'var neg' + str(low_angle) + "-" + str(high_angle) + "-" +
        str(sample_size) + ".csv",
        list(
            zip(angle1_xarr, angle1_yarr, angle2_xarr, angle2_yarr, ccd1x_arr,
                ccd1y_arr, ccd2x_arr, ccd2y_arr)))
    print("finished with variations!")
コード例 #8
0
def facet_ccd(wv, gridsize, bwaist, xoff, yoff, start_pos, pos_arr, f_name):
    link = pyz.createLink()
    link.zLoadFile(f_name)
    wavelength = wv / 1000

    #link.ipzGetLDE()
    #change start position
    link.zSetSurfaceData(2, 3, start_pos)
    link.zSetWave(1, wavelength, 1)
    print(link.zGetWave(1))
    setfile = link.zGetFile().lower().replace('.zmx', '.CFG')
    S_512 = 5
    grid_size = gridsize
    GAUSS_WAIST, WAIST_X, WAIST_Y, DECENTER_X, DECENTER_Y = 0, 1, 2, 3, 4
    beam_waist, x_off, y_off = bwaist, xoff, yoff
    cfgfile = link.zSetPOPSettings('irr',
                                   setfile,
                                   startSurf=2,
                                   endSurf=2,
                                   field=1,
                                   wave=1,
                                   beamType=GAUSS_WAIST,
                                   paramN=((WAIST_X, WAIST_Y, DECENTER_X,
                                            DECENTER_Y),
                                           (beam_waist, beam_waist, x_off,
                                            y_off)),
                                   sampx=S_512,
                                   sampy=S_512,
                                   widex=grid_size,
                                   widey=grid_size,
                                   tPow=1,
                                   auto=0)

    #ipath = r"C:\Users\pwfa-facet2\Desktop\slacecodes\FACET_model_current\wavelength_runs\\facet_2_2_offset_img\\"
    outfile = r"C:\Users\pwfa-facet2\Desktop\slacecodes\FACET_model_current\wavelength_runs\facet_2_2_offset_img\irradiancesetttings.txt"
    screen_width_file = r"C:\Users\pwfa-facet2\Desktop\slacecodes\FACET_model_current\wavelength_runs\facet_2_2_offset_img\widths.txt"
    waists_gridx = []
    waists_gridy = []
    with open(outfile, "w") as text_file:
        for i in range(len(pos_arr)):
            link.zModifyPOPSettings(cfgfile, endSurf=pos_arr[i])
            irr_data, grid_data = link.zGetPOP(cfgfile, displayData=True)
            #waistxy.write(float(irr_data.widthX) + '\t')
            #waistxy.write(float(irr_data.widthY) + '\n')
            #print(irr_data)
            waists_gridx.append(irr_data.widthX)
            waists_gridy.append(irr_data.widthY)
            text_file.write(str(irr_data) + '\n')
            #print(irr_data)
            #irr_data, irr_grid_plot = link.zGetPOP(settingsFile=setfile, displayData=True)
            fpath = r"C:\Users\pwfa-facet2\Desktop\slacecodes\FACET_model_current\wavelength_runs\facet_2_2_offset_img"
            grid_file = fpath + "\\" + str(wv) + "_" + str(bwaist) + "_" + str(
                start_pos) + "_pos" + str(pos_arr[i]) + "_irr_offset.csv"
            np.savetxt(grid_file, grid_data)
    np.savetxt(screen_width_file, list(zip(waists_gridx, waists_gridy)))

    #out_file = open(ipath+"\\"+"irrdata_pos"+str(start_pos)+".txt", "w")

    pyz.closeLink()
コード例 #9
0
ファイル: test lens.py プロジェクト: shuaixue/slacecodes
def decentering(file, x_off, y_off):
    link = pyz.createLink()
    link.zLoadFile(file)
    link.zSetSurfaceParameter(16,1, x_off)#decenter x,y : 1,2
    link.zSetSurfaceParameter(21,1, -x_off)
    link.zSetSurfaceParameter(16,2, y_off)#decenter x,y : 1,2
    link.zSetSurfaceParameter(21,2, -y_off)
    link.zSaveFile(file)
    pyz.closeLink()
コード例 #10
0
def set_start_vars_fix(file):
    link = pyz.createLink()
    link.zLoadFile(file)
    #var
    link.zSetSurfaceParameter(3, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(3, 4, 0)
    link.zSetSurfaceParameter(3, 5, 0)

    link.zSetSurfaceParameter(7, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(7, 4, 0)
    link.zSetSurfaceParameter(7, 5, 0)

    #fix
    link.zSetSurfaceParameter(4, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(4, 4, 0)
    link.zSetSurfaceParameter(4, 5, 0)

    link.zSetSurfaceParameter(6, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(6, 4, 0)
    link.zSetSurfaceParameter(6, 5, 0)

    #var
    link.zSetSurfaceParameter(12, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(12, 4, 0)
    link.zSetSurfaceParameter(12, 5, 0)

    link.zSetSurfaceParameter(16, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(16, 4, 0)
    link.zSetSurfaceParameter(16, 5, 0)
    #fix
    link.zSetSurfaceParameter(13, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(13, 4, 0)
    link.zSetSurfaceParameter(13, 5, 0)

    link.zSetSurfaceParameter(15, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(15, 4, 0)
    link.zSetSurfaceParameter(15, 5, 0)

    #var
    link.zSetSurfaceParameter(23, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(23, 4, 0)
    link.zSetSurfaceParameter(23, 5, 0)

    link.zSetSurfaceParameter(27, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(27, 4, 0)
    link.zSetSurfaceParameter(27, 5, 0)
    #fix
    link.zSetSurfaceParameter(24, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(24, 4, 0)
    link.zSetSurfaceParameter(24, 5, 0)

    link.zSetSurfaceParameter(26, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(26, 4, 0)
    link.zSetSurfaceParameter(26, 5, 0)
    link.zSaveFile(file)
    pyz.closeLink()
コード例 #11
0
def ccd_vector(file):
    link = pyz.createLink()
    link.zLoadFile(file)
    arr = []
    ccd1x = link.zOperandValue('POPD', 10, 1, 0, 11)
    ccd1y = link.zOperandValue('POPD', 10, 1, 0, 12)
    ccd2x = link.zOperandValue('POPD', 21, 1, 0, 11)
    ccd2y = link.zOperandValue('POPD', 21, 1, 0, 12)
    ccd3x = link.zOperandValue('POPD', 34, 1, 0, 11)
    ccd3y = link.zOperandValue('POPD', 34, 1, 0, 12)
    arr = [ccd1x, ccd1y, ccd2x, ccd2y, ccd3x, ccd3y]
    pyz.closeLink()
    return (arr)
コード例 #12
0
def config_simulation(file, conf_array):
    link = pyz.createLink()
    link.zLoadFile(file)
    link.zSetWave(1, .800, 1)
    setfile = link.zGetFile().lower().replace('.zmx', '.CFG')
    S_512 = 5
    grid_size = 20
    GAUSS_WAIST, WAIST_X, WAIST_Y, DECENTER_X, DECENTER_Y = 0, 1, 2, 3, 4
    beam_waist, x_off, y_off = 5, 0, 0
    cfgfile = link.zSetPOPSettings('irr',
                                   setfile,
                                   startSurf=2,
                                   endSurf=2,
                                   field=1,
                                   wave=1,
                                   beamType=GAUSS_WAIST,
                                   paramN=((WAIST_X, WAIST_Y, DECENTER_X,
                                            DECENTER_Y),
                                           (beam_waist, beam_waist, x_off,
                                            y_off)),
                                   sampx=S_512,
                                   sampy=S_512,
                                   widex=grid_size,
                                   widey=grid_size,
                                   tPow=1,
                                   auto=0,
                                   ignPol=1)
    link.zModifyPOPSettings(cfgfile, endSurf=26)
    link.zModifyPOPSettings(cfgfile, paramN=((1, 2, 3, 4), (5, 5, 0, 0)))
    link.zModifyPOPSettings(cfgfile, widex=grid_size)
    link.zModifyPOPSettings(cfgfile, widey=grid_size)
    link.zModifyPOPSettings(cfgfile, ignPol=1)

    chief_angle1_x = conf_array[0]
    chief_angle1_y = conf_array[1]

    chief_angle2_x = conf_array[2]
    chief_angle2_y = conf_array[3]

    chief_angle3_x = conf_array[4]
    chief_angle3_y = conf_array[5]

    chief_surface(file, 2, chief_angle1_x, chief_angle1_y)
    chief_surface(file, 11, chief_angle2_x, chief_angle2_y)
    chief_surface(file, 22, chief_angle3_x, chief_angle3_y)

    set_start_vars_fix(file)

    link.zSaveFile(file)
    pyz.closeLink()
    print('config set for testing!')
コード例 #13
0
def algo_facet2_var(file, var_arr):
    link = pyz.createLink()
    link.zLoadFile(file)
    l_var = 0
    h_var = var_arr[0]
    var1x = np.random.uniform(l_var, h_var)
    var1y = np.random.uniform(l_var, h_var)
    h_var = var_arr[1]
    var2x = np.random.uniform(l_var, h_var)
    var2y = np.random.uniform(l_var, h_var)
    h_var = var_arr[2]
    var3x = np.random.uniform(l_var, h_var)
    var3y = np.random.uniform(l_var, h_var)
    h_var = var_arr[3]
    var4x = np.random.uniform(l_var, h_var)
    var4y = np.random.uniform(l_var, h_var)
    h_var = var_arr[4]
    var5x = np.random.uniform(l_var, h_var)
    var5y = np.random.uniform(l_var, h_var)

    var6x = np.random.uniform(l_var, h_var)
    var6y = np.random.uniform(l_var, h_var)
    print('variations inputs:')
    vec = np.matrix([[var1x], [var1y], [var2x], [var2y], [var3x], [var3y],
                     [var4x], [var4y], [var5x], [var5y], [var6x], [var6y]])
    print(vec)
    #var M1
    surface_control_xvar(file, 3, var1x)
    surface_control_yvar(file, 3, var1y)

    surface_control_xvar(file, 12, var2x)
    surface_control_yvar(file, 12, var2y)

    surface_control_xvar(file, 21, var3x)
    surface_control_yvar(file, 21, var3y)

    surface_control_xvar(file, 30, var4x)
    surface_control_yvar(file, 30, var4y)

    surface_control_xvar(file, 39, var5x)
    surface_control_yvar(file, 39, var5y)

    surface_control_xvar(file, 48, var6x)
    surface_control_yvar(file, 48, var6y)
    print('variations finished')
    pyz.closeLink()
    np.savetxt(
        r'C:\Users\pwfa-facet2\Desktop\slacecodes\raytracing\f2beamvarmod.csv',
        vec)
コード例 #14
0
def chief_surface(file, surface, anglex, angley):
    link = pyz.createLink()
    link.zLoadFile(file)

    #chief x
    link.zSetSurfaceParameter(surface, 3, anglex)
    link.zSetSurfaceParameter(surface + 6, 3, anglex)
    #chief y
    link.zSetSurfaceParameter(surface, 4, angley)
    link.zSetSurfaceParameter(surface + 6, 4, angley)
    #chief z
    link.zSetSurfaceParameter(surface, 5, 0)
    link.zSetSurfaceParameter(surface + 6, 5, 0)
    link.zSaveFile(file)
    pyz.closeLink()
コード例 #15
0
ファイル: test lens.py プロジェクト: shuaixue/slacecodes
def standard_variation(low_var, high_var, delta):
    deg_range = np.arange(low_var, high_var+delta,delta)
    
    link = pyz.createLink()
    link.zLoadFile(file)
    setfile = link.zGetFile().lower().replace('.zmx', '.CFG')
    S_512 = 5
    grid_size = 20
    GAUSS_WAIST, WAIST_X, WAIST_Y, DECENTER_X, DECENTER_Y = 0, 1, 2, 3, 4
    beam_waist, x_off, y_off = 5, 0, 0
    cfgfile = link.zSetPOPSettings('irr', setfile, startSurf=2, endSurf=2, field=1,
                                   wave=1, beamType=GAUSS_WAIST, paramN=( (WAIST_X, WAIST_Y, DECENTER_X, DECENTER_Y), (beam_waist, beam_waist, x_off, y_off) ),
                                   sampx=S_512, sampy=S_512, widex=grid_size, widey=grid_size, tPow=1, auto=0, ignPol=1)
    link.zModifyPOPSettings(cfgfile, endSurf=26)
    link.zModifyPOPSettings(cfgfile, paramN=( (1, 2, 3, 4), (5, 5,
                                     0, 0) ))
    link.zModifyPOPSettings(cfgfile, widex=grid_size)
    link.zModifyPOPSettings(cfgfile, widey=grid_size)
    link.zModifyPOPSettings(cfgfile, ignPol=1)
#1 to ignore pol;0 to use
    link.zSaveFile(file)
    #add variations
    beforem1_x=[]
    beforem1_y=[]
        #link.zSetSurfaceParameter(3,5, chief_angle1_z)

#fix var/pos empty 
    link.zSaveFile(file)
    for i in deg_range:
        link.zSetSurfaceParameter(4, 3, i) #3 = x-tilt, 4=y-tilt
        link.zSetSurfaceParameter(4, 4, i)
        link.zSetSurfaceParameter(4, 5, 0)

        link.zSetSurfaceParameter(8, 3, i) #3 = x-tilt, 4=y-tilt
        link.zSetSurfaceParameter(8, 4, -i)
        link.zSetSurfaceParameter(8, 5, 0)
        link.zSaveFile(file)
        #get offsets 
        t_ccdx = link.zOperandValue('POPD', 26, 1, 0, 11)
        t_ccdy = link.zOperandValue('POPD', 26, 1, 0, 12)
        beforem1_x.append(t_ccdx)
        beforem1_y.append(t_ccdy)
    img_str = str(r'C:\Users\pwfa-facet2\Desktop\slacecodes\raytracing')+'\\'+'img-norm.csv'
    print(img_str)
    link.zGetTextFile(textFileName=img_str, analysisType='Pop')
    pyz.closeLink()
    np.savetxt(str(r"C:\Users\pwfa-facet2\Desktop\slacecodes\raytracing\\") + "m1m2l1-nodecenteringlensy-"+str(low_var)+"-"+str(high_var)+"-"+str(delta)+'.csv', list(zip(deg_range, beforem1_x, beforem1_y)))
    print("done")
コード例 #16
0
def facet_transport(wv, gridsize, bwaist, xoff, yoff, start_pos, pos_arr,
                    f_name):

    link = pyz.createLink()
    link.zLoadFile(f_name)
    wavelength = wv / 1000

    #link.ipzGetLDE()
    #change start position
    link.zSetSurfaceData(2, 3, start_pos)
    link.zSetWave(1, wavelength, 1)
    print(link.zGetWave(1))
    setfile = link.zGetFile().lower().replace('.zmx', '.CFG')
    S_512 = 5
    grid_size = gridsize
    GAUSS_WAIST, WAIST_X, WAIST_Y, DECENTER_X, DECENTER_Y = 0, 1, 2, 3, 4
    beam_waist, x_off, y_off = bwaist, xoff, yoff
    cfgfile = link.zSetPOPSettings('irr',
                                   setfile,
                                   startSurf=2,
                                   endSurf=2,
                                   field=1,
                                   wave=1,
                                   beamType=GAUSS_WAIST,
                                   paramN=((WAIST_X, WAIST_Y, DECENTER_X,
                                            DECENTER_Y),
                                           (beam_waist, beam_waist, x_off,
                                            y_off)),
                                   sampx=S_512,
                                   sampy=S_512,
                                   widex=grid_size,
                                   widey=grid_size,
                                   tPow=1)

    waists_values = waist_extractor(pos_arr, cfgfile, link)
    pyz.closeLink()
    fpath = r"C:\Users\pwfa-facet2\Desktop\slacecodes\FACET_model_current\wavelength_runs"
    waist_file = fpath + "\\" + str(wv) + "_" + str(bwaist) + "_" + str(
        start_pos) + 'offset.csv'
    np.savetxt(waist_file, waists_values[0])
    irr_file = fpath + "\\" + str(wv) + "_" + str(bwaist) + "_" + str(
        start_pos) + "_irr_offset" '.csv'
    np.savetxt(irr_file, waists_values[2])
    surf_pop_file = fpath + "\\" + str(wv) + "_" + str(bwaist) + "_" + str(
        start_pos) + "_popinfo_offset" '.txt'
    #np.savetxt(surf_pop_file,waists_values[1] )
    return (waists_values)
コード例 #17
0
ファイル: 4mirrors.py プロジェクト: shuaixue/slacecodes
def algo_facet2_var(file, var_arr):
    link = pyz.createLink()
    link.zLoadFile(file)
    l_var = -var_arr[0]
    h_var = var_arr[0]
    var1x = np.random.uniform(l_var, h_var)
    var1y = np.random.uniform(l_var, h_var)
    l_var = -var_arr[1]
    h_var = var_arr[1]
    var2x = np.random.uniform(l_var, h_var)
    var2y = np.random.uniform(l_var, h_var)
    h_var = var_arr[2]
    l_var = -var_arr[2]
    var3x = np.random.uniform(l_var, h_var)
    var3y = np.random.uniform(l_var, h_var)
    #h_var = var_arr[3]
    #var4x = np.random.uniform(l_var, h_var)
    #var4y = np.random.uniform(l_var, h_var)

    vec = np.matrix([ 
            [var1x],
            [var1y],
            [var2x],
            [var2y],
            [var3x],
            [var3y]])
    """
            [var4x],
            [var4y]])
    """
    print(vec)
    #var M1
    surface_control_xvar(file, 3, var1x)
    surface_control_yvar(file, 3, var1y)
    
    surface_control_xvar(file, 12, var2x)
    surface_control_yvar(file, 12, var2y)
    
    surface_control_xvar(file, 21, var3x)
    surface_control_yvar(file, 21, var3y)
    
    #surface_control_xvar(file, 30, var4x)
    #surface_control_yvar(file, 30, var4y)
    print('variations finished')
    pyz.closeLink()
    np.savetxt(r'C:\Users\pwfa-facet2\Desktop\slacecodes\raytracing\f2beam-org-var.csv', vec)
コード例 #18
0
ファイル: 4mirrors.py プロジェクト: shuaixue/slacecodes
def algo_fix(file):
    link= pyz.createLink()
    link.zLoadFile(file)
      
    imax = 20
    corr_mem = []
    it = 0
    
    beam_1x =[]
    beam_1y =[]
    beam_2x =[]
    beam_2y =[]
    beam_3x =[]
    beam_3y =[]
    #beam_4x =[]
    #beam_4y =[]

    
    v_1x =[]
    v_1y =[]
    v_2x =[]
    v_2y =[]
    v_3x =[]
    v_3y =[]
    #v_4x =[]
    #v_4y =[]
    #check for misalignments 
    beam_mem =[] 
    status = 'not done'
    finv = np.linalg.inv(f_beamline(optics_deg))
    curr_beam_pos = ccd_screens(file)
    
    var_vec = np.rad2deg(np.matmul(finv, curr_beam_pos))
    print(var_vec)

    np.savetxt(r'C:\Users\pwfa-facet2\Desktop\slacecodes\raytracing\vartrack.csv', misalign_vec)
    np.savetxt(r'C:\Users\pwfa-facet2\Desktop\slacecodes\raytracing\beamtrack.csv', curr_beam_pos)
    

    
    
    
    
    pyz.closeLink()
コード例 #19
0
ファイル: mscript.py プロジェクト: shuaixue/slacecodes
def facet_ccd(wv, gridsize, bwaist, xdeg_off, pos_ccd, f_name):
    link = pyz.createLink()
    link.zLoadFile(f_name)
    wavelength = wv / 1000

    waistx = []
    waisty = []
    #link.ipzGetLDE()
    #change start position
    #link.zSetSurfaceData(2, 3, start_pos)
    link.zSetSurfaceParameter(4, 3, xdeg_off)
    link.zSetSurfaceParameter(6, 3, -xdeg_off)
    link.zSaveFile(file)
    link.zSetWave(1, wavelength, 1)
    print(link.zGetWave(1))
    setfile = link.zGetFile().lower().replace('.zmx', '.CFG')
    """
    S_512 = 5
    grid_size = gridsize
    GAUSS_WAIST, WAIST_X, WAIST_Y, DECENTER_X, DECENTER_Y = 0, 1, 2, 3, 4
    beam_waist, x_off, y_off = bwaist, 0, 0
    cfgfile = link.zSetPOPSettings('irr', setfile, startSurf=2, endSurf=2, field=1, wave=1, beamType=GAUSS_WAIST,
                             paramN=( (WAIST_X, WAIST_Y, DECENTER_X, DECENTER_Y), (beam_waist, beam_waist,
                                     x_off, y_off) ), sampx=S_512, sampy=S_512,
                             widex=grid_size, widey=grid_size, tPow=1, auto=0)
    """
    link.zModifyPOPSettings(setfile, endSurf=pos_ccd)
    link.zModifyPOPSettings(setfile, paramN=((1, 2, 3, 4), (5, 5, 0, 0)))
    link.zModifyPOPSettings(setfile, widex=gridsize)
    link.zModifyPOPSettings(setfile, widey=gridsize)
    irr_data, grid_data = link.zGetPOP(setfile, displayData=True)
    waists_gridx, waists_gridy = irr_data.widthX, irr_data.widthY
    print(waists_gridx, waists_gridy)
    pyz.closeLink()
    irr_file = outfile + "\\" + str(xdeg_off) + ".csv"
    np.savetxt(irr_file, grid_data)
    screen_width_file = outfile + "\\" + str(xdeg_off) + "_" + "widths.txt"
    np.savetxt(screen_width_file, ((waists_gridx, waists_gridy)))
コード例 #20
0
def ccd_vector(file):
    link = pyz.createLink()
    link.zLoadFile(file)
    arr = []
    ccd1x = link.zOperandValue('POPD', 13, 1, 0, 11)
    ccd1y = link.zOperandValue('POPD', 13, 1, 0, 12)
    ccd2x = link.zOperandValue('POPD', 25, 1, 0, 11)
    ccd2y = link.zOperandValue('POPD', 25, 1, 0, 12)
    ccd3x = link.zOperandValue('POPD', 34, 1, 0, 11)
    ccd3y = link.zOperandValue('POPD', 34, 1, 0, 12)

    ccd4x = link.zOperandValue('POPD', 46, 1, 0, 11)
    ccd4y = link.zOperandValue('POPD', 46, 1, 0, 12)
    ccd5x = link.zOperandValue('POPD', 55, 1, 0, 11)
    ccd5y = link.zOperandValue('POPD', 55, 1, 0, 12)
    ccd6x = link.zOperandValue('POPD', 67, 1, 0, 11)
    ccd6y = link.zOperandValue('POPD', 67, 1, 0, 12)
    arr = [
        ccd1x, ccd1y, ccd2x, ccd2y, ccd3x, ccd3y, ccd4x, ccd4y, ccd5x, ccd5y,
        ccd6x, ccd6y
    ]
    pyz.closeLink()
    return (arr)
コード例 #21
0
def ccd_camera_variations(file_name , surf_modified, surface_list, wavenum, angle_variation):
    link = pyz.createLink()
    link.zLoadFile(file_name)
    wavelength = wavenum /1000
    link.zSetWave(1, wavelength, 1) 
    
    link.zSetSurfaceParameter(4, 3, 0) #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(6, 3, 0)
    link.zSetSurfaceParameter(4, 4, 0)
    link.zSetSurfaceParameter(6, 4, 0)

    link.zSaveFile(file_name)
     #modify entries 
    link.zSetSurfaceParameter(surf_modified, 3, angle_variation)
    link.zSetSurfaceParameter(surf_modified+2, 3, -angle_variation)
    link.zSaveFile(file_name)
    
    setfile = link.zGetFile().lower().replace('.zmx', '.CFG')
    S_512 = 5
    grid_size = 20
    GAUSS_WAIST, WAIST_X, WAIST_Y, DECENTER_X, DECENTER_Y = 0, 1, 2, 3, 4
    beam_waist, x_off, y_off = 5, 0, 0
    cfgfile = link.zSetPOPSettings('irr', setfile, startSurf=2, endSurf=2, field=1, wave=1, beamType=GAUSS_WAIST,
                             paramN=( (WAIST_X, WAIST_Y, DECENTER_X, DECENTER_Y), (beam_waist, beam_waist,
                                     x_off, y_off) ), sampx=S_512, sampy=S_512, widex=grid_size, widey=grid_size, tPow=1, auto=0)
    link.zModifyPOPSettings(cfgfile, endSurf=2)
    link.zModifyPOPSettings(cfgfile, paramN=( (1, 2, 3, 4), (5, 5, 0, 0) ))
    link.zModifyPOPSettings(cfgfile, widex=grid_size)
    link.zModifyPOPSettings(cfgfile, widey=grid_size) 
    
    for i in surface_list:
        link.zModifyPOPSettings(settingsFile=cfgfile, endSurf=i)
        fname =  r"C:\Users\pwfa-facet2\Desktop\slacecodes\FACET_model_current\wavelength_runs\\" +str(wavenum)+ str("_")+str(i)+'_1.csv'
        #print(fname)
        link.zGetPOP(settingsFile=cfgfile, displayData=True, keepFile=True, txtFile=fname)
        #link.zGetTextFile(fname, analysisType='POP',settingsFile=cfgfile, flag=0)
    pyz.closeLink()
コード例 #22
0
ファイル: algo.py プロジェクト: shuaixue/slacecodes
def algo_fix(file):
    link = pyz.createLink()
    link.zLoadFile(file)
    #extract offsets:
    status = "not done"
    angle_fix_approx_arr = []
    offset_correction_arr = []
    ccd1x_arr = []
    ccd1y_arr = []
    ccd2x_arr = []
    ccd2y_arr = []
    curr_r = 0
    print("current trial num (this is the initial must fix:", curr_r)
    ccd1_offsetx = link.zOperandValue('POPD', 30, 1, 0, 11)
    ccd1_offsety = link.zOperandValue('POPD', 30, 1, 0, 12)

    ccd2_x = link.zOperandValue('POPD', 32, 1, 0, 11)
    ccd2_y = link.zOperandValue('POPD', 32, 1, 0, 12)

    ccd1x_arr.append(ccd1_offsetx)
    ccd1y_arr.append(ccd1_offsety)
    ccd2x_arr.append(ccd2_x)
    ccd2y_arr.append(ccd2_y)

    #make offsets vector
    curr_vec = np.matrix([[ccd1_offsetx], [ccd1_offsety], [ccd2_x], [ccd2_y]])
    print("input offsets:", np.transpose(curr_vec))
    offset_correction_arr.append(curr_vec)
    #get variations:
    inv_f = np.linalg.inv(f_sys)
    #extract predictions of the variations

    curr_angle_vector = np.rad2deg(np.matmul(inv_f, (curr_vec)))

    pred_alpha1x_arr = []
    pred_alpha1y_arr = []
    pred_alpha2x_arr = []
    pred_alpha2y_arr = []

    angle_fix_approx_arr.append(curr_angle_vector)

    pred_alpha1x = (curr_angle_vector.item(0))
    pred_alpha1y = (curr_angle_vector.item(1))
    pred_alpha2x = (curr_angle_vector.item(2))
    pred_alpha2y = (curr_angle_vector.item(3))

    pred_alpha1x_arr.append(pred_alpha1x)
    pred_alpha1y_arr.append(pred_alpha1y)
    pred_alpha2x_arr.append(pred_alpha2x)
    pred_alpha2y_arr.append(pred_alpha2y)

    print("predicted variations:", np.transpose(curr_angle_vector))

    #input this adjustments to system to see rectification
    link.zSetSurfaceParameter(5, 3, -pred_alpha1x)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(5, 4, -pred_alpha1y)
    link.zSetSurfaceParameter(5, 5, 0)

    link.zSetSurfaceParameter(7, 3, pred_alpha1x)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(7, 4, pred_alpha1y)
    link.zSetSurfaceParameter(7, 5, 0)

    link.zSetSurfaceParameter(21, 3, -pred_alpha2x)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(21, 4, -pred_alpha2y)
    link.zSetSurfaceParameter(21, 5, 0)

    link.zSetSurfaceParameter(23, 3, pred_alpha2x)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(23, 4, pred_alpha2y)
    link.zSetSurfaceParameter(23, 5, 0)
    link.zSaveFile(file)
    n_ccd1_offsetx = link.zOperandValue('POPD', 30, 1, 0, 11)
    n_ccd1_offsety = link.zOperandValue('POPD', 30, 1, 0, 12)

    n_ccd2_x = link.zOperandValue('POPD', 32, 1, 0, 11)
    n_ccd2_y = link.zOperandValue('POPD', 32, 1, 0, 12)
    #make offsets vector
    n_curr_vec = np.matrix([[n_ccd1_offsetx], [n_ccd1_offsety], [n_ccd2_x],
                            [n_ccd2_y]])
    offset_correction_arr.append(n_curr_vec)
    i = 0
    print("first initial fix:", np.transpose(n_curr_vec))
    ccd1x_arr.append(n_ccd1_offsetx)
    ccd1y_arr.append(n_ccd1_offsety)
    ccd2x_arr.append(n_ccd2_x)
    ccd2y_arr.append(n_ccd2_y)
    #print(np.transpose(angle_fix_approx_arr))

    while status != "done":
        #get new variations
        curr_r = curr_r + 1
        print("current trial run:", curr_r)
        print("before adjustments vector:", np.transpose(n_curr_vec))
        n_var_angle_vector = np.rad2deg(np.matmul(inv_f, (n_curr_vec)))
        #get the new approximation
        best_fix = angle_fix_approx_arr[i] + n_var_angle_vector
        #print(np.transpose(angle_fix_approx_arr))
        b_pred_alpha1x = (best_fix.item(0))
        b_pred_alpha1y = (best_fix.item(1))
        b_pred_alpha2x = (best_fix.item(2))
        b_pred_alpha2y = (best_fix.item(3))
        angle_fix_approx_arr.append(best_fix)
        i = i + 1
        #print(angle_fix_approx_arr)
        print("new correction (adding predictions):", np.transpose(best_fix))
        #make adjustments for better fit
        link.zSetSurfaceParameter(5, 3, -b_pred_alpha1x)  #3 = x-tilt, 4=y-tilt
        link.zSetSurfaceParameter(5, 4, -b_pred_alpha1y)
        link.zSetSurfaceParameter(5, 5, 0)

        link.zSetSurfaceParameter(7, 3, b_pred_alpha1x)  #3 = x-tilt, 4=y-tilt
        link.zSetSurfaceParameter(7, 4, b_pred_alpha1y)
        link.zSetSurfaceParameter(7, 5, 0)

        link.zSetSurfaceParameter(21, 3,
                                  -b_pred_alpha2x)  #3 = x-tilt, 4=y-tilt
        link.zSetSurfaceParameter(21, 4, -b_pred_alpha2y)
        link.zSetSurfaceParameter(21, 5, 0)

        link.zSetSurfaceParameter(23, 3, b_pred_alpha2x)  #3 = x-tilt, 4=y-tilt
        link.zSetSurfaceParameter(23, 4, b_pred_alpha2y)
        link.zSetSurfaceParameter(23, 5, 0)
        link.zSaveFile(file)

        #add new fit angles
        pred_alpha1x_arr.append(b_pred_alpha1x)
        pred_alpha1y_arr.append(b_pred_alpha1y)
        pred_alpha2x_arr.append(b_pred_alpha2x)
        pred_alpha2y_arr.append(b_pred_alpha2y)

        #see fixes
        n_ccd1_offsetx = link.zOperandValue('POPD', 30, 1, 0, 11)
        n_ccd1_offsety = link.zOperandValue('POPD', 30, 1, 0, 12)
        n_ccd2_x = link.zOperandValue('POPD', 32, 1, 0, 11)
        n_ccd2_y = link.zOperandValue('POPD', 32, 1, 0, 12)
        n_curr_vec = np.matrix([[n_ccd1_offsetx], [n_ccd1_offsety], [n_ccd2_x],
                                [n_ccd2_y]])
        print("new offsets:", np.transpose(n_curr_vec))
        offset_correction_arr.append(n_curr_vec)
        print("++++++++")
        #add new offsets
        ccd1x_arr.append(n_ccd1_offsetx)
        ccd1y_arr.append(n_ccd1_offsety)
        ccd2x_arr.append(n_ccd2_x)
        ccd2y_arr.append(n_ccd2_y)

        error = 0.00001
        if np.abs(n_ccd1_offsetx) <= error and np.abs(
                n_ccd1_offsety) <= error and np.abs(
                    n_ccd2_x) <= error and np.abs(n_ccd2_y) <= error:
            status = "done"
            pyz.closeLink()
            #np.savetxt('var'+'.csv', list(zip(angles_xtilt, beam_x, beam_y,ccd1x_arr,ccd1y_arr,ccd2x_arr,ccd2y_arr)))
            return (pred_alpha1x_arr, pred_alpha1y_arr, pred_alpha2x_arr,
                    pred_alpha2y_arr, ccd1x_arr, ccd1y_arr, ccd2x_arr,
                    ccd2y_arr)
        else:
            status = "not done"
コード例 #23
0
def ccd_system(start_angle, end_angle, chief_angle_x, chief_angle_y, file,
               exp_run):
    link = pyz.createLink()
    link.zLoadFile(file)

    setfile = link.zGetFile().lower().replace('.zmx', '.CFG')
    S_512 = 5
    grid_size = 20
    GAUSS_WAIST, WAIST_X, WAIST_Y, DECENTER_X, DECENTER_Y = 0, 1, 2, 3, 4
    beam_waist, x_off, y_off = 5, 0, 0
    cfgfile = link.zSetPOPSettings('irr',
                                   setfile,
                                   startSurf=2,
                                   endSurf=2,
                                   field=1,
                                   wave=1,
                                   beamType=GAUSS_WAIST,
                                   paramN=((WAIST_X, WAIST_Y, DECENTER_X,
                                            DECENTER_Y),
                                           (beam_waist, beam_waist, x_off,
                                            y_off)),
                                   sampx=S_512,
                                   sampy=S_512,
                                   widex=grid_size,
                                   widey=grid_size,
                                   tPow=1,
                                   auto=0)
    link.zModifyPOPSettings(setfile, endSurf=27)
    link.zModifyPOPSettings(setfile, paramN=((1, 2, 3, 4), (5, 5, 0, 0)))
    link.zModifyPOPSettings(setfile, widex=grid_size)
    link.zModifyPOPSettings(setfile, widey=grid_size)
    link.zSaveFile(file)
    #no offset to chief ray
    link.zSetSurfaceParameter(3, 3, chief_angle_x)
    link.zSetSurfaceParameter(7, 3, chief_angle_x)
    link.zSetSurfaceParameter(3, 4, chief_angle_y)
    link.zSetSurfaceParameter(7, 4, chief_angle_y)

    link.zSetSurfaceParameter(4, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(6, 3, 0)
    link.zSetSurfaceParameter(4, 4, 0)
    link.zSetSurfaceParameter(6, 4, 0)

    link.zSetSurfaceParameter(18, 3, 0)
    link.zSetSurfaceParameter(20, 3, 0)
    link.zSetSurfaceParameter(18, 4, 0)
    link.zSetSurfaceParameter(20, 4, 0)

    link.zSaveFile(file)
    non_var_bx = []
    non_var_by = []

    for i in range(exp_run + 1):
        nooffset_t_ccdx = link.zOperandValue('POPD', 26, 1, 0, 11)
        nooffset_t_ccdy = link.zOperandValue('POPD', 26, 1, 0, 12)
        non_var_bx.append(nooffset_t_ccdx)
        non_var_by.append(nooffset_t_ccdy)

    alphax_arr = []
    alphay_arr = []
    alpha2x_arr = []
    alpha2y_arr = []
    beamx_offset = []
    beamy_offset = []
    ccd2_beamx_offset = []
    ccd2_beamy_offset = []
    exp_run_arr = []
    beam_y = []
    beam_x = []
    for i in range(exp_run + 1):
        alpha_1x = np.random.uniform(start_angle, end_angle)
        alpha_1y = np.random.uniform(start_angle, end_angle)
        alpha_2x = np.random.uniform(start_angle, end_angle)
        alpha_2y = np.random.uniform(start_angle, end_angle)
        alphax_arr.append(alpha_1x)
        alphay_arr.append(alpha_1y)
        alpha2x_arr.append(alpha_2x)
        alpha2y_arr.append(alpha_2y)
        exp_run_arr.append(i)
        #make offsets in zemax system
        link.zSetSurfaceParameter(4, 3, alpha_1x)  #3 = x-tilt, 4=y-tilt
        link.zSetSurfaceParameter(6, 3, -alpha_1x)
        link.zSetSurfaceParameter(4, 4, alpha_1y)
        link.zSetSurfaceParameter(6, 4, -alpha_1y)

        link.zSetSurfaceParameter(18, 3, alpha_2x)  #3 = x-tilt, 4=y-tilt
        link.zSetSurfaceParameter(20, 3, -alpha_2x)
        link.zSetSurfaceParameter(18, 4, alpha_2y)
        link.zSetSurfaceParameter(20, 4, -alpha_2y)

        link.zSaveFile(file)
        #alpha_2x = np.random.uniform(start_angle, end_angle)
        #alpha_2y = np.random.uniform(start_angle, end_angle)

        #add offsets
        t_ccdx = link.zOperandValue('POPD', 15, 1, 0, 11)
        t_ccdy = link.zOperandValue('POPD', 15, 1, 0, 12)

        ccd1_offsetx = link.zOperandValue('POPD', 26, 1, 0, 11)
        ccd1_offsety = link.zOperandValue('POPD', 26, 1, 0, 12)

        ccd2_x = link.zOperandValue('POPD', 28, 1, 0, 11)
        ccd2_y = link.zOperandValue('POPD', 28, 1, 0, 12)

        beam_x.append(t_ccdx)
        beam_y.append(t_ccdy)

        beamx_offset.append(ccd1_offsetx)
        beamy_offset.append(ccd1_offsety)

        ccd2_beamx_offset.append(ccd2_x)
        ccd2_beamy_offset.append(ccd2_y)

    pyz.closeLink()
    np.savetxt(
        'testbothmirrors' + str(chief_angle_x) + '_chief_angley_' +
        str(chief_angle_y) + '_start_angle' + str(start_angle) +
        '_end_angle_' + str(end_angle) + '_' + str(exp_run) + '.csv',
        list(
            zip(exp_run_arr, alphax_arr, alphay_arr, alpha2x_arr, alpha2y_arr,
                beam_x, beam_y, beamx_offset, beamy_offset, ccd2_beamx_offset,
                ccd2_beamy_offset)))
    return (exp_run_arr, alphax_arr, alphay_arr, beamx_offset, beamy_offset,
            ccd2_beamx_offset, ccd2_beamy_offset)
コード例 #24
0
ファイル: popdtest.py プロジェクト: shuaixue/slacecodes
def vector_generator_cdd(start_angle, end_angle, f):
    
    #generate random angles
    alpha_1 = np.random.uniform(start_angle, end_angle) # offset on mirror 1
    alpha_2 = np.random.uniform(start_angle, end_angle) #offset on mirror 2
    offset_1_pos_x = []
    offset_1_pos_y = []
    offset_2_pos_x = []
    offset_2_pos_y = []
    
    link = pyz.createLink()
    link.zLoadFile(f)
    #no offset to chief ray
    link.zSetSurfaceParameter(4, 3, 0)
    link.zSetSurfaceParameter(6, 3, 0)
    link.zSetSurfaceParameter(4, 4, 0)
    link.zSetSurfaceParameter(6, 4, 0)
    
    link.zSetSurfaceParameter(17, 3, 0)
    link.zSetSurfaceParameter(19, 3, 0)
    link.zSetSurfaceParameter(17, 4, 0)
    link.zSetSurfaceParameter(19, 4, 0)
    link.zSaveFile(f)
    
    ccd1_noffset = link.zGetTrace(waveNum=1, mode=0, surf=22,hx=0,hy=0,px=0,py=0)
    ccd2_noffset = link.zGetTrace(waveNum=1, mode=0, surf=24,hx=0,hy=0,px=0,py=0)

    
    alpha_2_norm = 0
   #offset only on m1 
    i = alpha_1
    j = alpha_2_norm
    link.zSetSurfaceParameter(4, 3, i)
    link.zSetSurfaceParameter(6, 3, -i)
    link.zSetSurfaceParameter(17, 4, j)
    link.zSetSurfaceParameter(19, 4, -j)
    link.zSaveFile(f)
    
    ccd1_offset_m1 = link.zGetTrace(waveNum=1, mode=0, surf=22,hx=0,hy=0,px=0,py=0)
    ccd2_offset_m1 = link.zGetTrace(waveNum=1, mode=0, surf=24,hx=0,hy=0,px=0,py=0)
        #errors, vig, x,y,z, dcos...
    

    ##offset on m1 and m2 (m2 added)
    
    j = alpha_2
    link.zSetSurfaceParameter(4, 3, i)
    link.zSetSurfaceParameter(6, 3, -i)
    link.zSetSurfaceParameter(17, 4, j)
    link.zSetSurfaceParameter(19, 4, -j)
    link.zSaveFile(f)
    
    ccd1_offset_m2 = link.zGetTrace(waveNum=1, mode=0, surf=22,hx=0,hy=0,px=0,py=0)
    ccd2_offset_m2 = link.zGetTrace(waveNum=1, mode=0, surf=24,hx=0,hy=0,px=0,py=0)
        
    pyz.closeLink()
    return(ccd1_noffset[2], ccd1_noffset[3], #0,1
           ccd2_noffset[2], ccd2_noffset[3], #2,3
           0,0, #4,5
           ccd1_offset_m1[2], ccd1_offset_m1[3], #6,7
           ccd2_offset_m1[2], ccd2_offset_m1[3], #8,9
           alpha_1, alpha_2_norm, #10,11
           ccd1_offset_m2[2], ccd1_offset_m2[3], #12,13
           ccd2_offset_m2[2], ccd2_offset_m2[3], #14,15
           alpha_1, alpha_2) #16,17
コード例 #25
0
ファイル: plotSpiralSpot.py プロジェクト: B2015/PyZDDE
from __future__ import print_function
import os
import matplotlib.pyplot as plt
import pyzdde.zdde as pyz

ln = pyz.createLink()
filename = os.path.join(ln.zGetPath()[1], 'Sequential', 'Objectives', 
                        'Cooke 40 degree field.zmx')
# Load a lens file into the ZEMAX DDE server
ln.zLoadFile(filename)
hx = 0.0
hy = 0.4
spirals = 10 #100
rays = 600   #6000
(xb,yb,zb,intensityb) = ln.zSpiralSpot(hx,hy,1,spirals,rays)
(xg,yg,zg,intensityg) = ln.zSpiralSpot(hx,hy,2,spirals,rays)
(xr,yr,zr,intensityr) = ln.zSpiralSpot(hx,hy,3,spirals,rays)
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111)
ax.set_aspect('equal')
ax.scatter(xr,yr,s=5,c='red',linewidth=0.35,zorder=20)
ax.scatter(xg,yg,s=5,c='lime',linewidth=0.35,zorder=21)
ax.scatter(xb,yb,s=5,c='blue',linewidth=0.35,zorder=22)
ax.set_xlabel('x');ax.set_ylabel('y')
fig.suptitle('Spiral Spot')
ax.grid(color='lightgray', linestyle='-', linewidth=1)
ax.ticklabel_format(scilimits=(-2,2))

# close the communication channel before calling show plot
pyz.closeLink()
plt.show()
コード例 #26
0
ファイル: f-method1.py プロジェクト: shuaixue/slacecodes
def align_m1(file):

    link = pyz.createLink()
    link.zLoadFile(file)

    #extract variations:
    ccd1_offsetx = link.zOperandValue('POPD', 26, 1, 0, 11)
    ccd1_offsety = link.zOperandValue('POPD', 26, 1, 0, 12)
    beam_vec = np.matrix([[ccd1_offsetx], [ccd1_offsety]])
    print("initial beam vector:")
    print(beam_vec)
    beam_vec = np.matrix([[.5 * beam_vec.item(0)], [.25 * beam_vec.item(1)]])
    print('adjusting beam vector:')
    print(beam_vec)

    #var_vec
    inv_beamline = np.linalg.inv(one_mirror(45, 0, 400))
    vec = np.matrix([[0], [0], [0], [0], [1]])
    var_vec = np.matmul(inv_beamline, beam_vec)
    print("print initial variation vector:")
    print(np.rad2deg(var_vec))
    ##feed them into system
    """
        t_varx, t_vary = np.rad2deg(var_vec.item(0)),np.rad2deg(var_vec.item(1))
    
    no_decenter_sys = lens_dec_matrix(201.654, 200,200,200,45,0,90,t_varx,t_vary,0,0)*vec
    print(no_decenter_sys)
    ##feed variations
    link.zSetSurfaceParameter(5, 3, -float(t_varx)) #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(5, 4, -float(t_vary))
    link.zSetSurfaceParameter(5, 5, 0)

    link.zSetSurfaceParameter(7, 3, float(t_varx)) #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(7, 4, float(t_vary))
    link.zSetSurfaceParameter(7, 5, 0)
    link.zSaveFile(file)  
    print("second stage:")
    #extract variations:
    ccd1_offsetx = link.zOperandValue('POPD', 26, 1, 0, 11)
    ccd1_offsety = link.zOperandValue('POPD', 26, 1, 0, 12)
    beam_vec = np.matrix([[ccd1_offsetx], [ccd1_offsety]])
    print("initial beam vector:")
    print(beam_vec)
    
    #var_vec
    inv_beamline = np.linalg.inv(one_mirror(45,0,400))
    vec = np.matrix([[0], [0], [0], [0], [1]])
    var_vec = np.matmul(inv_beamline, 0.5*beam_vec) 
    print("print initial variation vector:")
    print(np.rad2deg(var_vec))
    ##feed them into system 
    
    t_varx, t_vary = np.rad2deg(var_vec.item(0)),np.rad2deg(var_vec.item(1))
    
    no_decenter_sys = lens_dec_matrix(201.654, 200,200,200,45,0,90,t_varx,t_vary,0,0)*vec
    print(no_decenter_sys)
    
    link.zSetSurfaceParameter(5, 3, -float(t_varx)) #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(5, 4, -float(t_vary))
    link.zSetSurfaceParameter(5, 5, 0)

    link.zSetSurfaceParameter(7, 3, float(t_varx)) #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(7, 4, float(t_vary))
    link.zSetSurfaceParameter(7, 5, 0)
    link.zSaveFile(file)  
    
    vec = np.matrix([[0], [0], [0], [0], [1]])
    vec_nodec = lens_no_errors_matrix(201.654, 200, 200,200,45,0,90,-t_varx, -t_vary)
    no_lens_dec_vec = np.matmul(vec_nodec,vec)
    diff_x = no_lens_dec_vec[0] - beam_vec[0]
    diff_y = no_lens_dec_vec[1] - beam_vec[1]
    print("ray tracing expected xy positions (with lens but not decentered):")
    print(no_lens_dec_vec[0], no_lens_dec_vec[1])
    print("decentering first estimation:")
    print(diff_x, diff_y)
    
    link.zSetSurfaceParameter(17, 1, -float(diff_x)) #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(20, 1, float(diff_x))
    link.zSetSurfaceParameter(17, 2, -float(diff_y)) #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(20, 2, float(diff_y))
    link.zSaveFile(file)
    
    ccd1_offsetx = link.zOperandValue('POPD', 26, 1, 0, 11)
    ccd1_offsety = link.zOperandValue('POPD', 26, 1, 0, 12)
    beam_vec = np.matrix([[ccd1_offsetx], [ccd1_offsety]])
    print("adjusting with decentering and variations (first fix) beam vector:")
    print(beam_vec)

    status = "not done"
    
  
    #extract current variations 
    var_vec = np.matmul(inv_beamline, .5*beam_vec) 
    print("print initial variation vector:")
    print(np.rad2deg(var_vec))
    
    #feed projected dx dy into system with decentering 
    tvx, tvy = np.rad2deg(var_vec[0]),np.rad2deg(var_vec[1])
    lens_d_m = lens_dec_matrix(200,200,200,200,45,0,90,tvx,tvy,diff_x,diff_y)
    lens_d_vec = lens_d_m*vec
    print("projected lens d vec")
    print(lens_d_vec)
    corr_x = lens_d_vec[0] + diff_x
    corr_y = lens_d_vec[1] + diff_y

    ccd1_offsetx = link.zOperandValue('POPD', 26, 1, 0, 11)
    ccd1_offsety = link.zOperandValue('POPD', 26, 1, 0, 12)
    beam_vec = np.matrix([[ccd1_offsetx], [ccd1_offsety]])
    print("adjusting with decentering and variations (first fix) beam vector:")
    print(beam_vec)
    """
    pyz.closeLink()
コード例 #27
0
ファイル: f-method1.py プロジェクト: shuaixue/slacecodes
def config_simulation(file, chief_angle1_x, chief_angle1_y, chief_angle1_z):
    link = pyz.createLink()
    link.zLoadFile(file)
    link.zSetWave(1, .800, 1)
    setfile = link.zGetFile().lower().replace('.zmx', '.CFG')
    S_512 = 5
    grid_size = 20
    GAUSS_WAIST, WAIST_X, WAIST_Y, DECENTER_X, DECENTER_Y = 0, 1, 2, 3, 4
    beam_waist, x_off, y_off = 5, 0, 0
    cfgfile = link.zSetPOPSettings('irr',
                                   setfile,
                                   startSurf=2,
                                   endSurf=2,
                                   field=1,
                                   wave=1,
                                   beamType=GAUSS_WAIST,
                                   paramN=((WAIST_X, WAIST_Y, DECENTER_X,
                                            DECENTER_Y),
                                           (beam_waist, beam_waist, x_off,
                                            y_off)),
                                   sampx=S_512,
                                   sampy=S_512,
                                   widex=grid_size,
                                   widey=grid_size,
                                   tPow=1,
                                   auto=0,
                                   ignPol=1)
    link.zModifyPOPSettings(cfgfile, endSurf=26)
    link.zModifyPOPSettings(cfgfile, paramN=((1, 2, 3, 4), (5, 5, 0, 0)))
    link.zModifyPOPSettings(cfgfile, widex=grid_size)
    link.zModifyPOPSettings(cfgfile, widey=grid_size)
    link.zModifyPOPSettings(cfgfile, ignPol=1)
    #1 to ignore pol;0 to use
    link.zSaveFile(file)
    link.zSetSurfaceParameter(3, 3, chief_angle1_x)
    link.zSetSurfaceParameter(3, 4, chief_angle1_y)
    link.zSetSurfaceParameter(3, 5, chief_angle1_z)

    link.zSetSurfaceParameter(9, 3, chief_angle1_x)
    link.zSetSurfaceParameter(9, 4, chief_angle1_y)
    link.zSetSurfaceParameter(9, 5, chief_angle1_z)

    #fix lens decentering too
    link.zSetSurfaceParameter(16, 1, 0)  #decenter x,y : 1,2
    link.zSetSurfaceParameter(21, 1, 0)
    link.zSetSurfaceParameter(16, 2, 0)  #decenter x,y : 1,2
    link.zSetSurfaceParameter(21, 2, 0)

    link.zSetSurfaceParameter(17, 1, 0)  #decenter x,y : 1,2
    link.zSetSurfaceParameter(20, 1, 0)
    link.zSetSurfaceParameter(17, 2, 0)  #decenter x,y : 1,2
    link.zSetSurfaceParameter(20, 2, 0)
    #link.zSetSurfaceParameter(3,5, chief_angle1_z)
    link.zSaveFile(file)

    #var
    link.zSetSurfaceParameter(4, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(4, 4, 0)
    link.zSetSurfaceParameter(4, 5, 0)

    link.zSetSurfaceParameter(8, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(8, 4, 0)
    link.zSetSurfaceParameter(8, 5, 0)

    #####
    #fix
    link.zSetSurfaceParameter(5, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(5, 4, 0)
    link.zSetSurfaceParameter(5, 5, 0)

    link.zSetSurfaceParameter(7, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(7, 4, 0)
    link.zSetSurfaceParameter(7, 5, 0)
    link.zSaveFile(file)
    n_ccd1_offsetx = link.zOperandValue('POPD', 26, 1, 0, 11)
    n_ccd1_offsety = link.zOperandValue('POPD', 26, 1, 0, 12)
    print(n_ccd1_offsetx, n_ccd1_offsety)
    img_str = str(
        r'C:\Users\pwfa-facet2\Desktop\slacecodes\raytracing\img-norm.csv')
    print(img_str)
    link.zGetTextFile(textFileName=img_str, analysisType='Pop')
    pyz.closeLink()
    print('config set for testing!')
コード例 #28
0
    link.zSetSurfaceParameter(23, 4, pred_alpha2y)
    link.zSaveFile(file)

    ccd1_offsetx_fix = link.zOperandValue('POPD', 30, 1, 0, 11)
    ccd1_offsety_fix = link.zOperandValue('POPD', 30, 1, 0, 12)

    ccd2_offsetx_fix = link.zOperandValue('POPD', 32, 1, 0, 11)
    ccd2_offsety_fix = link.zOperandValue('POPD', 32, 1, 0, 12)

    ccd1x_fix.append(ccd1_offsetx_fix)
    ccd1y_fix.append(ccd1_offsety_fix)
    ccd2x_fix.append(ccd2_offsetx_fix)
    ccd2y_fix.append(ccd2_offsety_fix)
    print("fix pos:")
    print(ccd1_offsetx_fix, ccd1_offsety_fix, ccd2_offsetx_fix,
          ccd2_offsety_fix)

pyz.closeLink()

np.savetxt(
    'vardata-f-t1.csv',
    list(
        zip(exp_run_arr, alpha1x_arr, alpha1y_arr, alpha2x_arr, alpha2y_arr,
            beamx_offset, beamy_offset, ccd2_beamx_offset, ccd2_beamy_offset)))
np.savetxt(
    'fixdata-f-t1.csv',
    list(
        zip(exp_run_arr, pred_alpha1x_arr, pred_alpha1y_arr, pred_alpha2x_arr,
            pred_alpha2y_arr, ccd1x_fix, ccd1y_fix, ccd2x_fix, ccd2y_fix)))
print("done with code!")
コード例 #29
0
def go(args, cfg):
    zmx_link = pyz.createLink()
    zcontroller = Controller(zmx_link)

    print "Loading file " + cfg['GENERAL']['zmx_file']
    zcontroller.loadZemaxFile(cfg['GENERAL']['zmx_file'])

    # Label all lens surfaces with comments for easier identification.
    print "Adding surface comments."
    for lens in cfg['LENSES']:
        for surf in range(lens['start_surface_number'],
                          lens['end_surface_number'] + 1):
            zcontroller.setSurfaceComment(int(surf),
                                          str(lens['label']),
                                          append=True)

    # Set variable solves for detector, if requested.
    #
    # distance
    if cfg['SYSTEM']['variable_detector_surface_distance']:
        print "Setting detector distance as variable."
        zcontroller.setSurfaceThicknessSolveVariable(
            cfg['SYSTEM']['detector_surface_number'])

    # decentre
    if cfg['SYSTEM']['variable_detector_surface_decentre']:
        print "Setting detector decentre as variable."
        zcontroller.setSolveCoordBreakDecentres(
            cfg['SYSTEM']['detector_surface_number'], solve_type=1)

    # tilt
    if cfg['SYSTEM']['variable_detector_surface_tilt']:
        print "Setting detector tilt as variable."
        zcontroller.setSolveCoordBreakTilts(
            cfg['SYSTEM']['detector_surface_number'], solve_type=1)

    # Add tilts and decentres.
    #
    # Need to keep track of the first coordinate break surfaces and dummy surface
    # numbers.
    # The former contains information pertaining to the tilts and decentres, the
    # latter the air gap spacing.
    #

    # First make sure that the lenses in the config file are in monotonically
    # increasing order.
    #
    lenses = {}
    for lens in cfg['LENSES']:
        lenses[lens['label']] = int(lens['start_surface_number'])
    lenses_sorted = sorted(lenses, key=lenses.get)

    # Now add the required surfaces.
    #
    offset = 0  # how much we need to offset the surface number
    coordinate_break_surface_numbers = {}  # tilts, decentres
    dummy_surface_numbers = {}  # air gaps
    print "Adding coordinate breaks."
    for lens in lenses_sorted:
        this_lens_entry = lookUpLensEntryFromConfig(cfg, lens)
        start_surface_number = this_lens_entry['start_surface_number'] + offset
        end_surface_number = this_lens_entry['end_surface_number'] + offset
        label = str(this_lens_entry['label'])
        z_pivot = float(this_lens_entry['z_pivot'])

        # Initialise the relevant tilt/decentre coordinate breaks
        #
        # cb1 = coord changing surface number,
        # cb2 = return surface number (PICKUP),
        # dummy = air gap surface number.
        #
        cb1, cb2, dummy = zcontroller.addTiltAndDecentreAboutPivot(
            start_surface_number,
            end_surface_number,
            z_pivot,
            x_c=0.,
            y_c=0.,
            x_tilt=0.,
            y_tilt=0.)
        coordinate_break_surface_numbers[label] = int(cb1)
        dummy_surface_numbers[label] = int(dummy)
        offset = offset + 3 + (end_surface_number - start_surface_number)

    # Set variable solves for lenses, if requested.
    #
    # air gaps
    if cfg['SYSTEM']['variable_air_gaps']:
        print "Setting air gaps as variable."
        for k, v in dummy_surface_numbers.iteritems():
            zcontroller.setSurfaceThicknessSolveVariable(v)

    # decentres
    if cfg['SYSTEM']['variable_lens_decentres']:
        print "Setting lens decentres as variable."
        for k, v in coordinate_break_surface_numbers.iteritems():
            zcontroller.setSolveCoordBreakDecentres(v, solve_type=1)
    # tilts
    if cfg['SYSTEM']['variable_lens_tilts']:
        print "Setting lens tilts as variable."
        for k, v in coordinate_break_surface_numbers.iteritems():
            zcontroller.setSolveCoordBreakTilts(v, solve_type=1)

    # Next we make the Merit Functions, if requested. If not, the existing merit
    # functions at the predefined locations below will be used.
    #
    MF = MeritFunction(zmx_link, zcontroller, cfg['GENERAL']['zpl_path'],
                       cfg['GENERAL']['zpl_filename'])
    if args.o == 'SPOT':
        print "Creating merit function for optimising SPOT SIZE."
        MF.createDefaultMF()  # optimise for SPOT SIZE
    elif args.o == 'WAVE':
        print "Creating merit function for optimising WAVEFRONT."
        MF.createDefaultMF(data=0)  # optimise for WAVEFRONT
    else:
        raise goErrorException("Couldn't recognise optimiser argument.", 1)

    # Delete the air gap comment, add new constraints and save it.
    ins_row_number = MF.getRowNumberFromMFContents(
        'BLNK', 'No air or glass \
                                                 constraints.')
    MF.delMFOperand(ins_row_number)
    print "Setting air gap constraints."
    for lens in cfg['LENSES']:
        MF.setAirGapConstraints(ins_row_number,
                                dummy_surface_numbers[lens['label']],
                                lens['min_air_gap'], lens['max_air_gap'])

    # Finally, we can go through the various combinations of tilts/decentres and
    # optimise (optional) and evaluate the MF for each.
    #
    # First step of this process is to get all possible combinations of the
    # lenses in the barrel
    #
    lens_configurations = []
    n_lenses = 0
    for lens in cfg['LENSES']:
        n_lenses += 1
        for data in lens['data']:
            lens_configurations.append(
                str(lens['label']) + '_' + str(data['mount_position']))
    all_mount_combinations = [
        x for x in itertools.combinations(lens_configurations, n_lenses)
    ]

    # Then we remove entries where a lens has been used more than once
    #
    all_mount_combinations_nodup = []
    for comb in all_mount_combinations:
        counter = collections.Counter([entry.split('_')[0] for entry in comb])
        if counter.most_common(1)[0][1] == 1:
            all_mount_combinations_nodup.append(comb)

    # And optimise/evaluate the MF for each.
    #
    print "Beginning optimisation/evaluation of merit functions."
    mf_values = []
    combinations = []
    for index, combination in enumerate(all_mount_combinations_nodup):
        for entry in combination:
            lens = entry.split('_')[0]
            mount_position = entry.split('_')[1]
            x_dc, y_dc, x_tilt, y_tilt = lookUpLensAxisDataFromConfig(
                cfg, lens, mount_position)

            # Set the corresponding decentres and tilts, if requested.
            if cfg['SYSTEM']['use_decentres']:
                zcontroller.setCoordBreakDecentreX(
                    coordinate_break_surface_numbers[lens], x_dc)
                zcontroller.setCoordBreakDecentreY(
                    coordinate_break_surface_numbers[lens], y_dc)
            if cfg['SYSTEM']['use_tilts']:
                zcontroller.setCoordBreakTiltX(
                    coordinate_break_surface_numbers[lens], x_tilt)
                zcontroller.setCoordBreakTiltY(
                    coordinate_break_surface_numbers[lens], y_tilt)

        zcontroller.DDEToLDE()
        mf_value = zcontroller.doOptimise(nCycles=args.n)
        mf_values.append(mf_value)
        combinations.append(combination)

        print "Combination number:\t" + str(index)
        print "Combination:\t\t" + ', '.join(combination)
        print "MF value:\t\t" + str(round(mf_value, 4))
        print

    best_mf_index = np.argmin([i for i in mf_values if i > 0])
    print "Best merit function index:\t" + str(best_mf_index)
    print "Best merit function value:\t" + str(mf_values[best_mf_index])
    print "Best combination:\t\t" + ', '.join(combinations[best_mf_index])

    worst_mf_index = np.argmax([i for i in mf_values if i > 0])
    print "Worst merit function index:\t" + str(worst_mf_index)
    print "Worst merit function value:\t" + str(mf_values[worst_mf_index])
    print "Worst combination:\t\t" + ', '.join(combinations[worst_mf_index])

    if args.p:
        plt.plot(mf_values, 'kx')
        plt.xlabel("Iteration number")
        plt.ylabel("MF value")
        plt.show()

    # Update the LDE with the worst configuration, and save
    for configuration in all_mount_combinations_nodup[worst_mf_index]:
        lens = configuration.split('_')[0]
        mount_position = configuration.split('_')[1]
        x_dc, y_dc, x_tilt, y_tilt = lookUpLensAxisDataFromConfig(
            cfg, lens, mount_position)

        if cfg['SYSTEM']['use_decentres']:
            zcontroller.setCoordBreakDecentreX(
                coordinate_break_surface_numbers[lens], x_dc)
            zcontroller.setCoordBreakDecentreY(
                coordinate_break_surface_numbers[lens], y_dc)
        if cfg['SYSTEM']['use_tilts']:
            zcontroller.setCoordBreakTiltX(
                coordinate_break_surface_numbers[lens], x_tilt)
            zcontroller.setCoordBreakTiltY(
                coordinate_break_surface_numbers[lens], y_tilt)
    zcontroller.DDEToLDE()
    zcontroller.doOptimise(nCycles=args.n)
    zcontroller.saveZemaxFile(os.getcwd() + "\\" + "WORST.zmx")

    # Update the LDE with the best configuration, and saavce
    for configuration in all_mount_combinations_nodup[best_mf_index]:
        lens = configuration.split('_')[0]
        mount_position = configuration.split('_')[1]
        x_dc, y_dc, x_tilt, y_tilt = lookUpLensAxisDataFromConfig(
            cfg, lens, mount_position)

        if cfg['SYSTEM']['use_decentres']:
            zcontroller.setCoordBreakDecentreX(
                coordinate_break_surface_numbers[lens], x_dc)
            zcontroller.setCoordBreakDecentreY(
                coordinate_break_surface_numbers[lens], y_dc)
        if cfg['SYSTEM']['use_tilts']:
            zcontroller.setCoordBreakTiltX(
                coordinate_break_surface_numbers[lens], x_tilt)
            zcontroller.setCoordBreakTiltY(
                coordinate_break_surface_numbers[lens], y_tilt)
    zcontroller.DDEToLDE()
    zcontroller.doOptimise(nCycles=args.n)
    zcontroller.saveZemaxFile(os.getcwd() + "\\" + "BEST.zmx")

    pyz.closeLink()
コード例 #30
0
ファイル: test-lim.py プロジェクト: shuaixue/slacecodes
def config_simulation(file, chief_angle1_x, chief_angle1_y, chief_angle1_z,
                      chief_angle2_x, chief_angle2_y, chief_angle2_z):
    link = pyz.createLink()
    link.zLoadFile(file)

    setfile = link.zGetFile().lower().replace('.zmx', '.CFG')
    S_512 = 5
    grid_size = 20
    GAUSS_WAIST, WAIST_X, WAIST_Y, DECENTER_X, DECENTER_Y = 0, 1, 2, 3, 4
    beam_waist, x_off, y_off = 5, 0, 0
    cfgfile = link.zSetPOPSettings('irr',
                                   setfile,
                                   startSurf=2,
                                   endSurf=2,
                                   field=1,
                                   wave=1,
                                   beamType=GAUSS_WAIST,
                                   paramN=((WAIST_X, WAIST_Y, DECENTER_X,
                                            DECENTER_Y),
                                           (beam_waist, beam_waist, x_off,
                                            y_off)),
                                   sampx=S_512,
                                   sampy=S_512,
                                   widex=grid_size,
                                   widey=grid_size,
                                   tPow=1,
                                   auto=0,
                                   ignPol=1)
    link.zModifyPOPSettings(cfgfile, endSurf=24)
    link.zModifyPOPSettings(cfgfile, paramN=((1, 2, 3, 4), (5, 5, 0, 0)))
    link.zModifyPOPSettings(cfgfile, widex=grid_size)
    link.zModifyPOPSettings(cfgfile, widey=grid_size)
    link.zModifyPOPSettings(cfgfile, ignPol=1)
    #1 to ignore pol;0 to use
    link.zSaveFile(file)
    link.zSetSurfaceParameter(3, 3, chief_angle1_x)
    link.zSetSurfaceParameter(3, 4, chief_angle1_y)
    link.zSetSurfaceParameter(3, 5, chief_angle1_z)

    link.zSetSurfaceParameter(9, 3, chief_angle1_x)
    link.zSetSurfaceParameter(9, 4, chief_angle1_y)
    link.zSetSurfaceParameter(9, 5, chief_angle1_z)

    link.zSetSurfaceParameter(19, 3, chief_angle2_x)
    link.zSetSurfaceParameter(19, 4, chief_angle2_y)
    link.zSetSurfaceParameter(19, 5, chief_angle2_z)

    link.zSetSurfaceParameter(25, 3, chief_angle2_x)
    link.zSetSurfaceParameter(25, 4, chief_angle2_y)
    link.zSetSurfaceParameter(25, 5, chief_angle2_z)

    #fix var/pos empty
    link.zSaveFile(file)

    #var
    link.zSetSurfaceParameter(4, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(4, 4, 0)
    link.zSetSurfaceParameter(4, 5, 0)

    link.zSetSurfaceParameter(8, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(8, 4, 0)
    link.zSetSurfaceParameter(8, 5, 0)

    #####
    #fix
    link.zSetSurfaceParameter(5, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(5, 4, 0)
    link.zSetSurfaceParameter(5, 5, 0)

    link.zSetSurfaceParameter(7, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(7, 4, 0)
    link.zSetSurfaceParameter(7, 5, 0)

    #####

    link.zSetSurfaceParameter(20, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(20, 4, 0)
    link.zSetSurfaceParameter(20, 5, 0)

    link.zSetSurfaceParameter(24, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(24, 4, 0)
    link.zSetSurfaceParameter(24, 5, 0)

    #####
    link.zSetSurfaceParameter(21, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(21, 4, 0)
    link.zSetSurfaceParameter(21, 5, 0)

    link.zSetSurfaceParameter(23, 3, 0)  #3 = x-tilt, 4=y-tilt
    link.zSetSurfaceParameter(23, 4, 0)
    link.zSetSurfaceParameter(23, 5, 0)

    link.zSaveFile(file)
    pyz.closeLink()
    print('config set for testing!')
コード例 #31
0
def standard_variation(low_var, high_var, delta):
    deg_range = np.arange(low_var, high_var + delta, delta)

    link = pyz.createLink()
    link.zLoadFile(file)

    setfile = link.zGetFile().lower().replace('.zmx', '.CFG')
    S_512 = 5
    grid_size = 20
    GAUSS_WAIST, WAIST_X, WAIST_Y, DECENTER_X, DECENTER_Y = 0, 1, 2, 3, 4
    beam_waist, x_off, y_off = 5, 0, 0
    cfgfile = link.zSetPOPSettings('irr',
                                   setfile,
                                   startSurf=2,
                                   endSurf=2,
                                   field=1,
                                   wave=1,
                                   beamType=GAUSS_WAIST,
                                   paramN=((WAIST_X, WAIST_Y, DECENTER_X,
                                            DECENTER_Y),
                                           (beam_waist, beam_waist, x_off,
                                            y_off)),
                                   sampx=S_512,
                                   sampy=S_512,
                                   widex=grid_size,
                                   widey=grid_size,
                                   tPow=1,
                                   auto=0,
                                   ignPol=1)
    link.zModifyPOPSettings(cfgfile, endSurf=24)
    link.zModifyPOPSettings(cfgfile, paramN=((1, 2, 3, 4), (5, 5, 0, 0)))
    link.zModifyPOPSettings(cfgfile, widex=grid_size)
    link.zModifyPOPSettings(cfgfile, widey=grid_size)
    link.zModifyPOPSettings(cfgfile, ignPol=1)
    #1 to ignore pol;0 to use
    link.zSaveFile(file)
    #add variations
    beforem1_x = []
    beforem1_y = []

    ccd1xarr = []
    ccd1yarr = []

    ccd2xarr = []
    ccd2yarr = []

    for i in deg_range:
        link.zSetSurfaceParameter(4, 3, i)  #3 = x-tilt, 4=y-tilt
        link.zSetSurfaceParameter(4, 4, i)
        link.zSetSurfaceParameter(4, 5, 0)

        link.zSetSurfaceParameter(8, 3, -i)  #3 = x-tilt, 4=y-tilt
        link.zSetSurfaceParameter(8, 4, -i)
        link.zSetSurfaceParameter(8, 5, 0)

        link.zSetSurfaceParameter(20, 3, i)  #3 = x-tilt, 4=y-tilt
        link.zSetSurfaceParameter(20, 4, i)
        link.zSetSurfaceParameter(20, 5, 0)

        link.zSetSurfaceParameter(24, 3, -i)  #3 = x-tilt, 4=y-tilt
        link.zSetSurfaceParameter(24, 4, -i)
        link.zSetSurfaceParameter(24, 5, 0)
        link.zSaveFile(file)
        #get offsets
        t_ccdx = link.zOperandValue('POPD', 17, 1, 0, 11)
        t_ccdy = link.zOperandValue('POPD', 17, 1, 0, 12)

        ccd1_offsetx = link.zOperandValue('POPD', 30, 1, 0, 11)
        ccd1_offsety = link.zOperandValue('POPD', 30, 1, 0, 12)

        ccd2_x = link.zOperandValue('POPD', 32, 1, 0, 11)
        ccd2_y = link.zOperandValue('POPD', 32, 1, 0, 12)

        beforem1_x.append(t_ccdx)
        beforem1_y.append(t_ccdy)
        ccd1xarr.append(ccd1_offsetx)
        ccd1yarr.append(ccd1_offsety)
        ccd2xarr.append(ccd2_x)
        ccd2yarr.append(ccd2_y)
    pyz.closeLink()
    np.savetxt(
        str(r"C:\Users\pwfa-facet2\Desktop\slacecodes\raytracing\\") +
        "m1m2-" + str(low_var) + "-" + str(high_var) + "-" + str(delta) +
        '.csv',
        list(
            zip(deg_range, beforem1_x, beforem1_y, ccd1xarr, ccd1yarr,
                ccd2xarr, ccd2yarr)))
    print("done")