import numpy as np

def meaner(t,x,m):
  # makes mean values of dataset _x_ and timearray _t_ with a mean of _m_ values
  # does only work for EQUALLY SPACED dataset WITHOUT DATAGAPS
  # known bugs: If a "NaN" is in the designated interval, running mean will be "NaN" as well...
  nx=x[::m][:-1]
  l=len(nx)
  for q in range(1,m):
    nx+=x[q::m][:l]
  nx/=m
  nt=t[m/2::m][:l]
  return nt,nx


### example
import matplotlib.pyplot as plt
t=np.linspace(0,20,300)
x=np.linspace(0,20,300)
x=np.sin(t)
m=10
#print t,x
plt.plot(t,x,'+')
nt,nx=meaner(t,x,m)
#print nt,nx
plt.plot(nt,nx,'o')
plt.show()
### example

"""### example 2
from datetime import datetime
from datetime import timedelta
import matplotlib.pyplot as plt
data_path="/home/pacifix/kuehl/work/analysis/solar_event/80_onset_times/10_hesperia_pene/merged_15min/data/"
event=2
data=np.loadtxt("%sfermi_klk_#%03d.dat"%(data_path,event))
pene_y,pene_mon,pene_day,pene_hour,pene_min=data[:,0],data[:,1],data[:,2],data[:,3],data[:,4]
t=[(datetime(int(pene_y[date]),int(pene_mon[date]),1,0)+timedelta(int(pene_day[date])-1,hours=int(pene_hour[date]),minutes=int(pene_min[date]))) for date in range(len(pene_y))]
x=data[:,5:]
x=x.reshape(len(x),)
plt.plot_date(t,x,'k-',lw=2)
nt,nx=meaner(t,x,8)
plt.plot_date(nt,nx,'r-',lw=2)
plt.show()
### example"""
