annotate python/indicators.py @ 321:a5e40bd04cf4

rearranged LCSS indicator functions
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 07 May 2013 02:02:55 +0200
parents 43e62b9cb652
children 28661c5887d3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
244
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1 #! /usr/bin/env python
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2 '''Class for indicators, temporal indicators, and safety indicators'''
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4 __metaclass__ = type
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
5
269
a9988971aac8 removed legacy code + tweaks
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 265
diff changeset
6 import moving
a9988971aac8 removed legacy code + tweaks
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 265
diff changeset
7
244
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
8 # need for a class representing the indicators, their units, how to print them in graphs...
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
9 class TemporalIndicator:
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
10 '''Class for temporal indicators
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
11 i.e. indicators that take a value at specific instants
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
12
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
13 values should be
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
14 * a dict, for the values at specific time instants
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
15 * or a list with a time interval object if continuous measurements
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
16
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
17 it should have more information like name, unit'''
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
18
269
a9988971aac8 removed legacy code + tweaks
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 265
diff changeset
19 def __init__(self, name, values, timeInterval=None, maxValue = None):
244
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
20 self.name = name
306
93d851d0d21e bug correction, minor work on indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 287
diff changeset
21 self.isCosine = (name.find('Cosine') >= 0)
244
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
22 if timeInterval:
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
23 assert len(values) == timeInterval.length()
282
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
24 self.timeInterval = timeInterval
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
25 self.values = {}
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
26 for i in xrange(int(round(self.timeInterval.length()))):
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
27 self.values[self.timeInterval[i]] = values[i]
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
28 else:
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
29 self.values = values
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
30 instants = sorted(self.values.keys())
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
31 if instants:
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
32 self.timeInterval = moving.TimeInterval(instants[0], instants[-1])
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
33 else:
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
34 self.timeInterval = moving.TimeInterval()
269
a9988971aac8 removed legacy code + tweaks
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 265
diff changeset
35 self.maxValue = maxValue
244
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
36
287
66691c06928c first version of indicator LCSS
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 286
diff changeset
37 def __len__(self):
66691c06928c first version of indicator LCSS
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 286
diff changeset
38 return len(self.values)
66691c06928c first version of indicator LCSS
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 286
diff changeset
39
244
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
40 def empty(self):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
41 return len(self.values) == 0
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
42
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
43 def __getitem__(self, i):
287
66691c06928c first version of indicator LCSS
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 286
diff changeset
44 'Returns ith value in time interval'
282
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
45 if i in self.values.keys():
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
46 return self.values[i]
244
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
47 else:
282
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
48 return None
244
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
49
287
66691c06928c first version of indicator LCSS
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 286
diff changeset
50 def getIthValue(self, i):
285
5957aa1d69e1 Integrating Mohamed's changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 282
diff changeset
51 sortedKeys = sorted(self.values.keys())
5957aa1d69e1 Integrating Mohamed's changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 282
diff changeset
52 if 0<=i<len(sortedKeys):
5957aa1d69e1 Integrating Mohamed's changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 282
diff changeset
53 return self.values[sortedKeys[i]]
5957aa1d69e1 Integrating Mohamed's changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 282
diff changeset
54 else:
5957aa1d69e1 Integrating Mohamed's changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 282
diff changeset
55 return None
5957aa1d69e1 Integrating Mohamed's changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 282
diff changeset
56
244
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
57 def __iter__(self):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
58 self.iterInstantNum = 0 # index in the interval or keys of the dict
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
59 return self
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
60
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
61 def next(self):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
62 if self.iterInstantNum >= len(self.values):#(self.timeInterval and self.iterInstantNum>=self.timeInterval.length())\
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
63 # or (self.iterInstantNum >= self.values)
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
64 raise StopIteration
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
65 else:
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
66 self.iterInstantNum += 1
287
66691c06928c first version of indicator LCSS
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 286
diff changeset
67 return self.getIthValue(self.iterInstantNum-1)
244
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
68
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
69 def getTimeInterval(self):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
70 return self.timeInterval
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
71
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
72 def getValues(self):
287
66691c06928c first version of indicator LCSS
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 286
diff changeset
73 return [self.__getitem__(t) for t in self.timeInterval]
244
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
74
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
75 def getAngleValues(self):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
76 '''if the indicator is a function of an angle,
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
77 transform it to an angle (eg cos)
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
78 (no transformation otherwise)'''
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
79 from numpy import arccos
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
80 values = self.getValues()
306
93d851d0d21e bug correction, minor work on indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 287
diff changeset
81 if self.isCosine:
244
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
82 return [arccos(c) for c in values]
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
83 else:
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
84 return values
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
85
269
a9988971aac8 removed legacy code + tweaks
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 265
diff changeset
86 def plot(self, options = '', xfactor = 1., **kwargs):
a9988971aac8 removed legacy code + tweaks
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 265
diff changeset
87 from matplotlib.pylab import plot,ylim
a9988971aac8 removed legacy code + tweaks
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 265
diff changeset
88 if self.getTimeInterval().length() == 1:
a9988971aac8 removed legacy code + tweaks
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 265
diff changeset
89 marker = 'o'
a9988971aac8 removed legacy code + tweaks
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 265
diff changeset
90 else:
a9988971aac8 removed legacy code + tweaks
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 265
diff changeset
91 marker = ''
282
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
92 time = sorted(self.values.keys())
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
93 plot([x/xfactor for x in time], [self.values[i] for i in time], options+marker, **kwargs)
269
a9988971aac8 removed legacy code + tweaks
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 265
diff changeset
94 if self.maxValue:
a9988971aac8 removed legacy code + tweaks
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 265
diff changeset
95 ylim(ymax = self.maxValue)
308
8bafd054cda4 Added a function to compute LCSS distance between two indcators
Mohamed Gomaa
parents: 282
diff changeset
96
8bafd054cda4 Added a function to compute LCSS distance between two indcators
Mohamed Gomaa
parents: 282
diff changeset
97 def valueSorted(self):
312
6c068047edbf merged with Mohamed s work
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 306 308
diff changeset
98 ''' return the values after sort the keys in the indicator
321
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
99 This should probably not be used: to delete'''
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
100 print('Deprecated: values should not be accessed in this way')
308
8bafd054cda4 Added a function to compute LCSS distance between two indcators
Mohamed Gomaa
parents: 282
diff changeset
101 values=[]
8bafd054cda4 Added a function to compute LCSS distance between two indcators
Mohamed Gomaa
parents: 282
diff changeset
102 keys = self.values.keys()
8bafd054cda4 Added a function to compute LCSS distance between two indcators
Mohamed Gomaa
parents: 282
diff changeset
103 keys.sort()
8bafd054cda4 Added a function to compute LCSS distance between two indcators
Mohamed Gomaa
parents: 282
diff changeset
104 for key in keys:
8bafd054cda4 Added a function to compute LCSS distance between two indcators
Mohamed Gomaa
parents: 282
diff changeset
105 values.append(self.values[key])
8bafd054cda4 Added a function to compute LCSS distance between two indcators
Mohamed Gomaa
parents: 282
diff changeset
106 return values
312
6c068047edbf merged with Mohamed s work
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 306 308
diff changeset
107
308
8bafd054cda4 Added a function to compute LCSS distance between two indcators
Mohamed Gomaa
parents: 282
diff changeset
108 @staticmethod
313
43e62b9cb652 solved issues to make the files importable (caution with getDLCSS)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 312
diff changeset
109 def getDLCSS(indic1, indic2, threshold, delta = float('inf') , method ='min' ):
308
8bafd054cda4 Added a function to compute LCSS distance between two indcators
Mohamed Gomaa
parents: 282
diff changeset
110 ''' compute the distance between two indicators using LCSS
8bafd054cda4 Added a function to compute LCSS distance between two indcators
Mohamed Gomaa
parents: 282
diff changeset
111 two common methods are used: min or mean of the indicators length'''
321
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
112 print('Deprecated: this is not appropriate method for indicator comparison')
313
43e62b9cb652 solved issues to make the files importable (caution with getDLCSS)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 312
diff changeset
113 l1 = indic1.valueSorted
43e62b9cb652 solved issues to make the files importable (caution with getDLCSS)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 312
diff changeset
114 l2 = indic2.valueSorted
43e62b9cb652 solved issues to make the files importable (caution with getDLCSS)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 312
diff changeset
115 DLCSS = None
43e62b9cb652 solved issues to make the files importable (caution with getDLCSS)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 312
diff changeset
116 if method == 'min':
43e62b9cb652 solved issues to make the files importable (caution with getDLCSS)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 312
diff changeset
117 DLCSS = 1- (LCSS(l1,l2, threshold, delta, distance))/min(len(l1),len(l2))
43e62b9cb652 solved issues to make the files importable (caution with getDLCSS)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 312
diff changeset
118 if method == 'mean':
43e62b9cb652 solved issues to make the files importable (caution with getDLCSS)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 312
diff changeset
119 average = len(l1)+len(l2)/2
43e62b9cb652 solved issues to make the files importable (caution with getDLCSS)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 312
diff changeset
120 DLCSS = 1- ((LCSS(l1,l2, threshold, delta, distance))/average)
43e62b9cb652 solved issues to make the files importable (caution with getDLCSS)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 312
diff changeset
121 return DLCSS
308
8bafd054cda4 Added a function to compute LCSS distance between two indcators
Mohamed Gomaa
parents: 282
diff changeset
122
282
abbd4bc13dac modified indicator class (same interface)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 269
diff changeset
123
321
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
124 def computeLCSS(indicator1, indicator2, threshold, delta = float('inf')):
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
125 ''' compute the LCSS between two indicators using LCSS'''
286
fa95796a76b3 simplified indicators (only non-measured values, whether measurable or not)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 285
diff changeset
126 from utils import LCSS
287
66691c06928c first version of indicator LCSS
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 286
diff changeset
127
66691c06928c first version of indicator LCSS
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 286
diff changeset
128 def distance(x, y): # lambda x,y:abs(x-y)
66691c06928c first version of indicator LCSS
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 286
diff changeset
129 if x == None or y == None:
66691c06928c first version of indicator LCSS
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 286
diff changeset
130 return float('inf')
321
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
131 else:
287
66691c06928c first version of indicator LCSS
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 286
diff changeset
132 return abs(x-y)
321
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
133 if indicator1 and indicator2:
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
134 return LCSS(indicator1.getValues(), indicator2.getValues(), threshold, distance, delta)
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
135 else:
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
136 return 0
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
137
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
138 def computeNormalizedLCSS(indicator1, indicator2, threshold, delta = float('inf'), method= 'min'):
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
139 ''' compute the normalized LCSS between two indicators using LCSS
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
140 ie, the LCSS divided by the min or mean of the indicator lengths'''
287
66691c06928c first version of indicator LCSS
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 286
diff changeset
141
321
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
142 if indicator1 and indicator2:
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
143 if method == 'min':
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
144 denominator = min(len(indicator1), len(indicator2))
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
145 elif method == 'mean':
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
146 denominator = float(len(indicator1) + len(indicator2))/2
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
147 else:
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
148 print('Unknown denominator method name')
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
149 denominator = 1.
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
150 return float(computeLCSS(indicator1, indicator2, threshold, delta))/denominator
286
fa95796a76b3 simplified indicators (only non-measured values, whether measurable or not)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 285
diff changeset
151 else:
321
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
152 return 0.
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
153
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
154 def computeDLCSS(indicator1, indicator2, threshold, delta = float('inf'), method = 'min'):
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
155 ''' compute the LCSS distance between two indicators using LCSS'''
a5e40bd04cf4 rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 313
diff changeset
156 return 1-computeNormalizedLCSS(indicator1, indicator2, threshold, delta, method)
285
5957aa1d69e1 Integrating Mohamed's changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 282
diff changeset
157
244
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
158 class SeverityIndicator(TemporalIndicator):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
159 '''Class for severity indicators
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
160 field mostSevereIsMax is True
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
161 if the most severe value taken by the indicator is the maximum'''
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
162
286
fa95796a76b3 simplified indicators (only non-measured values, whether measurable or not)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 285
diff changeset
163 def __init__(self, name, values, timeInterval=None, mostSevereIsMax=True, maxValue = None):
269
a9988971aac8 removed legacy code + tweaks
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 265
diff changeset
164 TemporalIndicator.__init__(self, name, values, timeInterval, maxValue)
244
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
165 self.mostSevereIsMax = mostSevereIsMax
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
166
285
5957aa1d69e1 Integrating Mohamed's changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 282
diff changeset
167 def getMostSevereValue(self, minNInstants=1): # TODO use scoreatpercentile
244
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
168 from matplotlib.mlab import find
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
169 from numpy.core.multiarray import array
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
170 from numpy.core.fromnumeric import mean
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
171 values = array(self.values.values())
286
fa95796a76b3 simplified indicators (only non-measured values, whether measurable or not)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 285
diff changeset
172 indices = range(len(values))
244
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
173 if len(indices) >= minNInstants:
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
174 values = sorted(values[indices], reverse = self.mostSevereIsMax) # inverted if most severe is max -> take the first values
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
175 return mean(values[:minNInstants])
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
176 else:
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
177 return None
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
178
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
179 # functions to aggregate discretized maps of indicators
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
180 # TODO add values in the cells between the positions (similar to discretizing vector graphics to bitmap)
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
181
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
182 def indicatorMap(indicatorValues, trajectory, squareSize):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
183 '''Returns a dictionary
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
184 with keys for the indices of the cells (squares)
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
185 in which the trajectory positions are located
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
186 at which the indicator values are attached
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
187
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
188 ex: speeds and trajectory'''
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
189
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
190 from numpy import floor, mean
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
191 assert len(indicatorValues) == trajectory.length()
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
192 indicatorMap = {}
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
193 for k in xrange(trajectory.length()):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
194 p = trajectory[k]
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
195 i = floor(p.x/squareSize)
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
196 j = floor(p.y/squareSize)
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
197 if indicatorMap.has_key((i,j)):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
198 indicatorMap[(i,j)].append(indicatorValues[k])
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
199 else:
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
200 indicatorMap[(i,j)] = [indicatorValues[k]]
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
201 for k in indicatorMap.keys():
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
202 indicatorMap[k] = mean(indicatorMap[k])
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
203 return indicatorMap
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
204
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
205 def indicatorMapFromPolygon(value, polygon, squareSize):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
206 '''Fills an indicator map with the value within the polygon
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
207 (array of Nx2 coordinates of the polygon vertices)'''
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
208 import matplotlib.nxutils as nx
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
209 from numpy.core.multiarray import array, arange
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
210 from numpy import floor
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
211
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
212 points = []
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
213 for x in arange(min(polygon[:,0])+squareSize/2, max(polygon[:,0]), squareSize):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
214 for y in arange(min(polygon[:,1])+squareSize/2, max(polygon[:,1]), squareSize):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
215 points.append([x,y])
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
216 inside = nx.points_inside_poly(array(points), polygon)
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
217 indicatorMap = {}
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
218 for i in xrange(len(inside)):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
219 if inside[i]:
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
220 indicatorMap[(floor(points[i][0]/squareSize), floor(points[i][1]/squareSize))] = 0
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
221 return indicatorMap
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
222
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
223 def indicatorMapFromAxis(value, limits, squareSize):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
224 '''axis = [xmin, xmax, ymin, ymax] '''
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
225 from numpy.core.multiarray import arange
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
226 from numpy import floor
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
227 indicatorMap = {}
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
228 for x in arange(limits[0], limits[1], squareSize):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
229 for y in arange(limits[2], limits[3], squareSize):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
230 indicatorMap[(floor(x/squareSize), floor(y/squareSize))] = value
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
231 return indicatorMap
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
232
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
233 def combineIndicatorMaps(maps, squareSize, combinationFunction):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
234 '''Puts many indicator maps together
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
235 (averaging the values in each cell
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
236 if more than one maps has a value)'''
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
237 #from numpy import mean
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
238 indicatorMap = {}
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
239 for m in maps:
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
240 for k,v in m.iteritems():
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
241 if indicatorMap.has_key(k):
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
242 indicatorMap[k].append(v)
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
243 else:
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
244 indicatorMap[k] = [v]
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
245 for k in indicatorMap.keys():
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
246 indicatorMap[k] = combinationFunction(indicatorMap[k])
5027c174ab90 moved indicators to new file, added ExtrapolatedTrajectory class to extrapolation file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
247 return indicatorMap
247
8f0ed138d373 moved the tests for indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 244
diff changeset
248
8f0ed138d373 moved the tests for indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 244
diff changeset
249 if __name__ == "__main__":
8f0ed138d373 moved the tests for indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 244
diff changeset
250 import doctest
8f0ed138d373 moved the tests for indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 244
diff changeset
251 import unittest
8f0ed138d373 moved the tests for indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 244
diff changeset
252 suite = doctest.DocFileSuite('tests/indicators.txt')
8f0ed138d373 moved the tests for indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 244
diff changeset
253 unittest.TextTestRunner().run(suite)
8f0ed138d373 moved the tests for indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 244
diff changeset
254 # #doctest.testmod()
8f0ed138d373 moved the tests for indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 244
diff changeset
255 # #doctest.testfile("example.txt")