Package theia :: Package optics :: Module component
[hide private]
[frames] | no frames]

Source Code for Module theia.optics.component

  1  '''Defines the SetupComponent class for theia.''' 
  2   
  3  # Provides: 
  4  #   class SetupComponent 
  5  #       __init__ 
  6  #       __str__ 
  7  #       lines 
  8  #       isHit 
  9  #       hit 
 10  #       translate 
 11   
 12  import numpy as np 
 13  from abc import ABCMeta, abstractmethod 
 14  from ..helpers.tools import formatter 
15 16 -class SetupComponent(object):
17 ''' 18 19 SetupComponent class. 20 21 This is an Abstract Base Class for all the components (optical or not) of 22 the setup. Its methods may be implemented in daughter classes. 23 24 *=== Attributes ===* 25 SetupCount: class attribute, counts setup components. [integer] 26 HRCenter: center of the principal face of the component in space. 27 [3D vector] 28 ARCenter: center of the secondary face of the component in space. 29 [3D vector] 30 HRNorm: normal unitary vector the this principal face, supposed to point 31 outside the media. [3D vector] 32 Thick: thickness of the component, counted in opposite direction to 33 HRNorm. [float] 34 Dia: diameter of the component. [float] 35 Name: name of the component. [string] 36 InBeams: list of all beams incident on the component. [list of GaussianBeam] 37 OutBeams: list of all beams out 38 Ref: reference string (for keeping track with the lab). [string] 39 40 41 ''' 42 43 __metaclass__ = ABCMeta 44 SetupCount = 0 #counts the setup components 45 Name = "SetupComponent" 46
47 - def __init__(self, HRCenter, HRNorm, Ref, Thickness, Diameter, ARCenter):
48 '''SetupComponent initializer. 49 50 Parameters are the attributes of the object to construct. 51 52 Returns a setupComponent. 53 54 ''' 55 # allow empty initializer 56 if Ref is None: 57 Ref = "Set%s" % str(SetupComponent.SetupCount) 58 # initialize data 59 self.HRCenter = HRCenter 60 self.ARCenter = ARCenter 61 self.HRNorm = HRNorm 62 self.Thick = Thickness 63 self.Dia = Diameter 64 self.Ref = Ref 65 66 SetupComponent.SetupCount = SetupComponent.SetupCount + 1
67
68 - def __str__(self):
69 '''String representation of the component, when calling print(object). 70 71 ''' 72 return formatter(self.lines())
73 74 @abstractmethod
75 - def lines(self):
76 '''Method to return the list of strings to __str__. 77 78 Abstract (pure virtual) method. 79 80 ''' 81 pass
82 83 @abstractmethod
84 - def isHit(self, beam):
85 '''Method to determine if component is hit by a beam. 86 87 Abstract (pure virtual) method. 88 89 ''' 90 pass
91 92 @abstractmethod
93 - def hit(self, beam, order, threshold):
94 '''Compute the refracted and reflected beams after interaction. 95 96 Abstract (pure virtual) method. 97 98 '''
99
100 - def translate(self, X = 0., Y = 0., Z = 0.):
101 '''Move the component to (current position + (X, Y, Z)). 102 103 This version only takes care of the HRCenter, version of sub classes 104 take care of ARCenter if relevant. 105 106 X, Y, Z: components of the translation vector. 107 108 No return value. 109 ''' 110 self.HRCenter = self.HRCenter + np.array([X, Y, Z], dtype = np.float64)
111