API Reference#
This page provides detailed documentation for the NWM Coastal Python API.
Configuration Classes#
CoastalCalibConfig#
CoastalCalibConfig
dataclass
#
CoastalCalibConfig(
slurm,
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.:
${slurm.user}-> value ofslurm.user${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
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 1103 1104 1105 1106 1107 1108 1109 1110 | |
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
SlurmConfig#
SlurmConfig
dataclass
#
SlurmConfig(
job_name="coastal_calibration",
partition=DEFAULT_SLURM_PARTITION,
time_limit=None,
account=None,
qos=None,
user=(lambda: get("USER"))(),
)
SLURM job scheduling configuration.
Contains only parameters related to job scheduling (partition, account,
time limits). Compute resources (nodes, tasks) are model-specific and
live on the concrete :class:ModelConfig subclasses.
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,
nfs_mount=(lambda: DEFAULT_NFS_MOUNT)(),
nwm_dir=(lambda: DEFAULT_NWM_DIR)(),
hot_start_file=None,
conda_env_name=DEFAULT_CONDA_ENV_NAME,
parm_dir=(lambda: DEFAULT_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.
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 have been populated.
Source code in src/coastal_calibration/config/schema.py
validate
abstractmethod
#
create_stages
abstractmethod
#
generate_job_script_lines
abstractmethod
#
Return #SBATCH directives specific to this model's compute needs.
SchismModelConfig#
SchismModelConfig
dataclass
#
SchismModelConfig(
singularity_image=(lambda: DEFAULT_SING_IMAGE_PATH)(),
nodes=2,
ntasks_per_node=18,
exclusive=True,
nscribes=2,
omp_num_threads=2,
oversubscribe=False,
binary=_DEFAULT_SCHISM_BINARY,
include_noaa_gages=False,
)
Bases: ModelConfig
SCHISM model configuration.
Contains compute parameters (MPI layout, SCHISM binary) that were
previously split across MPIConfig and SlurmConfig.
| PARAMETER | DESCRIPTION |
|---|---|
singularity_image
|
Path to the Singularity/Apptainer SIF image used to run
SCHISM and its pre-/post-processing scripts inside a
container. SFINCS manages its own container independently
(see :attr:
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:
|
binary
|
SCHISM executable name.
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:
|
schism_mesh
#
SCHISM ESMF mesh file path for the given domain.
SfincsModelConfig#
SfincsModelConfig
dataclass
#
SfincsModelConfig(
prebuilt_dir,
model_root=None,
include_noaa_gages=False,
observation_points=list(),
observation_locations_file=None,
merge_observations=False,
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,
container_tag="latest",
container_image=None,
omp_num_threads=0,
)
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:
|
include_noaa_gages
|
When True, automatically query NOAA CO-OPS for water level
stations within the model domain and add them as observation
points. Requires the
TYPE:
|
observation_points
|
Observation point specifications as list of dicts with
TYPE:
|
observation_locations_file
|
Path to a GeoJSON file with observation point locations.
TYPE:
|
merge_observations
|
Whether to merge with pre-existing observation points.
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 metres added to the boundary-condition water levels before they enter SFINCS. Tidal-only sources such as TPXO provide oscillations centred 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 metres 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 locally compiled SFINCS executable. When set, the
TYPE:
|
container_tag
|
Tag for the
TYPE:
|
container_image
|
Path to a pre-pulled Singularity SIF file.
TYPE:
|
omp_num_threads
|
Number of OpenMP threads. Defaults to the number of physical CPU
cores on the current machine (see :func:
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.
Workflow Runner#
CoastalCalibRunner#
CoastalCalibRunner
#
Main workflow runner for coastal model calibration.
This class orchestrates the entire calibration workflow, managing stage execution, SLURM job submission, 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
submit
#
Submit workflow as a SLURM job.
Executes the same stage pipeline as :meth:run, but Python-only
stages run on the login node while container stages are bundled
into a SLURM bash script and submitted as a job.
| PARAMETER | DESCRIPTION |
|---|---|
wait
|
If True, wait for job completion (interactive mode). If False, return immediately after job submission.
TYPE:
|
log_file
|
Custom path for SLURM output log. If not provided, logs are
written to
TYPE:
|
start_from
|
Stage name to start from (skip earlier stages).
TYPE:
|
stop_after
|
Stage name to stop after (skip later stages).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
WorkflowResult
|
Result with job submission details. |
Source code in src/coastal_calibration/runner.py
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 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 1311 | |
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
222 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 | |
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
Downloader#
validate_date_ranges#
validate_date_ranges
#
Validate that requested dates are within available ranges.
Source code in src/coastal_calibration/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/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/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/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/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/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 471 | |
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/coops_api.py
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 849 | |
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/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_SING_IMAGE_PATH = Path("/ngencerf-app/singularity/ngen-coastal.sif")
DEFAULT_PARM_DIR = Path("/ngen-test/coastal/ngwpc-coastal")
DEFAULT_NFS_MOUNT = Path("/ngen-test")
DEFAULT_CONDA_ENV_NAME = "ngen_forcing_coastal"
DEFAULT_NWM_DIR = Path("/ngen-app/nwm.v3.0.6")
DEFAULT_OTPS_DIR = Path("/ngen-app/OTPSnc")
DEFAULT_SLURM_PARTITION = "c5n-18xlarge"
Default Path Templates#
DEFAULT_WORK_DIR_TEMPLATE = (
"/ngen-test/coastal/${slurm.user}/"
"${model}_${simulation.coastal_domain}_${boundary.source}_${simulation.meteo_source}/"
"${model}_${simulation.start_date}"
)
DEFAULT_RAW_DOWNLOAD_DIR_TEMPLATE = (
"/ngen-test/coastal/${slurm.user}/"
"${model}_${simulation.coastal_domain}_${boundary.source}_${simulation.meteo_source}/"
"raw_data"
)