def zero_crossing(trace, base=15, shift=10, chi=0.6, falling=True): """ NIMA 775 (2015) 71–76 """ try: bs = numpy.average(trace[0:base]) inv = numpy.zeros(trace.shape) inv[shift:] = trace[0:-shift] - bs zc = chi * (trace - bs) - inv if falling: zc *= -1 t_lim, = numpy.unravel_index(zc.argmax(), zc.shape) t0 = numpy.argmax(zc[t_lim:] < 0) + t_lim t_zc = numpy.arange(t0 - 3, t0 + 3) y_zc = zc[t0 - 3:t0 + 3] cs = CubicSpline(t_zc, y_zc) r = cs.solve(0.0) for ri in r: if numpy.isreal(ri) and t_zc[0] < ri < t_zc[-1]: return ri except ValueError: pass return 0
def fluxFunc(x): return -1 * cs(x, 1) flux = fluxFunc(thermocline) print("The flux at", thermocline.item(0), "m is ", flux.item(0)) plt.figure() plt.plot(x, y, 'o', label='data') plt.plot(xs, cs(xs), label="C (℃/m)") plt.plot(xs, cs(xs, 1), label="C'") plt.plot(xs, cs(xs, 2), label="C''") plt.legend() plt.figure() plt.plot(xs, -1 * cs(xs, 1), label=r"J $ \left( \frac{cal}{m^2s}\right)$") plt.legend() #plt.plot(x, f(x), label="S'") plt.show() tempat17 = cs(1.7) depthat50 = cs.solve(50) print("Depth at 50 degrees is ", depthat50.item(0), "m") print("Temperature at 1.7 m is ", tempat17.item(0))