Changeset 978 in lmdz_wrf for trunk/tools
- Timestamp:
- Aug 8, 2016, 5:13:30 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r957 r978 2166 2166 return 2167 2167 2168 class std_stats2Val(object): 2169 """two variables standard Statistics class providing: 2170 vals1 = variable 1 2171 vals2 = variable 2 2172 self.bias=mean(var1-var2) 2173 self.mae=mean(abs(var1-var2)) 2174 self.rmse=sqrt((var1-var2)**2) 2175 self.explvar = stddev1/stddev2 2176 self.correlation (and p-value) 2177 """ 2178 2179 def __init__(self, vals1, vals2): 2180 import numpy as np 2181 from scipy import stats as sts 2182 2183 fname = 'std_stats2Val' 2184 2185 if vals1 is None: 2186 self.bias = None 2187 self.mae = None 2188 self.rmse = None 2189 self.explvar = None 2190 self.corr = None 2191 else: 2192 values1 = vals1.flatten() 2193 values2 = vals2.flatten() 2194 2195 Nvals1 = len(values1) 2196 Nvals2 = len(values2) 2197 2198 2199 if not len(values1) == len(values2): 2200 print errormsg 2201 print ' ' + fname + ': lengths of variables differ!! Lvar1: ', Nvals1, \ 2202 ' Lvar2: ', Nvals2,' statistics between them can not be computed!' 2203 quit(-1) 2204 2205 self.bias = 0. 2206 self.mae = 0. 2207 self.rmse = 0. 2208 self.explvar = 0. 2209 self.corr = np.zeros(2, dtype=np.float) 2210 2211 for inum in range(Nvals1): 2212 Sval = values1[inum] - values2[inum] 2213 self.mae = self.mae + abs(Sval) 2214 self.rmse = self.rmse + Sval**2 2215 2216 self.bias = np.mean(vals1) - np.mean(vals2) 2217 self.mae = self.mae/Nvals1 2218 self.rmse = np.sqrt(self.rmse/Nvals1) 2219 self.explvar = np.var(vals1)/np.var(vals2) 2220 2221 self.corr[0], self.corr[1] = sts.pearsonr(values1, values2) 2222 2223 return 2224 2168 2225 class stats2Val(object): 2169 2226 """two variables Statistics class providing: … … 2213 2270 self.mean2v1Pv2 = None 2214 2271 self.stdv1Pv2 = None 2272 self.bias = None 2215 2273 self.mae = None 2216 2274 self.rmse = None … … 2251 2309 self.mean2v1Pv2=0. 2252 2310 self.stdv1Pv2=0. 2311 self.bias = 0. 2253 2312 self.mae = 0. 2254 2313 self.rmse = 0. 2255 self.corr = np. array([0., 0.])2314 self.corr = np.zeros(2, dtype=np.float) 2256 2315 self.linRegress = np.zeros(5, float) 2257 2316 self.polRegress = np.zeros(power+1, float) … … 2284 2343 Dval = values1[inum] / values2[inum] 2285 2344 2345 self.bias = self.bias + Sval 2286 2346 self.mae = self.mae + abs(Sval) 2287 2347 self.rmse = self.rmse + Sval**2 … … 2335 2395 self.stdv1Pv2 = np.sqrt(self.mean2v1Pv2-self.meanv1Pv2*self.meanv1Pv2) 2336 2396 2397 self.bias = self.bias/self.Nokvalues12 2337 2398 self.mae = self.mae/self.Nokvalues12 2338 2399 self.rmse = np.sqrt(self.rmse/self.Nokvalues12) 2339 2400 2340 self.corr = sts.pearsonr(values1, values2) 2341 2401 self.corr[0], self.corr[1] = sts.pearsonr(values1, values2) 2342 2402 self.linRegress[0], self.linRegress[1], self.linRegress[2], self.linRegress[3], self.linRegress[4] = sts.linregress(values1, values2) 2343 2403
Note: See TracChangeset
for help on using the changeset viewer.