1 '''Defines some generic functions for theia.'''
2
3
4
5
6
7
8
9
10
11
12
13
14 import time as tm
15 import re
16
18 '''TotalReflectionError class.
19
20 Is raised when an interaction results in total reflection.
21
22 *=== Attributes ===*
23 Message: exception message. [string]
24
25
26 '''
27
29 '''TotalReflectionError exception initializer.
30
31 '''
32 self.Message = message
33
35 '''Printing error function.
36
37 '''
38 return repr(self.Message)
39
61
63 '''Decorator function to log execution time of other functions.'''
64
65 def wrapped(*args, **kw):
66 t1 = tm.time()
67 func(*args, **kw)
68 t2 = tm.time()
69 dt = t2 -t1
70 st = "theia: Debug: %s exec with '%s' in %s ms." \
71 % (str(func.__name__), str(*args), str(dt*1000.))
72 print st
73
74 return wrapped
75
88
90 '''Returns the short reference corresponding to string.
91
92 Change all 't2nrt' in 'R', all 't(2n+1)rt' in 'T' and 'r' in 'R'
93 in string. Used to write short references to beams.
94
95 '''
96 f = inStr.find('-')
97 prefix = inStr[:f+1]
98 s1 = re.sub("tr(rr)*t", "R", inStr[f+1:])
99 s2 = re.sub("t(rr)+t", "T", s1)
100 s3 = re.sub("tt", "T", s2)
101 s4 = re.sub("t", "T", s3)
102 return prefix + re.sub("r", "R", s4)
103