schimpy package

Submodules

schimpy.base_io module

This module is a simple common base for text file IO. @outhor: Kijin Nam, knam@water.ca.gov

class schimpy.base_io.BaseIO(logger=None)

Bases: object

Common IO routines to handle text inputs

Attributes:
linecounter
property linecounter

schimpy.batch_metrics module

Create metrics plots in batch mode

schimpy.batch_metrics.generate_metricsplots(path_inputfile)

schimpy.bctide module

This class will read in a yaml file which defines SCHISM boundary and generate bctides.in. It supports all type of elevation, velocity, salinity, temperature and tracer boundaries. At the end of this script, there is a synthetic example which demonstrates the format of bctide YAML file.

schimpy.bctide.load_boundary(fn)

schimpy.bound_linear module

schimpy.bound_linear.bound_linear(z, z_low, z_high, val_low, val_high)

schimpy.cencoos_download module

schimpy.cencoos_download.cencoos_schism_opendap(lat_lo, lon_lo, lat_hi, lon_hi, file_base, to_cache, from_cache)

Download cencoos opendap data for all time based on a bounding set of lat/lon file_base : str prefix for files to_cache : bool whether to stash data in numpy arrays to make it easier next time from_cache : use cache rather than download)

The strategy for this download may change with time. When the script was originally written, blocking the query in time was very inefficient

schimpy.cencoos_download.merc_to_latlon(x, y)
schimpy.cencoos_download.time_block_report(message, told)

This routine is for reporting incremental timing of parts of the script

schimpy.check_mesh_skewness module

Calculate skewness of elements form gr3 file

schimpy.check_mesh_skewness.calculate_skewness(mesh, normalize=True, mask_tri=False)

Calculate skewness of elements

Parameters:
mesh: schism_mesh
normalize: bool, optional

Normalize skewness if True.

mask_tri: bool, optional

If true, mask skewness of triangular elements with zero

schimpy.check_mesh_skewness.create_arg_parser()

Create an argument parser

schimpy.check_mesh_skewness.main()

main function

schimpy.check_mesh_skewness.write_prop(fpath, data)

Write a prop file with a prop vector

schimpy.clip_dems module

schimpy.clip_dems.bounding_coords(image)
schimpy.clip_dems.clip_dem(xlo, xhi, demlist='dem.txt', outformat='AAIGrid', hshift=False, prefix='clipped', verbose=False)
schimpy.clip_dems.create_arg_parser()
schimpy.clip_dems.main()

schimpy.combine_consume module

schimpy.combine_consume.appears_done(wdir, fb, exten, firstblock, lastblock)

Decide if entire file block already appears to have been combined based on existence of combined file. Date not checked

schimpy.combine_consume.archive_blocks(ar_file, tbase, blocks_per_day=1, ndxmin=1, ndxmax=None)
schimpy.combine_consume.combine(wdir, blocks, fbase, combine_exe, consume=True, assume_done=True)
schimpy.combine_consume.combine_consume(is_test=False)
schimpy.combine_consume.combine_hotstart(wdir, combine_hotstart_exe, minstep=0, maxstep=99999999, consume=True)
schimpy.combine_consume.create_arg_parser()

Create argument parser for

schimpy.combine_consume.detect_min_max_index(wdir, sample_fbase)
schimpy.combine_consume.do_combine(wdir, begin, end, filebase)
schimpy.combine_consume.do_combine_hotstart(wdir, step)
schimpy.combine_consume.failed_incomplete(e)
schimpy.combine_consume.gather_ppf_names(wdir, blocks)
schimpy.combine_consume.main()
schimpy.combine_consume.prune_ppf_files(wdir, blocks, fbase, list_only=False)
schimpy.combine_consume.setup(wdir, filebase)
schimpy.combine_consume.split(alist, n)
schimpy.combine_consume.touch(fname, times=None)

schimpy.combine_flux module

Command line tool to merge possibly overlapping flux.dat files from hotstart runs

schimpy.combine_flux.combine_flux(infiles, outfile, prefer_last=False)

Merge possibly overlapping flux.dat files from hostart runs

schimpy.combine_flux.create_arg_parser()
schimpy.combine_flux.main()

Driver to parse arguments

schimpy.combine_flux.test_combine_flux()

schimpy.contour_smooth module

This module contains tools for a smoother for DEMs (currently tiff format) based on curvature flow The algorithm is based on one by Malladi and Sethian, and results in a simplification of contours while allowing sharp gradients as long as they are persistent. So it is not a cure for pressure gradient errors a la Hannah. The script shows some artefacts of a time when it wasn’t particularly stable and could run out of memory. In particular, the algorithm dumps out intermediate arrays as it goes along and these have to be visualized or saved using the appropriate subcommands or functions. Stability is no longer an issue. it has been good for quite a while. Not so sure about memory. We’ve not tested a big problem yet on a big DEM on 64bit python.

class schimpy.contour_smooth.RasterWrapper(filename)

Bases: object

Methods

write_copy

write_copy(filename, data)
schimpy.contour_smooth.calc_f(t, data, width_shape)

Right hand side of the semi-discretized operator (in space) so that it can be integrated in time

schimpy.contour_smooth.contour_smooth(input, scales, max_time, nstep, report_interval, fill_val=2.0, **kwargs)

Driver function for smoothing a DEM

schimpy.contour_smooth.contour_smooth2d(dem, scales, max_time, nstep, report_interval)
schimpy.contour_smooth.create_arg_parser()
schimpy.contour_smooth.main()
schimpy.contour_smooth.save_smooth(dumpfile, original, outfile, **kwargs)
schimpy.contour_smooth.view_smooth(file0, file1, levels, vmin, vmax, **kwargs)

View the dumped files to graphically explore smoothing progress

schimpy.convert_linestrings module

Command line tool to convert SCHISM line strings in YAML to Shapefile and vice versa

schimpy.convert_linestrings.create_arg_parser()

Create an argument parser

schimpy.convert_linestrings.main()

A main function to convert polygon files

schimpy.convert_mesh module

Mesh converter

schimpy.convert_mesh.convert_mesh(args)

Converts mesh files to new format (shape file, gr3 etc)

schimpy.convert_mesh.create_arg_parser()
schimpy.convert_mesh.main()

schimpy.convert_polygons module

Command line tool to convert SCHISM polygons in YAML to Shapefile and vice versa

schimpy.convert_polygons.create_arg_parser()

Create an argument parser

schimpy.convert_polygons.main()

A main function to convert polygon files

schimpy.convert_sav_class_to_number module

schimpy.convert_sav_class_to_number.create_arg_parse()

Create argument parser Parameters ———-

schimpy.convert_sav_class_to_number.main()
schimpy.convert_sav_class_to_number.read_density_tiff(fpath_densitiy_tiff)

Read geotiff values for density It is assumed that the projected regular coordinates.

Parameters:
fpath_densitiy_tiff: str

filename for SAV desity diff

Returns:
numpy.ndarray

3D array containing x’s, y’s, and density. The shape is (n_x, n_y, 3)

schimpy.create_mesh_n_levels module

Create a mesh file with the number of vertical levels as nodal value

schimpy.create_mesh_n_levels.create_arg_parser()

Create an argument parser

schimpy.create_mesh_n_levels.main()

Just a main function

schimpy.create_vgrid_lsc2 module

Create LSC2 vertical grid lsc2.py

The min and max layers can be specified in polygons in yaml or shp with minlayer and maxlayer attributes.

schimpy.create_vgrid_lsc2.create_arg_parser()

Create argument parser for

schimpy.create_vgrid_lsc2.main()
schimpy.create_vgrid_lsc2.plot_vgrid(hgrid_file, vgrid0_file, vgrid_file, vgrid_version, eta, transectfiles)
schimpy.create_vgrid_lsc2.vgrid_gen(hgrid, vgrid_out, vgrid_version, eta, minmaxlayerfile, archive_nlayer='out', nlayer_gr3='nlayer.gr3')

schimpy.cruise module

schimpy.cruise.create_arg_parser()
schimpy.cruise.cruise_xyt(path, station_data, base_time, outfile)
schimpy.cruise.do_depth_plot(station, cruise_data, surrounding_profiles, ax, xlabel, ylabel, add_legend=False)
schimpy.cruise.gen_profile_plot(base_date, cruise_time, survey_file, model_file, station_file, xytfile)
schimpy.cruise.gen_station_xyt(base_date, cruise_time, survey_file, station_file, xytfile)
schimpy.cruise.longitudinal(cruise_data, station_data, ax, context_label=None, add_labels=False, xlabel=None, xmin=None, xmax=None, max_depth=None)
schimpy.cruise.main(base_date, cruise_time, obs_file, model_file, station_file, xytfile)
schimpy.cruise.match_cruise(time, station, x, z, times, data)
schimpy.cruise.model_data_for_longitude(cruise_data, station_data, x, z, times, model_data, base_date)
schimpy.cruise.process_cruise(path)
schimpy.cruise.process_stations(station_file)
schimpy.cruise.process_xyt(path, casts, base_time)

schimpy.cut_mesh module

Functions to cut certain parts in the mesh by cutting lines.

schimpy.cut_mesh.cut_mesh(fpath_gr3_in, lines, fpath_gr3_out, cut_side='left')

Remove elements of a mesh in one side of cutting polyline segments. A mesh is read in from a gr3, and a result mesh is written in another gr3 file.

A user needs to be careful that line segments forms a closed division. Otherwise, all elements would be deleted.

Parameters:
fpath_gr3_in

Filename of the input grid in gr3

lines: array-like

An array of coordinates of line segments specifying the location of cuts

fpath_gr3_out

Filename of the output grid in gr3

cut_side: str, optional

If cut_side is ‘left,’ which is default, the left side of cutting lines when one sees the second point from the first point of a line will be removed. If this value is ‘right,’ the right side will be removed.

schimpy.cut_mesh.read_lines(fpath)

Read coordinates of cutting line segments from a plain text file.

The expected format is:

x1 y1 x2 y2

in each line.

Parameters:
fpath

Name of a file containing coordinates of cutting lines

Returns:
list

List of coordinates of cutting lines

schimpy.cut_mesh.read_lines_from_shapefile(fpath)

Read coordinates of cutting line segments from a ESRI Shapefile containing line features.

Parameters:
fpath

Name of a file containing coordinates of cutting lines

Returns:
list

List of coordinates of cutting lines

schimpy.download_hrrr module

Created on Fri Jan 20 09:07:50 2023 Download NOAA High-Resolution Rapid Refresh (HRRR) Model using AWS bucket service

schimpy.download_hrrr.create_arg_parser()

Create an argument parser return: argparse.ArgumentParser

schimpy.download_hrrr.download_hrr(start_date, rnday, pscr, bbox)
schimpy.download_hrrr.main()

Main function

schimpy.embed_raster module

Embed finer gridded data in coarser, using curvature flow smoothing to reconcile

Main function is called embed_fine

schimpy.embed_raster.create_arg_parser()
schimpy.embed_raster.embed_raster(input_fg, input_bg, output, nsmooth_init=2, nsmooth_final=1, plot=False, max_time_init=3, max_time_final=1, nstep=50, report_interval=1, **kwargs)

Embed a smoother DEM in a coarser

The two inputs and output are filenames. The basic plans is this: 1. Smooth the fine data enough to resample without aliasing or distortion 2. Interpolate/resample the result to the coarser mesh 3. Where the result of 1-2 has good data, replace coarser data 4. Smooth the final grid lightly to remove kinks/discontinuity

The smoothing is done with contour_smooth2d

schimpy.gaussian_quadrature module

Gaussian quadrature in 2D space

class schimpy.gaussian_quadrature.GaussianQuadrature(order)

Bases: object

Abstract base class of GaussianQuadrature

Methods

average(vertices, values)

Calculate the average of the value over the domain.

calculate_quadrature_points_and_weights()

Calculate quadrature points and weights

domain_size(vertices)

Abstract method to calculate the size of the domain

integrate(vertices[, values])

Integrate values over a quad element

jacobian_det(vertices)

Determinant of Jacobian at quadrature points

number_of_quadrature_points()

Get the number of quadrature points

quadrature_vector(vertices)

Create a quadrature matrix for quadrature integration Taking a dot product this quadrature matrix and the values at the quadrature points will result in quadrature

shape(pts)

Abstract shape function

shape_derivative(pts)

Abstract shape derivative function

values_at_quadrature_points(values)

Get quadrature points

average(vertices, values)

Calculate the average of the value over the domain.

Parameters:
vertices: numpy.array

coordinates of vertices (or nodes) The shape needs to be (:, 2) or more columns. The values in the first two columns will be used.

Returns:
float

the length of the line

calculate_quadrature_points_and_weights()

Calculate quadrature points and weights

Parameters:
pts: np.ndarray

Coordinates of the nodes

Returns:
ptsreal

quadrature points

domain_size(vertices)

Abstract method to calculate the size of the domain

integrate(vertices, values=None)

Integrate values over a quad element

Parameters:
vertices: numpy.array

coordinates of vertices (or nodes) with values. The shape needs to be (:, 2)

values: numpy.array, optional

A value vector at vertices If it is not provided, the thrid column will be used as values

Returns:
float

result of integration

jacobian_det(vertices)

Determinant of Jacobian at quadrature points

Parameters:
vertices: numpy.array

coordinates of vertices (or nodes) The shape needs to be (:, 2) or more columns. The values in the first two columns will be used.

Returns:
numpy.array

array of determinant ant quadrature points

number_of_quadrature_points()

Get the number of quadrature points

Returns:
int

Number of quadrature points

quadrature_vector(vertices)

Create a quadrature matrix for quadrature integration Taking a dot product this quadrature matrix and the values at the quadrature points will result in quadrature

Parameters:
vertices: numpy.array

coordinates of vertices (or nodes) with values. The shape needs to be (:, 2)

Returns:
numpy.array

two-dimensional matrix of quadrature matrix

shape(pts)

Abstract shape function

Parameters:
pts: np.ndarray

Coordinates of the nodes

shape_derivative(pts)

Abstract shape derivative function

Parameters:
pts: np.ndarray

Coordinates of the nodes

values_at_quadrature_points(values)

Get quadrature points

Parameters:
values: numpy.array

values at quadrature points

Returns:
numpy.array

values of Gaussian quadrature points

class schimpy.gaussian_quadrature.GaussianQuadratureLine2(order)

Bases: GaussianQuadrature

Gaussian quadrature on line with two end points in 2-D space

Methods

average(vertices, values)

Integrate values over a quad element

calculate_quadrature_points_and_weights()

Calculate quadrature points and weights

domain_size(vertices)

Size of domian, which is the length of the line in this case

integrate(vertices[, values])

Integrate values over a quad element

jacobian_det(vertices)

Determinant of Jacobian at quadrature points, 1-D version

number_of_quadrature_points()

Get the number of quadrature points

quadrature_vector(vertices)

Create a quadrature matrix for quadrature integration Taking a dot product this quadrature matrix and the values at the quadrature points will result in quadrature

shape(pts)

Shape functions Ordering is counter-clockwise direction

shape_derivative(pts)

Derivatives of shape functions

values_at_quadrature_points(values)

Get quadrature points

average(vertices, values)

Integrate values over a quad element

Parameters:
vertices: numpy.array

coordinates of vertices (or nodes) with values. The shape needs to be (-1, 2)

values: numpy.array

The values at vertices

Returns:
averagefloat

result of integration

calculate_quadrature_points_and_weights()

Calculate quadrature points and weights

Parameters:
pts: np.ndarray

Coordinates of the nodes

Returns:
ptsreal

quadrature points

domain_size(vertices)

Size of domian, which is the length of the line in this case

Parameters:
vertices: numpy.array

coordinates of vertices (or nodes) The shape needs to be (2, 2) or more columns. The values in the first two columns will be used.

Returns:
float

the length of the line

jacobian_det(vertices)

Determinant of Jacobian at quadrature points, 1-D version

Parameters:
vertices: numpy.array

coordinates of vertices (or nodes) The shape needs to be (-1, 2) or more columns. The values in the first two columns will be used.

Returns:
numpy.array

array of determinant ant quadrature points

shape(pts)

Shape functions Ordering is counter-clockwise direction

Parameters:
pts: numpy.array

Local coordinates.

Returns:
numpy.array

matrix of shape function value at the given points

shape_derivative(pts)

Derivatives of shape functions

Parameters:
pts: numpy.array

Local coordinates. The dimension is (-1, 2)

Returns:
numpy.array

matrix of shape function derivative wrt xi value at (*, eta)

class schimpy.gaussian_quadrature.GaussianQuadratureQuad4(order)

Bases: GaussianQuadrature

Gaussian Quadrature for a quadrilateral with four nodes

Methods

average(vertices, values)

Calculate the average of the value over the domain.

calculate_quadrature_points_and_weights()

Calculate quadrature points and weights

domain_size(vertices)

Size of domain, which is the area of the quadrilateral in this case.

integrate(vertices[, values])

Integrate values over a quad element

jacobian(vertices[, local_coord])

Create a Jacobian matrix or matrixes at the given local coordinates

jacobian_det(vertices)

Determinant of Jacobian at quadrature points

number_of_quadrature_points()

Get the number of quadrature points

quadrature_vector(vertices)

Create a quadrature matrix for quadrature integration Taking a dot product this quadrature matrix and the values at the quadrature points will result in quadrature

shape(pts)

Shape functions Ordering is counter-clockwise direction

shape_derivative(pts)

Derivatives of shape functions

values_at_quadrature_points(values)

Get quadrature points

calculate_quadrature_points_and_weights()

Calculate quadrature points and weights

domain_size(vertices)

Size of domain, which is the area of the quadrilateral in this case. The area is calculated with shoelace equation.

Parameters:
vertices: numpy.array

coordinates of vertices (or nodes) The shape needs to be (4, 2) or more columns. The values in the first two columns will be used.

Returns:
ret_size: float

the length of the line

jacobian(vertices, local_coord=None)

Create a Jacobian matrix or matrixes at the given local coordinates

Parameters:
vertices: numpy.array

coordinates of vertices (or nodes) The shape needs to be (4, 2) or more columns. The values in the first two columns will be used.

local_coord: numpy.array

local coordinates where a Jacobian is calculated

Returns:
numpy.array

Jacobian matrix

shape(pts)

Shape functions Ordering is counter-clockwise direction

Parameters:
pts: numpy.array

Local coordinates. The dimension is (-1, 2)

Returns:
numpy.array

matrix of shape function value at (xi, eta)

shape_derivative(pts)

Derivatives of shape functions

Parameters:
pts: numpy.array

Local coordinates. The dimension is (-1, 2)

Returns:
numpy.array

matrix of shape function derivative wrt xi value at (*, eta)

class schimpy.gaussian_quadrature.GaussianQuadratureTri3(order)

Bases: GaussianQuadrature

Gaussian Quadrature for triangles with three nodes

Methods

average(vertices, values)

Calculate the average of the value over the domain.

calculate_quadrature_points_and_weights()

Calculate quadrature points and weights

domain_size(vertices)

Size of domian, which is the area of the quadrilateral in this case.

integrate(vertices[, values])

Integrate values over a quad element

jacobian(vertices[, local_coord])

Create a Jacobian matrix or matrixes at the given local coordinates

jacobian_det(vertices)

Determinant of Jacobian at quadrature points

number_of_quadrature_points()

Get the number of quadrature points

quadrature_vector(vertices)

Create a quadrature matrix for quadrature integration Taking a dot product this quadrature matrix and the values at the quadrature points will result in quadrature

shape(pts)

Shape functions Ordering is counter-clockwise direction

shape_derivative(pts)

Derivatives of shape functions

values_at_quadrature_points(values)

Get quadrature points

calculate_quadrature_points_and_weights()

Calculate quadrature points and weights

domain_size(vertices)

Size of domian, which is the area of the quadrilateral in this case. The area is calculated with shoelace equation.

Parameters:
vertices: numpy.array

coordinates of vertices (or nodes) The shape needs to be (3, 2) or more columns. The values in the first two columns will be used.

Returns:
float

the length of the line

jacobian(vertices, local_coord=None)

Create a Jacobian matrix or matrixes at the given local coordinates

Parameters:
vertices: numpy.array

coordinates of vertices (or nodes) The shape needs to be (4, 2) or more columns. The values in the first two columns will be used.

local_coord: numpy.array

local coordinates where a Jacobian is calculated

Returns:
numpy.array

Jacobian matrix

jacobian_det(vertices)

Determinant of Jacobian at quadrature points

Parameters:
vertices: numpy.array

coordinates of vertices (or nodes) but it is not used

Returns:
numpy.array

array of determinant ant quadrature points

shape(pts)

Shape functions Ordering is counter-clockwise direction

Parameters:
pts: numpy.array

Local coordinates. Not used

Returns:
numpy.array

matrix of shape function value at (xi, eta)

shape_derivative(pts)

Derivatives of shape functions

Parameters:
pts: numpy.array

Local coordinates. Not used

Returns:
numpy.array

matrix of shape function derivative wrt xi value at (*, eta)

schimpy.gen_elev2d module

Generate elev2D.th for a Bay-Delta SCHSIM model using tides at Point Reyes and Monterey.

2015-06-16: Customized

class schimpy.gen_elev2d.BinaryTHWriter(fpath_out, nloc, starttime)

Bases: THWriter

Methods

write_all

write_step

write_all(times, vals)
write_step(iter, time, vals)
class schimpy.gen_elev2d.NetCDFTHWriter(fpath_out, nloc, starttime, dt)

Bases: THWriter

Methods

write_all

write_step

write_all(times, vals)
write_step(iter, time, vals)
class schimpy.gen_elev2d.THWriter(path, size, starttime)

Bases: object

Methods

write_all

write_step

write_all(times, vals)
write_step(iter, time, vals)
schimpy.gen_elev2d.create_arg_parser()
schimpy.gen_elev2d.gen_elev2D(hgrid_fpath, outfile, pt_reyes_fpath, monterey_fpath, start, end, slr)
schimpy.gen_elev2d.main()

schimpy.geo_tools module

schimpy.geo_tools.FindMultiPoly(poly_array)
schimpy.geo_tools.Polylen(poly)
schimpy.geo_tools.geometry2coords(geo_obj)
schimpy.geo_tools.geometry2coords_points(geo_obj)
schimpy.geo_tools.ic_to_gpd(fn, crs=None)

Read ic yaml file and convert the polygons to geopandas format

schimpy.geo_tools.ll2utm(lonlat, crs=None)

lonlat can be numpy arrays. lonlat = np.asarray([lon,lat]) default crs = epsg:26910

schimpy.geo_tools.partition_check(mesh, poly_fn, regions, centering='node', crs=None, allow_overlap=False, allow_incomplete=False)

Check if the schism mesh division by the polygon features in poly_fn is unique and complete. The partition check is based on either node or element, and the function checks:

  • if there are any orphaned nodes, and

  • if any nodes/elems were assigned to multiple polygons.

schimpy.geo_tools.project_fun(crs=None)
schimpy.geo_tools.shapely_to_geopandas(features, crs=None, shp_fn=None)

Convert shapely features to geopandas and generate shapefiles as needed

schimpy.geo_tools.shp2yaml(shp_fn, yaml_fn=None, crs=None)

Convert a shapefile to yaml file

Parameters:
shp_fnstr

Input shape filename

yaml_fnstr

Output yaml filename

crsstr, optional

Output projection. The default is None.

Returns:
None.
schimpy.geo_tools.utm2ll(utm_xy, crs=None)

utm_xy can be numpy arrays. utm_xy = np.asarray([utm_x,utm_y]) default crs = epsg:26910

schimpy.geo_tools.yaml2shp(fn, shp_fn=None, crs=None)

schimpy.gr3 module

Package to read a mesh in GR3 format.

class schimpy.gr3.Gr3IO(logger=None)

Bases: BaseIO

A class that manages I/O of GR3 files

Attributes:
linecounter

Methods

read([gr3_fname, mode])

Read in a hgrid.gr3 file.

write(mesh, fname[, node_attr, boundary])

Write a GR3 format grid.

read(gr3_fname='hgrid.gr3', mode=0)

Read in a hgrid.gr3 file. If mode is 1, it does not read in boundary information.

write(mesh, fname, node_attr=None, boundary=False)

Write a GR3 format grid. mesh = SCHISM mesh (schism_mesh) instance fname = output file name node_attr = a list of node attribute boundary = If true, boundary information will be added. Otherwise, it will not be appended.

schimpy.grid_opt module

Routines to perform grid optimization for volumetric consistency with finer DEM

There are two methods:

  1. lsqr without constraint to solve \(Ax=b\) (scipy.sparse.linalg.lsqr)

  2. minimize function \(1/2*||Ax-b||^2\) using the L-BFGS-B algorithm (scipy.optimize.fmin_l_bfgs_b)

where

x is depth at nodes with respect to a nominal reference surface (which may be greater than sea level in upstream locations).

Regularization:

  1. close to the original values for all nodes: damp

  2. minimize the 1st derivative of node elevation along land boundaries: damp_shoreline

Notes:

  • The function cal_z_ref only applies to the Bay Delta grid and need to be modified for other grids.

  • This script create an optimized gr3 file (_opt.gr3) only when one set of optimization parameters is specified.

class schimpy.grid_opt.GridOptimizer(**kwargs)

Bases: object

Grid optimizer class

Methods

assemble_element_matrix(areas)

Build a matrix for element optimization

assemble_face_matrix(edges)

Build a matrix for face optimization The order of the quadrature is fixed

build_boundary_equations(ref_surf_at_nodes)

Build a matrix and vector of land boundary constraints

build_global_matrix_and_vector(params, ...)

Build a global matrix and vector for optimization

calculate_depth_at_element_quad_points(...)

Calculate depth at quad points

calculate_depth_at_face_quad_points(edges, ...)

Calculate depth at quad points

calculate_edge_lengths(edges)

Calculate areas of all edges

calculate_element_areas()

Calculate areas of all elements

calculate_element_volumes_w_dem(depth_at_quads)

Calculate volumes of elements based on DEM

calculate_face_areas_w_dem(edges, depth_at_quads)

Calculate area of faces based on DEM

calculate_max_elevation_in_balls(elev)

Calculate maximum elevation in a ball from a node

calculate_reference_surface(coords)

Define reference water surface at locations specified in nodes based on the assumptions, which only applicable to Bay Delta grid

calculate_reference_surface_at_face_quadarture_points(...)

Calculate reference surface at quadrature points

calculate_reference_surface_maximum()

Create reference surface elevation at individual nodes

calculate_total_number_of_quadrature_points()

Calculate total number of quadrature points of the mesh with the given order

calculate_values_at_element_quadarture_points(values)

Calculate values at quadrature points

calculate_values_at_face_quadarture_points(...)

Calculate values at quadrature points

collect_edges([exclude_land_boundaries])

Collect edges for the optimization

collect_element_quadrature_points_for_dem()

Collect all quadrature points to calculate volumes of elements with DEM

collect_face_quadrature_points_for_dem(edges)

Collect all quadrature points to calculate areas of faces with DEM

count_boundary_equations()

Count how many boundary constraint equations there are

get_dem_elevation(list_of_points)

Get elevations from DEM

integrate_over_edges(edges, values)

Integrate over edges with the values at nodes

integrate_over_elements(values)

Integrate over elements with the values at nodes

optimize(params[, solver])

Perform a grid optimization

select_solver(solver)

Select solver

show_parameters(solver, param)

Show optimization parameters

assemble_element_matrix(areas)

Build a matrix for element optimization

Parameters:
areas: numpy.array

areas of the elements

assemble_face_matrix(edges)

Build a matrix for face optimization The order of the quadrature is fixed

Parameters:
edges: numpy.array

list of edges

Returns:
lil_matrix

matrix for face (edge) optimization

build_boundary_equations(ref_surf_at_nodes)

Build a matrix and vector of land boundary constraints

Returns:
numpy.sparse.lil_matrix

Matrix of land boundary equations

numpy.array

Vector of land boundary equations

build_global_matrix_and_vector(params, mat_elem, mat_face, vec_elem, vec_face, mat_bnd, vec_bnd, depths_at_nodes, solver='L-BFGS-B')

Build a global matrix and vector for optimization

Parameters:
params: dict

Dict of optimization parameters

solver: str, optional

solver name

Returns:
numpy.sparce.lil_matrix
calculate_depth_at_element_quad_points(elev_at_quads, ref_surf_at_nodes)

Calculate depth at quad points

This depth is calculated by subtracting bottom elevation at quadrature points from the reference surface at quadrature points that is calculated by reference elevation at nodes with shape functions.

Parameters:
elev_at_quads: numpy.array

Elevation vector at quadrature points

ref_surf_at_nodes: numpy.array

Reference elevation at nodes

Returns:
numpy.array

Vector of depth at quadrature points

calculate_depth_at_face_quad_points(edges, elev_at_quads, ref_surf_at_nodes)

Calculate depth at quad points

This depth is calculated by subtracting bottom elevation at quadrature points from the reference surface at quadrature points that is calculated by reference elevation at nodes with shape functions.

Parameters:
elev_at_quads: numpy.array

Elevation vector at quadrature points

ref_surf_at_nodes: numpy.array

Reference elevation at nodes

Returns:
numpy.array

Vector of depth at quadrature points

calculate_edge_lengths(edges)

Calculate areas of all edges

Returns:
numpy.array

array of the areas of edges

calculate_element_areas()

Calculate areas of all elements

Returns:
numpy.array

array of the areas of elements

calculate_element_volumes_w_dem(depth_at_quads)

Calculate volumes of elements based on DEM

Parameters:
depth_at_quad: numpy.array

Vector of depth at the quadrature points

Returns:
numpy.array

Volumes of elements

calculate_face_areas_w_dem(edges, depth_at_quads)

Calculate area of faces based on DEM

Parameters:
edges: numpy.array
depth_at_quad: numpy.array

Vector of depth at the quadrature points

Returns:
numpy.array

Areas of faces

calculate_max_elevation_in_balls(elev)

Calculate maximum elevation in a ball from a node

Parameters:
elev: numpy.array

array of elevation at nodes

Returns:
numpy.array

maximum elevation at nodes

calculate_reference_surface(coords)

Define reference water surface at locations specified in nodes based on the assumptions, which only applicable to Bay Delta grid

  1. The surface elevation increases linearly from west (ocean) to east

  2. east of (x_old_river, y_old_river), the elevation increases linearly towards the south

NOTE: This is Bay-Delta Specific. Coordinates for the calculation are hard-wired.

Parameters:
coords: numpy.array

Coordinates to calculate reference surface The dimension of the array is (-1, 2) or more columns. The first two columns are used.

Returns:
numpy.array

Reference water surface for Bay-Delta

calculate_reference_surface_at_face_quadarture_points(ref_surf)

Calculate reference surface at quadrature points

calculate_reference_surface_maximum()

Create reference surface elevation at individual nodes

Steps:

  1. derive max elevation within connected elements

  2. compare with the reference calculated by calculate_reference_surface() and use the higher value between the two

Returns:
numpy.array

Vector of reference elevation at nodes

calculate_total_number_of_quadrature_points()

Calculate total number of quadrature points of the mesh with the given order

Returns:
int

Total number of quadrature points of the mesh

calculate_values_at_element_quadarture_points(values)

Calculate values at quadrature points

Parameters:
values: numpy.array

A vector of nodal values

Returns:
numpy.array

A vector of values at quadrature points

calculate_values_at_face_quadarture_points(edges, values)

Calculate values at quadrature points

Parameters:
values: numpy.array

A vector of nodal values

Returns:
numpy.array

A vector of values at quadrature points

collect_edges(exclude_land_boundaries=False)

Collect edges for the optimization

Parameters:
exclude_land_boundaries: bool, optional

Switch to exclude land edges

Returns:
numpy.array

matrix of nodal indices of edges

collect_element_quadrature_points_for_dem()

Collect all quadrature points to calculate volumes of elements with DEM

Returns:
numpy.array

Quadrature points of all elements

collect_face_quadrature_points_for_dem(edges)

Collect all quadrature points to calculate areas of faces with DEM

Parameters:
edges: numpy.array

list of edges containing indices of the two end nodes

Returns:
numpy.array

Quadrature points of faces

count_boundary_equations()

Count how many boundary constraint equations there are

get_dem_elevation(list_of_points)

Get elevations from DEM

Do this once to save time

Parameters:
list_of_points: list of numpy.array

array of coordinate matrices of points to get DEM elevations

Returns:
listnp.ndarray

list of elevation vectors

integrate_over_edges(edges, values)

Integrate over edges with the values at nodes

Parameters:
values: numpy.array

Values at nodes to integrate

Returns:
numpy.array

Vector of integration over each edge

integrate_over_elements(values)

Integrate over elements with the values at nodes

Parameters:
values: numpy.array

Values at nodes to integrate

Returns:
numpy.array

Vector of integration over each element

optimize(params, solver='L-BFGS-B')

Perform a grid optimization

Two solvers are available:

  1. L-BFGS-B (default): minimize function \(1/2*||Ax-b||^2\)

  2. linear least square solver (Ax=b).

Parameters:
params: dict

Dict of optimization parameters

solver: str, optional

solver name

Returns:
numpy.array

optimized elevation

select_solver(solver)

Select solver

Parameters:
solver: str

Name of a solver for the optimization

show_parameters(solver, param)

Show optimization parameters

Parameters:
solver: str

solver name

param: dict

parameters for the optimization

schimpy.grid_opt.create_arg_parser()

Create argument parser

schimpy.grid_opt.fprime(x, A, b)

The gradient of the objective function with respect to the heights. This gradient is a vector the same size as x.

schimpy.grid_opt.grid_opt_with_args(args)

Optimize grid with arguments parsed by argparse

schimpy.grid_opt.init_logger()
schimpy.grid_opt.main()

A main function to manage command line run

schimpy.grid_opt.object_func(x, A, b)

Objective function for the optimization for L-BFGS-B

schimpy.hotstart_inventory module

schimpy.hotstart_inventory.create_arg_parser()
schimpy.hotstart_inventory.hotstart_inventory(run_start=None, dt=None, nday=None, workdir='.', paramfile=None, hot_freq=None)

Create an inventory of existing hotstarts or expected hotstarts

Existing vs expected depends on whether workdir is an outputs or study dir.

Parameters:
startConvertible to Datetime

Start date of run. If None inferred from paramfile. Error if

dtfloat

dt in seconds, for instance perhaps 90s for clinic or 120s for tropic. This is needed to intepret the so-called iteration number in the hotstart labels which are really time step numbers.

workdirstr

Directory to inventory. If it is an outputs directory, the inventory

comprise existing hotstarts.
paramfilestr

Name of param.nml file, expected in workdir or workdir/.. If None, then both start and dt must be supplied. If all three are None, the name “param.nml” will be attempted

Returns:
Dataframe, if programatic, listing hotstarts. Should look like “Date, Iteration” pairs. CLI should print it out.

Notes

If the listing is done in the run dir, this will be the expected hotstarts. If it is in the outputs dir, it will be an inventory of existing hotstarts.

schimpy.hotstart_inventory.hotstart_inventory2(start, dt=90)
schimpy.hotstart_inventory.main()

schimpy.hrr3 module

adapted from pyschism, original work of Linlin Cui.

class schimpy.hrr3.AWSGrib2Inventory(start_date: datetime | None = None, record=1, pscr=None, product='conus')

Bases: object

Attributes:
bucket
files
output_interval
s3
tmpdir
property bucket
property files
property output_interval: timedelta
property s3
property tmpdir
class schimpy.hrr3.HRRR(start_date=None, rnday=None, pscr=None, record=1, bbox=None)

Bases: object

Methods

gen_sflux

modified_latlon

gen_sflux(date, record, pscr)
modified_latlon(grbfile)
schimpy.hrr3.localize_datetime(d)
schimpy.hrr3.nearest_cycle(input_datetime=None, period=6, method='floor')

schimpy.interp_2d module

invdisttree.py: inverse-distance-weighted interpolation using KDTree

class schimpy.interp_2d.Invdisttree(x, nnear=10, leafsize=10)

Bases: object

Inverse-distance-weighted interpolation using KDTree

Examples

tree = interp_2d.Invdisttree(obs_xy) # initialize KDTree with observational points tree.weights(node_xy) # calculate weights for each node. values_v = tree.interp(obs.temperature.values) # perform spatial interpolation with the calculated weights from the previous step

Methods

interp(obs[, ninterp])

Perform interpolation

weights(node_xy[, eps, p, weights])

Find the nearest neighbors and assign weights to each neibors

interp(obs, ninterp=6)

Perform interpolation

Parameters:
obsnp.ndarray

observational values; nan values are allowed and will be ignored.

ninterppositive int, ninterp<=nnear

The number of nearest points to perform interpolation The default is 6.

Returns:
val_interpnp.ndarray

interpolated values

weights(node_xy, eps=0, p=2, weights=None)

Find the nearest neighbors and assign weights to each neibors

Parameters:
node_xynp.ndarray, shape (n,2)

Coordinates of the query points n is the number of query points

epspositive float, optional

approximate nearest, dist <= (1 + eps) * true nearest. The default is 0.

ppositive int, optional

power. The default is 2.

weightsfloat, optional

optional multiplier for weights, same dimension as node_xy The default is None.

Returns:
None.

schimpy.interpolate_structure module

schimpy.interpolate_structure.create_arg_parser()
schimpy.interpolate_structure.ensure_offset(arg)
schimpy.interpolate_structure.interpolate_structure(template_th, output_th, dt=None, int_cols=['install', 'ndup_weir', 'ndup_culvert', 'ndup_pipe'])

Interpolate a dated th “template” for a structure The interpolation adds time detail, maintain data types. Comments are removed and floating precision is hardwired to two digits

The input template file must have a header and time stamps that are neat with respect to dt. This is checked.

Parameters:
template_thstr

Path to the template file

output_thstr

Name of the output file

dtinterval_type

Number of hours between changes, default is 1 hour. Can be any time (string, delta, offset) that can be coerced to offset

int_colslist

List of column names that should be integers. This can be a superset, and it shouldn’t change much if you name your template columns the standard way.

schimpy.interpolate_structure.main()
schimpy.interpolate_structure.test_date_label_correct(fname_th)

Make sure that the date column in the file doens’t have comment marker and raise error if it does

schimpy.interpolate_structure.test_template_times(template, dt)

schimpy.laplace_smooth_data module

schimpy.laplace_smooth_data.laplace_smooth_data(mesh, data, rate=0.05, iter_total=150)
schimpy.laplace_smooth_data.laplace_smooth_data2(mesh, data, kappa=0.05, dt=1.0, iter_total=150)
schimpy.laplace_smooth_data.laplace_smooth_with_vel(mesh, data, vel, kappa=0.05, dt=1.0, iter_total=1)
schimpy.laplace_smooth_data.laplace_smooth_with_vel2(mesh, data, vel, kappa=0.05, dt=1.0, iter_total=1)
schimpy.laplace_smooth_data.laplace_smooth_with_vel3(mesh, nlayer, data, vel, kappa=0.05, dt=1.0, iter_total=1)

schimpy.lsc2 module

Methods for generating local sigma coordinates These routines are meant to be called a pair. First, default_num_layers is called to obtain the recommended number of layers for each node based on depth. Then, gen_sigma is called to generate the actual local sigma values at each level (nlevels = nlayers+1).

Note that in this script eta is the “reference” free surface at which the mesh is conditioned, which can be a global scalar or array of local nodal values. Using a medium-higher value (2-4 depending on typical flood levels) usually does’t hurt the final product in low water. The example() shows how to visualize a mesh generated on one ref water surface on another surface.

The major user parameters are already set at their defaults. It is mildly important to realize that the S coordinate parameters have the same qualitative interpretation, but that the S system is really just used as a heuristic and everything is manipulated locally.

Besides theta (refinement to the surface) the mostly likely item to manipulate will be minlayer and maxlayer. These can be supplied locally (if these are given as arrays) or globally (if provided as scalars).

class schimpy.lsc2.BilinearMeshDensity

Bases: object

Methods

density

depth

density(z, h, x)
depth(t, h, x)
class schimpy.lsc2.CubicLSC2MeshFunction

Bases: object

Methods

density

depth

density(x, tlev)
depth(x, tlev)
schimpy.lsc2.default_num_layers(x, eta, h0, minlayer, maxlayer, dz_target, meshfun, maxlev=100)

Returns the number of layers that, according to meshfun, gives a depth matching eta + h0 In the (likely) case of inexact fit) the lower bound n- of the number of layers not yet outfitted for variation in x

schimpy.lsc2.default_num_layers0(total_ref_depth, minlayer, maxlayer)
schimpy.lsc2.example()
schimpy.lsc2.example2()
schimpy.lsc2.example3()
schimpy.lsc2.flip_sigma(sigma)

Flip the ordering of non-nan sigma values.

The output of get_sigma starts from 0.0, but sigma in vgrid.in from -0.1. So it needs to be flipped for further use.

Parameters:
sigma: numpy.ndarray
Returns:
numpy.ndarray

New sigma array that has flipped ordering.

schimpy.lsc2.gen_sigma(nlayer, minlayer, maxlayer, eta, h, mesh, meshfun, nsmoothlay=0)

“ Generate local sigma coordinates based on # layers, reference surface and depth

Parameters:
nlayer: ndarray

Veector of size np (number of nodes) giving desired # layers for each node in the mesh

eta: ndarray or float

reference water level heights at each node at which generation is to occur.

h: ndarray

unperturbed depth for each node in the mesh

meshfloat

maximum theta to use in S calculations. This is interpreted the same as a standard S grid theta although it will be varied according to depth

meshfun: float

S coordinate parameter b

nsmoothlay: how many layers to smooth on the bottom
hc: float

S coordinate parameter hc (do not alter)

schimpy.lsc2.label_components(mesh, nlayer, thresh, exclude)
schimpy.lsc2.lowest_layer_height(htrans, nlevel, klev=0)
schimpy.lsc2.mesh_function_depths(nlayer, depth, mesh, meshfun)
schimpy.lsc2.plot_mesh(ax, x, zcor, startvis, stopvis, c='black', linewidth=1)
schimpy.lsc2.process_orphans(mesh, nlayer, depth, hcor)
schimpy.lsc2.process_orphans2(mesh, nlayer, depth, hcor)
schimpy.lsc2.sigma_z(sigma, eta, h)
schimpy.lsc2.smooth_bed(mesh, eta, h, hcor, nlevel, speed)
schimpy.lsc2.szcoord(s, h, eta, theta, b, hc)
schimpy.lsc2.z_sigma(zcor)

schimpy.material_poly module

schimpy.material_poly.create_arg_parser()
schimpy.material_poly.create_poly(shapefile, dsetname, keyfile, polyfile, type, default=None)

Converts a polygon shapefile to the yaml input of the preprocessor

schimpy.material_poly.read_keyfile(keyfile)

Reads a file pairing labels and values

schimpy.merge_th module

schimpy.merge_th.create_arg_parser()
schimpy.merge_th.main()
schimpy.merge_th.merge_th(th_spec)
schimpy.merge_th.read_locations_from_input(fname, role)
schimpy.merge_th.read_th_spec(fname)
schimpy.merge_th.write_th(df, fname, elapsed, ref_time=None)

schimpy.metricsplot module

Metrics plot

schimpy.metricsplot.plot_comparison(*args, style_palette, **kwargs)

Create a simple comparison plot without metrics calculation

Parameters:
*args: variable number of TimeSeries
Returns:
matplotlib.pyplot.figure.Figure
schimpy.metricsplot.plot_metrics(obs, tssim, style_palette, **kwargs)

Create a metrics plot

Parameters:
*args: variable number of TimeSeries
Returns:
matplotlib.pyplot.figure.Figure

schimpy.model_time module

Script to make model date conversion convenient, converting elapsed model seconds to or from dates

schimpy.model_time.clip(args)

Clip file to dates

schimpy.model_time.create_arg_parser()
schimpy.model_time.describe_elapsed(times, start, dt=None)
schimpy.model_time.describe_timestamps(timestamps, start, dt=None)
schimpy.model_time.file_to_elapsed(infile, start, outpath=None, annotate=False, skip_nan=False)
schimpy.model_time.file_to_timestamp(infile, start, outpath=None, annotate=False, elapsed_unit='s', time_format='%Y-%m-%dT%H:%M ')
schimpy.model_time.main()
schimpy.model_time.multi_file_to_elapsed(input_files, output, start, name_transform='prune_dated')
schimpy.model_time.prune_dated(name)
schimpy.model_time.to_datetime(args)

Convert elapsed inputs to dated

schimpy.model_time.to_elapsed(args)

Convert dated inputs to elapsed times

schimpy.nml module

class schimpy.nml.Namelist(d)

Bases: object

The Namelist class simply creates an attribute for each key-value pair in the dictionary.

class schimpy.nml.TopLevelNamelist(d)

Bases: object

TopLevelNamelist is a class for the top-level elements of the dictionary, and Namelist is a class for all other nested elements. The TopLevelNamelist class creates attributes for each key-value pair in the dictionary and, if the value is itself a dictionary, creates a new Namelist object with the nested dictionary.

schimpy.nml.map_to_dict(obj)

This function takes an object of type TopLevelNamelist as input and returns a dictionary representation of the object. The function uses the vars built-in function to get a dictionary of attributes and values for the object, and then iterates over the key-value pairs in the dictionary. If the value is an instance of the Namelist class, it recursively maps the Namelist object to a dictionary using the map_to_dict function. If the value is not an instance of the Namelist class, it simply adds the key-value pair to the dictionary. This way, you can easily map an object of type TopLevelNamelist back to a dictionary representation, preserving the structure of the original dictionary.

schimpy.nml.map_to_object(d)

In this example, TopLevelNamelist is a class for the top-level elements of the dictionary, and Namelist is a class for all other nested elements. The TopLevelNamelist class creates attributes for each key-value pair in the dictionary and, if the value is itself a dictionary, creates a new Namelist object with the nested dictionary. The Namelist class simply creates an attribute for each key-value pair in the dictionary.

The map_to_object function takes a dictionary d as input and returns a new TopLevelNamelist object with the values from d.

This way, you can easily map the dictionary returned by parse_namelist to objects, with different classes for the top-level and nested elements, and access the values in the dictionary as attributes of the objects.

schimpy.nml.parse(file_content)

Here’s a simple implementation of a parser for the Fortran namelist format If there’s a line starting with !, the parser will store it as the full_line_comment and attach it to the next key-value pair it encounters. If there’s an inline comment starting with !, it will be stored as inline_comment.

For the most part this parser is comment preserving; you might notice some whitespace and blank line(s) being eliminated in the round trip through write method below

schimpy.nml.write(namelist_data)

writes out the namelist dictionary from the parse method to a string. The comments are preserved but not the whitespace or indentations

schimpy.nudging module

Created on Tue Jun 8 10:19:56 2021

@author: zzhang To be implemented: other weights function (length scale) from OI in additional to gaussian

class schimpy.nudging.Nudging(yaml_fn, crs=None, suffix=None, **kwargs)

Bases: object

A class to create schism nudging

Attributes:
mesh_gpd
z

Methods

create_nudging([create_file])

Parameters:

read_yaml()

read yaml and load mesh grid

concatenate_nudge

construct_weights

create_region_nudging

gaussian_weights

gen_nudge_3dfield

gen_nudge_obs

gen_region_weight

get_nudging_comb

in_vertices

organize_nudging

plot

read_data

reorder_variables

signa

concatenate_nudge(weights_var, values_var, imap_var, var_newlist, create_file=True)
construct_weights(attribute, x, y, x0, y0, norm_factor)
create_nudging(create_file=True)
Parameters:
suffixTYPE, optional

Options to give a suffix to the output nuding files. The default is ‘nu.nc’

create_fileTYPE, optional

Options to create nudging files. The default is True.

Returns
——-
None.
create_region_nudging(region_info)
static gaussian_weights(xy, xyc, attribute)
gen_nudge_3dfield(region_info)
gen_nudge_obs(region_info)
gen_region_weight(attribute, vertices)
get_nudging_comb()
in_vertices(vertices)
property mesh_gpd
organize_nudging(weights_comb, values_comb, imap_comb)
plot(imap, values, **kwargs)
read_data(data)
read_yaml()

read yaml and load mesh grid

static reorder_variables(var_info, var_ordered_list)
static signa(x1, x2, x3, y1, y2, y3)
property z
schimpy.nudging.create_arg_parser()
schimpy.nudging.main()
schimpy.nudging.write_to_log(message)

schimpy.param module

class schimpy.param.Params(fname, default=None)

Bases: object

Attributes:
hotstart_freq
nc_out_freq
nc_stack
run_start

Get start time as datetime

station_out_freq

Methods

adjust_dt()

Adjust dt without perturbing variables that depend on it

copy()

Return a copy of this Params set

diff(other[, defaults])

Compare to another instance of Params

get_run_start()

Get start time as datetime

process_default(default)

Process default parameters

searchfor(key[, section])

Search for key in all the sections

set_hotstart_freq(freq)

Set hotstart frequency using Pandas offset or string that evaluates as offset

set_interval(name, freq)

Set binary output frequency using Pandas offset or string that evaluates as offset

set_nc_out_freq(freq)

Set binary output frequency using Pandas offset or string that evaluates as offset

set_nc_stack(freq)

Set binary output frequency using Pandas offset or string that evaluates as offset

set_run_start(run_start)

Set start time

set_station_out_freq(freq)

Set station output frequency

update(other[, defaults])

Update from another instance of Params in-place

validate()

Validation tests

get_hotstart_freq

get_interval

get_nc_out_freq

get_nc_stack

get_station_out_freq

sections

to_dataframe

write

adjust_dt()

Adjust dt without perturbing variables that depend on it

copy()

Return a copy of this Params set

diff(other, defaults=False)

Compare to another instance of Params

Parameters:
other: str | Params

Can be a string that evaluates to param filename, a Param object

defaultsbool

Search includes defaults

Returns:
diffpd.DataFrame

Data with multi index for section and parameter, including only parameters that are different, including possibly one being absent from one Param set

get_hotstart_freq()
get_interval(name)
get_nc_out_freq()
get_nc_stack()
get_run_start()

Get start time as datetime

get_station_out_freq()
property hotstart_freq
property nc_out_freq
property nc_stack
process_default(default)

Process default parameters

Parameters:
defaultstr or Param instance or ‘repo’

If default is ‘repo’, default is the GitHub repo version. If it is a filename, that name is evaluated. If it is a templated version, that version is read. (config part of this not done yet)

property run_start

Get start time as datetime

searchfor(key, section=False)

Search for key in all the sections

Parameters:
keystr

Key to search for

section = bool If boolean, returns a tuple of section, value

default = str Name of default to use for backup

Returns

Value cached under key

Raises

IndexError if key not present

sections(defaults=False)
set_hotstart_freq(freq)

Set hotstart frequency using Pandas offset or string that evaluates as offset

Parameters:
freq
If None, frequency will be set using default (or 1 Hour) and station output disabled
set_interval(name, freq)

Set binary output frequency using Pandas offset or string that evaluates as offset

set_nc_out_freq(freq)

Set binary output frequency using Pandas offset or string that evaluates as offset

set_nc_stack(freq)

Set binary output frequency using Pandas offset or string that evaluates as offset

set_run_start(run_start)

Set start time

Parameters:
startdatetime
Coercible to datetime
set_station_out_freq(freq)

Set station output frequency

Parameters:
freqoffset or string

Sets output interval for staout files and ensures that output is enabled. If None, frequency will be set using default (or 1 Hour) and station output disabled

property station_out_freq
to_dataframe(defaults=None)
update(other, defaults=False)

Update from another instance of Params in-place

Parameters:
other: str | Params

Can be a string that evaluates to param filename, a Param object

defaultsbool

Search includes defaults

validate()

Validation tests

write(fname)
schimpy.param.param_from_template(name)

Returns param based on named template files

schimpy.param.read_params(fname, default=None)
schimpy.param.test_param()

schimpy.params module

class schimpy.params.Core(*, dt, eco_class, ibc, ibtp, ihfskip, ipre, mdc2, msc2, nspool, ntracer_age, ntracer_gen, rnday, sed_class, name)

Bases: Parameterized

dt = 0.0
eco_class = 0
ibc = 0
ibtp = 0
ihfskip = 0
ipre = 0
mdc2 = 0
msc2 = 0
name = 'Core'
nspool = 0
ntracer_age = 0
ntracer_gen = 0
rnday = 0.0
sed_class = 0
class schimpy.params.HydroOutput(*, air_pressure, air_temperature, barotropic_pres_grad_xy, bottom_stress_xy, depth_avg_vel_xy, diffusivity, downward_longwave, dry_flag_node, elevation, evaporation_rate, horizontal_side_vel_xy, horizontal_vel_xy, latent_heat, mixing_length, precipitation_rate, salinity, salinity_at_element, sensible_heat, solar_radiation, specific_humidity, temperature, temperature_at_element, total_heat, turbulent_kinetic_ener, upward_longwave, vertical_vel_at_element, vertical_velocity, viscosity, water_density, wind_speed_xy, wind_stress_xy, z_coordinates, name)

Bases: OutControls

Class to specify which variables to output from the SCHISM model

Methods

from_iof_array

get_iof_array_names

to_iof_array

air_pressure = False
air_temperature = False
barotropic_pres_grad_xy = False
bottom_stress_xy = False
depth_avg_vel_xy = False
diffusivity = False
downward_longwave = False
dry_flag_node = True
elevation = False
evaporation_rate = False
horizontal_side_vel_xy = False
horizontal_vel_xy = False
latent_heat = False
mixing_length = False
name = 'HydroOutput'
precipitation_rate = False
salinity = False
salinity_at_element = False
sensible_heat = False
solar_radiation = False
specific_humidity = False
temperature = False
temperature_at_element = False
total_heat = False
turbulent_kinetic_ener = False
upward_longwave = False
vertical_vel_at_element = False
vertical_velocity = False
viscosity = False
water_density = False
wind_speed_xy = False
wind_stress_xy = False
z_coordinates = False
class schimpy.params.Opt(*, alphaw, btrack_nudge, coricoef, courant_weno, cur_wwm, dfh0, dfv0, dramp, dramp_ss, drampbc, drampwafo, drampwind, dtb_max, dtb_min, dzb_min, eos_a, eos_b, eps1_tvd_imp, eps2_tvd_imp, epsilon1, epsilon2, epsilon3, flag_fib, flag_ic, fwvor_advxy_stokes, fwvor_advz_stokes, fwvor_breaking, fwvor_gradpress, fwvor_streaming, fwvor_wveg, fwvor_wveg_NL, gen_wsett, h0, h1_bcc, h1_pp, h2_bcc, h2_pp, h_bcc1, h_massconsv, h_tvd, hmin_airsea_ex, hmin_man, hmin_radstress, hmin_salt_ex, hvis_coef0, hw_depth, hw_ratio, i_hmin_airsea_ex, i_hmin_salt_ex, i_prtnftl_weno, iadjust_mass_consv0, ibcc_mean, ibdef, ibtrack_test, ic_elev, icou_elfe_wwm, ics, ielad_weno, ielm_transport, ieos_pres, ieos_type, if_source, iflux, iflux_out_format, iharind, ihconsv, ihdif, ihhat, ihorcon, ihot, ihydraulics, iloadtide, imm, indvel, inter_mom, inu_elev, inu_tr, inu_uv, inunfl, inv_atm_bnd, ip_weno, ipre2, iprecip_off_bnd, irouse_test, isav, isconsv, ishapiro, itr_met, itransport_only, itur, iunder_deep, iupwind_mom, iwbl, iwind_form, iwindoff, izonal5, kr_co, lev_tr_source, level_age, loadtide_coef, max_subcyc, meth_sink, mid, moitn0, mxitn0, nadv, nchi, ncor, niter_shap, nquad, nramp_elev, nstep_ice, nstep_wwm, ntd_weno, nu_sum_mult, nws, prmsl_ref, rearth_eq, rearth_pole, rho0, rinflation_icm, rlatitude, rmaxvel, rtol0, s1_mxnbt, s2_mxnbt, sfea0, shapiro0, shorewafo, shw, slam0, slr_rate, small_elad, stab, start_day, start_hour, start_month, start_year, step_nu_tr, tdmin_pp1, tdmin_pp2, thetai, turbinj, turbinjds, utc_start, vclose_surf_frac, vdmax_pp1, vdmax_pp2, vdmin_pp1, vdmin_pp2, velmin_btrack, vnf1, vnf2, vnh1, vnh2, wafo_obcramp, wtiminc, xlsc0, name)

Bases: Parameterized

alphaw = 0.0
btrack_nudge = 0.009013
coricoef = 1.0
courant_weno = 0.8
cur_wwm = False
dfh0 = 0.0
dfv0 = 1.0
dramp = 1.0
dramp_ss = 60.0
drampbc = 1.0
drampwafo = 0.0
drampwind = 86400.0
dtb_max = 100.0
dtb_min = 1.0
dzb_min = 1e-05
eos_a = -0.1
eos_b = 1001.0
eps1_tvd_imp = 0.001
eps2_tvd_imp = 0.0001
epsilon1 = 1e-05
epsilon2 = 0.001
epsilon3 = 0.0001
flag_fib = 0
flag_ic = 0
fwvor_advxy_stokes = False
fwvor_advz_stokes = False
fwvor_breaking = False
fwvor_gradpress = False
fwvor_streaming = False
fwvor_wveg = False
fwvor_wveg_NL = False
gen_wsett = True
h0 = 1.0
h1_bcc = 1.0
h1_pp = 0.2
h2_bcc = 0.5
h2_pp = 1.0
h_bcc1 = 1.5
h_massconsv = 0.001
h_tvd = 2.0
hmin_airsea_ex = 0.01
hmin_man = 0.05
hmin_radstress = 0.1
hmin_salt_ex = 0.01
hvis_coef0 = 0.1
hw_depth = 15.0
hw_ratio = 1.2
i_hmin_airsea_ex = 1
i_hmin_salt_ex = 1
i_prtnftl_weno = 1
iadjust_mass_consv0 = 1
ibcc_mean = 0
ibdef = 10
ibtrack_test = 1
ic_elev = 0.0
icou_elfe_wwm = 0
ics = 0
ielad_weno = 0
ielm_transport = 0
ieos_pres = 0.0
ieos_type = 0
if_source = 2
iflux = 2
iflux_out_format = 0
iharind = 1
ihconsv = 0
ihdif = 0
ihhat = 0
ihorcon = 0
ihot = 0
ihydraulics = 0
iloadtide = 0
imm = 0
indvel = 0
inter_mom = 1
inu_elev = 1
inu_tr = 0
inu_uv = 1
inunfl = True
inv_atm_bnd = False
ip_weno = 0
ipre2 = 0
iprecip_off_bnd = 1
irouse_test = 0
isav = 0
isconsv = 0
ishapiro = 0
itr_met = 3
itransport_only = 0
itur = 0
iunder_deep = 0
iupwind_mom = 0
iwbl = 0
iwind_form = 1
iwindoff = 0
izonal5 = 0
kr_co = 0.5
lev_tr_source = 1
level_age = [-999.0]
loadtide_coef = 1.0
max_subcyc = 10
meth_sink = 2
mid = 'KL'
moitn0 = 0.1
mxitn0 = 5
nadv = 3
name = 'Opt'
nchi = 50
ncor = 1
niter_shap = 0
nquad = 5
nramp_elev = 0.0
nstep_ice = 0
nstep_wwm = 1
ntd_weno = 1
nu_sum_mult = 1.0
nws = 0
prmsl_ref = 1013.25
rearth_eq = 6378.137
rearth_pole = 6356.75
rho0 = 1000.0
rinflation_icm = 2.0
rlatitude = 47.5
rmaxvel = 2.0
rtol0 = 1e-06
s1_mxnbt = 0.0
s2_mxnbt = 0.0
sfea0 = 45
shapiro0 = 0.8
shorewafo = 0.0
shw = 0.025
slam0 = -124
slr_rate = 0.0
small_elad = 1e-06
stab = 'GA'
start_day = 1
start_hour = 0
start_month = 1
start_year = 2000
step_nu_tr = 0.001
tdmin_pp1 = 0.01
tdmin_pp2 = 0.001
thetai = 0.7
turbinj = False
turbinjds = 0.0
utc_start = 8
vclose_surf_frac = 0.0
vdmax_pp1 = 0.02
vdmax_pp2 = 0.01
vdmin_pp1 = 1e-05
vdmin_pp2 = 1e-05
velmin_btrack = 0.0001
vnf1 = 1
vnf2 = 1
vnh1 = 1
vnh2 = 0
wafo_obcramp = 1
wtiminc = 3600.0
xlsc0 = 1.0
class schimpy.params.OutControls(*, name)

Bases: Parameterized

Parameters controlling output

Methods

from_iof_array

get_iof_array_names

to_iof_array

from_iof_array(iof_array)
get_iof_array_names()
name = 'OutControls'
to_iof_array()
class schimpy.params.Params(core, opt, schout)

Bases: tuple

Methods

count(value, /)

Return number of occurrences of value.

index(value[, start, stop])

Return first index of value.

core

Alias for field number 0

opt

Alias for field number 1

schout

Alias for field number 2

class schimpy.params.Schout(*, iof_age, iof_ana, iof_cos, iof_dvd, iof_eco, iof_fib, iof_ice, iof_icm_ba, iof_icm_cbp, iof_icm_core, iof_icm_dbg, iof_icm_ph, iof_icm_sav, iof_icm_sed, iof_icm_silica, iof_icm_veg, iof_icm_zb, iof_marsh, iof_sed, iof_sed2d, iof_ugrid, iout_sta, nc_out, nhot, nhot_write, nspool_sta, name)

Bases: Parameterized

iof_age = False
iof_ana = False
iof_cos = False
iof_dvd = False
iof_eco = False
iof_fib = False
iof_gen = TracerGenOutput(name='TracerGenOutput00004', ntracer_gen=0)
iof_hydro = HydroOutput(air_pressure=False, air_temperature=False, barotropic_pres_grad_xy=False, bottom_stress_xy=False, depth_avg_vel_xy=False, diffusivity=False, downward_longwave=False, dry_flag_node=True, elevation=False, evaporation_rate=False, horizontal_side_vel_xy=False, horizontal_vel_xy=False, latent_heat=False, mixing_length=False, name='HydroOutput00002', precipitation_rate=False, salinity=False, salinity_at_element=False, sensible_heat=False, solar_radiation=False, specific_humidity=False, temperature=False, temperature_at_element=False, total_heat=False, turbulent_kinetic_ener=False, upward_longwave=False, vertical_vel_at_element=False, vertical_velocity=False, viscosity=False, water_density=False, wind_speed_xy=False, wind_stress_xy=False, z_coordinates=False)
iof_ice = False
iof_icm_ba = False
iof_icm_cbp = False
iof_icm_core = False
iof_icm_dbg = False
iof_icm_ph = False
iof_icm_sav = False
iof_icm_sed = False
iof_icm_silica = False
iof_icm_veg = False
iof_icm_zb = False
iof_marsh = False
iof_sed = False
iof_sed2d = False
iof_ugrid = False
iof_wwm = WindWaveOutput(bottom_excursion_period=True, bottom_wave_period=True, charnock_coeff=True, continuous_peak_period=True, discrete_peak_direction=True, diss_rate_bott_friction=True, diss_rate_dep_breaking=True, diss_rate_vegetation=True, diss_rate_whitecapping=True, dominant_direction=True, energy_input_atmos=True, frictional_velocity=True, mean_dir_spreading=True, mean_wave_direction=True, mean_wave_length=True, mean_wave_number=True, mean_wave_period=True, name='WindWaveOutput00003', orbital_velocity=True, peak_group_vel=True, peak_n_factor=True, peak_period=True, peak_phase_vel=True, peak_spreading=True, peak_wave_length=True, peak_wave_number=True, rms_orbital_velocity=True, roller_diss_rate=True, roughness_length=True, sig_wave_height=True, tm_10=True, u_resell_number=True, wave_energy_dir_x=True, wave_energy_dir_y=True, zero_downcross_period=True)
iout_sta = 0
name = 'Schout'
nc_out = True
nhot = 0
nhot_write = 0
nspool_sta = 0
class schimpy.params.TracerGenOutput(*, ntracer_gen, name)

Bases: Parameterized

Methods

get_tracer_names

get_tracer_names()
name = 'TracerGenOutput'
ntracer_gen = 0
class schimpy.params.WindWaveOutput(*, bottom_excursion_period, bottom_wave_period, charnock_coeff, continuous_peak_period, discrete_peak_direction, diss_rate_bott_friction, diss_rate_dep_breaking, diss_rate_vegetation, diss_rate_whitecapping, dominant_direction, energy_input_atmos, frictional_velocity, mean_dir_spreading, mean_wave_direction, mean_wave_length, mean_wave_number, mean_wave_period, orbital_velocity, peak_group_vel, peak_n_factor, peak_period, peak_phase_vel, peak_spreading, peak_wave_length, peak_wave_number, rms_orbital_velocity, roller_diss_rate, roughness_length, sig_wave_height, tm_10, u_resell_number, wave_energy_dir_x, wave_energy_dir_y, zero_downcross_period, name)

Bases: OutControls

A collection of parameters that define the wind wave outputs.

Methods

from_iof_array

get_iof_array_names

to_iof_array

bottom_excursion_period = True
bottom_wave_period = True
charnock_coeff = True
continuous_peak_period = True
discrete_peak_direction = True
diss_rate_bott_friction = True
diss_rate_dep_breaking = True
diss_rate_vegetation = True
diss_rate_whitecapping = True
dominant_direction = True
energy_input_atmos = True
frictional_velocity = True
mean_dir_spreading = True
mean_wave_direction = True
mean_wave_length = True
mean_wave_number = True
mean_wave_period = True
name = 'WindWaveOutput'
orbital_velocity = True
peak_group_vel = True
peak_n_factor = True
peak_period = True
peak_phase_vel = True
peak_spreading = True
peak_wave_length = True
peak_wave_number = True
rms_orbital_velocity = True
roller_diss_rate = True
roughness_length = True
sig_wave_height = True
tm_10 = True
u_resell_number = True
wave_energy_dir_x = True
wave_energy_dir_y = True
zero_downcross_period = True
schimpy.params.build_iof_dict(iof_name, vdict, cls)

Builds dictionary of names from the class cls and the values that have the form iof_name(n) = 0 or 1 where n is an integer and the values are 0 or 1 which map onto False (0) or True (1)

schimpy.params.coerce_to_type(schema, value)
schimpy.params.create_params(namelists)
schimpy.params.get_type_dict(cls)
schimpy.params.get_value_dict(map, cls)

Create a dict from namelist from name: value elements and coerce to the type in the schema

schimpy.plot_default_formats module

Convenient routines to set up and to tweak matplotlib plots.

schimpy.plot_default_formats.set_color_cycle_dark2()

Set color cycles of Dark2 theme of colorbrewer.org globally. Just calling this function once before finalize a plot is enough to change the color cycles.

Returns:
brewer_colors: list

list of the colors

schimpy.plot_default_formats.set_dual_axes(ax, ts, cell_method='inst')

Create a dual y-axis with unit information in the given time series. It converts SI units to non-SI one.

Parameters:
ax: matplotlib.axes

axes of a plot to manage

ts: vtools.data.TimeSeries

timeseries with unit information

schimpy.plot_default_formats.set_dual_axes_elev(ax1, filtered=False)

Set dual axes for elevation.

Parameters:
ax: matplotlib axes
schimpy.plot_default_formats.set_dual_axes_salt(ax1, filtered=False)

Set a dual y-axis for salt with a PSU y-axis

Parameters:
ax: axis

a Matplotlib axes

schimpy.prepare_schism module

Driver module to prepares input files for a SCHISM run.

schimpy.prepare_schism.prepare_schism(args, use_logging=True)

schimpy.priority_queue module

class schimpy.priority_queue.priorityDictionary

Bases: dict

Methods

clear()

copy()

fromkeys(iterable[, value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

keys()

pop(key[, default])

If key is not found, default is returned if given, otherwise KeyError is raised

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key, val)

Reimplement setdefault to call our customized __setitem__.

smallest()

Find smallest item after removing deleted items from heap.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

setdefault(key, val)

Reimplement setdefault to call our customized __setitem__.

smallest()

Find smallest item after removing deleted items from heap.

schimpy.profile_plot module

schimpy.profile_plot.get_index_bounds()
schimpy.profile_plot.nearest_neighbor_fill(arr)
schimpy.profile_plot.profile_plot(x, z, data, ax, context_label=None, add_labels=False, xlabel=None, xmin=None, xmax=None, max_depth=None)

UnTRIM-like profile plot of salinity xmin,xmax are the bounds (in km) of the profile max_depth is the maximum depth, data assumed to be

schimpy.profile_plot.set_index_bounds(min_station, max_station, max_depth)
schimpy.profile_plot.vertical_fill(arr)

schimpy.raster_to_nodes module

Functions to process raster data for schimpy pre-processing.

This add rasterstats, boto3 dependency to calculate raster stastistics such as means.

schimpy.raster_to_nodes.raster_to_nodes(mesh, nodes_sel, path_raster, bins=None, mapped_values=None, mask_value=None, fill_value=None, band=1)

Applies raster values to mesh by calculating means over surrounding elementss.

When an element contains no raster data, zero will be assigned. When an element is partly covered by the raster data, an masked average is calculated.

If the bins are provided, the raster data will be binned and bins mapped to the mapped_values before the averaging begins. The binning uses numpy.digitize to classification, and in particular the i’th mapped value is used between the values of bins (i-1) and (i). There are some extra padding values provided as shown in the example

If the mask_value is given, raster data with the given mask value will be replaced with the fill_value before binning the data. This masking will only be used when bins are provided and pertains to special cases involving vegetation data.

Parameters:
mesh: schimpy.SchismMesh

The base mesh to work on

nodes_sel: array-like

The array or list of the nodes to process

path_raster: string-like

File fath to the raster data

bins: array-like, optional

Array of bins. It has to be 1-dimensional and monotonic

mapped_values: array-like, optional

The values of the classes. It should be bigger by one than the bins. The i’th value will be applied between the (i-1) and i value of bins.

band: int, optional

The band index to use from the raster data. The default value is 1.

Returns:
numpy.array

means of raster values of the element balls around the nodes

Notes

An example of this function in the pre-processor yaml is below:

gr3:
  sav_N.gr3:
   default: 0.
   polygons:
     - attribute: raster_to_nodes.raster_to_nodes(mesh, nodes_sel, 'NDVI.tif', bins=[-998., 0.0001, 0.3, 0.6, 1.0], mapped_values=[-999., 0., 40., 70., 100., -999.], maske_value=-10., fill_value=0.1)
       imports: schimpy.raster_to_nodes
       type: none
       vertices:
       #...

The values mesh and node_sel mean the SCHISM mesh and the selected node indices by a polygon. The example bins (or classifies) the raster values from 0.0001 to 0.3 and assigns the value 0., then assigns 40. for values between 0.3 and 0.6 and so forth.

schimpy.read_output_xyt module

Read outputs from read_output*_xyt and create a neat list of Vtools time series. This module depends on deprecated vtools code and is scheduled for removal

schimpy.read_output_xyt.read_depth_avg_from_output7b_xyt(fpath, time_basis)

Read output file from read_output7b_xyt and return depth and depth-averaged values in vtools.data.timeseries.

Parameters:
fpath: str

master input file name of read_output7b_xyt

time_basis: datetime.datetime

time base of the outputs

Returns:
lists of a set vtools.data.timeseries of depth and depth-averaged values

For scalars, the list has only one set of time series. For vectors, the list has two sets of time series. Each time series has multiple columns of data, and each column is for stations.

schimpy.schism_hotstart module

Module for creating a schism hotstart file

Options:

  1. Centering:

    • node2D: node (2D surface)

    • node3D: node at whole level

    • edge: edge center at whole level (mainly for horizontal velocty)

    • elem: element center at whole level (mainly for vertical velocity)

    • prism: prism center (for tracers); three different variables tr_el, tr_nd,

    • tr_el need to be generated for the hotstart.nc file.
      • tr_nd = tr_nd0 (on nodes)

      • tr_el (on element at middle level)

  2. Initializer:

    • text_init: 2D map input from either *.prop or *.ic files; require input text file.

    • simple_trend: can either be a number or an equation that depends on x (lat) and y(lon). e.g,: 0.97 + 1.e-5*x

    • patch_init: regional-based method. Polygon shapefile input required.

    • extrude_casts: 3D nearest neighbourhood interpolation based on Polaris cruise transects.

    • obs_points: interpolated from 1D (time series of) observational points.

    • hotstart_nc: initialize with a previous hotstart output from the same or a different mesh.

    • schout_nc: initialize with a schism output snapshot.

Required data files:
  • param.in

  • hgrid.gr3

  • vgrid.in

  • hotstart.yaml and input files defined in the yaml file.

class schimpy.schism_hotstart.SCHISMHotstart

Bases: object

Mock object

class schimpy.schism_hotstart.VariableField(v_meta, vname, mesh, depths, date, crs, tr_mname, hotstart_ini=None, **kwargs)

Bases: object

A class initializing each varaible for the hotstart file

Methods

define_new_grid(mesh)

Generating hgrid and vgrid based on centering option for a new grid

elem2node_values(vmap)

equation converting 2D values on element to nodes.

extrude_casts([ini_meta, inpoly])

get_grid()

Getting the number and coordinates of horizontal nodes/elems/edges for different centering options and return them as grid.

initializer_options()

Options for input file initializers The input initializer overwrites self.initializer

map_to_3D(v_2d, nz)

polulate the 2D map values to 3D by applying the uniform values over dpeth.

obs_points([ini_meta, inpoly])

obs_file includes Lat, Lon, and values for the variable.

patch_initializer_options(initializer)

Options for patch initializers The input initializer overwrites self.initializer

simple_trend([ini_meta, inpoly])

Assigning a spatially uniformed value or an equation that's dependent on lat, lon

text_init([ini_meta, inpoly])

Reading 2D map from either a .prop (on element) or a .ic (on node) file If a prop file is read, the element values will need to be converted to node values.

GenerateField

create_dataarray

get_key

get_value

hotstart_nc

interp_from_mesh

node2elem_values

patch_init

schout_nc

var_centering

GenerateField()
create_dataarray(var)
define_new_grid(mesh)
Generating hgrid and vgrid based on centering option for a new grid

Parameters

elem2node_values(vmap)

equation converting 2D values on element to nodes.

extrude_casts(ini_meta=None, inpoly=None)
get_grid()

Getting the number and coordinates of horizontal nodes/elems/edges for different centering options and return them as grid.

classmethod get_key(dict_obj)
classmethod get_value(dict_obj)
hotstart_nc(ini_meta=None, inpoly=None)
initializer_options()

Options for input file initializers The input initializer overwrites self.initializer

interp_from_mesh(hgrid_fn, vin, vgrid_fn=None, vgrid_version=5.8, inpoly=None, dist_th=None, method=None)
classmethod map_to_3D(v_2d, nz)

polulate the 2D map values to 3D by applying the uniform values over dpeth.

node2elem_values(vmap)
obs_points(ini_meta=None, inpoly=None)

obs_file includes Lat, Lon, and values for the variable.

patch_init(poly_fn=None)
patch_initializer_options(initializer)

Options for patch initializers The input initializer overwrites self.initializer

schout_nc(var, ini_meta=None, inpoly=None)
simple_trend(ini_meta=None, inpoly=None)

Assigning a spatially uniformed value or an equation that’s dependent on lat, lon

text_init(ini_meta=None, inpoly=None)

Reading 2D map from either a .prop (on element) or a .ic (on node) file If a prop file is read, the element values will need to be converted to node values.

var_centering()
schimpy.schism_hotstart.create_arg_parser()
schimpy.schism_hotstart.describe_tracers(param_nml, modules=['HYDRO'])

return the number of tracers, the sequence of the tracers and a list of tracer names based on the input list of modules and corresponding input files.

Availabel modules are:

  1. T (default)

  2. S (default)

  3. GEN

  4. AGE

  5. SED3D: SED

  6. EcoSim: ECO

  7. ICM: ICM and/or ICM_PH

  8. CoSiNE: COSINE

  9. Feco: FIB

  10. TIMOR

  11. FABM

The script is mainly translated from schism_ini.F90

class schimpy.schism_hotstart.hotstart(yaml_fn=None, modules=None, crs=None)

Bases: object

A class to generate hotstart initial condition for SCHISM

Methods

map_to_schism()

map the hotstart variable to the variable names required by SCHISM hotstart file.

read_yaml()

read yaml and load mesh grid

wet_dry_check()

modify idry_e, idry, and idry_s based on eta2 and water depth.

create_hotstart

generate_3D_field

initialize_netcdf

create_hotstart()
generate_3D_field(variable)
initialize_netcdf(default_turbulence=True)
map_to_schism()

map the hotstart variable to the variable names required by SCHISM hotstart file.

read_yaml()

read yaml and load mesh grid

wet_dry_check()

modify idry_e, idry, and idry_s based on eta2 and water depth.

schimpy.schism_hotstart.hotstart_to_outputnc(hotstart_fn, init_date, hgrid_fn='hgrid.gr3', vgrid_fn='vgrid.in', vgrid_version=5.8, outname='hotstart_out.nc')

convert hotstart.nc to schism output nc file format that can be read by VisIt.

schimpy.schism_hotstart.main()
schimpy.schism_hotstart.num(s)
schimpy.schism_hotstart.project_mesh(mesh, new_crs)
schimpy.schism_hotstart.read_hotstart()

Mock method to read existing hotstart

schimpy.schism_hotstart.read_param_nml(nml_fn)

read param.in file and generate a dict object with key, value pairs for all the parameters

schimpy.schism_input module

This module handles SCHISM input data which are a mesh, structures, and sources/sinks. @author: Kijin Nam, knam@water.ca.gov

class schimpy.schism_input.SchismInput(logger=None)

Bases: object

Attributes:
mesh
nudging
sources
structures
time_start

Methods

add_structure

clear_structures

n_sinks

n_sources

n_structures

add_structure(value)
clear_structures()
property mesh
n_sinks()
n_sources()
n_structures()
property nudging
property sources
property structures
property time_start

schimpy.schism_linestring module

Line String data based on Shapely LineStrings

class schimpy.schism_linestring.LineString(coordinates=None, prop=None)

Bases: LineString

Attributes:
area

Unitless area of the geometry (float)

boundary

Returns a lower dimension geometry that bounds the object

bounds

Returns minimum bounding region (minx, miny, maxx, maxy)

centroid

Returns the geometric center of the object

convex_hull

Imagine an elastic band stretched around the geometry: that’s a

coords

Access to geometry’s coordinates (CoordinateSequence)

envelope

A figure that envelopes the geometry

geom_type

Name of the geometry’s type, such as ‘Point’

has_z

True if the geometry’s coordinate sequence(s) have z values (are

is_closed

True if the geometry is closed, else False

is_empty

True if the set of points in this geometry is empty, else False

is_ring

True if the geometry is a closed ring, else False

is_simple

True if the geometry is simple, meaning that any self-intersections

is_valid

True if the geometry is valid (definition depends on sub-class),

length

Unitless length of the geometry (float)

minimum_clearance

Unitless distance by which a node could be moved to produce an invalid geometry (float)

minimum_rotated_rectangle

Returns the oriented envelope (minimum rotated rectangle) that encloses the geometry.

oriented_envelope

Returns the oriented envelope (minimum rotated rectangle) that encloses the geometry.

prop
type
wkb

WKB representation of the geometry

wkb_hex

WKB hex representation of the geometry

wkt

WKT representation of the geometry

xy

Separate arrays of X and Y coordinate values

Methods

almost_equals(other[, decimal])

True if geometries are equal at all coordinates to a specified decimal place.

buffer(distance[, quad_segs, cap_style, ...])

Get a geometry that represents all points within a distance of this geometry.

contains(other)

Returns True if the geometry contains the other, else False

contains_properly(other)

Returns True if the geometry completely contains the other, with no common boundary points, else False

covered_by(other)

Returns True if the geometry is covered by the other, else False

covers(other)

Returns True if the geometry covers the other, else False

crosses(other)

Returns True if the geometries cross, else False

difference(other[, grid_size])

Returns the difference of the geometries.

disjoint(other)

Returns True if geometries are disjoint, else False

distance(other)

Unitless distance to other geometry (float)

dwithin(other, distance)

Returns True if geometry is within a given distance from the other, else False.

equals(other)

Returns True if geometries are equal, else False.

equals_exact(other, tolerance)

True if geometries are equal to within a specified tolerance.

hausdorff_distance(other)

Unitless hausdorff distance to other geometry (float)

interpolate(distance[, normalized])

Return a point at the specified distance along a linear geometry

intersection(other[, grid_size])

Returns the intersection of the geometries.

intersects(other)

Returns True if geometries intersect, else False

line_interpolate_point(distance[, normalized])

Return a point at the specified distance along a linear geometry

line_locate_point(other[, normalized])

Returns the distance along this geometry to a point nearest the specified point

normalize()

Converts geometry to normal form (or canonical form).

offset_curve(distance[, quad_segs, ...])

Returns a LineString or MultiLineString geometry at a distance from the object on its right or its left side.

overlaps(other)

Returns True if geometries overlap, else False

parallel_offset(distance[, side, ...])

Alternative method to offset_curve() method.

point_on_surface()

Returns a point guaranteed to be within the object, cheaply.

project(other[, normalized])

Returns the distance along this geometry to a point nearest the specified point

relate(other)

Returns the DE-9IM intersection matrix for the two geometries (string)

relate_pattern(other, pattern)

Returns True if the DE-9IM string code for the relationship between the geometries satisfies the pattern, else False

representative_point()

Returns a point guaranteed to be within the object, cheaply.

reverse()

Returns a copy of this geometry with the order of coordinates reversed.

segmentize(max_segment_length)

Adds vertices to line segments based on maximum segment length.

simplify(tolerance[, preserve_topology])

Returns a simplified geometry produced by the Douglas-Peucker algorithm

svg([scale_factor, stroke_color, opacity])

Returns SVG polyline element for the LineString geometry.

symmetric_difference(other[, grid_size])

Returns the symmetric difference of the geometries.

touches(other)

Returns True if geometries touch, else False

union(other[, grid_size])

Returns the union of the geometries.

within(other)

Returns True if geometry is within the other, else False

geometryType

property prop
class schimpy.schism_linestring.LineStringIo

Bases: object

Methods

read

write

read(**kwargs)
write(**kwargs)
class schimpy.schism_linestring.LineStringIoFactory

Bases: object

Methods

get_reader

get_writer

get_reader(name)
get_writer(name)
registered_readers = {'shp': 'LineStringShapefileReader', 'yaml': 'LineStringYamlReader'}
registered_writers = {'shp': 'LineStringShapefileWriter', 'yaml': 'LineStringYamlWriter'}
class schimpy.schism_linestring.LineStringShapefileReader

Bases: LineStringIo

Methods

read(fpath, **kwargs)

Parameters:

write

read(fpath, **kwargs)
Parameters:
fpath: str

input file name

Returns:
lines

list of LineStrings

class schimpy.schism_linestring.LineStringShapefileWriter

Bases: LineStringIo

Methods

write(fpath, lines[, spatial_reference, ...])

Parameters:

read

write(fpath, lines, spatial_reference=None, driver_name=None, **kwargs)
Parameters:
fpath: str

output file name

lines: array of schism_linestring.LineString

list of LineStrings

spatial_reference: osgeo.osr.SpatialReference
default: NAD83, UTM zone 10N, meter
todo: reference needs to be in api right now hard to use
class schimpy.schism_linestring.LineStringYamlReader

Bases: LineStringIo

Methods

read

write

read(fpath, **kwargs)
class schimpy.schism_linestring.LineStringYamlWriter

Bases: LineStringIo

Write line strings from a YAML file

Methods

read

write

write(fpath, lines)
schimpy.schism_linestring.read_linestrings(fpath)
schimpy.schism_linestring.write_linestrings(fpath, lines)
Parameters:
fpath: str

output file name

lines: array of schism_linestring.LineString

list of LineStrings

schimpy.schism_mesh module

3D Version of schism_mesh

schimpy.schism_mesh.BoundaryType

alias of Enum

class schimpy.schism_mesh.SchismMesh

Bases: TriQuadMesh

Memory model of 3D SCHISM mesh

Attributes:
boundaries

An array of the boundary information

edges

Get the array of edges

elems

Array of node indexes of all elements.

n_vert_levels
node2elems
nodes

Node array consisting of three-dimensional coordinates of each node.

vmesh
z

Get the elevation of levels at all the nodes

Methods

add_boundary(nodes, btype[, comment])

Add one boundary.

allocate(n_elems, n_nodes)

Allocate memory for nodes and elems

areas()

Get the array of element areas

build_edgecenters()

Build centers of sides

build_edges_from_elems([shift])

Build edge array from the elements.

build_elem_balls()

Build balls of elements around each node

build_z([elev])

Build vertical coordinates

centroids()

Get a Numpy array of element centroids Returns ------- numpy.ndarray

clear_boundaries()

Delete all the current boundary information

compare(mesh)

Compare the mesh with another

edge_len()

Get a NumPy array of edge lengths The ordering of the edges is decided from triquadmesh.

elem(elem_i)

Get connectivity of an element

element2edges(elem_i)

Get edge indexes of the give element index

fill_land_and_island_boundaries()

Fill land and island boundaries for boundary edges not assigned to boundaries.

fill_open_boundaries()

Fill open boundaries for boundary edges not assigned to boundaries.

find_closest_elems(pos[, count])

Find indexes of the closet elems with the given position.

find_closest_nodes(pos[, count, boundary])

Returns the count closest nodes to the given node in 2D space.

find_edge(nodes[, direction])

Find an edge index with the two given node indexes.

find_elem(pos)

Find a element index from a coordinate pos = A coordinate (2D) return = element index

find_intersecting_elems_with_line(line_segment)

Format of the line segment: start_x, start_y, end_x, end_y

find_neighbors_on_segment(line_segment)

Find elements on the line_segment and neighbors that are all to the left (downstream) Format of the line segment: start_x, start_y, end_x, end_y Returns a list of elements on the segment and a list of neighbors.

find_nodes_in_box(box)

Find nodes in a bounding box.

find_two_neighboring_node_paths(line_segment)

Find two neighboring node paths around a line_segment

get_centers_of_elements()

Get the array of the centers of the element

get_centers_of_sides()

Get the array of the centers of the sides

get_coordinates_3d()

Get the array of each 3-d nodes

get_edges_from_node(node_i)

Get edge indexes related to node_i

get_elems_i_from_node(node_i)

Get the ball of elements around a node, node_i

get_neighbor_nodes(node_i)

Get neighboring node indexes from the given node index.

is_elem_on_boundary(elem_i)

Check if the given element with index elem_i is on the boundary

mark_elem_deleted(elem_i)

Mark an element as deleted or invalid.

merged_mesh()

merge all the meshes to create a boundary polygon

n_boundaries([btype])

Get the number of boundaries.

n_edges()

Get the total number of edges.

n_elems()

Get the total number of elements.

n_nodes()

Get the total number of nodes.

n_total_boundary_nodes(btype)

Get the total node boundary of a given type

node(node_i)

Selects a single node

plot_elems([var, ax, inpoly, plot_nan])

Plot variables (1D array on element) based on SCHISM mesh grid.

plot_mesh_boundary([ax, edgecolor])

Plot the edge of the computational grid.

renumber()

removes duplicate elems and nodes that are not referenced by any element, as well as elems that have been deleted (==-1) This function is lifted and modified slightly from Rusty's code.

set_elem(index, connectivity)

Set element connectivity information.

set_node(index, coords)

Set one node information.

shortest_path(n1, n2[, boundary_only])

Dijkstra on the edge graph from node n1 to n2.

to_geopandas([feature_type, crs, shp_fn, ...])

Create mesh polygon and points as geopandas dataframe and shapefiles if Shap_fn file name is supplied.

trim_elems(paths[, left])

Given a path, trim all elems to the left of it.

trim_to_left_of_mesh(line_segments)

Trim mesh using line_segments.

plot_edges

plot_nodes

add_boundary(nodes, btype, comment=None)

Add one boundary.

Parameters:
nodes: an array of integer

array of inter node indexes in the boundary path

btype: integer

an integer constant for boundary types.

comment: optional, string
areas()

Get the array of element areas

Returns:
numpy.ndarray
property boundaries

An array of the boundary information

Getter:

Get the array of the boundary information

build_z(elev=0.0)

Build vertical coordinates

Returns:
numpy.ndarray
centroids()

Get a Numpy array of element centroids Returns ——- numpy.ndarray

clear_boundaries()

Delete all the current boundary information

edge_len()

Get a NumPy array of edge lengths The ordering of the edges is decided from triquadmesh. Look edges properties to find out connectivity

Returns:
numpy.ndarray
fill_land_and_island_boundaries()

Fill land and island boundaries for boundary edges not assigned to boundaries.

fill_open_boundaries()

Fill open boundaries for boundary edges not assigned to boundaries.

find_two_neighboring_node_paths(line_segment)

Find two neighboring node paths around a line_segment

Parameters:
line_segment: array-like

two end points of the line segment, start_x, start_y, end_x, end_y

Returns
——
up_path: array of int

upstream side of node paths

down_path: array of int

downstream side of node paths

get_centers_of_elements()

Get the array of the centers of the element

Returns:
numpy.ndarray

Array of 2-d coordinates of the centers of the elements The shape of the array is (n_elems, 2)

get_centers_of_sides()

Get the array of the centers of the sides

Returns:
numpy.ndarray

Array of 3-d coordinates of the centers of the elements The shape of the array is (n_elems, 2)

get_coordinates_3d()

Get the array of each 3-d nodes

Returns:
numpy.ndarray

Array of 3-d coordinates The shape of the array is (n_nodes * n_vert_levels, 3) The points below the most bottom level will be filled with the elevation of the the bottom level

merged_mesh()

merge all the meshes to create a boundary polygon

n_boundaries(btype=None)

Get the number of boundaries. If a boundary type is given, it counts only boundaries with the corresponding type.

Parameters:
btype: integer, optional

Type of the boundary.

n_total_boundary_nodes(btype)

Get the total node boundary of a given type

Parameters:
btype: integer

Type of the boundary.

property n_vert_levels
plot_edges(var, ax=None, size=500, inpoly=None, **kwargs)
plot_elems(var=None, ax=None, inpoly=None, plot_nan=False, **kwargs)

Plot variables (1D array on element) based on SCHISM mesh grid. if var is None,just plot the grid.

plot_mesh_boundary(ax=None, edgecolor='k', **kwargs)

Plot the edge of the computational grid.

plot_nodes(var, ax=None, inpoly=None, plot_nan=False, **kwargs)
to_geopandas(feature_type='polygon', crs=None, shp_fn=None, node_values=None, elem_values=None, edge_values=None, value_name=None, create_gdf=True)

Create mesh polygon and points as geopandas dataframe and shapefiles if Shap_fn file name is supplied.

trim_to_left_of_mesh(line_segments)

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

property vmesh
property z

Get the elevation of levels at all the nodes

Returns:
numpy.ndarray

Depth array of each levels at the nodes. The shape of the array is (n_nodes, n_vert_levels) The levels below the most bottom level will be filled with the elevation of the bottom level

schimpy.schism_mesh.read_mesh(fpath_mesh, fpath_vmesh=None, vgrid_version='5.10', **kwargs)

Read a mesh data

Returns:
SchismMesh
schimpy.schism_mesh.write_mesh(mesh, fpath_mesh, node_attr=None, write_boundary=False, crs=None, **kwargs)

Write a horizontal mesh

Parameters:
mesh: SchismMesh

Mesh

fpath_mesh: str

schimpy.schism_polygon module

Polygon data structure with preprocessor-related attributes and converters

class schimpy.schism_polygon.SchismPolygon(shell=None, holes=None, prop=None)

Bases: Polygon

A polygon class based on shapely.geometry.Polygon. This class has extra information

Attributes:
area

Unitless area of the geometry (float)

attribute
boundary

Returns a lower dimension geometry that bounds the object

bounds

Returns minimum bounding region (minx, miny, maxx, maxy)

centroid

Returns the geometric center of the object

convex_hull

Imagine an elastic band stretched around the geometry: that’s a

coords

Access to geometry’s coordinates (CoordinateSequence)

envelope

A figure that envelopes the geometry

exterior
geom_type

Name of the geometry’s type, such as ‘Point’

has_z

True if the geometry’s coordinate sequence(s) have z values (are

interiors
is_closed

True if the geometry is closed, else False

is_empty

True if the set of points in this geometry is empty, else False

is_ring

True if the geometry is a closed ring, else False

is_simple

True if the geometry is simple, meaning that any self-intersections

is_valid

True if the geometry is valid (definition depends on sub-class),

length

Unitless length of the geometry (float)

minimum_clearance

Unitless distance by which a node could be moved to produce an invalid geometry (float)

minimum_rotated_rectangle

Returns the oriented envelope (minimum rotated rectangle) that encloses the geometry.

name
oriented_envelope

Returns the oriented envelope (minimum rotated rectangle) that encloses the geometry.

prop
type
wkb

WKB representation of the geometry

wkb_hex

WKB hex representation of the geometry

wkt

WKT representation of the geometry

xy

Separate arrays of X and Y coordinate values

Methods

almost_equals(other[, decimal])

True if geometries are equal at all coordinates to a specified decimal place.

buffer(distance[, quad_segs, cap_style, ...])

Get a geometry that represents all points within a distance of this geometry.

contains(point)

Check the polygon contains the point

contains_properly(other)

Returns True if the geometry completely contains the other, with no common boundary points, else False

covered_by(other)

Returns True if the geometry is covered by the other, else False

covers(other)

Returns True if the geometry covers the other, else False

crosses(other)

Returns True if the geometries cross, else False

difference(other[, grid_size])

Returns the difference of the geometries.

disjoint(other)

Returns True if geometries are disjoint, else False

distance(other)

Unitless distance to other geometry (float)

dwithin(other, distance)

Returns True if geometry is within a given distance from the other, else False.

equals(other)

Returns True if geometries are equal, else False.

equals_exact(other, tolerance)

True if geometries are equal to within a specified tolerance.

from_bounds(xmin, ymin, xmax, ymax)

Construct a Polygon() from spatial bounds.

hausdorff_distance(other)

Unitless hausdorff distance to other geometry (float)

interpolate(distance[, normalized])

Return a point at the specified distance along a linear geometry

intersection(other[, grid_size])

Returns the intersection of the geometries.

intersects(val)

Check the polygon intersects with the point

line_interpolate_point(distance[, normalized])

Return a point at the specified distance along a linear geometry

line_locate_point(other[, normalized])

Returns the distance along this geometry to a point nearest the specified point

normalize()

Converts geometry to normal form (or canonical form).

overlaps(other)

Returns True if geometries overlap, else False

point_on_surface()

Returns a point guaranteed to be within the object, cheaply.

project(other[, normalized])

Returns the distance along this geometry to a point nearest the specified point

relate(other)

Returns the DE-9IM intersection matrix for the two geometries (string)

relate_pattern(other, pattern)

Returns True if the DE-9IM string code for the relationship between the geometries satisfies the pattern, else False

representative_point()

Returns a point guaranteed to be within the object, cheaply.

reverse()

Returns a copy of this geometry with the order of coordinates reversed.

segmentize(max_segment_length)

Adds vertices to line segments based on maximum segment length.

simplify(tolerance[, preserve_topology])

Returns a simplified geometry produced by the Douglas-Peucker algorithm

svg([scale_factor, fill_color, opacity])

Returns SVG path element for the Polygon geometry.

symmetric_difference(other[, grid_size])

Returns the symmetric difference of the geometries.

touches(other)

Returns True if geometries touch, else False

union(other[, grid_size])

Returns the union of the geometries.

within(other)

Returns True if geometry is within the other, else False

geometryType

property attribute
contains(point)

Check the polygon contains the point

Parameters:
point: np.ndarray or shapely.geometry.polygon.Polygon
Returns:
bool
intersects(val)

Check the polygon intersects with the point

Parameters:
point: np.ndarray or shapely.geometry.polygon.Polygon
Returns:
bool
property name
property prop
property type
class schimpy.schism_polygon.SchismPolygonDictConverter

Bases: SchismPolygonIo

Convert a tree to a list of polygons

Methods

read

read(data)
class schimpy.schism_polygon.SchismPolygonIo

Bases: object

SchismPolygon I/O abstract class

Methods

read

read(stream)
class schimpy.schism_polygon.SchismPolygonIoFactory

Bases: object

A factory class for SchismPolygonIo

Methods

get_reader

get_writer

show_registered_readers

get_reader(name)
get_writer(name)
registered_readers = {'dict': 'SchismPolygonDictConverter', 'shp': 'SchismPolygonShapefileReader', 'yaml': 'SchismPolygonYamlReader'}
registered_writers = {'shp': 'SchismPolygonShapefileWriter', 'yaml': 'SchismPolygonYamlWriter'}
show_registered_readers()
class schimpy.schism_polygon.SchismPolygonShapefileReader

Bases: SchismPolygonIo

Read polygons from a shape file

Methods

read(fpath)

Read polygons from a Shapefile and return a list of SchismPolygons.

read(fpath)

Read polygons from a Shapefile and return a list of SchismPolygons.

Parameters:
fpath: str

Filename of a Shapefile containing Polygons with data columns such as name, type, and attribute.

Returns:
list

list of SchismPolygons

class schimpy.schism_polygon.SchismPolygonShapefileWriter

Bases: SchismPolygonIo

Methods

write(fpath, polygons[, spatial_reference, ...])

Convert SCHISM polygon YAML file to a shapefile

read

write(fpath, polygons, spatial_reference=None, driver_name=None)

Convert SCHISM polygon YAML file to a shapefile

Parameters:
fpath: str

output file name

polygons: array of schism_polygon.SchismPolygon

polygons to write

spatial_reference: osgeo.osr.SpatialReference or crs string

default: NAD83, UTM zone 10N, meter

driver_name: osgeo.ogr Driver name

default: ESRI Shapefile

class schimpy.schism_polygon.SchismPolygonYamlReader

Bases: SchismPolygonIo

Read polygons from a SCHISM YAML polygon file

Methods

read

read(fpath)
class schimpy.schism_polygon.SchismPolygonYamlWriter

Bases: SchismPolygonIo

Write polygons into a YAML file

Methods

read

write

write(fpath, polygons)
schimpy.schism_polygon.read_polygons(fpath)

Read a polygon file

schimpy.schism_polygon.write_polygons(fpath, polygons)

schimpy.schism_setup module

Setup and processes SCHISM Inputs

class schimpy.schism_setup.SchismSetup(logger=None)

Bases: object

A class to manage SCHISM input data

Attributes:
input
mesh

Mesh

Methods

adopt_new_mesh(fname)

Adopt a new grid.

apply_polygons(polygons, default)

Partition the grid with the given polygons.

creart_sources_from_user_input()

Create a source from a user input

create_flux_regions(linestrings[, out_fname])

Create and write flux_regions.gr3 with the given lines

create_node_partitioning(gr3_fname, ...)

Create a gr3 file with node partitioning using polygons in the polygon file.

create_open_boundaries(segments)

Create open boundaries with linestrings

create_prop_partitioning(prop_fname, ...)

Create a prop file with element partitioning using polygons in the polygon file.

create_source_sink_in(source_sinks[, out_fname])

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

create_structures(structures[, nudging])

Create structures

elements_on_linestring(coords)

List elements along linestring

interpolate_tide(time_start, time_end, dt, ...)

Interpolate an observed tide time series with the given dt.

load(dir)

Read SCHISM input

modify_depth(polygon_data)

Modify depth with the polygon information

reorder_open_boundaries(order)

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_to_left_of_mesh(line_segments)

Trim mesh using line_segments.

write_hgrid(fname[, attr, boundary])

Write a hgrid file only.

write_hgrid_ll(fname, boundary[, input_crs, ...])

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

write_structures([fname])

Write a SCHISM structure file fname = output file name

apply_linestring_ops

get_closest_node_i_from_new_mesh

adopt_new_mesh(fname)

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

apply_linestring_ops(default, linestrings)
apply_polygons(polygons, default)

Partition the grid with the given polygons. Each node (not element) will be assigned with an integer ID which is the index of the polygons. If some polygons overlap, the latter one will trump the former one. The area that are not covered by any of the given polygons will have a default negative one attribute.

Parameters:
polygons: list

a list of polygon dict (from YAML most of time)

Returns:
numpy.ndarray

attributes

creart_sources_from_user_input()

Create a source from a user input

create_flux_regions(linestrings, out_fname='fluxflag.prop')

Create and write flux_regions.gr3 with the given lines

Parameters:
linestrings: list

A list containing information for flux regions. It must contains ‘linestrings.’

out_fname: str, optional

Output file name

create_node_partitioning(gr3_fname, polygons, default, smooth)

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

create_open_boundaries(segments)

Create open boundaries with linestrings

create_prop_partitioning(prop_fname, polygons, default)

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='source_sink.in')

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

create_structures(structures, nudging=None)

Create structures

elements_on_linestring(coords)

List elements along linestring

get_closest_node_i_from_new_mesh(mesh, node_i)
property input
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

load(dir)

Read SCHISM input

Parameters:
dir: String

An directory where the SCHISM inputs reside

property mesh

Mesh

Getter:

Return the mesh.

modify_depth(polygon_data)

Modify depth with the polygon information

reorder_open_boundaries(order)

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_to_left_of_mesh(line_segments)

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_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, boundary, input_crs='EPSG:26910', output_crs='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 26910, NAD83/UTM10N.

output_epsg: int, optional

output EPSG. default value is 4269, NAD83

write_structures(fname='hydraulics.in')

Write a SCHISM structure file fname = output file name

schimpy.schism_setup.check_and_suggest(testees, list_words, logger=None)

Check testtees in list_words and if not suggest something if possible

schimpy.schism_setup.check_similarity(testee, list_words)

Check similarity of a word

schimpy.schism_setup.create_schism_setup(fname, logger=None)

Read a mesh and return a SCHISM input set-up instance.

Parameters:
fname: str
Returns:
SCHISM input set-up instance
schimpy.schism_setup.load_schism(dir)

A load function

schimpy.schism_source module

class schimpy.schism_source.SchismSource

Bases: object

A class to hold structure information

Attributes:
coord
element_id
note
type
property coord
property element_id
property note
property type
class schimpy.schism_source.SchismSourceIO(input)

Bases: object

A class to manage source/sink I/O

Methods

read

write

read(fname)
write(fname='source_sink.in')
schimpy.schism_source.read_sources(fname)

schimpy.schism_sources_sinks module

schimpy.schism_sources_sinks.concat_msource_csv(csv_fn1, csv_fn2, merged_source_sink_in, csv_merged, freq='infer', how='left')
schimpy.schism_sources_sinks.concat_source_sink_yaml(yaml_fn1, yaml_fn2, new_yaml)
schimpy.schism_sources_sinks.concat_vsource_sink_csv(csv_fn1, csv_fn2, merged_source_sink_in, csv_type, csv_merged, freq='infer', how='left')

Concatenate source and sink files

Parameters:
csv_fn1STR

Filename of the 1st dated vsource.csv or vsink.csv

csv_fn2STR

Filename of the 2nd dated vsource.csv or vsink.csv

merged_source_sink_inSTR

Filename of source_sink.in or source_sink.yaml

csv_typeSTR

Indicate if the files are “sources” or “sinks”

csv_mergedSTR

Output merged csv filename

freqSTR, optional

Frequency for the output csv file. The default is ‘infer’.

howSTR, optional

Options see pandas.join(). The default is ‘left’.

Returns:
None.
Raises:
NotImplementedError

DESCRIPTION.

schimpy.schism_sources_sinks.csv2yaml(source_csv, source_yaml)

Converting from source csv to source yaml file

Parameters:
source_csvCSV FILENAME

DESCRIPTION.

source_yamlYAML FILENAME

DESCRIPTION.

Returns:
None
schimpy.schism_sources_sinks.read_source_sink_csv(csv_fn)
schimpy.schism_sources_sinks.read_source_sink_in(source_sink_in)

Parse source sink.in file

Parameters:
source_sink_inSTR

source_sink.in

Returns
——-
source_dfPANDAS DATAFRAME

a dataframe of source names

sink_dfTYPE

a dataframe of sink names

schimpy.schism_sources_sinks.read_source_sink_th(th_fn, source_or_sink_df)

Read source_sink.th file

Parameters:
th_fnSTR

*.th file

source_or_sink_dfPANDAS DATAFRAME

source_df or sink_df produced by read_source_sink_in.

Returns:
thPANDAS DATAFRAME

source or sink data frame with time series data of T, S and other variables

schimpy.schism_sources_sinks.read_source_sink_yaml(yaml_fn)

Read source sink yaml file

Parameters:
yaml_fnstr

source_sink.yaml filename.

Returns:
df_sourcesPANDAS dataframe

For sources

df_sinksPANDAS dataframe

For sinks

schimpy.schism_sources_sinks.unsorted_unique(a)

Find unique elements with no sorting

np.unique automatically sorts the elements. This function performs unique without sorting.

Parameters:
aList or array

Input array

Returns:
a_uniquearray

Unsorted unique array

schimpy.schism_sources_sinks.write_source_sink_csv(th, csv_fn)
schimpy.schism_sources_sinks.write_source_sink_in(source_sink_yaml, hgrid_fn, source_sink_in='source_sink.in')

Create source_sink.in based on hgrid and source_sink.yaml using the create_source_sink_in function in schimpy preprocessor

Parameters:
source_sink_yamlSTR

Filename for source_sink.yaml

hgrid_fnSTR

schism hgrid.gr3

source_sink_inSTR, optional

Filename for source_sink.in. The default is ‘source_sink.in’.

Returns:
None.
schimpy.schism_sources_sinks.write_source_sink_yaml(df_sources, df_sinks, yaml_fn)

Write source sink to yaml

Parameters:
df_sourcesPANDAS dataframe

with colums:[‘x’,’y’]

df_sinksTYPE

DESCRIPTION.

yaml_fnTYPE

DESCRIPTION.

Returns:
None.
schimpy.schism_sources_sinks.yaml2csv(source_yaml, source_csv)

Converting source yaml file to source csv file

Parameters:
source_yaml :YAML FILENAME

DESCRIPTION.

source_csvCSV FILENAME

DESCRIPTION.

Returns:
None.

schimpy.schism_structure module

class schimpy.schism_structure.SchismStructure

Bases: object

A class to hold structure information

Attributes:
coords
n_duplicate
name
node_pairs
properties
reference
reference_pair
type
use_timeseries

Methods

n_node_pairs

property coords
property n_duplicate
n_node_pairs()
property name
property node_pairs
property properties
property reference
property reference_pair
property type
property use_timeseries
class schimpy.schism_structure.SchismStructureIO(input)

Bases: BaseIO

A class to manage hydraulic structure I/O files

Attributes:
linecounter

Methods

read(fname)

Read in 'hydraulics.in' file.

write([fname])

Write out 'hydraulics.in' file.

read(fname)

Read in ‘hydraulics.in’ file.

write(fname='hydraulics.in')

Write out ‘hydraulics.in’ file.

schimpy.schism_vertical_mesh module

SchismVerticalMesh class with a reader

schimpy.schism_vertical_mesh.read_vmesh(fpath_vmesh, vgrid_version=None)

Read a vgrid file

schimpy.schism_yaml module

A customized version of YAML parser for SCHISM It stores document in an ordered dict and supports variable substitution.

class schimpy.schism_yaml.ArgumentParserYaml(prog=None, usage=None, description=None, epilog=None, version=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True)

Bases: ArgumentParser

Extended parser to handle YAML file as file input for ArgumentParser. If a file input given with ‘fromfile_prefix_chars’ has a YAML extension, ‘.yaml’, it will be handled as optional pairs for ArgumentParser. For example, ‘script.py’ can use a YAML file for an input file of ArgumentParser as follow: parser = schism_yaml.ArgumentParserYaml(fromfile_prefix_chars=’@’) parser.parse_arg()

$script.py @args.yaml

And when ‘args.yaml’ contains: input1: 1 input2: 2 3

it has the same effect as $script.py –input1 1 –input2 2 3

Methods

add_argument(add_argument)

add_subparsers(**kwargs)

error(message)

Prints a usage message incorporating the message to stderr and exits.

exit([status, message])

format_usage()

parse_args([args, namespace])

print_usage([file])

register(registry_name, value, object)

set_defaults(**kwargs)

add_argument_group

add_mutually_exclusive_group

convert_arg_line_to_args

format_help

get_default

parse_intermixed_args

parse_known_args

parse_known_intermixed_args

print_help

class schimpy.schism_yaml.YamlAction(option_strings, dest, nargs=None, **kwargs)

Bases: Action

Custom action to parse YAML files for argparse. This action reads in simple pairs of data from a YAML file, and feeds them to the parser. A YAML file must be a list of pairs without multiple levels of tree. Example: parser.add_argument(”–yaml”, action=YamlAction)

Methods

__call__(parser, namespace, values[, ...])

Call self as a function.

format_usage

schimpy.schism_yaml.dump(data, stream=None, Dumper=<class 'yaml.dumper.Dumper'>, **kwds)

Serialize a Python object into a YAML stream. If stream is None, return the produced string instead.

schimpy.schism_yaml.load(stream)

Load a schism YAML

schimpy.separate_species module

Separation of tidal data into species The key function in this module is separate_species, which decomposes tides into subtidal, diurnal, semidiurnal and noise components. A demo function is also provided that reads tide series (6min intervl) from input files, seperates the species, writes results and optionally plots an example

schimpy.separate_species.create_arg_parser()
schimpy.separate_species.main()
schimpy.separate_species.plot_result(ts, ts_semi, ts_diurnal, ts_sub_tide, station)
schimpy.separate_species.run_example()

This is the data for the example. Note that you want the data to be at least 4 days longer than the desired output

schimpy.separate_species.separate_species(ts, noise_thresh_min=40)

Separate species into subtidal, diurnal, semidiurnal and noise components

Input:

ts: timeseries to be decomposed into species, assumed to be at six minute intervals. The filters used have long lenghts, so avoid missing data and allow for four extra days worth of data on each end.

Output:

four regular time series, representing subtidal, diurnal, semi-diurnal and noise

schimpy.separate_species.write_th(filename, ts_output)

This works fine for fairly big series

schimpy.simulation_timing module

schimpy.simulation_timing.create_arg_parser()
schimpy.simulation_timing.schism_timing(workdir, start=1, end=None, block_days=1.0)

schimpy.small_areas module

schimpy.small_areas.create_arg_parser()

Create ArgumentParser

schimpy.small_areas.main()
schimpy.small_areas.small_areas(mesh, warn=10.0, fail=1.0, logger=None, write_out_smalls=False)

schimpy.sms2gr3 module

Manage conversion from SMS 2dm format to gr3. Some material borrowed @author: snegusse

class schimpy.sms2gr3.Boundary(name, btype, nodestring)

Bases: object

schimpy.sms2gr3.addnode(list)
schimpy.sms2gr3.convert_2dm(file, outfile=None, elev2depth=False, logger=None)
schimpy.sms2gr3.create_arg_parser()

schimpy.split_quad module

PoC of quad splitting

schimpy.split_quad.split_all_quads(mesh)

Split all quad elements into triangular ones and return a new triangular mesh. This function maintains the original node indices. Currently this function does not add boundary information to the new mesh.

Parameters:
mesh: SchismMesh

a mesh with elements to split

Returns:
SchismMesh

A new triangular mesh. It does not contain any extra information, e.g. boundary information.

schimpy.stacked_dem_fill module

Routines to fill elevation (or other scalar) values at points from a prioritized list of rasters

schimpy.stacked_dem_fill.ParseType(type)
schimpy.stacked_dem_fill.Usage()
schimpy.stacked_dem_fill.bilinear(points, gt, raster)

Bilinear interpolated point using data on raster points: npoint x 3 array of (x,y,z points) gt: geotransform information from gdal raster: the data

schimpy.stacked_dem_fill.create_arg_parser()
schimpy.stacked_dem_fill.filelist_main(demlistfile, pointlistfile, sep='')

higher level driver routine that parses the names of the DEMs from demfilelist points ( x,y or x,y,z ) from pointlistfile

schimpy.stacked_dem_fill.fill_2dm(infile, outfile, files, na_fill=2.0)
schimpy.stacked_dem_fill.fill_gr3(infile, outfile, files, elev2depth=True, na_fill=2.0)
schimpy.stacked_dem_fill.main()
schimpy.stacked_dem_fill.stacked_dem_fill(files, points, values=None, negate=False, require_all=True, na_fill=None)

Fill values at an array of points using bilinear interpolation from a prioritized stack of dems. This routine controls prioritization of the dems, gradually filling points that are still marked nan

Parameters:
files: list[str]

list of files. Existence is checked and ValueError for bad file

points: np.ndarray

this is a numpy array of points, nrow = num of points and ncol = 2 (x,y).

values: np.ndarray

values at each point – this is an output, but this gives an opportunity to use an existing data structure to receive

negate: bool

if True, values will be inverted (from elevation to depth)

require_all: bool

if True, a ValueError is raised if the list of DEMs does not cover all the points. In either case (True/False) a file is created or overwritten (dem_misses.txt) that will show all the misses.

na_fill: float

value to substitute at the end for values that are NA after all DEMs are processed. If require_all = True na_fill must be None

Returns:
valuesnp.ndarray

Values at the nodes

schimpy.stacked_dem_fill.test_main()

schimpy.station module

schimpy.station.convert_db_station_in(outfile='station.in', stationdb=None, sublocdb=None, station_request='all', default=-0.5)
schimpy.station.create_arg_parser()

Create an argument parser

schimpy.station.example()
schimpy.station.flux_stations_from_yaml(inp)

Retrieve station id of fluxlines from yaml file or content

schimpy.station.main()

A main function to convert polygon files

schimpy.station.merge_station_subloc(station_dbase, station_subloc, default_z)

Merge BayDeltaSCHISM station database with subloc file, producing the union of all stations and sublocs including a default entry for stations with no subloc entry

Parameters:
station_dbaseDataFrame

This should be the input that has only the station id as an index and includes other metadata like x,y,

station_sublocDataFrame

This should have (id,subloc) as an index

Returns:
ResultDataFrame

DataFrame that links the information.

schimpy.station.read_flux_out(fpath, names, reftime)

Read fluxes from a SCHISM flux.out file

Parameters:
fpathstr
Path to the file
namesstr
name of file that contains names of flux areas, typically something like flow_xsects.yaml
reftimestr
start of simulation, against which relative times will be calculated

Read an obs_links csv file which has comma as delimiter and (id,subloc,variable) as index

schimpy.station.read_staout(fname, station_infile, reftime, ret_station_in=False, multi=False, elim_default=False, time_unit='s')

Read a SCHISM staout_* file into a pandas DataFrame

Parameters:
fpathfname

Path to input staout file or a variable name in [“elev”, “air pressure”, “wind_x”, “wind_y”, “temp”, “salt”, “u”, “v”, “w”] whose 1-index will be mapped to a name like staout_1 for elev

station_infilestr or DataFrame

Path to station.in file or DataFrame from read_station_in

reftimeTimestampe

Start of simulation, time basis for staout file elapse time

ret_station_inbool

Return station_in DataFrame for use, which may speed reading of a second file

multibool

Should the returned data have a multi index for the column with location and sublocation. If False the two are collapsed

elim_defaultbool

If the MultiIndex is collapsed, stations with subloc “default” will be collapsed. Eg. (“CLC”,”default”) becomes “CLC_default”

time_unitstring

Convertible to pandas frequency string, this is the timestamp of the file.

Returns:
ResultDataFrame

DataFrame with hierarchical index (id,subloc) and columns representing the staout data (collapsed as described above

Examples

>>> staout1,station_in = read_staout("staout_1","station.in",reftime=pd.Timestamp(2009,2,10),
                             ret_station_in = True,multi=False,elim_default=True)
>>> staout6 = read_staout("staout_6",station_in,reftime=pd.Timestamp(2009,2,10),multi=False,elim_default=True)
schimpy.station.read_station_dbase(fpath)

Read a BayDeltaSCHISM station data base csv file into a pandas DataFrame

The BayDelta SCHISM format is open, but expects these columns: index x y z ! id subloc “Name”

Parameters:
fpathfname

Path to input dbase style file

Returns:
ResultDataFrame

DataFrame with hierarchical index (id,subloc) and columns x,y,z,name

schimpy.station.read_station_in(fpath)

Read a SCHISM station.in file into a pandas DataFrame

Note

This only reads the tabular part, and assumes the BayDelta SCHISM format with columns: index x y z ! id subloc “Name”

Note that there is no header and the delimiter is a space. Also note that the text beginning with ! is extra BayDeltaSCHISM extra metadata, not required for vanilla SCHISM

Parameters:
fpathfname

Path to input station.in style file

Returns:
ResultDataFrame

DataFrame with hierarchical index (id,subloc) and columns x,y,z,name

schimpy.station.read_station_out(fpath_base, stationinfo, var=None, start=None)
schimpy.station.read_station_subloc(fpath)

Read a BayDeltaSCHISM station_sublocs.csv file into a pandas DataFrame

The BayDelta SCHISM format has a header and uses “,” as the delimiter and has these columns: id,subloc,z

The id is the station id, which is the key that joins this file to the station database. ‘subloc’ is a label that describes the sublocation or subloc and z is the actual elevation of the instrument

Example might be: id,subloc,z 12345,upper,-0.5

Other columns are allowed, but this will commonly merged with the station database file so we avoid column names like ‘name’ that might collide

Parameters:
fpathfname

Path to input station.in style file

Returns:
ResultDataFrame

DataFrame with hierarchical index (id,subloc) and data column z

schimpy.station.staout_name(var)
schimpy.station.station_names_from_file(fpath)
schimpy.station.station_subset(fpath, run_start, locs, extract_freq, convert=None, stationfile=None, isflux='infer', miss='raise')

Extract a subset of stations from an staout file or flux.out file

Parameters:
fpathstr

Path to the output file to be read

run_startpd.Timestamp

Start time (reference time) for the simulation elapsed time

locspd.DataFrame or str

A DataFrame with rows specifying the data to subset or a string that is the path to such a file. There are a few options. Minimally this file should have either one column called “station_id” or one called “id” and another called “subloc”. If you use station_id, it should be an underscore-connected combination of id and subloc which should be unique, and this will be the treatment of the output. of the station. If you use “subloc” you can use “default” leave the subloc column blank. You can also use another optional column called “alias” and this will become the label used.

extract_freqstr or pd.tseries.TimeOffset

Frequency to extract … this allows some economies if you want, say, 15min data. Use pandas freq string such as ‘15T’ for 15min

convert: str or function

A small number of conversions are supported (“ft”, “ec” for uS/cm, “cfs” for flow)

stationfilestr

Name of station file such as station.in. In the case of flow this will be a yaml file or fluxflag.prop file produced by our preprocessing system. If you leave this None, ‘station.in’ in the same directory as the output file will be assumed for staout files. For flow, a string must be supplied but will be tested first in the directory of execution and then side-by-side in that order.

isflux‘infer’ | True | False

Is the request for flux.out?

miss‘raise’ | ‘drop’ | ‘nan’

What to do when a requested station_id does not exist. The default, raise, helps station lists from growing faulty. ‘drop’ will ignore the column and ‘nan’ will return nans for the column.

Returns:
ResultDataFrame

DataFrame that returns the converted and subsetted data. Column names will be the ids unless ‘alias’ is provided in locs, in which case those names will be swapped in.

schimpy.station.station_subset_multidir(dirs, staoutfile, run_start, locs, extract_freq, convert, stationfile=None, names=None, isflux='infer', miss='raise')

Extract a subset of stations from an staout file or flux.out file across a list of directories

Parameters:
dirslist(str)

List of directories. The output dataframe will have a column multindex (dir,station_id) where dir is the directory of the output.

fpathstr

Path to the output file to be read

run_startpd.Timestamp

Start time (reference time) for the simulation elapsed time

locspd.DataFrame or str

A DataFrame with rows specifying the data to subset or a string that is the path to such a file. There are a few options for staout station files. Minimally this file should have either one column called “station_id” or one called “id” and another called “subloc”. If you use station_id, it should be an underscore-connected combination of id and subloc and this will be the index treatment of the output. Flux files only have the station_id option. If you use “subloc” you can use “default” leave the subloc column blank. You can also include another optional column called “alias” and this will become the label used.

extract_freqstr or pd.tseries.TimeOffset

Frequency to extract … this allows some economies if you want, say, 15min data. Use pandas freq string such as ‘15T’ for 15min

convert: str or function

A small number of conversions are supported (“ft”, “ec” for uS/cm, “cfs” for flow)

stationfilestr

Name or list of station file such as station.in. You can provide a list of the same length as dirs or a single value which will be assumed to be appropriate for all the directories. In the case of station.in, you can use None and ‘station.in’ in each directory will be assumed for staout files. For flow, a string (yaml file) must be supplied but will be tested first in the directory of execution and then side-by-side in that order.

isflux‘infer’ | True | False

Is the request for flux.out?

miss‘raise’ | ‘drop’ | ‘nan’

What to do when a requested station_id does not exist. The default, raise, helps station lists from growing faulty. ‘drop’ will ignore the column and ‘nan’ will return nans for the column.

Returns:
ResultDataFrame

DataFrame that returns the converted and subsetted data. Column names will be the ids unless ‘alias’ is provided in locs, in which case those names will be swapped in.

schimpy.station.u(x)
schimpy.station.write_station_in(fpath, station_in, request=None)

Write a SCHISM station.in file given a pandas DataFrame of metadata

Parameters:
fpathfname

Path to output station.in file

station_inDataFrame

DataFrame that has station id, x, y, z, name and subloc labels (id is the station id, index will be autogenerated)

request‘all’ or list(str)

List of variables to put in output request from the choices ‘elev’, ‘air pressure’, ‘wind_x’, ‘wind_y’, ‘temp’, ‘salt’, ‘u’, ‘v’, ‘w’ or ‘all’ to include them all

schimpy.subset_schism_output module

Created on Wed Oct 27 11:41:00 2021

@author: babban

schimpy.subset_schism_output.create_arg_parser()

Create an argument parser return: argparse.ArgumentParser

schimpy.subset_schism_output.create_partition(mesh, polygons, enforce_exact=False)

Takes a mesh and list of polygons and partitions according to where the centroids (mesh.centroids in schimpy) fall. Parameters ———— mesh : schimpy.SchismMesh The mesh to partition

polygons : Polygons (parsed from shape file or yaml into SCHIMPY

enforce_exact: bool Requires a unique, complete partition. Initially not implemented for True

Produces meshes and dicitonary(?) maps of local_to_global and global_to_local. (tuple or class)

schimpy.subset_schism_output.partition_schout(in_Schout_Files, partition_shp, combined=True, exclude=[], transform={'salt_depth_ave': ('depth_ave', 'salt')})

Partitions schout binary output files (start with combined) into a set of smaller schout files corresponding to each partition.

Initially implementation will be nodal variables but ultimately native centered (edge centered velocity, prism centered tracers).

Transform is an opportunity to generate new variables that are well determined with the data from one time step, but not based on time-stenciled operations.

Exclude would be an opportunity to prune variables not desired by dropping variables, although certain variables that are required for well-formedness (zcor, wet-dry) and visualization would not be “excludable” so exclude = “all_data” could be used to exclude all but the non-excludable. No output, but side effect is production of files. p0000/schout_1.nc.

schimpy.subset_schism_output.partition_scribeio(partition_shp, variables=['out2d', 'zCoordinates', 'salinity', 'horizontalVelX', 'horizontalVelY', 'verticalVelocity'])

Partitioning scribio format output files into a set of smaller files corresponding to each partitions. This function will loop all the schism scribeIO output files that contains varaibles defined by the input variables, and result subset outputs will be saved to a subset subdirectory.

Parameters:
partition_shparcgis shape file
shape files contains polygons where subset of output desried
variableslist of str
Output variables to be subsetted
schimpy.subset_schism_output.records(file)
schimpy.subset_schism_output.subset_schism_output()
schimpy.subset_schism_output.subset_schism_scribeIO_output(partition_shp)
schimpy.subset_schism_output.write_global_local_maps(dest, global_local, local_global)

writes maps out in the schism + visit format. Note that the global owner of a shared node is the lowest rank that contains it.

schimpy.three_point_linear_norm module

class schimpy.three_point_linear_norm.ThreePointLinearNorm(linthresh, vmin=None, vmax=None, clip=False)

Bases: Normalize

Attributes:
clip
vmax
vmin

Methods

__call__(value[, clip])

Normalize value data in the [vmin, vmax] interval into the [0.0, 1.0] interval and return it.

autoscale(A)

Set vmin, vmax to min, max of A.

autoscale_None(A)

autoscale only None-valued vmin or vmax

process_value(value)

Homogenize the input value for easy and efficient normalization.

scaled()

return true if vmin and vmax set

inverse

autoscale(A)

Set vmin, vmax to min, max of A.

autoscale_None(A)

autoscale only None-valued vmin or vmax

inverse(value)
scaled()

return true if vmin and vmax set

schimpy.trimesh module

This is a class to hold an unstructured triangular mesh.

Lots of the codes are copied from Rusty Chris Collerman’s trigrid program and modified a bit to meet our needs.

Prerequisite: Numpy, rtree package, and libspatialindex for rtree

schimpy.trimesh.BoundaryTypes

alias of Enum

schimpy.trimesh.EdgeTypes

alias of Enum

class schimpy.trimesh.TriMesh

Bases: object

Class that holds a triangular mesh information

Attributes:
edges

Array of edges

elems

Array of node indices of each element.

nodes

Node array consisting of three-dimensional coordinates of each node.

Methods

add_boundary(nodes, btype)

Add boundary types to an edge with the given array of node indices

allocate(n_elems, n_nodes)

Allocate memory for nodes and elems

build_edgecenters()

Build centers of sides

build_edges_from_elems()

This is a function copied and modified from TriGrid

deepcopy(mesh)

Deep copy mesh information.

element2edges(elem_i)

Get edge indices from the give element index elem_i = the element index return = generator of found edge indices

find_closest_elems(pos[, count])

Find indices of the closet elems with the given position.

find_closest_nodes(pos[, count, boundary])

Returns the count closest nodes to the given node in 2D space.

find_elem(pos)

Find a element index from a coordinate pos = A coordinate (2D) return = element index

find_elem_with_tolerance(pos, tolerance)

Find a element index from a coordinate with some tolerance pos = A coordinate (2D) return = element index

find_nodes_in_box(box)

Find nodse in a bounding box box = a numpy array of bounding box, [x_min, x_max, y_min, y_max] return = node indices

get_edges_from_node(node_i)

Get edge indices related to node_i

get_elems_i_from_node(node_i)

Get neighboring elements indexes of a node, so-called a ball.

get_neighbor_nodes(node_i)

Get neighboring node indices from the given node index.

is_elem_on_boundary(elem_i)

Check if the given element with index elem_i is on the boundary

n_edges()

Get the total number of edges.

n_elems()

Get the total nuber of elems.

n_nodes()

Get the total number of nodes.

set_elem(index, connectivities)

Set element connectivity information.

set_node(index, coords)

Set one node information.

shortest_path(n1, n2[, boundary_only])

dijkstra on the edge graph from n1 to n2.

trim_to_left(paths)

Given a path, trim all elems to the left of it.

add_boundary(nodes, btype)

Add boundary types to an edge with the given array of node indices

allocate(n_elems, n_nodes)

Allocate memory for nodes and elems

Parameters:
n_elems: integer

Total number of elems

n_nodes: integer

Total number of nodes

build_edgecenters()

Build centers of sides

Returns:
numpy.array

list of side centers

build_edges_from_elems()

This is a function copied and modified from TriGrid

deepcopy(mesh)

Deep copy mesh information.

property edges

Array of edges

Getter:

Get the array of the edges.

Type:

Numpy integer array

element2edges(elem_i)

Get edge indices from the give element index elem_i = the element index return = generator of found edge indices

property elems

Array of node indices of each element. The shape of the array is (# of elems, 3). It is assumed that all elems are triangular.

Getter:

Get the Numpy array of the node indices.

Type:

Numpy integer array

find_closest_elems(pos, count=1)

Find indices of the closet elems with the given position. The distance is measured with the element mass center. All triangular elems is assumed. pos = position tuple return = element indices

find_closest_nodes(pos, count=1, boundary=False)

Returns the count closest nodes to the given node in 2D space. pos = position count = # of nodes to retrieve boundary=1: only choose nodes on the boundary. Copied from TriGrid

find_elem(pos)

Find a element index from a coordinate pos = A coordinate (2D) return = element index

find_elem_with_tolerance(pos, tolerance)

Find a element index from a coordinate with some tolerance pos = A coordinate (2D) return = element index

find_nodes_in_box(box)

Find nodse in a bounding box box = a numpy array of bounding box, [x_min, x_max, y_min, y_max] return = node indices

get_edges_from_node(node_i)

Get edge indices related to node_i

get_elems_i_from_node(node_i)

Get neighboring elements indexes of a node, so-called a ball.

get_neighbor_nodes(node_i)

Get neighboring node indices from the given node index.

is_elem_on_boundary(elem_i)

Check if the given element with index elem_i is on the boundary

Parameters:
elem_iint

element index

Returns:
is_on_boundarybool
True if the element is on the boundary, otherwise False
n_edges()

Get the total number of edges.

n_elems()

Get the total nuber of elems.

n_nodes()

Get the total number of nodes.

property nodes

Node array consisting of three-dimensional coordinates of each node. The shape of the array is (# of nodes, 3)

Getter:

Get the array of the nodes.

Type:

Numpy float array.

set_elem(index, connectivities)

Set element connectivity information. Memory for elems must be allocated already.

Parameters:
index: integer

Zero-based element index

connectivities: Numpy array

a Numpy array of element connectivity, which means node indies in the element.

set_node(index, coords)

Set one node information. Memory for nodes must be allocated already.

Parameters:
index: integer

Zero-based node index

coords: Numpy array

a Numpy array of node coordinates

shortest_path(n1, n2, boundary_only=False)

dijkstra on the edge graph from n1 to n2. copied and modified form Rusty’s code. n1 = node_i for one end of the path n2 = node_i for the other end boundary_only = limit search to edges on the boundary (have a -1 for element2)

trim_to_left(paths)

Given a path, trim all elems to the left of it. This fuction is lifted and modified slightly from Rusty’s code.

schimpy.trimesh.enum(**enums)

A enum type definition. Copied from http://stackoverflow.com/questions/36932/how-can-i-represent-an-enum-in-python

schimpy.triquadmesh module

This is a class to hold an unstructured triangular and quad mesh for SCHISM copied and modified from Rusty Holleman’s trigrid.

Prerequisite: Numpy, rtree package, and libspatialindex for rtree

schimpy.triquadmesh.BoundaryType

alias of Enum

schimpy.triquadmesh.EdgeType

alias of Enum

schimpy.triquadmesh.NodeType

alias of Enum

class schimpy.triquadmesh.TriQuadMesh(logger=None)

Bases: object

Class that holds a triangular and quadrilateral mesh information

Attributes:
edges

Get the array of edges

elems

Array of node indexes of all elements.

node2elems
nodes

Node array consisting of three-dimensional coordinates of each node.

Methods

add_boundary(nodes, btype)

Add boundary types to an edge with the given array of node indexes

allocate(n_elems, n_nodes)

Allocate memory for nodes and elems

build_edgecenters()

Build centers of sides

build_edges_from_elems([shift])

Build edge array from the elements.

build_elem_balls()

Build balls of elements around each node

compare(mesh)

Compare the mesh with another

elem(elem_i)

Get connectivity of an element

element2edges(elem_i)

Get edge indexes of the give element index

find_closest_elems(pos[, count])

Find indexes of the closet elems with the given position.

find_closest_nodes(pos[, count, boundary])

Returns the count closest nodes to the given node in 2D space.

find_edge(nodes[, direction])

Find an edge index with the two given node indexes.

find_elem(pos)

Find a element index from a coordinate pos = A coordinate (2D) return = element index

find_intersecting_elems_with_line(line_segment)

Format of the line segment: start_x, start_y, end_x, end_y

find_neighbors_on_segment(line_segment)

Find elements on the line_segment and neighbors that are all to the left (downstream) Format of the line segment: start_x, start_y, end_x, end_y Returns a list of elements on the segment and a list of neighbors.

find_nodes_in_box(box)

Find nodes in a bounding box.

get_edges_from_node(node_i)

Get edge indexes related to node_i

get_elems_i_from_node(node_i)

Get the ball of elements around a node, node_i

get_neighbor_nodes(node_i)

Get neighboring node indexes from the given node index.

is_elem_on_boundary(elem_i)

Check if the given element with index elem_i is on the boundary

mark_elem_deleted(elem_i)

Mark an element as deleted or invalid.

n_edges()

Get the total number of edges.

n_elems()

Get the total number of elements.

n_nodes()

Get the total number of nodes.

node(node_i)

Selects a single node

renumber()

removes duplicate elems and nodes that are not referenced by any element, as well as elems that have been deleted (==-1) This function is lifted and modified slightly from Rusty's code.

set_elem(index, connectivity)

Set element connectivity information.

set_node(index, coords)

Set one node information.

shortest_path(n1, n2[, boundary_only])

Dijkstra on the edge graph from node n1 to n2.

trim_elems(paths[, left])

Given a path, trim all elems to the left of it.

add_boundary(nodes, btype)

Add boundary types to an edge with the given array of node indexes

allocate(n_elems, n_nodes)

Allocate memory for nodes and elems

Parameters:
n_elems: int

Total number of elems

n_nodes: int

Total number of nodes

build_edgecenters()

Build centers of sides

Returns:
numpy.array

list of side centers

build_edges_from_elems(shift=1)

Build edge array from the elements.

Parameters:
shift:

shift of indexing in edged building. It is introduce to keep the ordering of edges in line with SCHISM Mesh.

build_elem_balls()

Build balls of elements around each node

compare(mesh)

Compare the mesh with another

Parameters:
mesh: triquadmesh.TriQuadMesh

a mesh to compare

Returns:
boolean

True if they have identical node and element array

property edges

Get the array of edges

Getter:

Get the array of the edges.

Type:

Numpy integer array

elem(elem_i)

Get connectivity of an element

Parameters:
elem_i: int

element index

Returns:
Numpy int32 array

connectivity of the element (node indexes of the element) None, if the element is marked as deleted

element2edges(elem_i)

Get edge indexes of the give element index

Parameters:
elem_i: int

the element index

Returns
——-
array of int

edge indexes of the element

property elems

Array of node indexes of all elements. The shape of the array is (# of elems, 5).

Returns:
list of Numpy integer array

list of node indexes for all elements

find_closest_elems(pos, count=1)

Find indexes of the closet elems with the given position. The distance is measured with the element mass center. All triangular elems is assumed.

Parameters:
pos: array-like

2D position

Returns:
int or list

element index or indexes

find_closest_nodes(pos, count=1, boundary=False)

Returns the count closest nodes to the given node in 2D space. Roughly copied from trigrid

Parameters:
pos: array-like

position

count: int

# of nodes to retrieve

boundary: int 1

only choose nodes on the boundary.

Returns:
int or list

nearest node indexes

find_edge(nodes, direction=False)

Find an edge index with the two given node indexes.

Parameters:
nodes: array-like

two node indexes

direction:

match the ordering of the nodes when an edge is found.

Returns:
int

an edge index, None if not found

find_elem(pos)

Find a element index from a coordinate pos = A coordinate (2D) return = element index

find_intersecting_elems_with_line(line_segment)

Format of the line segment: start_x, start_y, end_x, end_y

find_neighbors_on_segment(line_segment)

Find elements on the line_segment and neighbors that are all to the left (downstream) Format of the line segment: start_x, start_y, end_x, end_y Returns a list of elements on the segment and a list of neighbors. The lists are not guarateed to be ordered spatially

find_nodes_in_box(box)

Find nodes in a bounding box. Note that the box is not interleaved. The backend is based on R-tree.

Parameters:
box: array-like

array of bounding box, [x_min, x_max, y_min, y_max]

Returns:
set

node indexes

get_edges_from_node(node_i)

Get edge indexes related to node_i

Parameters:
node_i: int

Node index (zero-based)

Returns
——-
list

a list of edges

get_elems_i_from_node(node_i)

Get the ball of elements around a node, node_i

Parameters:
node_i: int

node index (zero-based)

Returns:
set

set of element indexes

get_neighbor_nodes(node_i)

Get neighboring node indexes from the given node index.

is_elem_on_boundary(elem_i)

Check if the given element with index elem_i is on the boundary

Parameters:
elem_iint

element index

Returns:
is_on_boundarybool
True if the element is on the boundary, otherwise False
mark_elem_deleted(elem_i)

Mark an element as deleted or invalid.

Parameters:
elem_i: int

element index to mark

n_edges()

Get the total number of edges.

n_elems()

Get the total number of elements.

n_nodes()

Get the total number of nodes.

node(node_i)

Selects a single node

property node2elems
property nodes

Node array consisting of three-dimensional coordinates of each node. The shape of the array is (# of nodes, 3)

Getter:

Get the array of the nodes.

Type:

Numpy float array.

renumber()

removes duplicate elems and nodes that are not referenced by any element, as well as elems that have been deleted (==-1) This function is lifted and modified slightly from Rusty’s code.

Returns:
dict
{‘valid_elems’:new_elems, ‘pointmap’:old_indexes,

‘valid_nodes’:active_nodes}

set_elem(index, connectivity)

Set element connectivity information. Memory for elems must be allocated already.

Parameters:
index: integer

Zero-based element index

connectivity: Numpy array

a Numpy array of element connectivity, which means node indexes in the element.

set_node(index, coords)

Set one node information. Memory for nodes must be allocated already.

Parameters:
index: integer

Zero-based node index

coords: Numpy array

a Numpy array of node coordinates

shortest_path(n1, n2, boundary_only=False)

Dijkstra on the edge graph from node n1 to n2. copied and modified form Rusty’s code. Keep in mind that the solution can be non-unique because there are multiple paths that have the same distances.

Parameters:
n1: int

node index for one end of the path

n2: int

node_i for the other end

boundary_only: boolean

limit search to edges on the boundary

Returns:
numpy.ndarray

shortest node indexes or None if it cannot be found

trim_elems(paths, left=None)

Given a path, trim all elems to the left of it. This function is lifted and modified slightly from Rusty’s code.

Parameters:
paths: array of integer array-like

arrays of cut paths in arrays of node indexes

schimpy.triquadmesh.enum(**enums)

A enum type definition

Copied from http://stackoverflow.com/questions/36932/how-can-i-represent-an-enum-in-python

schimpy.unit_conversions module

schimpy.vgrid_opt2 module

Package for optimising vgrid smoothness, shape and completeness

schimpy.vgrid_opt2.example()
schimpy.vgrid_opt2.fix_depth(zcor, zcornew, x)
schimpy.vgrid_opt2.gradient_matrix(mesh, sidedist2, sidemasked)
schimpy.vgrid_opt2.hess_base(xvar, zcorig, mesh, nlayer, ndx, eta, depth, gradmat, sidelen2, nodemasked, sidemasked, ata, dx2fac, curvewgt, foldwgt, foldfrac)
schimpy.vgrid_opt2.incr_grad(grad, i, k, val, ndx)
schimpy.vgrid_opt2.index_interior(mat, nodemasked, nlevel=None)
schimpy.vgrid_opt2.laplace2(mesh, nodemasked, sidemasked)

produces a 2d matrix

schimpy.vgrid_opt2.mesh_opt(zcor, mesh, nlayer, ndx, eta, depth, gradmat, sidelen2, nodemasked, sidemasked, ata, dx2fac, curvewgt, foldwgt, foldfrac, href_hess, grad_hess, laplace_hess, maxiter=8000)
schimpy.vgrid_opt2.meshessp(xvar, p, zcorig, mesh, nlayer, ndx, eta, depth, gradmat, sidelen2, nodemasked, sidemasked, ata, dx2fac, curvewgt, foldwgt, foldfrac, href_hess, grad_hess, laplace_hess)
schimpy.vgrid_opt2.meshgrad(xvar, zcorig, mesh, nlayer, ndx, eta, depth, gradmat, sidelen2, nodemasked, sidemasked, ata, dx2fac, curvewgt, foldwgt, foldfrac, href_hess, grad_hess, laplace_hess)
schimpy.vgrid_opt2.meshobj(xvar, zcorig, mesh, nlayer, ndx, eta, depth, gradmat, sidelen2, nodemasked, sidemasked, ata, dx2fac, curvewgt, foldwgt, foldfrac, href_hess, grad_hess, laplace_hess)
schimpy.vgrid_opt2.smooth_heights(zcor, x, wgt=0.2)
schimpy.vgrid_opt2.targeth2inv(zbar, eta)
schimpy.vgrid_opt2.test_gradients()
schimpy.vgrid_opt2.test_vgrid_spacing(zcor, zcorig, nodemasked, foldfrac)
schimpy.vgrid_opt2.triweight(n)

schimpy.write_ts module

schimpy.write_ts.cdec_header(fname, ts, tz, var=None, unit=None)

Helper function to create a cdec-like header Requres some metadata like time zone, variable name and unit which will be pulled from series if omitted from input.

Parameters:
fname: str

Output file name or path

ts: :class:`~vtools.data.timeseries.TimeSeries`

The time series to be stored

tz: string

Time zone of data

var: string

Variable name

unit: string

Unit of the time series

Returns:
head: string

CDEC-style header

schimpy.write_ts.write_ts(ts, fname, dateformat='%Y-%m-%d %H:%M', fmt='%.2f', header=None, sep=',')

Estimate missing values within a time series by interpolation.

Parameters:
ts: :class:`~vtools.data.timeseries.TimeSeries`

The time series to be stored

fname: string

Output file name or path

dateformat: string

Date format compatible with datetime.datetime.strftime

fmt: string

Value format compatible withy numpy.savetxt

header: string

Header to add to top of file

sep: string

Delimieter for fields, often a space or comma

Returns:

Examples

Writing csv format with date format 2009-03-15 21:00 and space separated values

>>> write_ts(ts,"test.csv","%Y-%m-%d %H:%M","%.2f,%.2f","Datetime,u,v",",")

Write vtide format with same format and space separated values, this time taking advantage of defaults

>>> write_ts(ts,"test_vtide.dat",sep = " ")

Writing cdec format, with csv values and date and time separated. The header is generated with the cdec_header helper function

>>> head = cdec_header("practice.csv",ts,"PST","Wind Vel","m/s")
>>> write_ts(ts,"test_cdec.csv",CDECDATEFMT,"%.2f",header=head)

Module contents

Top-level package for schimpy.