The gefdc API

pygridtools.gefdc.write_cellinp(cell_array, outputfile='cell.inp', mode='w', writeheader=True, rowlabels=True, maxcols=125, flip=True)[source]

Writes the cell.inp input file from an array of cell definitions.

Parameters:
cell_array : numpy array

Integer array of the values written to outfile.

outputfile : optional string (default = “cell.inp”)

Path and filename to the output file. Yes, you have to tell it to call the file cell.inp

maxcols : optional int (default = 125)

Number of columns at which cell.inp should be wrapped. gefdc requires this to be 125.

flip : optional bool (default = True)

Numpy arrays have their origin in the upper left corner, so in a sense south is up and north is down. This means that arrays need to be flipped before writing to “cell.inp”. Unless you are _absolutely_sure_ that your array has been flipped already, leave this parameter as True.

Returns:
None

See also

make_gefdc_cells

pygridtools.gefdc.write_gefdc_control_file(outfile, title, max_i, max_j, bathyrows)[source]
pygridtools.gefdc.write_gridout_file(xcoords, ycoords, outfile)[source]
pygridtools.gefdc.write_gridext_file(tidydf, outfile, icol='ii', jcol='jj', xcol='easting', ycol='northing')[source]
pygridtools.gefdc.convert_gridext_to_gis(inputfile, outputfile, crs=None, river='na', reach=0)[source]

Converts gridext.inp from the rtools to a GIS file with geomtype = ‘Point’.

Parameters:
inputfile : string

Path and filename of the gridext.inp file

outputfile : string

Path and filename of the destination GIS file

crs : string, optional

A geopandas/proj/fiona-compatible string describing the coordinate reference system of the x/y values.

river : optional string (default = None)

The river to be listed in the output file’s attributes.

reach : optional int (default = 0)

The reach of the river to be listed in the output file’s attributes.

Returns:
geopandas.GeoDataFrame
pygridtools.gefdc.make_gefdc_cells(node_mask, cell_mask=None, triangles=False)[source]

Take an array defining the nodes as wet (1) or dry (0) create the array of cell values needed for GEFDC.

Parameters:
node_mask : numpy bool array (N x M)

Bool array specifying if a node is present in the raw (unmasked) grid.

cell_mask : optional numpy bool array (N-1 x M-1) or None (default)

Bool array specifying if a cell should be masked (e.g. due to being an island or something like that).

triangles : optional bool (default = False)

Currently not implemented. Will eventually enable the writting of triangular cells when True.

Returns:
cell_array : numpy array

Integer array of the values written to outfile.

class pygridtools.gefdc.GEFDCWriter(mg, directory)[source]

Bases: object

Convenience class to write the GEFDC files for a ModelGrid

Parameters:
mg : pygridtools.ModelGrid
directory : str or Path

Where all of the files will be saved

control_file(filename='gefdc.inp', bathyrows=0, title=None)[source]

Generates the GEFDC control (gefdc.inp) file for the EFDC grid preprocessor.

Parameters:
filename : str, optional

The name of the output file.

bathyrows : int, optional

The number of rows in the grid’s bathymetry data file.

title : str, optional

The title of the grid as portrayed in filename.

Returns:
gefdc : str

The text of the output file.

cell_file(filename='cell.inp', triangles=False, maxcols=125)[source]

Generates the cell definition/ASCII-art file for GEFDC.

Parameters:
filename : str, optional

The name of the output file.

triangles : bool, optional

Toggles the inclusion of triangular cells.

maxcols : int, optional

The maximum number of columns to write to each row. Cells beyond this number will be writted in separate section at the bottom of the file.

Returns:
cells : str

The text of the output file.

gridout_file(filename='grid.out')[source]

Writes to the nodes as coordinate pairs for GEFDC.

Parameters:
filename : str, optional

The name of the output file.

Returns:
df : pandas.DataFrame

The dataframe of node coordinate pairs.

gridext_file(filename='gridext.inp', shift=2)[source]

Writes to the nodes and I/J cell index as to a file for GEFDC.

Parameters:
filename : str, optional

The name of the output file.

shift : int, optional

The shift that should be applied to the I/J index. The default value to 2 means that the first cell is at (2, 2) instead of (0, 0).

Returns:
df : pandas.DataFrame

The dataframe of coordinates and I/J index.