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   
10  import numpy as np 
11  from abc import ABCMeta, abstractmethod 
12  from ..helpers.tools import formatter 
13 14 -class SetupComponent(object):
15 ''' 16 17 SetupComponent class. 18 19 This is an Abstract Base Class for all the components (optical or not) of 20 the setup. Its methods may be implemented in daughter classes. 21 22 *=== Attributes ===* 23 SetupCount: class attribute, counts setup components. [integer] 24 HRCenter: center of the principal face of the component in space. 25 [3D vector] 26 HRnorm: normal unitary vector the this principal face, supposed to point 27 outside the media. [3D vector] 28 Thick: thickness of the component, counted in opposite direction to 29 HRNorm. [float] 30 Dia: diameter of the component. [float] 31 Name: name of the component. [string] 32 Ref: reference string (for keeping track with the lab). [string] 33 34 35 ''' 36 37 __metaclass__ = ABCMeta 38 SetupCount = 0 #counts the setup components 39
40 - def __init__(self, HRCenter, HRNorm, 41 Name, Ref, Thickness, Diameter):
42 '''SetupComponent initializer. 43 44 Parameters are the attributes of the object to construct. 45 46 Returns a setupComponent. 47 48 ''' 49 # allow empty initializer 50 if Ref is None: 51 Ref = "Set" + str(SetupComponent.SetupCount) 52 # initialize data 53 self.HRCenter = np.array(HRCenter, dtype = np.float64) 54 self.HRNorm = np.array(HRNorm, dtype = np.float64) 55 self.HRNorm = self.HRNorm/np.linalg.norm(self.HRNorm) 56 self.Thick = Thickness 57 self.Dia = Diameter 58 self.Name = Name 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