cem_gridtools API

CGrid

General Curvlinear C-grid

class cem_gridtools.cem_gridtools.CGrid(x, y, beta)[source]

Bases: object

CGrid constructor

Parameters
  • x (array) – x boundary values

  • y (array) – y boundary values

  • beta (array) – beta values (corner status)

beta points
  • +1 for external corner or 90 degree clockwise turns

  • -1 for internal corner or 90 degree anti-clockwise turns

  • 0 all other boundary points

gen_grid(ni, nj, ulidx=0)[source]

Generates the (ni+1) x (nj+1) grid and calculates the full double-density points

Parameters
  • ni (int) – Number of required grid cells in the i-direction

  • nj (int) – Number of required grid cells in the j-direction

  • ulidx (int, optional) – The index of the upper left corner of the grid

plot(legend=False, dd=False, map=False)[source]

Simple plotting routine for gridlines using Matplotlib

get_grid_points()[source]

Returns the 2D grid corner points (gx, gy)

get_cell_centres()[source]

Returns the 2D cell centres for (xc, yc) for the grid

export_shoc_grid(name)[source]

Write SHOC grid to given file

Parameters

name (str) – output filename, overwrites file

get_cell_centres_as_points()[source]

Returns the cell centres as a shapely MultiPoint object

get_grid_as_lines()[source]

Returns the grid as a shapely MultiLineString object

  • This is still work in progress and the API is currently rapidly evolving …

get_grid_as_polygons()[source]

Returns the grid as a list of shapely Polygon objects

A MultiPolygon would have invalid geometry as they cannot share an edge

CGridRect

Rectangular Curvilinear Grid

class cem_gridtools.cem_gridtools.CGridRect(x, y, geo=False)[source]

Bases: cem_gridtools.cem_gridtools.CGrid

CGRidRect constructor

If geo=True then the resolution will be interpreted in “metres” from which the grid dimensions are calcuated based on the geographic centroid of the grid. Otherwise, units are assummed to be the same as the supplied input boundary

Parameters
  • x (array) – 1-d array of length 4

  • y (array) – 1-d array of length 4

  • geo (bool, optional) – whether this is geographic

gen_gridrect(resolution)[source]

Generate uniform grid

Parameters

resolution (float) – Required grid resolution

NN

Natural Neighbours (scattered) interpolation interface

class cem_gridtools.cem_gridtools.NN(x, y, z, irule='nn_sibson')[source]

NN constructor

Parameters
  • x (array) – X points (1-d)

  • y (array) – Y points (1-d)

  • z (array) – Z (depth) points (1-d)

  • irule (string) –

    interpolation method to use

    Choices are nn_sibson (default), nn_non_sibson and linear

interp(xo, yo)[source]

Perform interpolation on the given points

Parameters
  • xo (float) – x value(s) to interpolate onto

  • yo (float) – y value(s) to interpolate onto

xo,yo may be scalars or 1-d arrays

Returns

interpolated value(s)

Return type

float

export_shoc_bathy(name, iV=None)[source]

Write SHOC bathymetry data to given file

Parameters
  • name (str) – output filename, overwrites file

  • iV (array, optional) – Input vector to export

Coast

Interface to coast line files

class cem_gridtools.cem_gridtools.Coast(fname)[source]

Coast constructor

The type of data is inferred from the extension:

  • .cst : ASCII X,Y columns with NaN breaks

  • .shp : Shape file (not implemented yet)

Parameters

fname (str) – coast file name

get_num_polygons()[source]

Get the number of polygons found in the coasts file

Returns

number of polygons

Return type

integer

plot(ax=None)[source]

Plot all coastline polygons

Parameters

ax (optional) – Axis to plot on