Bay-Delta SELFE Tools

selfe_utility Module

Utility for SELFE Inputs

class selfe_utility.SelfeUtility

Bases: object

A class to manage SELFE input data



Adopt a new grid. fname = the file name of a new hgrid file


Create a source from a user input

create_flux_regions(fluxlines, out_fname)

Create fluxflag.gr3 in_fname = file name for flow transect information out_fname = output file name

create_node_partitioning(gr3_fname, polygon_data)

Create a gr3 file with node partitioning using polygons in the polygon file. gr3_fname = output gr3 file name polygons = polygons


Create open boundaries with the given two end points file fname = the end points file

create_prop_partitioning(prop_fname, polygon_data)

Create a prop file with element partitioning using polygons in the polygon file. prop_fname = output prop file name polygons = polygons

create_source_sink_in(source_sinks, out_fname='')

Create from source/sink location information in_fname = input file name


Create structures

get_closest_node_i_from_new_mesh(mesh, node_i)
interpolate_tide(time_start, time_end, dt, in_fname, out_fname)

Interpolate an observed tide time series with the given dt. time_start = start time in Python datetime time_end = end time in Python datetime dt = delta t for the interpolation output in_fname = input file name of tide records out_fname = output file name


Read SELFE input

Parameters :

dir: String :

An directory where the SELFE inputs reside



Getter :Return the mesh.

Modify depth with the polygon information


Reorder open boundaries with the given order order = list of open boundary names TODO: How to put the name of the boundaries is not settled.


Trim mesh using line_segments. This function trims the mesh on the left sides of the line segments. The left side here means left when you look at the second end point of a line segment from the first one. An actual path to trimming is a nodal path that is on the right side of the line segment. To manage torus like mesh topology, the argument takes an array of line segments. The user need to provides a set of line segments to make sure the left side of the line segments does not cover the whole mesh. To trim multiple parts of a mesh, use this function multiple times. This function clears up any boundary definitions associated with the original grid. It is user’s responsibility to create them again.

line_segments = array of line segments defined by two end points

write(dir, grid_fname='hgrid.gr3', struct_fname='', source_fname='')

Write SELFE output files into the given directory.

write_fluxregions(lines, out_fname='fluxflag.prop')

Create and write flux_regions.gr3 with the given lines lines = list of pairs of (X, Y) of line segments out_fname = output file name

write_hgrid(fname, attr=None, boundary=True)

Write a hgrid file only. fname = the output file name attr = attribute array in numpy format. If None, original data will be kept. boundary = If True, boundary info will be appended at the end of the file. Otherwise, not appended.

write_hgrid_ll(fname, input_epsg=26910, output_epsg=4269)

Write a hgrid.ll, lat-long mesh file, of the current mesh.

Parameters :

fname: str :

the output file name

input_epsg: int, optional :

input EPSG. default value is 26310, NAD83/UTM10N.

output_epsg: int, optional :

output EPSG. default value is 4269, NAD83


Write a SELFE structure file fname = output file name


Read a mesh in GR3 format, and return a SELFE input instance.

Parameters :fname: str :
Returns :SELFE input instance :

A load function