This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mld_thres(phi, phi_step, ref_depth=10, dim='depth'): | |
# Get the depth vector | |
z = phi[dim] | |
# Find the index closest to the reference depth | |
k_ref = int((np.abs(z - ref_depth)).argmin()) | |
from numba import guvectorize | |
@guvectorize(['void(float64[:], float64[:], intp, float64, float64[:])'], | |
'(n),(n),(),()->()', nopython=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
def expfit(phi, dim): | |
def exp_func(z, phi_bottom, delta_phi, z0): | |
return phi_bottom - delta_phi * np.exp(- z / z0) | |
mean_phi_max = phi.max(dim).mean() | |
mean_phi_min = phi.min(dim).mean() | |
delta_phi = mean_phi_max - mean_phi_min |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import numba | |
import xarray as xr | |
@numba.jit(nopython=True) | |
def lowess_1d(y, x, alpha=2. / 3., it=10): | |
"""lowess(x, y, f=2./3., iter=3) -> yest | |
Lowess smoother: Robust locally weighted regression. | |
The lowess function fits a nonparametric regression curve to a scatterplot. | |
The arrays x and y contain an equal number of elements; each pair |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
import numpy as np | |
import numba | |
import pandas as pd | |
from obspy.geodetics import kilometers2degrees | |
@numba.jit(nopython=True, parallel=True) | |
def _interp_over_lon_lat(data_in, lon_in, lat_in, data_out, lon_out, lat_out, dlon, dlat): | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bin_lat_lon(data, lon_min=0., lon_max=360., lon_res=1., | |
lat_min=-80., lat_max=80, lat_res=1.): | |
""" | |
Bin unidimensional data onto a regular latidude and longitude grid | |
by computing the median value and the number of corresponding | |
observations | |
Paraneters | |
---------- | |
data : xarray.DataArray |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
import numpy as np | |
import numba | |
import pandas as pd | |
import pyresample | |
def interpolate_rossby_radius(Rd, lon, lat, interp_type='gaussian', | |
radius_of_influence=500e3, fill_value=None, | |
reduce_data=True, nprocs=1, neighbours=8): | |
lat_min, lat_max = np.min(lat), np.max(lat) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dask.delayed as delayed | |
import xarray as xr | |
import numpy as np | |
@delayed(pure=True) | |
def lagged_difference(a, dim, lag, order=1): | |
return (a.shift(**{dim: -lag}) - a) ** order | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
import numpy as np | |
import pandas as pd | |
EARTH_RADIUS = 6371 * 1e3 | |
def latlon2yx(lat, lon): | |
""" | |
Convert latitude and longitude arrays to y and x arrays in m |