API

MicroInverse_utils

MicroInverse.MicroInverse_utils.inversion(x_grid, block_rows, block_cols, block_lon, block_lat, block_num_lons, block_num_lats, block_num_samp, Stencil_center, Stencil_size, Tau, Dt_secs, inversion_method='integral', dx_const=None, dy_const=None, b_9points=False, rotate=False, num_cores=18, radius=6371, dt_min=1825, ens=1, percentiles=[25, 50, 75])[source]

Invert gridded data using a local stencil. This function will setup variables and call the parallel_inversion function which will perform the actual inversion.

Parameters
x_gridnumpy.array

Input data of shape (y,x,time), where instead of (y,x) plane one could also use (z,x) or (y,z) plane.

block_rowsnumpy.array

y-indices, should include all points that are not nans

block_colsnumpy.array

x-indices, should include all points that are not nans for example block_rows, block_cols = np.where(np.isfinite(np.sum(x_grid,-1)))

block_lonnumpy.array

2D longitude of shape (y,x)

block_latnumpy.array

2D latitude of shape (y,x)

block_num_lonsnumpy.array

x_grid.shape[1], x-dimension

block_num_latsnp.array

x_grid.shape[0], y-dimension

block_num_sampnp.array

x_grid.shape[-1], time-dimension

Stencil_centerint

For a 5 point stencil should be 2 (for a 9 point stencil should be 4) .

Stencil_sizeint

5 point stencil is recommned (i.e. set to 5) - 9 point stencil is beta.

Tauint

Time lag. Units are the time units of x_grid: 1 day lag for daily data would be lag=1.

Dt_secsint

Time resolution of x_grid. For daily data Dt_secs=3600*24

inversion_methodstr, optional

Inversion method. We suggest ‘integral’ (default) which is domumented in Nummelin et al (2018).

dx_constint or numpy.array, optional

Grid size in meters. Default is None in which case dx and dy are calculated from block_lon and block_lat

dy_constint or numpy.array, optiona

Grid size in meters. Default is None in which case dx and dy are calculated from block_lon and block_lat

b_9pointsbool

If True a 9 point stencil (beta) will be used, default is False (recommened)

rotatebool

If False (default) the inversion will be done on a East-West, North-South stencil. If True the inversion will be done on a 45 degree rotated (counter-clockwise) stencil. Note that in this case U will be the (Southwest - Northeast) component and V will be the (Southeast - Northwest) component.

num_coresint

Number of cores to use for the inversion (default is 18); should be adjusted to your system.

radiusfloat

Radius of the planet in km, default is Earth (6371 km)

Returns
Unumpy.array

Zonal velocity [m s-1] (or if rotate=True will be Southwest - Northeast velocity)

Vnumpy.array

Meridional velocity [m s-1] (or if rotate=True will be Southeast - Northwest velocity)

Kxnumpy.array

Zonal diffusivity [m2 s-1] (or if rotate=True will be None)

Kxnumpy.array

Meridional diffusivity [m2 s-1] (or if rotate=True will be None)

Kxynumpy.array

If rotate=True will be Southwest - Northeast component of diffusivity [m2 s-1] (None if rotate=False) If b_9points=True, will be the off-diagonal part of the diffusion tensor.

Kyxnumpy.array

If rotate=True will be Southeast - Northwest component of diffusivity [m2 s-1] (None if rotate=False) If b_9points=True, will be the off-diagonal part of the diffusion tensor.

Rnumpy.array

Decay timescale in seconds

Bnumpy.array

Transport operator.

MicroInverse.MicroInverse_utils.load_data(filepath, fnames, jinds, iinds, varname, num_cores=20, dim4D=True, sum_over_depth=False, depth_lim=13, model_data=False, remove_clim=False, dt=1, depth_lim0=0)[source]

Load a timeseries of a 2D field (where possibly summing over depth if a 3D variable) in parallel

Parameters
filepathstr

Directory path pointing to the data folder Can be empty string if path is included in fnames

fnameslist

List of file names

jindslist

List of non-nan indices in y-direction.

iindslist

List of non-nan indices in x-direction Note that one should create jinds and iinds as follows 1) create a 2D mask: 1 where nan, else 0 usually landmask for ocean data 2) then do the following jinds,iinds = np.where(mask) jinds,iinds = np.meshgrid(jinds,iinds) jinds = jinds.flatten() iinds = iinds.flatten()

varnamestr

Name of the variable of interest in the data file

num_coresint

Number of cores to use (default 20)

dim4Dbool

True (default) if a file has more than one timestep

sum_over_depthbool

False (default) if the data has a depth axis and one wants a sum over a depth range.

depth_lim0integer

Upper limit for the depth average

depth_lim0integer

Lower limit for the depth average

remove_climboolean

If True a daily climatology will be removed. Best used only if the data is at daily time resolution

dtinteger

Time resolution of the input data in days

Returns
varnumpy.array

Timeseries of the requested variable (varname). Has the shape (time,jinds,iinds).

var_climnumpy.array

Climatology of the requested variable (varname). None if remove_clim=False (default)

MicroInverse.MicroInverse_utils.remove_climatology(var, dt, num_cores=18, rem6month=True)[source]

Remove annual cycle (fitted sine curve) from a numpy.array which has dimensions (nt,nx*ny)

Parameters
varnumpy.array

Data from which annual cycle is to be removed. Dimensions (nt,nx*ny), no nan’s allowed!

dtint

timestep in days

num_coresint, optional

Number of cores for multiprocessing (default 18)

rem6monthbool, optional

If True (default) also 6 month (180 day) signal is removed

Returns
outputnumpy.array

The output array from which the annual cycle has been removed