# Note: Endianness of the binary files written here is not explicitly set and will depend on the machine you are working on. Use [numpy.dtype.newbyteorder](https://docs.scipy.org/doc/numpy/reference/generated/numpy.dtype.newbyteorder.html) to explicitly set the endianness or compile mitgcm such that the machine default will be used. # %% # # %matplotlib notebook # %matplotlib inline import numpy as np import scipy as sp import matplotlib.pyplot as plt import os import gsw import xarray as xr import ocean_tools.utils as utils data_dir = os.path.expanduser('~/data/SamoanPassage/Bathy/') data_file = 'samoan_passage_bathymetry_200m_merged.mat' B = utils.loadmat(os.path.join(data_dir, data_file))['bathy2'] # It seems like float64 is the # default data type in numpy, but let's be # clear about this and write a little # test/conversion function. def CheckFloat64(x): if x.dtype == np.float64: print('its a float64') else: print('converting to float64') x = x.astype(np.float64) return x
# name: spamex # --- # %% [markdown] # # We want to create the best possible bathymetry... # %% import os import numpy as np import matplotlib.pyplot as plt import ocean_tools.utils as utils import munch from numba import jit import scipy.io as io B = munch.munchify(utils.loadmat('bathy_cleaned.mat')) @jit def weightgen(gd, bbs): w = np.zeros_like(gd, dtype=float) bbmax = (2*bbs)**2 nr, nc = gd.shape for i in range(nr): for j in range(nc): i1 = np.maximum(0, i-bbs) i2 = np.minimum(nr, i+bbs) j1 = np.maximum(0, j-bbs) j2 = np.minimum(nc, j+bbs) w[i, j] = gd[i1:i2, j1:j2].sum()/bbmax return w
# %% import os import numpy as np import matplotlib.pyplot as plt import ocean_tools.sandwell as ssb import ocean_tools.utils as utils import munch # LLC4320 bathymetry depth = np.fromfile('grid/Depth_144x185', '>f').reshape((185, 144)) XC = np.fromfile('grid/XC_144x185', '>f').reshape((185, 144)) YC = np.fromfile('grid/YC_144x185', '>f').reshape((185, 144)) bathy = np.fromfile('grid/BATHY_144x185_Box13', '>f').reshape((185, 144)) MB = munch.munchify(utils.loadmat('merged_bathy.mat')) def bilinear_interpolation(xa, ya, fg, x, y): i2 = np.searchsorted(xa, x) i1 = i2 - 1 j2 = np.searchsorted(ya, y) j1 = j2 - 1 dx = xa[i2] - xa[i1] dy = ya[j2] - ya[j1] f11, f21, f12, f22 = fg[i1, j1], fg[i2, j1], fg[i1, j2], fg[i2, j2] x1, y1, x2, y2 = xa[i1], ya[j1], xa[i2], ya[j2] fi = (f11 * (x2 - x) * (y2 - y) + f21 * (x - x1) * (y2 - y) + f12 * (x2 - x) * (y - y1) + f22 * (x - x1) * (y - y1)) / (dx * dy) return fi
# First we load all the datasets and interpolate/resize them onto a fine spatial grid. # %% import os import numpy as np import matplotlib.pyplot as plt import ocean_tools.sandwell as ssb import ocean_tools.utils as utils import munch import scipy.io as io import xarray as xr # DEFINE THE GRID USING GUNNARS GRID data_dir = os.path.expanduser('~/data/SamoanPassage/Bathy/') data_file = 'samoan_passage_bathymetry_200m_merged.mat' B = munch.munchify(utils.loadmat(os.path.join(data_dir, data_file))['bathy2']) lllon = B.lon.min() lllat = B.lat.min() urlon = B.lon.max() urlat = B.lat.max() # LOAD SMITH AND SANDWELL dll = 0.25 SSX, SSY, SSD = ssb.read_grid( [lllon - dll, urlon + dll, lllat - dll, urlat + dll]) SSX = SSX[:, 0] SSY = SSY[0, :] SSD = -1 * SSD.T # Transport necessary... want Y along i axis and X along j axis. # Gunnars merged bathymetry