Exemple #1
0
def propagateray(ray, lens_type, lens_curvature, lens_2nd_curvature = 0, word = "Yes"):
    """
    This function propagates the ray towards the lens. The RMS deviation at the focal point and the new ray object is returned.
    """
    if lens_type == 0:
        lens = rt.SphericalRefraction(lens_z0, lens_aperture, lens_curvature, surrounding_refractive_index, lens_refractive_index, word)    
    elif lens_type == 1:
        lens = rt.PlanoConvex(lens_z0, lens_depth, lens_curvature, surrounding_refractive_index, lens_refractive_index, word)
    elif lens_type == 2:
        lens = rt.BiSurface(lens_z0, lens_aperture, lens_depth, lens_curvature, lens_2nd_curvature, surrounding_refractive_index, lens_refractive_index, word)
    temp = ray.propagate(lens)
    if temp is None:
        return -1, -1
    if focal_method == 0:
        focal_position = ray.focalpoint_std()
    elif focal_method == 1:
        focal_position = ray.focalpoint_maxlength()
    if focal_position is None:
        output = rt.OutputPlane((lens_z0+lens_depth)*2.5)
        print "No focal point outside of the lens"
    else:
        output = rt.OutputPlane(focal_position[-1])
    temp = ray.propagate(output)
    if temp is None:
        return -1, -1
    rms = ray.rms_deviation("output")
    return rms, ray
Exemple #2
0
def xypositions(n, rmax, m, lens1, lens2):
    """Creates a list of the x-y positions of the rays incident on the output
       plane.
       
       Parameters
       ----------
       n:     integer_type
              The number of concentric circles of rays within the
              distribution.
       rmax:  float_type
              The maximum radius of the distribution of rays.
       m:     integer_type
              The rate at which the number of rays per concentric circle
              increases.
       lens1: instance_type
              An optical element as defined in the raytracer module, and is the
              first optical element that the bundle is propagated through.
       lens2: instance_type
              An optical element as defined in teh raytracer module, and is the
              second optical element that the bundle is propagated through.
    """
    # Placing the output plane at the focal point of lens1 and lens2.
    output_plane = rt.OutputPlane(rt.focal_point2(lens1, lens2), 10000)
    positions = []
    bundle=rt.bundle(n, rmax, m)
    for ray in bundle:
        lens1.propagate_ray(ray)
        lens2.propagate_ray(ray)
        output_plane.propagate_ray(ray)
        x = []
        y = []
        x.append(ray.positions[-1][0]) # Appends the last x position to "x".
        y.append(ray.positions[-1][1]) # Appends the last y position to "y".
        positions.append([x[0],y[0]]) # Creates a list of x-y coordinates.
    return positions
Exemple #3
0
def optimiselens(beam, n):
    """Find the best two lens curvatures to produce the minimum rms value, with
	n = number of curvature increments between -1 and 1, and beam = input beam"""
    rms = []
    outputplane = rt.OutputPlane(200)
    for i in np.linspace(-1.0, 1.0, n):
        for x in np.linspace(-1.0, 1.0, n):
            lens1 = rt.SphericalRefraction(100.0, i, 1.0, 1.5168, 29.74944)
            lens2 = rt.SphericalRefraction(105.0, x, 1.5168, 1.0, 29.74944)
            beam.trace2(lens1, lens2, outputplane)
            rms.append([i, x, beam.rms(outputplane)])
    m = MinList(rms, [0, 0, 100])
    print "lens 1 curvature = %s, lens 2 curvature = %s, rms = %s" % (
        m[0], m[1], m[1])
Exemple #4
0
def work(n, rmax, m):
    q=0
    u=0
    for ray in bundlerays(n, rmax, m):
        sphere = raytracer.SphericalRefraction(2.,0.03,1.,1.5,20.)
        H=raytracer.OutputPlane(150)
        sphere.propagate(ray)
        H.propagate(ray)
        k = ray.vertices()
        tmp = zip(*k)
        pyl.plot(tmp[2],tmp[0])
        #pyl.plot(tmp[1][-1],tmp[0][-1],'bo')
        #pyl.plot(tmp[1][0],tmp[0][0],'ro')
        q += tmp[0][-1]**2 + tmp[1][-1]**2
        u +=1 
Exemple #5
0
def Lens_trial(c,z0,z1,rmax,z0_out):
    """ This method produces a function that returns an rms value.
        The rms value will be minimised using an numerical optimisation function.
        c is a list with the curvatures of the two refractive surface elements.
        z0 is the intecept of the first spherical refraction surface with the z axis
        while z1 is the intercept for the second surface. rmax is the beam radius.
        z0_out is the position of the output plane.
            """
    test_rays = Bundle.bundle(n=5 , rmax=5  , m=4, initial_z = 0, direction = [0,0,1])
    Surface1 = rt.SphericalRefraction(100,c[0],1,1.5168,50)
    Surface2 = rt.SphericalRefraction(155,c[1],1.5168,1,50)
    Output = rt.OutputPlane(z0_out)
    for ray in test_rays:
        Surface1.propagate_ray(ray)
        Surface2.propagate_ray(ray)
        Output.propagate_ray(ray)
    rms = root_mean_square(test_rays)
    return rms
Exemple #6
0
    def propagate_ray(self,rays):
            """ The method takes a Systems class instance and a list of rays as arguements.
            It then propagates the rays through the spherical refraction elements.
            Next the paraxial focus is estimated and the Outputplane is positioned at this point.
            """

            elements = self.__list_of_elements

            for elem in elements:
                for ray in rays:
                    elem.propagate_ray(ray)

            z0 = self.paraxial_focus()
            OutputPlane = rt.OutputPlane(z0)

            for ray in rays:
                OutputPlane.propagate_ray(ray)
            return rays
Exemple #7
0
def zxPlot(n, rmax, m , lens1, lens2):
    """ Creates a plot in the z-x plane of a bundle of rays through two optical
        elements.  The optical elements can be chosen such that they form
        planoconvex lenses.
        
        Parameters
        ----------
        n:    integer_type
              The number of concentric circles of rays within the
              distribution.
       rmax:  float_type
              The maximum radius of the distribution of rays.
       m:     integer_type
              The rate at which the number of rays per concentric circle
              increases.
       lens1: instance_type
              An optical element as defined in the raytracer module, and is the
              first optical element that the bundle is propagated through.
       lens2: instance_type
              An optical element as defined in the raytracer module, and is the
              second optical element that the bundle is propagated through.
    """
    bundle = rt.bundle(n, rmax, m)
    # Defining the output plane to be at the focal point of the combination of 
    # lens1 and lens2.  An arbitrarily large aperture radius was chosen to
    # ensure that all rays were incident on the plane. 
    output_plane = rt.OutputPlane(rt.focal_point2(lens1, lens2), 10000)
    for ray in bundle:
        lens1.propagate_ray(ray)
        lens2.propagate_ray(ray)
        output_plane.propagate_ray(ray)
        x = []
        z = []
        for position in ray.positions:
            x.append(position[0])
            z.append(position[2]) 
        plt.plot(z,x)
    plt.xlabel('z axis /mm')
    plt.ylabel('x axis /mm')
    plt.show()
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 16 01:01:42 2016

@author: barnabysandeford
"""
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import raytracer as rt
reload(rt)

s = rt.SphericalRefraction(100, 0.03, 1.0, 1.5, (1 / 0.03))
# Finding the paraxial focal point of the spherical optical element
F = rt.focal_point1(s)
# The output plane is automatically placed at the paraxial focal point of "s".
p = rt.OutputPlane(F, 10000)


def zx_plot(n, rmax, m):
    """Creates a z-x plot of a bundle of rays propogated through "s".
    
       Parameters
       ----------
       n:    integer_type
             The number of concentric circles of rays within the
             distribution.
       rmax: float_type
             The maximum radius of the distribution of rays.
       m:    integer_type
             The rate at which the number of rays per concentric circle
             increases.
Exemple #9
0
def plotspots(a=1):
    """Produces three plots: 
    1) Spot diagram of initial bundle of rays in x-y plane. 
    2) Ray diagram in x-z plane showing rays passing through the lens.
    3) Spot diagram of ray bundle at the output plane i.e. the detector.
    Produces plots for either orientation of the lens depending on a.""" 
    
    if a == 1:
        lens1 = SR1
        lens2 = SR2
        
    else:
        lens1 = SR3
        lens2 = SR4
        
    x = findzintercept(lens1,lens2)
    focal = x[2]
    output = rt.OutputPlane(focal)
    print "Focal length for orientation %g is %g mm." % (a, focal)
    
    bundle = []    
    
    for r,t in gp.rtuniform(7, 5.0, 6): #rmax (5.0) must be a float
        xcoord = r*np.cos(t)
        ycoord = r*np.sin(t)
        
        ray = rt.Ray([xcoord,ycoord,0.0],[0.0,0.0,0.1])
        lens1.propagate_ray(ray)
        lens2.propagate_ray(ray)
        output.propagate_ray(ray)
        bundle.append(ray)
        
        plt.figure(a)
       
        if a == 1:
            plt.suptitle('Planoconvex Lens Orientation 1', size=16)
        else:
            plt.suptitle('Planoconvex Lens Orientation 2', size=16)
        
        ax1 = plt.subplot(2,2,1)
        ax1.plot(xcoord, ycoord, 'bo')
        ax1.set_title('Bundle of Rays at Source, z=0', size=12)
        ax1.axis('equal')
        
        ax2 = plt.subplot(2,2,2)
        x2 = [j[2] for j in ray.vertices()]
        y2 = [j[0] for j in ray.vertices()]
        ax2.plot(x2,y2,'r-')
        ax2.set_title('Propagation of Rays in xz Plane', size=12)
    
    x3 = [j._p[0] for j in bundle]
    y3 = [j._p[1] for j in bundle]
    ax3 = plt.subplot(2,2,3)
    ax3.plot(x3,y3,'bo')
    ax3.set_title('Bundle of Rays at Focus', size=12)
    ax3.locator_params(nbins=5)
    ax3.axis('equal')

    findrms(bundle)
    
    difflim = ((588*10**(-9))*focal)/10.0
    print "The diffraction limit is %g m." % difflim
Exemple #10
0
rays = Bundle.bundle(n=5,
                     rmax=5,
                     m=4,
                     initial_z=0,
                     direction=[0.1, 0.0, 1],
                     x1=0,
                     y1=0)

#surface
z0 = 100
curvature = -0.02  # change to 0.02 to see convex reflective surface, set to 0.0 to see the plane reflective surface
aperture = 50
surface = rt.SphericalReflection(z0, curvature, aperture)

#Output
Output = rt.OutputPlane()

x, y, z = [], [], []
for ray in rays:
    surface.propagate_ray(ray)
    Output.propagate_ray(ray)

for ray in rays:

    coord = ray.vertices()
    for j in coord:
        x = [j[0] for j in coord]
        y = [j[1] for j in coord]
        z = [j[2] for j in coord]

        plo.plotyz(z, y)
Exemple #11
0
import lens as ln
import raytracer as rt
import matplotlib.pyplot as plt
from raybundle import Bundle
from mpl_toolkits import mplot3d
import scipy as sp

# lens can be PlanoConcave, ConvexPlano or BiConvex
lens = ln.BiConvex(z=20,
                   curve=0.02,
                   separation=5,
                   n1=1,
                   n2=1.5168,
                   aperture=30)
output = rt.OutputPlane(z_1=lens.paraxial_focus())

beam = Bundle(5, 3)
origins = beam.con_circs()

# setting up figures and axes - used to allow projection to be set to 3d easily rather than just plotting
fig1 = plt.figure()
ax1 = plt.axes()
ax1.set_title('z = 0')

fig2 = plt.figure()
ax2 = plt.axes()
ax2.set_title('paraxial focus')

fig3 = plt.figure()
ax3 = plt.axes(projection='3d')
Exemple #12
0
"""

import raytracer as rt
from raybundle import Bundle
import matplotlib.pyplot as plt
import scipy as sp
from mpl_toolkits import mplot3d

# create a spherical surface and an output plane at the paraxial focus
surface = rt.SphericalRefraction(z_0=100,
                                 curve=-0.03,
                                 n1=1.0,
                                 n2=1.5,
                                 aperture=30.)
# a concave lens only has an imaginary focus behind it
output = rt.OutputPlane(z_1=250)

# creates a collimated beam with (radius, line density around outer circumference)
beam = Bundle(2, 3)

fig = plt.figure()
ax = plt.axes()
"""
origins = beam.con_circs()

# get points of rays into individual arrays and plot them
for o in origins:
    x = []
    y = []
    z = []
    r = rt.Ray(pos = [o[0], o[1], 0.], direc=[0., 0., 1.])
Exemple #13
0
To send rays through an optical element and plot their positions.
"""

import raytracer as rt
from raybundle import Bundle
import matplotlib.pyplot as plt
import scipy as sp
from mpl_toolkits import mplot3d

# create a spherical surface and an output plane at the paraxial focus
surface = rt.SphericalRefraction(z_0=100,
                                 curve=0.03,
                                 n1=1.0,
                                 n2=1.5,
                                 aperture=30.)
output = rt.OutputPlane(z_1=surface.paraxial_focus())

# creates a collimated beam with (radius, line density around outer circumference)
beam = Bundle(2, 3)

fig = plt.figure()
ax = plt.axes(projection="3d")

origins = beam.con_circs()

# get points of rays into individual arrays and plot them
for o in origins:
    x = []
    y = []
    z = []
    r = rt.Ray(pos=[o[0], o[1], 0.], direc=[0., 0., 1.])