Changeset 2121 in lmdz_wrf
- Timestamp:
- Aug 31, 2018, 3:47:50 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r2116 r2121 6335 6335 return vecv 6336 6336 6337 def running_mean(values, run ):6337 def running_mean(values, run, fill=None): 6338 6338 """ Function to compute a running mean of a series of values 6339 6339 running_mean(vals, int) 6340 6340 [vals]: series of values 6341 6341 [run]: interval to use to compute the running mean 6342 NOTE: resultant size would be the same but with None except at [run/2,size(vals)-run/2] 6342 [fill]: fill value to use 6343 [value]: value to use to fill outside runmean values 6344 'vals': using actual values instead 6345 NOTE: resultant size would be the same but with [fill] except at [run/2,size(vals)-run/2] 6343 6346 >>> running_mean(np.arange(100),10) 6344 6347 [None None None None None 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 12.5 13.5 14.5 … … 6362 6365 runmean[ip] = np.mean(values[ip-run/2:ip+run/2]) 6363 6366 6364 runmean = np.where(runmean == fillValue, None, runmean) 6367 if fill != 'vals': 6368 runmean = np.where(runmean == fillValue, fill, runmean) 6369 else: 6370 runmean = np.where(runmean == fillValue, values, runmean) 6371 6365 6372 6366 6373 return runmean
Note: See TracChangeset
for help on using the changeset viewer.