The difference_ops module.

This module implements averaging and differencing functions for data on a C-grid.

New at 0.5

  1. Relocated to subfilter.utils.

New at 0.4

  1. Use of xarray and dask.

Detailed Module Contents

The entire module is documented below.

difference_ops.py.

Created on Wed Apr 17 21:03:43 2019

Difference operators for C-grid data.

@author: Peter Clark

subfilter.utils.difference_ops.exec_fn(fn, field: xarray.core.dataarray.DataArray, axis: int) xarray.core.dataarray.DataArray

Execute function using map_overlap with overlap on selected axis.

Parameters
  • fn (function) – DESCRIPTION.

  • field (xarray.DataArray) – DESCRIPTION.

  • axis (int) – DESCRIPTION.

Returns

Return type

new xarray.DataArray

subfilter.utils.difference_ops.last_dim(z)

Remove all but last dimension of z.

Parameters

z (n-dimensional array.) –

Returns

z[0,0, etc. ,

Return type

]

@author: Peter Clark

subfilter.utils.difference_ops.interpolate(field, znew)

Interpolate field from z to zn.

Parameters
  • field (xarray nD field) –

  • znew (xarray coordinate new z.) –

Returns

Return type

field on zn levels

@author: Peter Clark

subfilter.utils.difference_ops.grid_conform_x(field, target_xdim)

Force field to target x grid by averaging if necessary.

Parameters
  • field (xarray) – Any multi-dimensional xarray with x dimension ‘x_u’ or ‘x_p’. Any other x dimensionm treated as ‘x_p’.

  • target_xdim (str) – Dimension name ‘x_u’ or ‘x_p’

Returns

field on target x grid.

Return type

xarray

subfilter.utils.difference_ops.grid_conform_y(field, target_ydim)

Force field to target y grid by averaging if necessary.

Parameters
  • field (xarray) – Any multi-dimensional xarray with y dimension ‘y_v’ or ‘y_p’. Any other y dimensionm treated as ‘y_p’.

  • target_xdim (str) – Dimension name ‘y_v’ or ‘y_p’

Returns

field on target y grid.

Return type

xarray

subfilter.utils.difference_ops.grid_conform_z(field, z, zn, target_zdim)

Force field to target x grid by interpolation if necessary.

Parameters
  • field (xarray) – Any multi-dimensional xarray with z dimension ‘z’ or ‘zn’.

  • z (xarray coord.) –

  • zn (xarray coord.) –

  • target_xdim (str) – Dimension name ‘z’ or ‘z’

Returns

field on target x grid.

Return type

xarray

subfilter.utils.difference_ops.grid_conform(field, z, zn, grid: str = 'p')

Force field to target grid by interpolation if necessary.

Parameters
  • field (xarray) – Any multi-dimensional xarray with z dimension ‘z’ or ‘zn’.

  • z (xarray coord.) –

  • zn (xarray coord.) –

  • grid (str | tuple(str)) – grid identifier ‘p’| ‘u’| ‘v’| ‘w’ or tuple (xdim, ydim, zdim).

Returns

field on target grid.

Return type

xarray

subfilter.utils.difference_ops.d_by_dx_field(field, z, zn, grid: str = 'p')

Differentiate field in x direction.

Parameters
  • field (xarray nD field) –

  • z (xarray coordinate) – zcoord on w levels - needed if changing vertical grid.

  • zn (xarray coordinate) – zcoord on p levels - needed if changing vertical grid.

  • grid (str | tuple of 2 strings) – destination grid (Default = ‘p’)

Returns

Return type

field on required grid

@author: Peter Clark

subfilter.utils.difference_ops.d_by_dy_field(field, z, zn, grid: str = 'p')

Differentiate field in y direction.

Parameters
  • field (xarray nD field) –

  • z (xarray coordinate) – zcoord on w levels - needed if changing vertical grid.

  • zn (xarray coordinate) – zcoord on p levels - needed if changing vertical grid.

  • grid (str | tuple of 2 strings) – destination grid (Default = ‘p’)

Returns

Return type

field on required grid

@author: Peter Clark

subfilter.utils.difference_ops.d_by_dz_field(field, z, zn, grid: str = 'p')

Differentiate field in z direction.

Parameters
  • field (xarray nD field) –

  • z (xarray coordinate) – zcoord on w levels - needed if changing vertical grid.

  • zn (xarray coordinate) – zcoord on p levels - needed if changing vertical grid.

  • grid (str | tuple of 2 strings) – destination grid (Default = ‘p’)

Returns

Return type

field on required grid

@author: Peter Clark

subfilter.utils.difference_ops.padleft(f, zt, axis=0)

Add dummy field at bottom of nD array.

Parameters
  • f (nD field) –

  • zt (1D zcoordinates) –

  • axis=0 (Specify axis to extend) –

Returns

Return type

extended field, extended coord

@author: Peter Clark

subfilter.utils.difference_ops.padright(f, zt, axis=0)

Add dummy field at top of nD array.

Parameters
  • f (nD field) –

  • zt (1D zcoordinates) –

  • axis=0 (Specify axis to extend) –

Returns

Return type

extended field, extended coord

@author: Peter Clark