Esempio n. 1
0
def set_start_vars_fix(file):
    link = pyz.createLink()
    link.zLoadFile(file)
    surface_control_xvar(file, 3, 0)
    surface_control_yvar(file, 3, 0)
    surface_control_xcorr(file, 4, 0)
    surface_control_ycorr(file, 4, 0)

    surface_control_xvar(file, 15, 0)
    surface_control_yvar(file, 15, 0)
    surface_control_xcorr(file, 16, 0)
    surface_control_ycorr(file, 16, 0)

    surface_control_xvar(file, 27, 0)
    surface_control_yvar(file, 27, 0)
    surface_control_xcorr(file, 28, 0)
    surface_control_ycorr(file, 28, 0)

    surface_control_xvar(file, 36, 0)
    surface_control_yvar(file, 36, 0)
    surface_control_xcorr(file, 37, 0)
    surface_control_ycorr(file, 37, 0)

    surface_control_xvar(file, 48, 0)
    surface_control_yvar(file, 48, 0)
    surface_control_xcorr(file, 49, 0)
    surface_control_ycorr(file, 49, 0)

    surface_control_xvar(file, 57, 0)
    surface_control_yvar(file, 57, 0)
    surface_control_xcorr(file, 58, 0)
    surface_control_ycorr(file, 58, 0)
Esempio n. 2
0
def trace_rays():
    ln = pyz.createLink()
    filename = os.path.join(ln.zGetPath()[1], 'Sequential', 'Objectives', 
                            'Cooke 40 degree field.zmx')
    ln.zLoadFile(filename)
    print("Loaded zemax file:", ln.zGetFile())
    ln.zGetUpdate()   # In general this should be done ...
    if not ln.zPushLensPermission():
        print("\nERROR: Extensions not allowed to push lenses. Please enable in Zemax.")
        ln.close()
        sys.exit(0)
    ln.zPushLens(1)   # FOR SOME REASON, THE ARRAY RAY TRACING SEEMS TO
                      # BE WORKING ON THE LENS THAT IS IN THE MAIN ZEMAX APPLICATION WINDOW!!!!
    ln.zNewLens()     # THIS IS JUST TO PROVE THE ABOVE POINT!!! RAY TRACING STILL ON THE LENS
                      # IN THE MAIN ZEMAX APPLICATION, EVENTHOUGH THE LENS IN THE DDE SERVER IS A "NEW LENS"
    numRays = 101**2    # 10201
    rd = at.getRayDataArray(numRays, tType=0, mode=0, endSurf=-1)
    radius = int(sqrt(numRays)/2)

    # Fill the rest of the ray data array
    k = 0
    for i in range(-radius, radius + 1, 1):
        for j in range(-radius, radius + 1, 1):
            k += 1
            rd[k].z = i/(2*radius)                   # px
            rd[k].l = j/(2*radius)                   # py
            rd[k].intensity = 1.0
            rd[k].wave = 1

    # Trace the rays
    ret = at.zArrayTrace(rd, timeout=5000)

    # Dump the ray trace data into a file
    outputfile = os.path.join(cd, "arrayTraceOutput.txt")
    if ret==0:
        k = 0
        with open(outputfile, 'w') as f:
            f.write("Listing of Array trace data\n")
            f.write("     px      py error            xout            yout"
                    "         l         m         n    opd    Exr     Exi"
                    "     Eyr     Eyi     Ezr     Ezi    trans\n")
            for i in range(-radius, radius + 1, 1):
                for j in range(-radius, radius + 1, 1):
                    k += 1
                    line = ("{:7.3f} {:7.3f} {:5d} {:15.6E} {:15.6E} {:9.5f} "
                            "{:9.5f} {:9.5f} {:7.3f} {:7.3f} {:7.3f} {:7.3f} "
                            "{:7.3f} {:7.3f} {:7.3f} {:7.4f}\n"
                            .format(i/(2*radius), j/(2*radius), rd[k].error,
                                    rd[k].x, rd[k].y, rd[k].l, rd[k].m, rd[k].n,
                                    rd[k].opd, rd[k].Exr, rd[k].Exi, rd[k].Eyr,
                                    rd[k].Eyi, rd[k].Ezr, rd[k].Ezi, rd[k].intensity))
                    f.write(line)
        print("Success")
        print("Ray trace data outputted to the file {}".format(outputfile))
    else:
        print("There was some problem in ray tracing")

    ln.zNewLens()
    ln.zPushLens()
    ln.close()
Esempio n. 3
0
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')
Esempio n. 4
0
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)
Esempio n. 5
0
def _plot_2D_layout_from_array_trace():
    "plot raypath through system using array trace" 
    import matplotlib.pylab as plt
    import pyzdde.zdde as pyz
    ln = pyz.createLink()
    # launch rays from same from off-axis field point
    # we create initial pos and dir using zGetTraceArray
    nRays=7;  
    startsurf= 1;  # in case of collimated input beam    
    lastsurf = ln.zGetNumSurf();
    hx,hy,px,py = 0, 0.5, 0, _np.linspace(-1,1,nRays);
    (_,_,pos,dir,_,_) = zGetTraceArray(hx,hy,px,py,bParaxial=False,surf=startsurf);    
    # trace ray until last surface
    points = _np.zeros((lastsurf+1,nRays,3));    # indexing: surf,ray,coord
    z0=0; points[startsurf]=pos;                # ray intersection points on starting surface
    for isurf in range(startsurf,lastsurf):
      # trace to next surface
      (error,vigcode,pos,dir,_,_)=zGetTraceDirectArray(pos,dir,bParaxial=False,startSurf=isurf,lastSurf=isurf+1);
      points[isurf+1]=pos;
      points[isurf+1,vigcode!=0]=_np.nan;        # remove vignetted rays
      # add thickness of current surface (assumes absence of tilts or decenters in system)      
      z0+=ln.zGetThickness(isurf);
      points[isurf+1,:,2]+=z0;
      print("  surface #%d at z-position z=%f" % (isurf+1,z0));
    # plot rays in y-z section
    plt.figure();
    x,y,z = points[startsurf:].T;
    ax=plt.subplot(111,aspect='equal')
    ax.plot(z.T,y.T,'.-')
    ln.close();      
Esempio n. 6
0
def trace_rays():
    ln = pyz.createLink()
    filename = os.path.join(ln.zGetPath()[1], 'Sequential', 'Objectives', 
                            'Cooke 40 degree field.zmx')
    ln.zLoadFile(filename)
    print("Loaded zemax file:", ln.zGetFile())
    ln.zGetUpdate()   # In general this should be done ...
    if not ln.zPushLensPermission():
        print("\nERROR: Extensions not allowed to push lenses. Please enable in Zemax.")
        ln.close()
        sys.exit(0)
    ln.zPushLens(1)   # FOR SOME REASON, THE ARRAY RAY TRACING SEEMS TO
                      # BE WORKING ON THE LENS THAT IS IN THE MAIN ZEMAX APPLICATION WINDOW!!!!
    ln.zNewLens()     # THIS IS JUST TO PROVE THE ABOVE POINT!!! RAY TRACING STILL ON THE LENS
                      # IN THE MAIN ZEMAX APPLICATION, EVENTHOUGH THE LENS IN THE DDE SERVER IS A "NEW LENS"
    numRays = 101**2    # 10201
    rd = at.getRayDataArray(numRays, tType=0, mode=0, endSurf=-1)
    radius = int(sqrt(numRays)/2)

    # Fill the rest of the ray data array
    k = 0
    for i in xrange(-radius, radius + 1, 1):
        for j in xrange(-radius, radius + 1, 1):
            k += 1
            rd[k].z = i/(2*radius)                   # px
            rd[k].l = j/(2*radius)                   # py
            rd[k].intensity = 1.0
            rd[k].wave = 1

    # Trace the rays
    ret = at.zArrayTrace(rd, timeout=5000)

    # Dump the ray trace data into a file
    outputfile = os.path.join(cd, "arrayTraceOutput.txt")
    if ret==0:
        k = 0
        with open(outputfile, 'w') as f:
            f.write("Listing of Array trace data\n")
            f.write("     px      py error            xout            yout"
                    "         l         m         n    opd    Exr     Exi"
                    "     Eyr     Eyi     Ezr     Ezi    trans\n")
            for i in xrange(-radius, radius + 1, 1):
                for j in xrange(-radius, radius + 1, 1):
                    k += 1
                    line = ("{:7.3f} {:7.3f} {:5d} {:15.6E} {:15.6E} {:9.5f} "
                            "{:9.5f} {:9.5f} {:7.3f} {:7.3f} {:7.3f} {:7.3f} "
                            "{:7.3f} {:7.3f} {:7.3f} {:7.4f}\n"
                            .format(i/(2*radius), j/(2*radius), rd[k].error,
                                    rd[k].x, rd[k].y, rd[k].l, rd[k].m, rd[k].n,
                                    rd[k].opd, rd[k].Exr, rd[k].Exi, rd[k].Eyr,
                                    rd[k].Eyi, rd[k].Ezr, rd[k].Ezi, rd[k].intensity))
                    f.write(line)
        print("Success")
        print("Ray trace data outputted to the file {}".format(outputfile))
    else:
        print("There was some problem in ray tracing")

    ln.zNewLens()
    ln.zPushLens()
    ln.close()
Esempio n. 7
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()
Esempio n. 8
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)
Esempio n. 9
0
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)
Esempio n. 10
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)
Esempio n. 11
0
    def save_n_transfer(self):
        #Save File
        '''Zemax Verbindung aufbauen'''
        self.link = pyz.createLink()

        #Check if in SC-Mode
        if not self.link._zGetMode()[0] == 0:
            self.link.close()
            QMessageBox.about(self, "Title",
                              "Function is not available in NSC-Mode.")
            return None

        time.sleep(1)
        print('saving started')
        success = self.link.zSaveFile(self.configDir + '/live' +
                                      '/lensfile.zmx')
        print('saving finished')
        time.sleep(1)

        self.link.close()
        if success == 0:
            print('SUCCES-File saved')
        else:
            print('ERROR-File not saved')
        self.Archive()
        #Transfer System to NSC-Group
        '''It is not supported by pyzdde to Convert from SC to NSC by Python-API'''
        '''The solution is to replace the user by a script.'''
        subprocess.call([
            "AHK\AutoHotkeyA32.exe", "Convert_to_NSGroup.ahk",
            self.configDir + '/live' + '/lens-NSC.zmx'
        ])
        time.sleep(10)

        self.set_ray_files()
Esempio n. 12
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()
Esempio n. 13
0
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!")
Esempio n. 14
0
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()
Esempio n. 15
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()
Esempio n. 16
0
    def save_detector_file(self):
        print('save detector file')
        #This function is a bit broken. It throws an error but still does it's job
        try:
            self.link = pyz.createLink()
            self.link.zGetDetectorViewer()
            self.link.close()
        except:
            self.link.close()
        time.sleep(4)
        print('Saving detectorFile finished')

        self.read_detector_power()
Esempio n. 17
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)
Esempio n. 18
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!')
Esempio n. 19
0
    def delete_old_merit(self):
        '''Zemax Verbindung aufbauen'''
        self.link = pyz.createLink()

        print('called deleteMFO')
        optimizer_row = ''
        for i in range(1, 300):
            comment = self.link.zGetOperand(row=i, column=2)
            if comment == 'OPTIMIZER':
                print('OPTIMIZER FOUND')
                print('row: ' + str(i))
                optimizer_row = i
                break

        optimizer_row_end = ''
        for j in range(1, 300):
            comment = self.link.zGetOperand(row=j, column=2)
            if comment == 'ENDOPTIMIZER':
                print('ENDOPTIMIZER FOUND')
                print('row_end: ' + str(j))
                optimizer_row_end = j
                break
        self.link.close()

        if (optimizer_row == '') or (optimizer_row_end == ''):
            print('OPTIMIZER row not found')
            QMessageBox.about(self, "Error", "'OPTIMIZER' row not found.")
            return
        elif (optimizer_row_end - optimizer_row) >= 2:
            self.link = pyz.createLink()
            self.link.zDeleteMFO(optimizer_row + 1)
            self.link.zPushLens()
            self.link.close()
            self.delete_old_merit()

        print('deleteMFO end')
        return
Esempio n. 20
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)
Esempio n. 21
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()
def set_up():
    """create dde link, and load lens into zemax, and push lens into
    zemax application (this is required for array ray tracing)
    """
    zmxfile = 'Cooke 40 degree field.zmx'
    ln = pyz.createLink()
    if not ln.zPushLensPermission():
        print("\nERROR: Extensions not allowed to push lenses. Please enable in Zemax.")
        ln.close()
        sys.exit(0)
    filename = os.path.join(ln.zGetPath()[1], "Sequential\Objectives", zmxfile)
    ln.zLoadFile(filename)
    ln.zGetUpdate()
    ln.zPushLens(1)
    return ln
Esempio n. 23
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=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")
Esempio n. 24
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)
Esempio n. 25
0
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)
Esempio n. 26
0
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))
    
    """
def set_up():
    """create dde link, and load lens into zemax, and push lens into
    zemax application (this is required for array ray tracing)
    """
    zmxfile = 'Cooke 40 degree field.zmx'
    ln = pyz.createLink()
    if not ln.zPushLensPermission():
        print(
            "\nERROR: Extensions not allowed to push lenses. Please enable in Zemax."
        )
        ln.close()
        sys.exit(0)
    filename = os.path.join(ln.zGetPath()[1], "Sequential\Objectives", zmxfile)
    ln.zLoadFile(filename)
    ln.zGetUpdate()
    ln.zPushLens(1)
    return ln
Esempio n. 28
0
def _plot_2D_layout_from_array_trace():
    "plot raypath through system using array trace"
    import matplotlib.pylab as plt
    import pyzdde.zdde as pyz
    ln = pyz.createLink()
    # launch rays from same from off-axis field point
    # we create initial pos and dir using zGetTraceArray
    nRays = 7
    startsurf = 1
    # in case of collimated input beam
    lastsurf = ln.zGetNumSurf()
    hx, hy, px, py = 0, 0.5, 0, _np.linspace(-1, 1, nRays)
    (_, _, pos, dir, _, _) = zGetTraceArray(hx,
                                            hy,
                                            px,
                                            py,
                                            bParaxial=False,
                                            surf=startsurf)
    # trace ray until last surface
    points = _np.zeros((lastsurf + 1, nRays, 3))
    # indexing: surf,ray,coord
    z0 = 0
    points[startsurf] = pos
    # ray intersection points on starting surface
    for isurf in range(startsurf, lastsurf):
        # trace to next surface
        (error, vigcode, pos, dir, _,
         _) = zGetTraceDirectArray(pos,
                                   dir,
                                   bParaxial=False,
                                   startSurf=isurf,
                                   lastSurf=isurf + 1)
        points[isurf + 1] = pos
        points[isurf + 1, vigcode != 0] = _np.nan
        # remove vignetted rays
        # add thickness of current surface (assumes absence of tilts or decenters in system)
        z0 += ln.zGetThickness(isurf)
        points[isurf + 1, :, 2] += z0
        print("  surface #%d at z-position z=%f" % (isurf + 1, z0))
    # plot rays in y-z section
    plt.figure()
    x, y, z = points[startsurf:].T
    ax = plt.subplot(111, aspect='equal')
    ax.plot(z.T, y.T, '.-')
    ln.close()
Esempio n. 29
0
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()
Esempio n. 30
0
def fix_mis(file):
    mirror_bl = fm_matrix(400, 45, 0, 90)
    lens_bl = fl_matrix(200, 200, 45,0, 900, 200)
    
    full_bl = mirror_bl + lens_bl
    var_pred = np.linalg.inv(full_bl);
    
    link = pyz.createLink()
    link.zLoadFile(file)
    #extract offsets:
    status = "not done"
    angle_fix_approx_arr=[]
    offset_correction_arr=[]
    ccd1x_arr =[]
    ccd1y_arr =[]

    curr_r=0
    print("current trial num (this is the initial must fix):",curr_r)
    ccd1_offsetx = link.zOperandValue('POPD', 26, 1, 0, 11)
    ccd1_offsety = link.zOperandValue('POPD', 26, 1, 0, 12)
    print("current beam vector")
    ccd1x_arr.append(ccd1_offsetx)
    ccd1y_arr.append(ccd1_offsety)
    beam_vec = np.matrix([ [ccd1_offsetx], [ccd1_offsety] ])
    
    #expected result from raytracing 

    
    variations_vec = (np.matmul(var_pred,beam_vec))
    print(np.rad2deg(variations_vec))
    
    varx, vary =variations_vec.item(0), variations_vec.item(1)
    theory_beamline = lens_no_errors_matrix(200,200,200,45,0,90,varx,vary)
    long_vec = np.matrix([ [0], [0],[0], [0], [1] ])
    expected_beam = np.matmul(theory_beamline, long_vec)
    print("expected beamline (no decenter):")
    print(expected_beam)
    print("diff with ccd:")
    diffx = -beam_vec.item(0) + expected_beam.item(0)
    diffy = -beam_vec.item(1) + expected_beam.item(1)
    print(diffx, diffy)
Esempio n. 31
0
    def ConvertCad(self):
        '''Zemax Verbindung aufbauen'''
        self.link = pyz.createLink()

        #Check if in SC-Mode
        if not self.link._zGetMode()[0] == 1:
            self.link.close()
            QMessageBox.about(self, "Title",
                              "Function is only available in NSC-Mode.")
            return None
        '''Save current NSC-Model'''
        time.sleep(0.5)
        success = self.link.zSaveFile(self.configDir + '/live' +
                                      '/lens-NSC.zmx')
        time.sleep(0.5)
        self.link.close()

        if success == 0:
            print('SUCCES-File saved')
        else:
            print('ERROR-File not saved')
        '''Execute userfunction. Saves Step-file in Live folder'''
        '''Win 7 and Win 10 have a different Save Dialoge. One more Tab is needed'''
        if platform.release() == '7':
            subprocess.call([
                "AHK\AutoHotkeyA32.exe", "Export_to_CAD_7.ahk",
                self.configDir + '/live/', 'lens-STEP.stp'
            ])
        elif platform.release() == '10':
            subprocess.call([
                "AHK\AutoHotkeyA32.exe", "Export_to_CAD_10.ahk",
                self.configDir + '/live/', 'lens-STEP.stp'
            ])
        else:
            QMessageBox.about(self, "Error", "OS not supported.")

        self.getInventorExec()
        subprocess.Popen(
            [self.InventorPath, self.configDir + '/live' + '/lens-STEP.stp'])
Esempio n. 32
0
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)))
Esempio n. 33
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)
Esempio n. 34
0
#-------------------------------------------------------------------------------
# Name:      plotSpiralSpot.py
# Purpose:   Example of using the "spiral spot" covenience function of pyZDDE.
#
# NOTE:      Please note that this code uses matplotlib plotting library from
#            http://matplotlib.org/ for 2D-plotting
#
# Copyright: (c) 2012- 2014
# Licence:   MIT License
#-------------------------------------------------------------------------------
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)
Esempio n. 35
0
 def __enter__(self):
   " initialize DDE connection to Zemax "
   self.link = pyz.createLink()
   if self.link is None:
     raise RuntimeError("Zemax DDE link could not be established.");
   return self;
Esempio n. 36
0
#-------------------------------------------------------------------------------
from __future__ import print_function
import sys
import traceback

#****************** Add PyZDDE to Python search path **************************

PyZDDEPath = 'C:\PyZDDE'  # Assuming PyZDDE unzipped here; if not, change the path 
                          # appropriately

if PyZDDEPath not in sys.path:
    sys.path.append(PyZDDEPath)
#******************************************************************************

import pyzdde.zdde as pyz

# Create a DDE link object
link = pyz.createLink()
try:
    # Write your code to interact with Zemax, for example
    zemaxVer = link.zGetVersion()
    print("Zemax version: ", zemaxVer)



except Exception, err:
    traceback.print_exc()
finally:
    #Close DDE link
    link.zDDEClose()