Пример #1
0
def main():
    peak = t.getFloat("Peak")
    width = t.getFloat("Width")

    sp = w.GaussianSpectrum(peak,width,5.0)
    sp.draw()
    plt.show()
Пример #2
0
def main():
    
    #        Get lens from database, get iris ration and set it
    lens = l.DataBaseLens()
    ratio = t.getFloat("Aperture Ratio",1.0)
    lens.setIris(ratio)
    
    #         Get angle and wavelength
    angle = math.radians(t.getFloat("Angle",0.0))
    wave = t.getFloat("Wavelength",0.55)
    design = 0.55         # Hard code design wavelength
    
    # set up wavefront analysis
    wa = a.WaveFrontAnalysis(lens,design)
    
    # do a 4th order Zernike fit with Collated lens 
    ze = wa.fitZernike(angle,wave,4,0)
    t.tprint("Reference point is : ",wa.refpt)
    
    t.tprint(repr(ze))

    #    Plot zernike as interfometer plot with tilt of 2 fringes
    inter = a.Interferometer(ze)
    inter.draw()
    plt.show()
Пример #3
0
def main():

    lens = len.DataBaseLens()
    print("Focal length is " + str(lens.focalLength()))

    mag = tio.getFloat("Magnification",-0.1)
    osize = tio.getFloat("Input plane size in mm",200)

    obj = an.OpticalImage(0.0,osize,osize,200,200).addTestGrid()

    print(repr(obj))

    startTime = time.clock()          # Start timer

    image = obj.getImage(lens,mag)


    print(repr(image))

    deltaTime = time.clock() - startTime # fine CPU time
    
    print("Time was  {0:6.2f} CPU seconds".format(deltaTime))

    image.draw()
    plt.grid()
    plt.show()
Пример #4
0
def main():

    l0 = tio.getFloat("Lambda_0", 0.08)
    beta = tio.getFloat("Beta", 1.25)
    index = w.Sellmeier(beta, l0)

    nd = index.getNd()
    vd = index.getVd()
    tio.tprint("Nd index : ", nd, " Abbe No: ", vd)

    index.draw()
    plt.show()
Пример #5
0
def main():
    xstart = t.getFloat("x start", 1.0)
    xend = t.getFloat("x end", 10.0)
    n = t.getInt("number", 100)

    a = t.getFloat("gradient", 0.5)
    b = t.getFloat("intercept", 1.5)
    sd = t.getFloat("sd", 0.0)

    x = np.linspace(xstart, xend, n)
    y = linear(x, a, b)
    y = np.random.normal(y, sd)
    e = np.full(x.size, sd)

    f.writeCSV(t.getFilename("File", "txt"), [x, y, e])
Пример #6
0
def main():

    lens = len.DataBaseLens()
    #SimpleSinglet(0.0,100.0,12.5,"planoconvex")

    #cp = lens.cardinalPoints()
    #fl = lens.focalLength()

    #knife = sur.KnifeEdgeAperture(cp[1],10.0,-0.01)
    #output = sur.ImagePlane(cp[1] + vector.Vector3d(0,0,fl),30,30)

    #xsize  = 3.0*lens.entranceAperture().maxRadius

    angle = tio.getFloat("Angle in degrees")

    output = anal.knifeEdgeTest(lens,math.radians(angle),0.0)
    #u = vector.Unit3d(vector.Angle(math.radians(angle)))
    #output = anal.OpticalImage(cp[3].propagate(2*fl,u),xsize,xsize)

    #pencil = ray.RayPencil().addCollimatedBeam(lens,u,"array",50)
    #.addMonitor(ray.RayPath())

    #pencil *= lens
    #psf = anal.Psf().optimalArea(pencil,cp[1].z)
    #knife = sur.KnifeEdgeAperture(psf,10.0,0.0,math.radians(0))
    #pencil *= knife
    #pencil *= output

    #lens.draw()
    #knife.draw()
    #pencil.draw()
    output.draw()
    plt.show()
Пример #7
0
def main():

    sampleLength = tio.getFloat("Sample length", 0.1)
    outFile = tio.openFile("Output file", "w", "txt", "sample")
    outFile.write("#              Data for Checkpoint 3\n")
    outFile.write("#              Sampled at 25 kHz\n")
    outFile.write("#\n")

    tdata = []
    vdata = []
    cdata = []
    pdata = []

    t = 0.0
    while t < sampleLength:
        v = voltage(t)
        c = current(v)
        v = random.gauss(v, 0.1 * math.sqrt(v))
        c = random.gauss(c, 0.1 * math.sqrt(c))
        tdata.append(t)
        vdata.append(v)
        cdata.append(c)
        pdata.append(math.log(v * c))
        outFile.write(str(v) + " , " + str(c) + "\n")
        t += deltaT

    plt.plot(tdata, pdata)
    plt.show()
Пример #8
0
def main():

    #      get the paramters
    width = t.getFloat("Slit width", 0.1)
    separ = t.getFloat("Slit seperation", 0.4)
    peak = t.getFloat("Peak", 5.0)

    #       Form the data
    slits = TwoSlits(separ, width, distance, peak, wave)
    x_array = np.linspace(-5.0, 5.0, 500)
    y_array = slits.getArrayValues(x_array)

    #      Plot the output
    plt.plot(x_array, y_array)
    plt.ylim(0.0, 1.0)
    plt.title("Two Slits")
    plt.xlabel("X positition")
    plt.ylabel("Intensity")
    plt.show()
Пример #9
0
def main():

    # read in csv file and plot
    file = t.openFile("Data", "r", "txt")
    xpos, intensity = csv.readCSV(file)
    peak = (xpos[0] + xpos[-1]) / 2

    t.tprint("Number of data points : ", xpos.size)
    t.tprint("X range is : ", xpos[0], " to ", xpos[-1])

    width = t.getFloat("Slit width", 0.1)
    separ = t.getFloat("Slit seperation", 0.4)
    peak = t.getFloat("Peak", peak)
    pintensity = t.getFloat("Peak Intensity", 1.0)

    # Make a guess od the slits
    slits = FitSlits(separ, width, distance, peak, wave, pintensity, 0.0)

    #     Do a curve fit wit p0 v=being the initial giess
    popt,pcov = curve_fit(slits.line,xpos,intensity,\
                          p0=[slits.separ,slits.width,slits.peak,slits.intensity,slits.offset])
    perr = np.sqrt(np.diag(pcov))
    # print(popt)
    # print(perr)

    #      Print out the results
    t.tprint("Separation: {0:7.5f} +/- {1:7.5}".format(popt[0], perr[0]))
    t.tprint("Slit width: {0:7.5f} +/- {1:7.5}".format(popt[1], perr[1]))
    t.tprint("Peak centre: {0:7.5f} +/- {1:7.5}".format(popt[2], perr[2]))
    t.tprint("Peak intensity: {0:7.5f} +/- {1:7.5}".format(popt[3], perr[3]))
    t.tprint("Offset: {0:7.5f} +/- {1:7.5}".format(popt[4], perr[4]))

    #    Plot outputs
    plt.plot(xpos, intensity, 'o')
    xfine = np.linspace(xpos[0], xpos[-1], 500)  # do a fine plot as comparison
    plt.plot(xfine, slits.getArrayValues(xfine))
    plt.ylim(0.0, slits.intensity)
    plt.title("Fit of Slit Data")
    plt.xlabel("X position")
    plt.ylabel("Intensity")

    plt.show()
Пример #10
0
def main():

    res = t.getFloat("Static resistance", 100.0)
    alpha = t.getFloat("Alpha", 2.0)
    maxv = t.getFloat("Maximum voltage", 50.0)
    offset = t.getFloat("Current offset", 0.0)
    sd = t.getFloat("SD of noise as percentage", 0.1)

    resistor = Resistor(res, alpha)

    v_array = np.linspace(0, maxv, 50)
    i_array = resistor.getCurrent(v_array) + offset
    imax = i_array[-1]
    sd *= imax
    e_array = np.full(v_array.size, sd)
    n_array = np.random.normal(i_array, sd)
    n_array = np.maximum(n_array, 0.0)  # Force to be positive

    f.writeCSV(t.getFilename("File : ", "txt"), [v_array, n_array, e_array])

    plt.plot(v_array, i_array, "r")

    plt.plot(v_array, n_array, "+")
    plt.show()
Пример #11
0
def main():


    s = t.getString("Give a string") 
    t.tprint("Given string was : ",s)

    y = t.getFloat("Give a float",max=100)
    t.tprint("Given value was : ",y)

    i = t.getInt("Give and int",default = 30)
    t.tprint("int value is ",i)

    z = t.getComplex("Give complex",cmath.sqrt(-6))
    t.tprint("Complex value is :",z)


    file = t.openFile("File","w","data","output")
    file.write("Hello\n")
    file.close()
Пример #12
0
def main():

    prismAngle = tio.getFloat("Prism angle in degrees",60,10,90)
    index = w.MaterialIndex()
    
    wData = np.linspace(w.BlueLimit,w.RedLimit,100)    # wavelength data
    devData = np.empty(len(wData))

    #          Fill up the deviation array
    for i,wave in enumerate(wData):
        devData[i] = deviation(prismAngle,index.getValue(wave))

    #          Do the plotting
    plt.plot(wData,devData,"g")
    plt.title("Angle of Minium Deviation for {0:s}".format(index.title))
    plt.xlabel("Wavelength")
    plt.ylabel("Angle in degrees")
               
    plt.show()
Пример #13
0
def main():

    res = w.Sodium_D/(w.Sodium_D2 - w.Sodium_D1)
    tio.tprint("Resolution target for Na Doublet is : ",res)

    index = w.MaterialIndex()
    tio.tprint(repr(index))
    tio.tprint("Nd index : ",index.getNd()," Abbe No: ",index.getVd())

    
    dn = index.getDerivative(w.Sodium_D)
    tio.tprint("dn / d :",dn)
    d = tio.getFloat("d in mm")
    d *= 1000
    pr = d*dn

    tio.tprint("Prism resolution  : ",pr)

    if abs(pr) > abs(res):
        tio.tprint("Doublet resolved")
    else:
        tio.tprint("Doublet not resolved")
Пример #14
0
def main():

   f = tio.openFile("Give file","r","lens")

   for l in f.readlines():
      tio.tprint(l)

   
   z = tio.getComplex("Give complex",complex(1,1))
   tio.tprint("Complex is " + repr(z))

   v = tio.getVector3d("Vector")
   tio.tprint("vector is : " + repr(v))
   
   options = ["start","close","quit","restart"]
   n,nopt = tio.getOption("Option",options)

   tio.tprint("Option {0:d} chosen, name is {1:s}".format(n,nopt))

   x = tio.getFloat("float",3.0,0.0,5.0)
   tio.tprint(x)

   st = tio.getString("and a string")
   tio.tprint(st)
Пример #15
0
def main():
    #     Get the input paramters
    width = t.getFloat("Slit width", 0.1)
    separ = t.getFloat("Slit seperation", 0.4)
    peak = t.getFloat("Peak", 5.0)

    samplestart = t.getFloat("Sample start", 2.5)
    sampleend = t.getFloat("Sample end", 7.5)
    samples = t.getInt("Samples", 50)
    imageSlit = t.getFloat("Image Slit width", 0.1)

    #     Make the slit object
    slits = TwoSlits(separ, width, distance, peak, wave)

    # sample spacing beteween sample start / end
    xpos = np.linspace(samplestart, sampleend, samples)
    intensity = np.empty(xpos.size)

    #      get intensity through slit for each x
    for i, x in enumerate(xpos):
        a = x - 0.5 * imageSlit  # left side of slit
        b = x + 0.5 * imageSlit  # righ side of slit
        y, err = quad(slits.getValue, a, b)  # integrate across slit
        intensity[i] = y / imageSlit  # scale output

    out = t.openFile("Output file", "w", "txt")
    csv.writeCSV(out, [xpos, intensity])

    #    Plot outputs
    plt.plot(xpos, intensity, 'o')
    xfine = np.linspace(samplestart, sampleend,
                        500)  # do a fine plot as comparison
    plt.plot(xfine, slits.getArrayValues(xfine))
    plt.ylim(0.0, 1.0)

    plt.title("Sample simulation")
    plt.xlabel("X position")
    plt.ylabel("Intensity")
    plt.show()