rompy.schism.grid.SCHISMGrid#
- pydantic model rompy.schism.grid.SCHISMGrid[source]#
SCHISM grid in geographic space.
Show JSON schema
{ "title": "SCHISMGrid", "description": "SCHISM grid in geographic space.", "type": "object", "properties": { "grid_type": { "const": "schism", "default": "schism", "description": "Model descriminator", "title": "Grid Type", "type": "string" }, "hgrid": { "$ref": "#/$defs/DataBlob", "description": "Path to hgrid.gr3 file" }, "vgrid": { "anyOf": [ { "$ref": "#/$defs/DataBlob" }, { "$ref": "#/$defs/VgridGenerator" }, { "$ref": "#/$defs/VGrid" }, { "type": "null" } ], "description": "Path to vgrid.in file", "title": "Vgrid" }, "drag": { "anyOf": [ { "$ref": "#/$defs/DataBlob" }, { "type": "number" }, { "$ref": "#/$defs/GR3Generator" }, { "type": "null" } ], "default": null, "description": "Path to drag.gr3 file", "title": "Drag" }, "rough": { "anyOf": [ { "$ref": "#/$defs/DataBlob" }, { "type": "number" }, { "$ref": "#/$defs/GR3Generator" }, { "type": "null" } ], "default": null, "description": "Path to rough.gr3 file", "title": "Rough" }, "manning": { "anyOf": [ { "$ref": "#/$defs/DataBlob" }, { "type": "number" }, { "$ref": "#/$defs/GR3Generator" }, { "type": "null" } ], "default": null, "description": "Path to manning.gr3 file", "title": "Manning" }, "hgridll": { "anyOf": [ { "$ref": "#/$defs/DataBlob" }, { "type": "integer" }, { "$ref": "#/$defs/GridLinker" }, { "type": "null" } ], "default": null, "description": "Path to hgrid.ll file", "title": "Hgridll" }, "diffmin": { "anyOf": [ { "$ref": "#/$defs/DataBlob" }, { "type": "number" }, { "$ref": "#/$defs/GR3Generator" }, { "type": "null" } ], "default": 1e-06, "description": "Path to diffmax.gr3 file or constant value", "title": "Diffmin" }, "diffmax": { "anyOf": [ { "$ref": "#/$defs/DataBlob" }, { "type": "number" }, { "$ref": "#/$defs/GR3Generator" }, { "type": "null" } ], "default": 1.0, "description": "Path to diffmax.gr3 file or constant value", "title": "Diffmax" }, "albedo": { "anyOf": [ { "$ref": "#/$defs/DataBlob" }, { "type": "number" }, { "$ref": "#/$defs/GR3Generator" }, { "type": "null" } ], "default": 0.15, "description": "Path to albedo.gr3 file or constant value", "title": "Albedo" }, "watertype": { "anyOf": [ { "$ref": "#/$defs/DataBlob" }, { "type": "integer" }, { "$ref": "#/$defs/GR3Generator" }, { "type": "null" } ], "default": 1, "description": "Path to watertype.gr3 file or constant value", "title": "Watertype" }, "windrot_geo2proj": { "anyOf": [ { "$ref": "#/$defs/DataBlob" }, { "type": "number" }, { "$ref": "#/$defs/GR3Generator" }, { "type": "null" } ], "default": 0.0, "description": "Path to windrot_geo2proj.gr3 file or constant value", "title": "Windrot Geo2Proj" }, "hgrid_WWM": { "anyOf": [ { "$ref": "#/$defs/DataBlob" }, { "$ref": "#/$defs/GridLinker" }, { "type": "null" } ], "default": null, "description": "Path to hgrid_WWM.gr3 file", "title": "Hgrid Wwm" }, "wwmbnd": { "anyOf": [ { "$ref": "#/$defs/DataBlob" }, { "$ref": "#/$defs/WWMBNDGR3Generator" }, { "type": "null" } ], "default": null, "description": "Path to wwmbnd.gr3 file", "title": "Wwmbnd" }, "crs": { "default": "epsg:4326", "description": "Coordinate reference system", "title": "Crs", "type": "string" } }, "$defs": { "DataBlob": { "additionalProperties": false, "description": "Data source for model ingestion.\n\nGeneric data source for files that either need to be copied to the model directory\nor linked if `link` is set to True.", "properties": { "model_type": { "default": "data_blob", "description": "Model type discriminator", "enum": [ "data_blob", "data_link" ], "title": "Model Type", "type": "string" }, "id": { "default": "data", "description": "Unique identifier for this data source", "title": "Id", "type": "string" }, "source": { "description": "URI of the data source, either a local file path or a remote uri", "title": "Source" }, "link": { "default": false, "description": "Whether to create a symbolic link instead of copying the file", "title": "Link", "type": "boolean" } }, "required": [ "source" ], "title": "DataBlob", "type": "object" }, "GR3Generator": { "additionalProperties": false, "properties": { "model_type": { "const": "gr3_generator", "default": "gr3_generator", "description": "Model discriminator", "title": "Model Type", "type": "string" }, "hgrid": { "anyOf": [ { "$ref": "#/$defs/DataBlob" }, { "format": "path", "type": "string" } ], "description": "Path to hgrid.gr3 file", "title": "Hgrid" }, "gr3_type": { "description": "Type of gr3 file. Must be one of 'albedo', 'diffmin', 'diffmax', 'watertype', 'windrot_geo2proj'", "title": "Gr3 Type", "type": "string" }, "value": { "default": null, "description": "Constant value to set in gr3 file", "title": "Value", "type": "number" }, "crs": { "default": "epsg:4326", "description": "Coordinate reference system", "title": "Crs", "type": "string" } }, "required": [ "hgrid", "gr3_type" ], "title": "GR3Generator", "type": "object" }, "GridLinker": { "additionalProperties": false, "properties": { "hgrid": { "anyOf": [ { "$ref": "#/$defs/DataBlob" }, { "format": "path", "type": "string" } ], "description": "Path to hgrid.gr3 file", "title": "Hgrid" }, "gridtype": { "description": "Type of grid to link", "title": "Gridtype", "type": "string" } }, "required": [ "hgrid", "gridtype" ], "title": "GridLinker", "type": "object" }, "VGrid": { "description": "Base class for SCHISM vertical grid generation.\nThis class directly mirrors the PyLibs create_schism_vgrid API.", "properties": { "model_type": { "const": "schism_vgrid", "default": "schism_vgrid", "description": "Model discriminator", "title": "Model Type", "type": "string" }, "ivcor": { "default": 1, "description": "Vertical coordinate type (1=LSC2, 2=SZ)", "title": "Ivcor", "type": "integer" }, "nvrt": { "default": 2, "description": "Number of vertical layers", "title": "Nvrt", "type": "integer" }, "zlevels": { "anyOf": [ { "items": { "type": "number" }, "type": "array" }, { "type": "number" } ], "default": -1000000.0, "description": "Z levels or transition depth (h_s)", "title": "Zlevels" }, "h_c": { "default": 10.0, "description": "Critical depth for SZ coordinate", "title": "H C", "type": "number" }, "theta_b": { "default": 0.5, "description": "Bottom theta parameter for SZ", "title": "Theta B", "type": "number" }, "theta_f": { "default": 1.0, "description": "Surface theta parameter for SZ", "title": "Theta F", "type": "number" } }, "title": "VGrid", "type": "object" }, "VgridGenerator": { "additionalProperties": false, "description": "Generate vgrid.in using the unified VGrid class from rompy.schism.vgrid.\nThis class directly uses the VGrid API which mirrors the create_schism_vgrid function from PyLibs.", "properties": { "model_type": { "const": "vgridgenerator", "default": "vgridgenerator", "description": "Model discriminator", "title": "Model Type", "type": "string" }, "vgrid_type": { "default": "2d", "description": "Type of vertical grid to generate (2d, lsc2, or sz)", "title": "Vgrid Type", "type": "string" }, "nvrt": { "default": 10, "description": "Number of vertical layers for 3D grids", "title": "Nvrt", "type": "integer" }, "hsm": { "default": 1000.0, "description": "Transition depth for LSC2 vertical grid", "title": "Hsm", "type": "number" }, "h_c": { "default": 10.0, "description": "Critical depth for SZ vertical grid", "title": "H C", "type": "number" }, "theta_b": { "default": 0.5, "description": "Bottom theta parameter for SZ vertical grid", "title": "Theta B", "type": "number" }, "theta_f": { "default": 1.0, "description": "Surface theta parameter for SZ vertical grid", "title": "Theta F", "type": "number" } }, "title": "VgridGenerator", "type": "object" }, "WWMBNDGR3Generator": { "additionalProperties": false, "properties": { "model_type": { "const": "wwmbnd_generator", "default": "wwmbnd_generator", "description": "Model discriminator", "title": "Model Type", "type": "string" }, "hgrid": { "anyOf": [ { "$ref": "#/$defs/DataBlob" }, { "format": "path", "type": "string" } ], "description": "Path to hgrid.gr3 file", "title": "Hgrid" }, "bcflags": { "default": null, "description": "List of boundary condition flags. This replicates the functionality of the gen_wwmbnd.in file. Must be the same length as the number of open boundaries in the hgrid.gr3 file. If not specified, it is assumed that all open hgrid files are open to waves", "items": { "type": "integer" }, "title": "Bcflags", "type": "array" } }, "required": [ "hgrid" ], "title": "WWMBNDGR3Generator", "type": "object" } }, "additionalProperties": false, "required": [ "hgrid" ] }
- Fields:
albedo (rompy.core.data.DataBlob | float | rompy.schism.grid.GR3Generator | None)
diffmax (rompy.core.data.DataBlob | float | rompy.schism.grid.GR3Generator | None)
diffmin (rompy.core.data.DataBlob | float | rompy.schism.grid.GR3Generator | None)
drag (rompy.core.data.DataBlob | float | rompy.schism.grid.GR3Generator | None)
hgrid_WWM (rompy.core.data.DataBlob | rompy.schism.grid.GridLinker | None)
hgridll (rompy.core.data.DataBlob | int | rompy.schism.grid.GridLinker | None)
manning (rompy.core.data.DataBlob | float | rompy.schism.grid.GR3Generator | None)
rough (rompy.core.data.DataBlob | float | rompy.schism.grid.GR3Generator | None)
watertype (rompy.core.data.DataBlob | int | rompy.schism.grid.GR3Generator | None)
windrot_geo2proj (rompy.core.data.DataBlob | float | rompy.schism.grid.GR3Generator | None)
wwmbnd (rompy.core.data.DataBlob | rompy.schism.grid.WWMBNDGR3Generator | None)
- Validators:
validate_gr3_fields
»all fields
validate_rough_drag_manning
»all fields
- field albedo: DataBlob | float | GR3Generator | None = 0.15#
Path to albedo.gr3 file or constant value
- field crs: str = 'epsg:4326'#
Coordinate reference system
- Validated by:
- field diffmax: DataBlob | float | GR3Generator | None = 1.0#
Path to diffmax.gr3 file or constant value
- field diffmin: DataBlob | float | GR3Generator | None = 1e-06#
Path to diffmax.gr3 file or constant value
- field grid_type: Literal['schism'] = 'schism'#
Model descriminator
- Validated by:
- field vgrid: DataBlob | VgridGenerator | VGrid | None [Optional]#
Path to vgrid.in file
- Validated by:
- field watertype: DataBlob | int | GR3Generator | None = 1#
Path to watertype.gr3 file or constant value
- field windrot_geo2proj: DataBlob | float | GR3Generator | None = 0.0#
Path to windrot_geo2proj.gr3 file or constant value
- boundary(tolerance=None) Polygon [source]#
Returns the convex hull boundary polygon from the grid.
- Parameters:
tolerance (float) – Simplify polygon shape based on maximum distance from original geometry, see https://shapely.readthedocs.io/en/stable/manual.html#object.simplify.
- Returns:
polygon – See https://shapely.readthedocs.io/en/stable/manual.html#Polygon
- Return type:
shapely.Polygon
- boundary_points(spacing=None) tuple [source]#
Returns array of coordinates from boundary polygon.
- Parameters:
tolerance (float) – Simplify polygon shape based on maximum distance from original geometry, see https://shapely.readthedocs.io/en/stable/manual.html#object.simplify.
spacing (float) – If specified, points are returned evenly spaced along the boundary at the specified spacing, otherwise all points are returned.
Returns
--------
points (tuple) – Tuple of x and y coordinates of the boundary points.
- copy_to(destdir: Path) SCHISMGrid [source]#
Copy the grid to a destination directory.
This method generates all the required grid files in the destination directory and returns a new SCHISMGrid instance pointing to these files.
- Parameters:
destdir (Path) – Destination directory
- Returns:
A new SCHISMGrid instance with sources pointing to the new files
- Return type:
- generate_tvprop(destdir: Path) Path [source]#
Generate tvd.prop file for SCHISM.
The tvd.prop file must have two columns in this format: 1. Two columns: element_number TVD_flag (space-separated) 2. One entry per element 3. TVD flag value of 1 for all entries (1 = upwind TVD) 4. Element numbers start from 1
Correct format:
` 1 1 2 1 3 1 ... 317 1 `
- Parameters:
destdir (Path) – Destination directory
- Returns:
Path to tvd.prop file
- Return type:
Path
- validator gr3_source_validator » watertype, albedo, diffmax, manning, windrot_geo2proj, drag, rough, diffmin[source]#
- model_post_init(context: Any, /) None #
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self – The BaseModel instance.
context – The context.
- plot(ax=None, plot_type='domain', add_coastlines=True, **kwargs)[source]#
Plot the SCHISM grid using native pylibs plotting functionality.
- Parameters:
ax (matplotlib.axes.Axes, optional) – The axes to plot on. If None, a new figure is created.
plot_type (str, optional) – Type of plot to create. Options are: - ‘domain’: Plot the full domain with boundaries (default) - ‘grid’: Plot just the grid triangulation - ‘bnd’: Plot just the boundaries
add_coastlines (bool, optional) – Whether to add coastlines to the plot (requires cartopy).
fmt (int, optional) – Plotting format. Options are: - 0: Plot grid only (default) - 1: Plot filled contours of depth/bathymetry - 2: Plot contour lines of depth/bathymetry - 3: Plot boundaries only
value (numpy.ndarray, optional) – Color values for plotting. If None, grid depth is used.
levels (int or array-like, optional) – If int, number of contour levels to use (default 51). If array-like, specific levels to plot.
clim ([min, max], optional) – Value range for plot/colorbar. If None, determined from data.
cmap (str, optional) – Colormap to use for depth visualization (default ‘jet’).
cb (bool, optional) – Whether to add a colorbar to the plot (default True).
**kwargs (dict) – Additional keyword arguments to pass to the pylibs plot functions.
- Returns:
fig (matplotlib.figure.Figure) – The figure object.
ax (matplotlib.axes.Axes) – The axes object.
Examples
# Plot grid with bathymetry as filled contours >>> grid.plot(fmt=1, cmap=’viridis’, levels=20)
# Plot specific depth contours with custom range >>> grid.plot(fmt=2, clim=[-100, 0], levels=[-100, -50, -20, -10, 0])
- plot_bathymetry(ax=None, add_coastlines=True, **kwargs)[source]#
Plot filled contours of depth/bathymetry.
- Parameters:
ax (matplotlib.axes.Axes, optional) – The axes to plot on. If None, a new figure is created.
add_coastlines (bool, optional) – Whether to add coastlines to the plot (requires cartopy).
**kwargs (dict) – Additional keyword arguments to pass to the pylibs plot functions.
- Returns:
fig (matplotlib.figure.Figure) – The figure object.
ax (matplotlib.axes.Axes) – The axes object.
- plot_contours(ax=None, add_coastlines=True, **kwargs)[source]#
Plot contour lines of depth/bathymetry.
- Parameters:
ax (matplotlib.axes.Axes, optional) – The axes to plot on. If None, a new figure is created.
add_coastlines (bool, optional) – Whether to add coastlines to the plot (requires cartopy).
**kwargs (dict) – Additional keyword arguments to pass to the pylibs plot functions.
- Returns:
fig (matplotlib.figure.Figure) – The figure object.
ax (matplotlib.axes.Axes) – The axes object.
- plot_grid(ax=None, add_coastlines=True, **kwargs)[source]#
Plot just the grid triangulation.
- Parameters:
ax (matplotlib.axes.Axes, optional) – The axes to plot on. If None, a new figure is created.
add_coastlines (bool, optional:w) – Whether to add coastlines to the plot (requires cartopy).
**kwargs (dict) – Additional keyword arguments to pass to the pylibs plot functions.
- Returns:
fig (matplotlib.figure.Figure) – The figure object.
ax (matplotlib.axes.Axes) – The axes object.
- plot_hgrid(figsize=(20, 10))[source]#
Create a comprehensive two-panel visualization of the SCHISM grid.
Left panel shows bathymetry/depth, right panel shows the mesh and boundaries.
- Parameters:
figsize (tuple, optional) – Size of the figure (width, height). Default is (20, 10).
- Returns:
fig (matplotlib.figure.Figure) – The figure object containing both panels.
(ax1, ax2) (tuple of matplotlib.axes.Axes) – The axes objects for the bathymetry and mesh panels.
- serialize_model(**kwargs)[source]#
Custom serializer to handle optional fields properly during serialization.
- validator validate_gr3_fields » all fields[source]#
Custom validator to handle GR3Generator conversion during deserialization.
- property is_3d#
- property ne: int#
- property nob#
- property nobn#
- property np: int#
- property nvrt#
- property pylibs_hgrid#
- property pylibs_vgrid#
- property pyschism_hgrid#
- property pyschism_vgrid#
- property x: ndarray#
- property y: ndarray#