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 HRNorm: normal unitary vector the this principal face, supposed to point 29 outside the media. [3D vector] 30 Thick: thickness of the component, counted in opposite direction to 31 HRNorm. [float] 32 Dia: diameter of the component. [float] 33 Name: name of the component. [string] 34 Ref: reference string (for keeping track with the lab). [string] 35 36 37 ''' 38 39 __metaclass__ = ABCMeta 40 SetupCount = 0 #counts the setup components 41 Name = "SetupComponent" 42
43 - def __init__(self, HRCenter, HRNorm, Ref, Thickness, Diameter):
44 '''SetupComponent initializer. 45 46 Parameters are the attributes of the object to construct. 47 48 Returns a setupComponent. 49 50 ''' 51 # allow empty initializer 52 if Ref is None: 53 Ref = "Set" + str(SetupComponent.SetupCount) 54 # initialize data 55 self.HRCenter = HRCenter 56 self.HRNorm = HRNorm 57 self.Thick = Thickness 58 self.Dia = Diameter 59 self.Ref = Ref 60 61 SetupComponent.SetupCount = SetupComponent.SetupCount + 1
62
63 - def __str__(self):
64 '''String representation of the component, when calling print(object). 65 66 ''' 67 return formatter(self.lines())
68 69 @abstractmethod
70 - def lines(self):
71 '''Method to return the list of strings to __str__. 72 73 Abstract (pure virtual) method. 74 75 ''' 76 pass
77 78 @abstractmethod
79 - def isHit(self, beam):
80 '''Method to determine if component is hit by a beam. 81 82 Abstract (pure virtual) method. 83 84 ''' 85 pass
86 87 @abstractmethod
88 - def hit(self, beam, order, threshold):
89 '''Compute the refracted and reflected beams after interaction. 90 91 Abstract (pure virtual) method. 92 93 '''
94
95 - def translate(self, X = 0., Y = 0., Z = 0.):
96 '''Move the component to (current position + (X, Y, Z)). 97 98 This version only takes care of the HRCenter, version of sub classes 99 take care of ARCenter if relevant. 100 101 X, Y, Z: components of the translation vector. 102 103 No return value. 104 ''' 105 self.HRCenter = self.HRCenter + np.array([X, Y, Z], dtype = np.float64)
106