def main(): lens = SimpleSinglet(200, 80, 10) obj, im = lens.planePair(-0.2, 200.0) tprint("Object plane : " + repr(obj)) tprint("Image plane : " + repr(im)) objectTarget = TargetPlane(obj, wavelength=0.6) imageTarget = TargetPlane(im) objectTarget.addGrid(5, 5) fig = plt.figure() panel = fig.add_subplot(1, 1, 1) panel.axis('equal') imageTarget.draw() targetPencil = objectTarget.getPencils(lens, wavelength=0.45) for pencil in targetPencil: pencil *= lens pencil *= imageTarget psf = Psf().setWithRays(pencil, imageTarget) psf.draw(colour=WavelengthColour(0.45)) plt.show()
def draw(self, plane, drawpsf=True): """ Draw the spot disagram to the current active MatPlotLib as circles with the centre given my the wavelelength of the first ray. :param plane: the plane where the diagram is located. :param drawpsf: draw the geometric psf on the disgram, (default = True) """ # Make an optical plane if needed if isinstance(plane, float) or isinstance(plane, Vector3d): plane = OpticalPlane(plane) xData = [] # X and Y point locations yData = [] for r in self.raypencil: if r: pt = r.pointInPlane(plane) # Find the point in the plane xData.append(pt.x) yData.append(pt.y) # Get the colour of the ray as a hex string col = WavelengthColour(self.raypencil[0].wavelength) # Scatter plot to the current figure axis('equal') scatter(xData, yData, color=col, marker='o') if drawpsf: # Make a psf if required and plot it psf = Psf().setWithRays(self.raypencil, plane) psf.draw()
def polarPlot(self, beam, index, points=200): """ Method to generate polar my rotating the one specided specfied component. The plot will be the beam intensity agaist angle :param beam: the input beam (this is not modified) :type beam: JonesVector :param index: the component to be rotated :type index: int :param key: plot key passes to plt.polar (Default = 'r') :type key: str :param points: Number of point on polar plot (Default = 200) :type points: int """ if isinstance(beam, list): # deal with a list for b in beam: self.polarPlot(b, index, points) else: self.setWavelength( beam) # Set the wavelength once for whole rotation. theta = np.linspace(0.0, 2 * math.pi, num=points, endpoint=True) intensity = np.empty(theta.size) for i, angle in enumerate(theta): self[index].setAngle(angle) outputBeam = beam * self intensity[i] = outputBeam.getIntensity() col = WavelengthColour(beam.wavelength) # Get the colour. polar(theta, intensity, color=col)
def draw(self): """ Draw the plane to the current axis. """ pt = self.getPoint() # Make a frame round the plane and plot it in black xframe = [pt.x - self.xsize/2, pt.x + self.xsize/2,\ pt.x + self.xsize/2, pt.x - self.xsize/2,\ pt.x - self.xsize/2] yframe = [pt.y + self.ysize/2, pt.y + self.ysize/2,\ pt.y - self.ysize/2, pt.y - self.ysize/2, pt.y + self.ysize/2] plt.plot(xframe, yframe, "k") # Now plot the targets at "x" xpt = [] ypt = [] for t in self.targets: pt = self.getSourcePoint(t) xpt.append(pt.x) ypt.append(pt.y) col = WavelengthColour(self.wavelength) plt.plot(xpt, ypt, linestyle='none', color=col, marker='x')
def draw(self): """ Plot to current axis with colour of ray given by its wavelength defined in wavelength.WavelengthColour. """ col = WavelengthColour(self.wavelength) plot(self.z, self.y, color=col)
def main(): waist = 0.1 # Initial waist wavelength = HeNeRed # Wavelength beam = GaussianBeam(0.0, waist, wavelength=wavelength) zData = np.linspace(0.0, 500, 100) # the z range rData = np.zeros(zData.size) # the radius data for i, z in enumerate(zData): # scan down the range beam.propagateTo(z) # propagate to position z rData[i] = beam.getRadius() # get tbe radius # Do the plot colour = WavelengthColour(wavelength) plt.plot(zData, rData, color=colour) plt.plot(zData, -rData, color=colour) plt.show()
def main(): xsize = 500 ysize = 200 minwave = 0.35 # Min wavelength maxwave = 0.75 # Max wavelength dw = (maxwave - minwave)/xsize # Make np array to hold colours image = np.empty((xsize,ysize,3)) # Loop over array filling it up for i in range(0,xsize): wave = minwave + i*dw colour = WavelengthColour(wave) for j in range(0,ysize): image[i,j] = colour plt.imshow(image,aspect = "equal") plt.show()
def polarPlot(self, points=200): """ Method to generate polar plot through an ideal rotated linear polarsier. The colour of the plot is caculated from the wavelenegth of tghe beam from :func: WavelengthColour :param points: number of points (Default = 200) :type points: int """ theta = np.linspace(0.0, 2 * math.pi, num=points, endpoint=True) intensity = np.empty(theta.size) pol = LinearPolariser() for i, angle in enumerate(theta): pol.setAngle(angle) b = self * pol intensity[i] = b.getIntensity() col = WavelengthColour(self.wavelength) polar(theta, intensity, color=col)