API Reference#
This page provides detailed documentation for the NWM Coastal Python API.
Configuration Classes#
CoastalCalibConfig#
CoastalCalibConfig
dataclass
#
CoastalCalibConfig(
simulation,
boundary,
paths,
model_config,
monitoring=MonitoringConfig(),
download=DownloadConfig(),
_base_config=None,
)
Complete coastal calibration workflow configuration.
Supports both SCHISM and SFINCS models via the polymorphic
:attr:model_config field. The concrete type is selected by the
model key in the YAML file and resolved through
:data:MODEL_REGISTRY.
from_yaml
classmethod
#
Load configuration from YAML file with optional inheritance.
Supports variable interpolation using ${section.key} syntax. Variables are resolved from other config values, e.g.:
${user}-> value of$USERenvironment variable${simulation.coastal_domain}-> value ofsimulation.coastal_domain${model}-> the model type string ("schism"or"sfincs")
| PARAMETER | DESCRIPTION |
|---|---|
config_path
|
Path to YAML configuration file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CoastalCalibConfig
|
Loaded configuration. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the configuration file does not exist. |
YAMLError
|
If the YAML file is malformed. |
Source code in src/coastal_calibration/config/schema.py
from_dict
classmethod
#
Create config from a plain dictionary.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Configuration dictionary with the same structure as the YAML
file (see :meth:
TYPE:
|
base_config_path
|
Path to a base configuration file (for YAML inheritance).
Only needed when the config was loaded via
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CoastalCalibConfig
|
|
Source code in src/coastal_calibration/config/schema.py
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 | |
to_yaml
#
Write configuration to YAML file.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to YAML output file. Parent directories will be created if they don't exist.
TYPE:
|
Source code in src/coastal_calibration/config/schema.py
to_dict
#
Convert config to dictionary.
Source code in src/coastal_calibration/config/schema.py
validate
#
Validate configuration and return list of errors.
Source code in src/coastal_calibration/config/schema.py
SimulationConfig#
SimulationConfig
dataclass
#
SimulationConfig(
start_date,
duration_hours,
coastal_domain,
meteo_source,
timestep_seconds=3600,
)
Simulation time and domain configuration.
BoundaryConfig#
BoundaryConfig
dataclass
#
Boundary condition configuration.
PathConfig#
PathConfig
dataclass
#
PathConfig(
work_dir,
raw_download_dir=None,
hot_start_file=None,
parm_dir=None,
nwm_dir=None,
otps_dir=None,
)
Path configuration for data and executables.
Only work_dir is required. All other fields are optional and
only needed by specific workflow stages (e.g. the create workflow
for SCHISM or SFINCS boundary processing that uses TPXO/OTPSnc).
meteo_dir
#
streamflow_dir
#
Directory for streamflow/hydro data.
Source code in src/coastal_calibration/config/schema.py
coastal_dir
#
geogrid_file
#
Geogrid file path for the given domain (requires parm_dir).
ModelConfig#
ModelConfig
#
Bases: ABC
Abstract base class for model-specific configuration.
Each concrete subclass owns its compute parameters, environment variable
construction, stage ordering, validation, and SLURM script generation.
This keeps model-specific concerns out of the shared configuration and
makes adding new models straightforward: create a new subclass,
implement the abstract methods, and register it in :data:MODEL_REGISTRY.
| ATTRIBUTE | DESCRIPTION |
|---|---|
omp_num_threads |
Number of OpenMP threads per process.
TYPE:
|
runtime_env |
Extra environment variables for the model run subprocess.
Merged last so they can override any auto-detected value.
Only used by model run stages (
TYPE:
|
model_name
abstractmethod
property
#
Return the model identifier string (e.g. 'schism', 'sfincs').
stage_order
abstractmethod
property
#
Ordered list of stage names for this model's pipeline.
build_environment
abstractmethod
#
Add model-specific environment variables to env (mutating).
Called by :meth:WorkflowStage.build_environment after shared
variables (OpenMP pinning, HDF5 file locking) have been populated.
Source code in src/coastal_calibration/config/schema.py
validate
abstractmethod
#
create_stages
abstractmethod
#
SchismModelConfig#
SchismModelConfig
dataclass
#
SchismModelConfig(
prebuilt_dir=Path(),
geogrid_file=Path(),
nodes=2,
ntasks_per_node=18,
exclusive=True,
nscribes=2,
omp_num_threads=2,
oversubscribe=False,
schism_exe=None,
include_noaa_gages=False,
discharge_file=None,
runtime_env=dict(),
)
Bases: ModelConfig
SCHISM model configuration.
Contains compute parameters (MPI layout, SCHISM binary), the path to a prebuilt model directory, and the geogrid file used for atmospheric forcing regridding.
| PARAMETER | DESCRIPTION |
|---|---|
prebuilt_dir
|
Path to the directory containing the pre-built SCHISM model
files (
TYPE:
|
geogrid_file
|
Path to the WRF geogrid file (e.g.
TYPE:
|
nodes
|
Number of SLURM nodes.
TYPE:
|
ntasks_per_node
|
MPI tasks per node.
TYPE:
|
exclusive
|
Request exclusive node access.
TYPE:
|
nscribes
|
Number of SCHISM scribe processes.
TYPE:
|
omp_num_threads
|
OpenMP threads per MPI rank.
TYPE:
|
oversubscribe
|
Allow MPI oversubscription.
TYPE:
|
schism_exe
|
Path to a compiled SCHISM executable. When set, the
TYPE:
|
include_noaa_gages
|
When True, automatically query NOAA CO-OPS for water level
stations within the model domain (computed from the concave
hull of open boundary nodes in
TYPE:
|
discharge_file
|
Path to a
TYPE:
|
SfincsModelConfig#
SfincsModelConfig
dataclass
#
SfincsModelConfig(
prebuilt_dir,
model_root=None,
discharge_locations_file=None,
merge_discharge=False,
include_precip=False,
include_wind=False,
include_pressure=False,
meteo_res=None,
forcing_to_mesh_offset_m=0.0,
vdatum_mesh_to_msl_m=0.0,
sfincs_exe=None,
omp_num_threads=0,
inp_overrides=dict(),
floodmap_dem=None,
floodmap_hmin=0.05,
floodmap_enabled=True,
runtime_env=dict(),
)
Bases: ModelConfig
SFINCS model configuration.
SFINCS runs on a single node using OpenMP (all available cores). There is no MPI or multi-node support.
| PARAMETER | DESCRIPTION |
|---|---|
prebuilt_dir
|
Path to the directory containing the pre-built model files
(
TYPE:
|
model_root
|
Output directory for the built model. Defaults to
TYPE:
|
discharge_locations_file
|
Path to a SFINCS
TYPE:
|
merge_discharge
|
Whether to merge with pre-existing discharge source points.
TYPE:
|
include_precip
|
When True, add precipitation forcing from the meteorological
data catalog entry (derived from
TYPE:
|
include_wind
|
When True, add spatially-varying wind forcing (
TYPE:
|
include_pressure
|
When True, add spatially-varying atmospheric pressure forcing
(
TYPE:
|
meteo_res
|
Output resolution (m) for gridded meteorological forcing
(precipitation, wind, pressure). When None (default) the
resolution is determined from the SFINCS quadtree grid — it
equals the base cell size (coarsest level) so that the meteo
grid is never finer than needed. Setting an explicit value
(e.g. .. note:: Without this parameter the HydroMT
TYPE:
|
forcing_to_mesh_offset_m
|
Vertical offset in meters added to the boundary-condition water levels before they enter SFINCS. Tidal-only sources such as TPXO provide oscillations centered on
zero (MSL) but carry no information about where MSL sits on the
mesh's vertical datum. This parameter anchors the forcing signal
to the correct geodetic height on the mesh. Set it to the
elevation of MSL in the mesh datum obtained from VDatum
(e.g. For sources that already report water levels in the mesh datum
(e.g. STOFS on a NAVD88 mesh) set this to Defaults to
TYPE:
|
vdatum_mesh_to_msl_m
|
Vertical offset in meters added to the simulated water level
before comparison with NOAA CO-OPS observations (which are in
MSL). The model output inherits the mesh vertical datum, so
this converts it to MSL (e.g. Defaults to
TYPE:
|
sfincs_exe
|
Path to a compiled SFINCS executable. When set, the
TYPE:
|
omp_num_threads
|
Number of OpenMP threads. Defaults to the number of physical CPU
cores on the current machine (see :func:
TYPE:
|
inp_overrides
|
Arbitrary key/value pairs written to
TYPE:
|
MonitoringConfig#
MonitoringConfig
dataclass
#
MonitoringConfig(
log_level="INFO",
log_file=None,
enable_progress_tracking=True,
enable_timing=True,
)
Workflow monitoring configuration.
DownloadConfig#
DownloadConfig
dataclass
#
Data download configuration.
SFINCS Creation Configuration#
SfincsCreateConfig#
SfincsCreateConfig
dataclass
#
SfincsCreateConfig(
aoi,
output_dir,
download_dir=None,
grid=GridConfig(),
elevation=ElevationConfig(),
mask=MaskConfig(),
subgrid=SubgridConfig(),
data_catalog=DataCatalogConfig(),
monitoring=MonitoringConfig(),
river_discharge=None,
add_noaa_gages=False,
observation_points=list(),
observation_locations_file=None,
merge_observations=False,
)
Root configuration for SFINCS model creation workflow.
Loaded from YAML via :meth:from_yaml. All paths are resolved to
absolute paths during construction.
stage_order
property
#
Ordered list of creation stages to execute.
Roughness is embedded in the quadtree subgrid tables, so there
is no separate roughness stage. The create_discharge stage
is included only when :attr:river_discharge is configured.
from_yaml
classmethod
#
Load configuration from a YAML file.
| PARAMETER | DESCRIPTION |
|---|---|
config_path
|
Path to YAML configuration file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SfincsCreateConfig
|
Loaded configuration. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the configuration file does not exist. |
YAMLError
|
If the YAML file is malformed. |
Source code in src/coastal_calibration/config/create_schema.py
from_dict
classmethod
#
Create config from a plain dictionary.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Configuration dictionary with the same structure as the YAML
file (see :meth:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SfincsCreateConfig
|
|
Source code in src/coastal_calibration/config/create_schema.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
to_yaml
#
Write configuration to a YAML file.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to YAML output file. Parent directories are created automatically.
TYPE:
|
Source code in src/coastal_calibration/config/create_schema.py
to_dict
#
Convert configuration to a plain dictionary.
Source code in src/coastal_calibration/config/create_schema.py
validate
#
Validate configuration and return a list of error messages.
| RETURNS | DESCRIPTION |
|---|---|
list of str
|
Validation errors (empty when the config is valid). |
Source code in src/coastal_calibration/config/create_schema.py
GridConfig#
GridConfig
dataclass
#
Grid generation configuration.
ElevationConfig#
ElevationConfig
dataclass
#
ElevationConfig(
datasets=(
lambda: [
ElevationDataset(
name="copdem_30m",
zmin=0.001,
source="copdem_30m",
),
ElevationDataset(
name="gebco_15arcs",
zmin=-20000,
source="gebco_15arcs",
),
]
)(),
buffer_cells=1,
)
Elevation and bathymetry configuration.
MaskConfig#
MaskConfig
dataclass
#
Active-cell mask and boundary configuration.
SubgridConfig#
SubgridConfig
dataclass
#
SubgridConfig(
nr_subgrid_pixels=5,
lulc_dataset="esa_worldcover",
lulc_source="esa_worldcover",
reclass_table=None,
manning_land=0.04,
manning_sea=0.02,
)
Subgrid table configuration.
Roughness parameters are included here because for quadtree grids the Manning coefficients are embedded directly in the subgrid tables.
RiverDischargeConfig#
RiverDischargeConfig
dataclass
#
River discharge source point configuration.
Derives discharge source points from user-provided flowline geometries (e.g. exported from the QGIS plugin). Each flowline's downstream endpoint (closest to the AOI boundary) is registered as a SFINCS discharge source location.
Workflow Runners#
CoastalCalibRunner#
CoastalCalibRunner
#
Main workflow runner for coastal model calibration.
This class orchestrates the entire calibration workflow, managing stage execution and progress monitoring.
Supports both SCHISM (model="schism", default) and SFINCS
(model="sfincs") pipelines. The model type is selected via
config.model.
Initialize the workflow runner.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
Coastal calibration configuration.
TYPE:
|
Source code in src/coastal_calibration/runner.py
validate
#
Validate configuration and prerequisites.
| RETURNS | DESCRIPTION |
|---|---|
list of str
|
List of validation error messages (empty if valid). |
Source code in src/coastal_calibration/runner.py
run
#
Execute the calibration workflow.
| PARAMETER | DESCRIPTION |
|---|---|
start_from
|
Stage name to start from (skip earlier stages).
TYPE:
|
stop_after
|
Stage name to stop after (skip later stages).
TYPE:
|
dry_run
|
If True, validate but don't execute.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
WorkflowResult
|
Result with execution details. |
Source code in src/coastal_calibration/runner.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
SfincsCreator#
SfincsCreator
#
Runner that orchestrates the SFINCS model creation pipeline.
Mirrors :class:~coastal_calibration.runner.CoastalCalibRunner but
operates on a :class:SfincsCreateConfig and delegates to
:class:~coastal_calibration.sfincs.create.CreateStage instances.
Source code in src/coastal_calibration/sfincs/create.py
run
#
Execute the SFINCS model creation workflow.
| PARAMETER | DESCRIPTION |
|---|---|
start_from
|
Stage name to start from (skip earlier stages).
TYPE:
|
stop_after
|
Stage name to stop after (skip later stages).
TYPE:
|
dry_run
|
If True, validate but don't execute.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
WorkflowResult
|
Result with execution details. |
Source code in src/coastal_calibration/sfincs/create.py
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 | |
WorkflowResult#
WorkflowResult
dataclass
#
WorkflowResult(
success,
job_id,
start_time,
end_time,
stages_completed,
stages_failed,
outputs,
errors,
)
Result of a workflow execution.
to_dict
#
Convert to dictionary.
Source code in src/coastal_calibration/runner.py
save
#
Save result to JSON file.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to output JSON file. Parent directories will be created if they don't exist.
TYPE:
|
Source code in src/coastal_calibration/runner.py
Plotting#
SfincsGridInfo#
SfincsGridInfo
dataclass
#
SfincsGridInfo(
grid_type,
crs,
base_resolution,
levels,
n_faces=None,
n_edges=None,
shape=None,
_verts=None,
_level_per_face=None,
_mask=None,
_grid_extent=None,
)
Summary of a SFINCS model grid.
Use :meth:from_model_root to construct from a SFINCS model
directory. The instance carries enough pre-computed state to
drive :func:plot_mesh without re-loading the model.
Examples:
>>> info = SfincsGridInfo.from_model_root("run/sfincs_model")
>>> print(info)
SfincsGridInfo(quadtree, EPSG:32619)
Faces: 293,850
Edges: 596,123
Level 1: 7,090 cells (512 m)
...
from_model_root
classmethod
#
Load grid metadata from a SFINCS model directory.
| PARAMETER | DESCRIPTION |
|---|---|
model_root
|
Path to the SFINCS model directory (must contain
TYPE:
|
Source code in src/coastal_calibration/sfincs/plotting.py
plot_mesh#
plot_mesh
#
plot_mesh(
info,
*,
ax=None,
title=None,
basemap=True,
basemap_source=None,
basemap_zoom=11,
figsize=(11, 7),
)
Plot the SFINCS mesh colored by refinement level.
| PARAMETER | DESCRIPTION |
|---|---|
info
|
Grid metadata from :meth:
TYPE:
|
ax
|
Existing axes to plot into. A new figure is created when None.
TYPE:
|
title
|
Plot title. Defaults to a description derived from info.
TYPE:
|
basemap
|
If True (default), overlay satellite imagery via contextily.
TYPE:
|
basemap_source
|
Tile provider passed to
TYPE:
|
basemap_zoom
|
Zoom level for the basemap tiles.
TYPE:
|
figsize
|
Figure size when ax is None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
(Figure, Axes)
|
|
Source code in src/coastal_calibration/sfincs/plotting.py
plot_floodmap#
plot_floodmap
#
plot_floodmap(
floodmap_path,
*,
ax=None,
title=None,
basemap=True,
basemap_source=None,
basemap_zoom=12,
max_display_px=2000,
vmax_percentile=98,
figsize=(11, 7),
color_map="viridis_r",
)
Plot a flood-depth COG with an optional satellite basemap.
Reads at an overview level that keeps the longest axis under max_display_px pixels, masks dry / NaN pixels, and renders with a reverse viridis color map.
| PARAMETER | DESCRIPTION |
|---|---|
floodmap_path
|
Path to the flood-depth GeoTIFF (e.g.
TYPE:
|
ax
|
Existing axes to plot into. A new figure is created when None.
TYPE:
|
title
|
Plot title. Defaults to
TYPE:
|
basemap
|
If True (default), overlay satellite imagery via contextily.
TYPE:
|
basemap_source
|
Tile provider passed to
TYPE:
|
basemap_zoom
|
Zoom level for the basemap tiles, by default 12.
TYPE:
|
max_display_px
|
Target maximum dimension (in pixels) for the rendered raster. Controls which overview level is read, by default 2000.
TYPE:
|
vmax_percentile
|
Upper percentile for the color-map range.
TYPE:
|
figsize
|
Figure size when ax is None, by default (11, 7).
TYPE:
|
color_map
|
Name of the Matplotlib colormap to use for plotting the flood depth, by default "viridis_r".
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
(Figure, Axes)
|
|
Source code in src/coastal_calibration/sfincs/plotting.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
plot_station_comparison#
plot_station_comparison
#
Create comparison figures of simulated vs observed water levels.
Stations that lack either valid observations or valid simulated data are skipped so that empty panels do not appear.
| PARAMETER | DESCRIPTION |
|---|---|
sim_times
|
Simulation datetimes.
TYPE:
|
sim_elevation
|
Simulated elevation of shape
TYPE:
|
station_ids
|
NOAA station IDs (one per column in sim_elevation).
TYPE:
|
obs_ds
|
Observed water levels with a
TYPE:
|
figs_dir
|
Output directory for figures.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Path]
|
Paths to the saved figures. |
Source code in src/coastal_calibration/plotting/stations.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
plotable_stations#
plotable_stations
#
Return (station_id, column_index) pairs that have data to plot.
A station is plotable only when both its simulated and observed time-series contain finite values — a comparison plot with only one series is not useful.
The returned list is sorted by numeric station ID so that figures are deterministic across runs.
Source code in src/coastal_calibration/plotting/stations.py
Flood Depth Map#
create_flood_depth_map#
create_flood_depth_map
#
create_flood_depth_map(
model_root,
dem_path,
output_path=None,
*,
index_path=None,
create_index=True,
hmin=0.05,
reproj_method="nearest",
nrmax=2000,
model=None,
log=None,
)
Create a downscaled flood depth map from SFINCS output.
Reads the maximum water surface elevation (zsmax) from the SFINCS
map output, optionally builds an index COG that maps DEM pixels to
SFINCS grid cells, then downscales onto a high-resolution DEM to
produce a Cloud Optimized GeoTIFF of maximum flood depth.
| PARAMETER | DESCRIPTION |
|---|---|
model_root
|
Path to the SFINCS model directory (must contain
TYPE:
|
dem_path
|
Path to a high-resolution DEM GeoTIFF covering the model domain.
TYPE:
|
output_path
|
Output flood depth COG path. Defaults to
TYPE:
|
index_path
|
Path for the index COG (DEM pixels -> SFINCS cell mapping).
Defaults to
TYPE:
|
create_index
|
If True (default), (re)generate the index COG via
:func:
TYPE:
|
hmin
|
Minimum flood depth (m) to classify a pixel as flooded.
TYPE:
|
reproj_method
|
Reprojection method (
TYPE:
|
nrmax
|
Maximum cells per processing block (controls peak memory).
TYPE:
|
model
|
An already-loaded :class:
TYPE:
|
log
|
Logging callback accepting a single message; falls back to the module logger when None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
Path to the generated flood depth COG. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the DEM or |
KeyError
|
If |
Source code in src/coastal_calibration/sfincs/floodmap.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
Downloader#
validate_date_ranges#
validate_date_ranges
#
Validate that requested dates are within available ranges.
Source code in src/coastal_calibration/data/downloader.py
NOAA CO-OPS API#
COOPSAPIClient#
COOPSAPIClient
#
Client for interacting with NOAA CO-OPS API.
Initialize COOPS API client.
| PARAMETER | DESCRIPTION |
|---|---|
timeout
|
Request timeout in seconds, by default 120
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ImportError
|
If plot optional dependencies are not installed. |
Source code in src/coastal_calibration/data/coops_api.py
stations_metadata
property
#
Get metadata for all water level stations as a GeoDataFrame.
| RETURNS | DESCRIPTION |
|---|---|
GeoDataFrame
|
GeoDataFrame with station metadata and Point geometries. |
validate_parameters
#
Validate API parameters.
| PARAMETER | DESCRIPTION |
|---|---|
product
|
Data product type
TYPE:
|
datum
|
Vertical datum
TYPE:
|
units
|
Unit system
TYPE:
|
time_zone
|
Time zone
TYPE:
|
interval
|
Time interval for predictions
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If any parameter is invalid |
Source code in src/coastal_calibration/data/coops_api.py
build_url
#
Build API request URL for a station.
| PARAMETER | DESCRIPTION |
|---|---|
station_id
|
Station ID
TYPE:
|
begin_date
|
Start date
TYPE:
|
end_date
|
End date
TYPE:
|
product
|
Data product
TYPE:
|
datum
|
Vertical datum
TYPE:
|
units
|
Unit system
TYPE:
|
time_zone
|
Time zone
TYPE:
|
interval
|
Time interval for predictions
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Complete API request URL |
Source code in src/coastal_calibration/data/coops_api.py
fetch_data
#
Fetch data from API for multiple URLs.
| PARAMETER | DESCRIPTION |
|---|---|
urls
|
List of API request URLs
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[dict | None]
|
List of JSON responses (None for failed requests) |
Source code in src/coastal_calibration/data/coops_api.py
get_datums
#
Retrieve datum information for one or more stations.
| PARAMETER | DESCRIPTION |
|---|---|
station_ids
|
Single station ID or list of station IDs
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StationDatum | list[StationDatum]
|
Single StationDatum object if input is str, list of StationDatum if input is list |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If no valid datum data is returned for any station. |
Source code in src/coastal_calibration/data/coops_api.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
query_coops_byids#
query_coops_byids
#
query_coops_byids(
station_ids,
begin_date,
end_date,
*,
product="water_level",
datum="MLLW",
units="metric",
time_zone="gmt",
interval=None,
)
Fetch water level data from NOAA CO-OPS API for multiple stations.
| PARAMETER | DESCRIPTION |
|---|---|
station_ids
|
List of station IDs to retrieve data for.
TYPE:
|
begin_date
|
Start date in format: yyyyMMdd, yyyyMMdd HH:mm, MM/dd/yyyy, or MM/dd/yyyy HH:mm
TYPE:
|
end_date
|
End date in same format as begin_date.
TYPE:
|
product
|
Data product to retrieve, by default
TYPE:
|
datum
|
Vertical datum for water levels, by default "MLLW".
TYPE:
|
units
|
Units for data, by default "metric".
TYPE:
|
time_zone
|
Time zone for returned data, by default "gmt".
TYPE:
|
interval
|
Time interval for predictions product only, by default None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dataset
|
Dataset containing water level data with dimensions (time, station). |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If invalid parameters are provided or if API returns errors. |
Source code in src/coastal_calibration/data/coops_api.py
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 | |
query_coops_bygeometry#
query_coops_bygeometry
#
query_coops_bygeometry(
geometry,
begin_date,
end_date,
*,
product="water_level",
datum="MLLW",
units="metric",
time_zone="gmt",
interval=None,
)
Fetch water level data from NOAA CO-OPS API for stations within a geometry.
| PARAMETER | DESCRIPTION |
|---|---|
geometry
|
Geometry to select stations within (Point, Polygon, etc.)
TYPE:
|
begin_date
|
Start date in format: yyyyMMdd, yyyyMMdd HH:mm, MM/dd/yyyy, or MM/dd/yyyy HH:mm
TYPE:
|
end_date
|
End date in same format as begin_date.
TYPE:
|
product
|
Data product to retrieve, by default
TYPE:
|
datum
|
Vertical datum for water levels, by default "MLLW".
TYPE:
|
units
|
Units for data, by default "metric".
TYPE:
|
time_zone
|
Time zone for returned data, by default "gmt".
TYPE:
|
interval
|
Time interval for predictions product only, by default None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dataset
|
Dataset containing water level data for stations within the geometry. |
Source code in src/coastal_calibration/data/coops_api.py
Type Aliases#
# Model type
ModelType = Literal["schism", "sfincs"]
# Meteorological data source
MeteoSource = Literal["nwm_retro", "nwm_ana"]
# Coastal domain identifier
CoastalDomain = Literal["prvi", "hawaii", "atlgulf", "pacific"]
# Boundary condition source
BoundarySource = Literal["tpxo", "stofs"]
# Logging level
LogLevel = Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
Constants#
Default Paths#
Default Path Templates#
DEFAULT_WORK_DIR_TEMPLATE = (
"/ngen-test/coastal/${user}/"
"${model}_${simulation.coastal_domain}_${boundary.source}_${simulation.meteo_source}/"
"${model}_${simulation.start_date}"
)
DEFAULT_RAW_DOWNLOAD_DIR_TEMPLATE = (
"/ngen-test/coastal/${user}/"
"${model}_${simulation.coastal_domain}_${boundary.source}_${simulation.meteo_source}/"
"raw_data"
)