136.01, 146.30, 157.71, 170.35, 184.37, 199.89, 217.09, 236.13, 257.21, 280.50, 306.24, 334.64, 365.93, 400.38 ]) z = np.hstack((0, np.cumsum(delR))) # np.unravel_index(np.argmin(a, axis=None), a.shape) T_ = T.copy() T_[hFacC < 1] = 1e10 T_[T > 1] = 1e10 Tm1 = T_ - 1 idxs = np.argmin(np.abs(Tm1), axis=0) idxs[(T_ == 1e10).all(axis=0)] = 10000 imin = np.min(idxs) dmin = utils.mid(z)[imin] print("Min depth {}".format(dmin)) fig, ax = plt.subplots(1, 1) ax.plot(delR, utils.mid(z), '.') ax.invert_yaxis() ax.axhline(dmax, color='r') ax.axhline(dmin, color='r') # %% [markdown] # # Make a new z # %% # 90 cells delR = np.array([ 1.00, 1.14, 1.30, 1.49, 1.70, 1.93, 2.20, 2.50, 2.84, 3.21, 3.63, 4.10,
# $$ # $$ # \rho = \alpha_T \theta # $$ # $$ # T_{z0} = \frac{N^2}{g \alpha_T} # $$ # %% zshift = 50 # shift peak by how many metres tmp = sec9.where(sec9.station == 12, drop=True) SA = gsw.SA_from_SP(tmp.s.squeeze(), tmp.p.squeeze(), tmp.lon, tmp.lat) CT = gsw.CT_from_t(SA, tmp.t.squeeze(), tmp.p.squeeze()) N2, pmid = gsw.Nsquared(SA, CT, tmp.p.squeeze(), tmp.lat) zmid = utils.mid(tmp.z.data) good = np.isfinite(N2) N2smooth = utils.convolve_smooth(N2[good], 100) zs = zmid[good] imax, _ = sp.signal.find_peaks(N2smooth, height=(3e-6, 5e-6), prominence=2e-6) hw = 220 ispeak = (zs > zs[imax - hw]) & (zs < zs[imax + hw]) N2filled = np.interp(zs, zs[~ispeak], N2smooth[~ispeak]) N2peak = (N2smooth - N2filled) fpeak = sp.interpolate.interp1d(zs, N2peak, bounds_error=False, fill_value=(0, 0)) N2shifted = N2filled + fpeak(zs + zshift)
axs[0].contour(X, Y, Bspamex, clevs, linewidths=linewidths, colors='k') axs[0].set_title('spamex unedited') C = axs[1].contourf(X, Y, Bspamex_, clevs, cmap='Blues', extend='both') axs[1].contour(X, Y, Bspamex_, clevs, linewidths=linewidths, colors='k') axs[1].set_title('spamex edited') axs[1].plot([slllon, slllon, surlon, surlon, slllon], [slllat, surlat, surlat, slllat, slllat], 'r') # %% # Spikes from gradient? This does seem very successful... fig, axs = plt.subplots(1, 2, figsize=(15, 10)) for ax in axs: ax.set_aspect('equal') C = axs[0].contourf(GX, utils.mid(GY), np.log10(np.diff(bspamex, axis=0))) C = axs[1].contourf(utils.mid(GX), GY, np.log10(np.diff(bspamex, axis=1))) plt.colorbar(C) # %% # Very small holes are bad... # bbs = 40 # How many points in a big square around the point to look at # gd = np.isfinite(bspamex) # bd = ~gd # wspamex = weightgen(gd, bbs)**4 tofill = (wspamex > 0.8) & bd fig, ax = plt.subplots(1, 1, figsize=(10, 10)) ax.pcolormesh(GX, GY, tofill)