def warp1(f,g): usmooth = 8.0 strainMax1 = 0.125 shiftMin = 0 shiftMax = 160 dw = DynamicWarping(shiftMin,shiftMax) dw.setErrorExtrapolation(DynamicWarping.ErrorExtrapolation.REFLECT) dw.setStrainMax(strainMax1) dw.setShiftSmoothing(usmooth,usmooth) e1 = dw.computeErrors1(f,g) d1 = dw.accumulateForward(e1) u1 = dw.backtrackReverse(d1,e1) nl = len(e1[0]) def plotShifts(): nl = len(e1[0]) sp = SimplePlot() sp.setSize(1400,500) sl = Sampling(nl,s1f.delta,shiftMin*s1f.delta) pv = sp.addPixels(s1f,sl,pow(transpose(e1),1.0)) pv.setInterpolation(PixelsView.Interpolation.NEAREST) pv.setColorModel(ColorMap.JET) pv.setPercentiles(2,98) pv = sp.addPoints(s1f,mul(s1f.delta,u1)) plotShifts() u1 = dw.smoothShifts(u1) plotShifts() n1,n2 = len(f[0]),len(f) h = zerofloat(n1,n2) u = zerofloat(n1,n2) for i2 in range(n2): copy(u1,u[i2]) dw.applyShifts(u1,g[i2],h[i2]) print "warp1: u min =",min(u)," max =",max(u) return u,h
def warp1(f, g): usmooth = 1.0 strainMax1 = 0.125 shiftMax = 80 shiftMin = -shiftMax dw = DynamicWarpingX(-shiftMax, shiftMax) dw.setStrainMax(strainMax1) dw.setShiftSmoothing(usmooth) e = dw.computeErrors(f, g) nl, n1, n2 = len(e[0][0]), len(e[0]), len(e) e1 = zerofloat(nl, n1) for i2 in range(n2): add(e[i2], e1, e1) dw.normalizeErrors(e1) d1 = dw.accumulateForward(e1) u1 = dw.backtrackReverse(d1, e1) u1 = dw.smoothShifts(u1) if False: sp = SimplePlot() sp.setSize(1800, 500) sl = Sampling(nl, 1.0, shiftMin) s1 = Sampling(n1, 1.0, 0.0) pv = sp.addPixels(s1, sl, pow(transpose(e1), 0.25)) pv.setInterpolation(PixelsView.Interpolation.NEAREST) pv.setColorModel(ColorMap.PRISM) pv = sp.addPoints(u1) h = zerofloat(n1, n2) u = zerofloat(n1, n2) for i2 in range(n2): copy(u1, u[i2]) dw.applyShifts(u1, g[i2], h[i2]) print "warp1: u min =", min(u), " max =", max(u) return u, h
def warp1(f, g): usmooth = 8.0 rsmooth = 101 strainMax1 = 0.125 #strainMax1 = 1.0 dstrainMax1 = 0.1 shiftMin = 0 shiftMax = 160 #shiftMax = 250 nr = rsmooth dr = 2.0 * strainMax1 / (nr - 1) fr = -strainMax1 sr = Sampling(nr, dr, fr) dw = DynamicWarping(shiftMin, shiftMax) dw.setErrorExtrapolation(DynamicWarping.ErrorExtrapolation.REFLECT) dw.setStrainMax(strainMax1) dw.setShiftSmoothing(usmooth, usmooth) e1 = dw.computeErrors1(f, g) d1 = dw.accumulateForward(e1) u1 = dw.backtrackReverse(d1, e1) nl = len(e1[0]) def plotShifts(): nl = len(e1[0]) sp = SimplePlot() sp.setSize(1400, 500) sl = Sampling(nl, s1f.delta, shiftMin * s1f.delta) pv = sp.addPixels(s1f, sl, pow(transpose(e1), 1.0)) pv.setInterpolation(PixelsView.Interpolation.NEAREST) pv.setColorModel(ColorMap.JET) pv.setPercentiles(2, 98) pv = sp.addPoints(s1f, mul(s1f.delta, u1)) plotShifts() #u1 = dw.smoothShifts(sr,u1) #u1 = dw.smoothShifts(u1) n1, n2 = len(f[0]), len(f) e1 = dw.computeErrorsRaw(f[n2 / 2], g[n2 / 2]) dw.findShiftsSmooth(dstrainMax1, u1[0], e1, u1) plotShifts() #u1 = dw.findShifts1(f,g) n1, n2 = len(f[0]), len(f) h = zerofloat(n1, n2) u = zerofloat(n1, n2) for i2 in range(n2): copy(u1, u[i2]) dw.applyShifts(u1, g[i2], h[i2]) print "warp1: u min =", min(u), " max =", max(u) return u, h
def warp2(f, g): #esmooth,usmooth = 0,0.0 esmooth, usmooth = 2, 8.0 rsmooth = 101 strainMax1 = 0.125 strainMax2 = 0.125 nr = int(rsmooth) dr = 2.0 * strainMax1 / (nr - 1) fr = -strainMax1 sr = Sampling(nr, dr, fr) shiftMax = 10 shiftMin = -shiftMax dw = DynamicWarping(shiftMin, shiftMax) dw.setErrorExtrapolation(DynamicWarping.ErrorExtrapolation.REFLECT) dw.setStrainMax(strainMax1, strainMax2) dw.setShiftSmoothing(usmooth) e = dw.computeErrors(f, g) for ismooth in range(esmooth): dw.smoothErrors(e, e) d = dw.accumulateForward1(e) u = dw.backtrackReverse1(d, e) #u = dw.smoothShifts(sr,u) u = dw.smoothShifts(u) h = dw.applyShifts(u, g) print "warp2: u min =", min(u), " max =", max(u) return u, h
def warp2(f, g): esmooth = 0 usmooth = 0.0 strainMax1 = 0.125 strainMax2 = 0.125 shiftMax = 5 shiftMin = -shiftMax dw = DynamicWarpingX(-shiftMax, shiftMax) dw.setStrainMax(strainMax1, strainMax2) dw.setShiftSmoothing(usmooth) e = dw.computeErrors(f, g) for ismooth in range(esmooth): dw.smoothErrors(e, e) d = dw.accumulateForward1(e) u = dw.backtrackReverse1(d, e) u = dw.smoothShifts(u) h = dw.applyShifts(u, g) print "warp2: u min =", min(u), " max =", max(u) return u, h
def warp2(f,g): #esmooth,usmooth = 0,0.0 esmooth,usmooth = 2,8.0 rsmooth = 101 strainMax1 = 0.125 strainMax2 = 0.125 shiftMax = 10 shiftMin = -shiftMax dw = DynamicWarping(shiftMin,shiftMax) dw.setErrorExtrapolation(DynamicWarping.ErrorExtrapolation.REFLECT) dw.setStrainMax(strainMax1,strainMax2) dw.setShiftSmoothing(usmooth) e = dw.computeErrors(f,g) for ismooth in range(esmooth): dw.smoothErrors(e,e) d = dw.accumulateForward1(e) u = dw.backtrackReverse1(d,e) u = dw.smoothShifts(u) h = dw.applyShifts(u,g) print "warp2: u min =",min(u)," max =",max(u) return u,h
def addShifts(u1, u2): dw = DynamicWarpingX(-1, 1) return add(u2, dw.applyShifts(u2, u1))