Changeset 2121 in lmdz_wrf


Ignore:
Timestamp:
Aug 31, 2018, 3:47:50 PM (7 years ago)
Author:
lfita
Message:

Adding 'fill' value to `running_mean'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2116 r2121  
    63356335    return vecv
    63366336
    6337 def running_mean(values, run):
     6337def running_mean(values, run, fill=None):
    63386338    """ Function to compute a running mean of a series of values
    63396339      running_mean(vals, int)
    63406340      [vals]: series of values
    63416341      [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]
    63436346      >>> running_mean(np.arange(100),10)
    63446347      [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
     
    63626365        runmean[ip] = np.mean(values[ip-run/2:ip+run/2])
    63636366
    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
    63656372
    63666373    return runmean
Note: See TracChangeset for help on using the changeset viewer.