some optimizations
This commit is contained in:
@@ -179,16 +179,16 @@ def getcp(dfgrouped,logarr):
|
||||
ww = group['power'].copy()
|
||||
|
||||
tmax = tt.max()
|
||||
newlen = int(tmax/2000.)
|
||||
print newlen,len(ww)
|
||||
newt = np.arange(newlen)*tmax/float(newlen)
|
||||
neww = griddata(tt.values,
|
||||
ww.values,
|
||||
newt,method='linear',
|
||||
rescale=True)
|
||||
newlen = int(tmax/5000.)
|
||||
if newlen < len(tt):
|
||||
newt = np.arange(newlen)*tmax/float(newlen)
|
||||
ww = griddata(tt.values,
|
||||
ww.values,
|
||||
newt,method='linear',
|
||||
rescale=True)
|
||||
|
||||
#tt = pd.Series(newt)
|
||||
#ww = pd.Series(neww)
|
||||
tt = pd.Series(newt)
|
||||
ww = pd.Series(ww)
|
||||
|
||||
try:
|
||||
avgpower[id] = int(ww.mean())
|
||||
@@ -198,41 +198,49 @@ def getcp(dfgrouped,logarr):
|
||||
length = len(ww)
|
||||
dt = []
|
||||
cpw = []
|
||||
for i in range(length-2):
|
||||
w_roll = ww.rolling(i+2).mean().dropna()
|
||||
if len(w_roll):
|
||||
# now goes with # data points - should be fixed seconds
|
||||
indexmax = w_roll.idxmax(axis=1)
|
||||
try:
|
||||
t_0 = tt.ix[indexmax]
|
||||
t_1 = tt.ix[indexmax-i]
|
||||
deltat = 1.0e-3*(t_0-t_1)
|
||||
wmax = w_roll.ix[indexmax]
|
||||
if not np.isnan(deltat) and not np.isnan(wmax):
|
||||
dt.append(deltat)
|
||||
cpw.append(wmax)
|
||||
except KeyError:
|
||||
pass
|
||||
for i in xrange(length-2):
|
||||
deltat,wmax = getmaxwattinterval(tt,ww,i)
|
||||
if not np.isnan(deltat) and not np.isnan(wmax):
|
||||
dt.append(deltat)
|
||||
cpw.append(wmax)
|
||||
|
||||
|
||||
|
||||
dt = pd.Series(dt)
|
||||
cpw = pd.Series(cpw)
|
||||
|
||||
if len(dt):
|
||||
|
||||
cpvalues = griddata(dt.values,
|
||||
cpw.values,
|
||||
logarr,method='linear',
|
||||
rescale=True)
|
||||
cpvalues = griddata(dt.values,
|
||||
cpw.values,
|
||||
logarr,method='linear',
|
||||
rescale=True)
|
||||
|
||||
for cpv in cpvalues:
|
||||
cpvalue.append(cpv)
|
||||
for d in logarr:
|
||||
delta.append(d)
|
||||
for cpv in cpvalues:
|
||||
cpvalue.append(cpv)
|
||||
for d in logarr:
|
||||
delta.append(d)
|
||||
|
||||
delta = pd.Series(delta,name='Delta')
|
||||
cpvalue = pd.Series(cpvalue,name='CP')
|
||||
return delta,cpvalue,avgpower
|
||||
|
||||
def getmaxwattinterval(tt,ww,i):
|
||||
w_roll = ww.rolling(i+2).mean().dropna()
|
||||
if len(w_roll):
|
||||
# now goes with # data points - should be fixed seconds
|
||||
indexmax = w_roll.idxmax(axis=1)
|
||||
try:
|
||||
t_0 = tt.ix[indexmax]
|
||||
t_1 = tt.ix[indexmax-i]
|
||||
deltat = 1.0e-3*(t_0-t_1)
|
||||
wmax = w_roll.ix[indexmax]
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
wmax = 0
|
||||
deltat = 0
|
||||
|
||||
return deltat,wmax
|
||||
|
||||
def df_resample(datadf):
|
||||
# time stamps must be in seconds
|
||||
|
||||
Reference in New Issue
Block a user