Python Reference#
The pyproject.toml of this repository primarily contains requirements for building documentation. The build sequence of the nwm-rte image is dynamic/configurable and involves multiple Python virtual environments.
CLI Help Menus#
These are raw outputs of the --help menu generated by Python's argparse library.
To update these, run: ./docs/update_python_cli_ref.sh
CLI Executable Modules#
run_default.py#
Called by run_default.sh
ngen_rte.run_default
#
Command-line executable to build and run a "default" realization. Supports realtime forcing configurations, e.g. "short_range", as well as historical/retrospective sources, e.g. "aorc".
This runs inside the ngen runtime environment.
The CLI structure is mimicked in part by configs.RTEDefaultConfig.
For settings that are not exposed by CLI arguments, see primarily consts.py.
See run_default.sh for example calls.
run_default
#
Run the provided default realization. Realization should already be built (rb.build_default_realization() already called).
Source code in bin_mounted/ngen_rte/run_default.py
cli_arg_parser
#
Build and return the CLI argument parser
Source code in bin_mounted/ngen_rte/run_default.py
run_calibration.py#
Called by run_calib.sh
ngen_rte.run_calibration
#
Command-line executable to build and run a "calibration" realization.
This runs inside the ngen runtime environment.
The CLI structure is mimicked in part by configs.RTECalibConfig.
For settings that are not exposed by CLI arguments, see primarily consts.py.
See run_calib.sh for example calls.
get_calibration_cmd
#
Get the command to run the calibration realization.
Source code in bin_mounted/ngen_rte/run_calibration.py
cli_arg_parser
#
Build and return the CLI argument parser
Source code in bin_mounted/ngen_rte/run_calibration.py
run_forecast.py#
Called by run_fcst.sh
ngen_rte.run_forecast
#
Command-line executable to build and run a "forecast" realization, optionally with a coldstart.
This runs inside the ngen runtime environment.
The CLI structure is mimicked in part by configs.RTEForecastConfig.
For settings that are not exposed by CLI arguments, see primarily consts.py.
See run_fcst.sh for example calls.
run_realization
#
Run the realization, which can be a coldstart, forecast, or lagged ensemble.
Source code in bin_mounted/ngen_rte/run_forecast.py
cli_arg_parser
#
Build and return the CLI argument parser
Source code in bin_mounted/ngen_rte/run_forecast.py
run_restart.py#
Called by run_default.sh
ngen_rte.run_restart
#
Command-line executable to restart a failed run from a saved checkpoint. Currently only functional for default and regionalization runs. Calls msw-mgr chcekpoint_restart to copy and configure the run, then infers the ngen command from the destination directory. A run can only be restarted if the original run was configured to save checkpoints using the --checkpoint_interval argument.
infer_gage_id
#
infer_rb
#
Infer and return a minimal RealizationBuilder from the destination directory structure
Source code in bin_mounted/ngen_rte/run_restart.py
run_restart
#
Run the provided checkpoint restart realization.
Source code in bin_mounted/ngen_rte/run_restart.py
run_tests.py#
Called by run_tests.sh
ngen_rte.tests.run_tests
#
Command-line executable to build and run a series of "forecast" realizations, optionally with a "calibration" realization preceding them.
This runs inside the ngen runtime environment.
The CLI structure is mimicked in part by configs.RTETestConfig.
For settings that are not exposed by CLI arguments, see primarily consts.py.
When realizations fail, this program does not halt, but rather moves to the next configuration type in the list, with the goal of "trying" many different realization configurations in one call. The status of each configuration's build step and run step is reported and written to a json file at the end.
This includes options for stopping realizations mid-way through their run, rather than waiting for them to complete.
See run_tests.sh for example calls.
calibrations__build_and_run
#
calibrations__build_and_run(
cfg: RTETestConfig, tm: TestsManager
) -> None
Build calibration realizations and run them as tests.
Source code in bin_mounted/ngen_rte/tests/run_tests.py
forecasts__build_and_run
#
forecasts__build_and_run(
cfg: RTETestConfig, tm: TestsManager, cs: bool
) -> None
Using ForecastTest, build and execute a list of forecast realizations.
tests_manager is modified in-place, so some test results may be available if this function is interrupted.
cs controls whether coldstart is used (not cfg.do_coldstart).
Source code in bin_mounted/ngen_rte/tests/run_tests.py
run_noop_mode
#
Run noop mode - verify imports and basic setup without executing workflows.
Source code in bin_mounted/ngen_rte/tests/run_tests.py
cli_arg_parser
#
Build and return the CLI argument parser
Source code in bin_mounted/ngen_rte/tests/run_tests.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 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 | |
Python Constants#
Currently bin_mounted/consts.py contains variables which rarely need editing.
ngen_rte.consts
#
Constants
FORCING_TEMPLATE_DIR
module-attribute
#
FORCING_TEMPLATE_DIR = "/ngen-app/ngen-python/lib/python3.11/site-packages/NextGen_Forcings_Engine_BMI/BMI_NextGen_Configs/config_templates/"
Directory of forcing configuration template yaml files.
Configuration Classes#
These mimic the CLI interfaces and perform some additional argument parsing and preparation of classes that are passed to other components of the system.
ngen_rte.configs
#
Primary configuration classes. Pydantic BaseModels directly associated with CLI executables.
RTEBaseConfig
#
Bases: BaseModelStrict
Base RTE configuration class to be inherited by child classes. Triggers certain setup actions, such as creation of WCOSS-path symlinks. Classes that inherit from this should call super().model_post_init(__context) inside their own model_post_init() method, if they have that method also defined in the child.
The primary usage of this class is to access property mswm_RealizationBuilder_kwargs for building (and later running) a realization using MSWM.
| ATTRIBUTE | DESCRIPTION |
|---|---|
delete_scratch_and_mesh_first |
Causes scratch dir and intermediate mesh file to be deleted before building the realization. Use with caution.
TYPE:
|
delete_forcing_raw_input_first |
Causes forcing raw input dir to be deleted before building the realization. Use with caution.
TYPE:
|
environment |
Operating environment, e.g. 'test' or 'oe'.
TYPE:
|
nprocs |
Number of processors to use for ngen execution.
TYPE:
|
global_domain |
Global domain, e.g. "CONUS" or "Hawaii". Must agree with the ID of the basin / gage / VPU being simulated.
TYPE:
|
forcing_static_dir |
Directory for static forcing data.
TYPE:
|
basin |
Basin identifier. Can be either Gage ID or VPU identifier.
TYPE:
|
gage_id |
Gage ID. When provided, sets subset_type to 'gage'.
TYPE:
|
vpu |
VPU identifier. When provided, sets subset_type to 'vpu'.
TYPE:
|
subset_type |
Type of basin identifier. Accepts 'gage' or 'vpu'.
TYPE:
|
model_formulation_cli_csv |
Comma-separated string of model names comprising the formulation.
TYPE:
|
model_formulation_cli_rootzone |
Boolean for model formulation rootzone parameter.
TYPE:
|
add_timestamp_to_run_name |
Boolean causing the final forecast run name to contain a timestamp suffix.
TYPE:
|
nwm_output_vars |
Boolean causing NWM output variables to be included in the output. Passed to MSWM NWMOutputConfig. Does not apply to calibration workflow.
TYPE:
|
output_format |
Output format(s) for output variables. Accepts 'CSV', 'NetCDF', or both. Defaults to ["CSV"] in MSWM.
TYPE:
|
hydrofab_file |
Optional hydrofabric file path. If provided, bypasses MSWM Icefabric server API call.
TYPE:
|
fcst_run_name |
Forecast run name.
TYPE:
|
cycle_datetime |
Cycle datetime for forecast
TYPE:
|
checkpoint_interval |
Integer number of timesteps for interval of checkpoint output
TYPE:
|
checkpoint_dir |
Optional directory to save checkpoint states. Defaults to work_dir>/checkpoint/ in msw-mgr.
TYPE:
|
load_state_from |
Path to existing state file to load at start of run
TYPE:
|
save_state |
Boolean to activate state save at end of run
TYPE:
|
save_state_directory |
Optional directory to save model state at end of run. Defaults in
TYPE:
|
lookback |
Optional override of the forcing template
TYPE:
|
Source code in bin_mounted/ngen_rte/configs.py
43 44 45 46 47 48 49 50 51 52 53 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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 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 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 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 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 | |
time_at_init
class-attribute
instance-attribute
#
Time at class instantiation.
errors
class-attribute
instance-attribute
#
List of exceptions encountered during init.
subset_type
class-attribute
instance-attribute
#
Subset_type set depending on vpu and gage_id args
basin
class-attribute
instance-attribute
#
Basin id set depending on vpu and gage_id args
use_lagged_ensemble
class-attribute
instance-attribute
#
Boolean indicating that lagged ensemble is to be used. Passed to MSWM.
lagged_ens_mem
class-attribute
instance-attribute
#
Lagged ensemble member name. Passed to MSWM.
forcing_lag
class-attribute
instance-attribute
#
Lagged ensemble forcing lag. Looked up based on lagged ensemble member name. Passed to MSWM.
le__open_loop_state
class-attribute
instance-attribute
#
File path for lagged ensemble open loop state.
le__closed_loop_state
class-attribute
instance-attribute
#
File path for lagged ensemble closed loop state.
realtime_mode
property
#
Realtime mode boolean, leveraged by default realization which can run both realtime and historical/retrospective configurations.
forcing_provider_paths
property
#
Helper class for managing forcing provider paths.
start_period__end_period
property
#
Tuple of start period and end period for calibration and default realizations.
model_formulation
property
#
Model formulation helper class for MSWM models list and rootzone parameter.
mswm_ModulePropertiesConfig
property
#
MSWM ModulePropertiesConfig instance
mswm_RegionalizationConfig
property
#
MSWM RegionalizationConfig instance
mswm_ForcingConfig
property
#
MSWM ForcingConfig instance. Contains dynamic logic for handling different types of child classes of RTEBaseConfig.
mswm_InputConfig
property
#
MSWM InputConfig instance. This is the composite MSWM class that contains the other sub-config classes.
mswm_RealizationBuilder_kwargs
property
#
Full set of kwargs that are passed to MSWM RealizationBuilder's constructor for bulding a realization.
valid_best_yaml
property
#
Validation yaml file (output from previously-ran calibration realization)
configure_ngen_log
#
Configure the ngen logging, by setting the associated OS env variable for the directory to hold the logs, and copying the associated json file into that directory.
fallback_log_dir is ignored when the RTE OS env var key NGEN_LOG_TO_RTE is true.
It is used to emulate behavior of nwm-cal-mgr and nwm-fcst-mgr (what they would use without RTE).
| PARAMETER | DESCRIPTION |
|---|---|
rb
|
An already built realization.
TYPE:
|
Source code in bin_mounted/ngen_rte/configs.py
RTEDefaultConfig
#
Bases: RTEBaseConfig
Configuration class for building and running one default realization (realtime forcing configuration or historical / retrospective forcing configuration).
| ATTRIBUTE | DESCRIPTION |
|---|---|
cycle_datetime |
Start time of the realization
TYPE:
|
duration |
Duration of the simulation (only used for historical / retrospective forcing configurations)
TYPE:
|
forcing_configuration |
Forcing configuration, e.g. "aorc" or "short_range"
TYPE:
|
fcst_run_name |
Name of the forecast realization run. Affects a directory name.
TYPE:
|
lagged_ensemble_args |
See CLI help menu for
TYPE:
|
Source code in bin_mounted/ngen_rte/configs.py
RTERegionConfig
#
Bases: RTEBaseConfig
Configuration class for building and running one regionalization realization (realtime forcing configuration or historical / retrospective forcing configuration).
| ATTRIBUTE | DESCRIPTION |
|---|---|
cycle_datetime |
Start time of the realization
TYPE:
|
duration |
Duration of the simulation (only used for historical / retrospective forcing configurations)
TYPE:
|
forcing_configuration |
Forcing configuration, e.g. "aorc" or "short_range"
TYPE:
|
fcst_run_name |
Name of the forecast realization run. Affects a directory name.
TYPE:
|
lagged_ensemble_args |
See CLI help menu for
TYPE:
|
form_assign_file |
File containing formulation assignments for catchments
TYPE:
|
cat_grp_file |
File containing catchment groupings for regionalization
TYPE:
|
Source code in bin_mounted/ngen_rte/configs.py
RTECalibConfig
#
Bases: RTEBaseConfig
Configuration class for building and running one calibration realization.
| ATTRIBUTE | DESCRIPTION |
|---|---|
objective_function |
Objective function, e.g. "kge"
TYPE:
|
optimization_algorithm |
Optimization algorithm, e.g. "dds"
TYPE:
|
calib_sim_start |
Calibration start time
TYPE:
|
duration |
Calibration simulation duration
TYPE:
|
calib_eval_delayment |
Used for evaluation / validation time windowing
TYPE:
|
valid_sim_advancement |
Used for evaluation / validation time windowing
TYPE:
|
valid_eval_curtailment |
Used for evaluation / validation time windowing
TYPE:
|
forcing_configuration |
Source of forcing data, e.g. "aorc" or "nwm"
TYPE:
|
worker_name |
Name of the ngen worker (used to build a directory name)
TYPE:
|
Source code in bin_mounted/ngen_rte/configs.py
RTEForecastConfig
#
Bases: RTEBaseConfig
Configuration class for building and running one forecast realization.
| ATTRIBUTE | DESCRIPTION |
|---|---|
objective_function |
Affects input realization path. Objective function of previously-ran calibration realization, e.g. "kge"
TYPE:
|
optimization_algorithm |
Affects input realization path. Optimization algorithm of previously-ran calibration realization, e.g. "dds"
TYPE:
|
cycle_datetime |
Start time of the realization (or end time for coldstart, if
TYPE:
|
cold_start_datetime |
Start time of the coldstart realization. If None, coldstart is not performed.
TYPE:
|
forcing_configuration |
Forcing configuration, e.g. "aorc" or "short_range"
TYPE:
|
fcst_run_name |
Name of the forecast realization run
TYPE:
|
lagged_ensemble_args |
See CLI help menu for
TYPE:
|
Source code in bin_mounted/ngen_rte/configs.py
RTEAsyncConfig
#
Bases: RTEBaseConfig
Minimal configuration class for run using NgenRunnerAsync Set RTEBaseConfigs variables to defaults, not used by NgenRunnerAsync
Source code in bin_mounted/ngen_rte/configs.py
RTETestConfig
#
Bases: RTEBaseConfig
Configuration class for building and running a set of test realizations.
| ATTRIBUTE | DESCRIPTION |
|---|---|
skip_forecast |
Causes forecast to be skipped (only do calibration)
TYPE:
|
quit_forecast_after_duration |
Causes forecasts to be stopped midway after a set duration (seconds of processing time)
TYPE:
|
do_calibration |
Causes calibration to be ran, before forecasts (needed if a calibration has not yet been ran for the gage)
TYPE:
|
quit_calibration_after_duration |
Causes calibrations to be stopped midway after a set duration (seconds of processing time)
TYPE:
|
objective_functions |
For calibration, list of objective functions to run, e.g. "kge". Replaced with full list when do_all_objective_functions = True
TYPE:
|
do_all_objective_functions |
For calibration, causes all objective functions to be used.
TYPE:
|
optimization_algorithms |
For calibration, list of optimization algorithms to run, e.g. "dds". Replaced with full list when do_all_optimization_algorithms = True
TYPE:
|
model_formulations_file |
File containing model formulations to iterate over
TYPE:
|
calibration_forcing_sources |
Calibration forcing configurations, e.g. "aorc" "nwm"
TYPE:
|
do_all_optimization_algorithms |
For calibration, causes all optimization algorithms to be used.
TYPE:
|
do_all_forcing_configs |
Causes all forcing configurations to be used, e.g. "short_range", "standard_ana", "medium_range_blend", "extended_ana", "short_range_hawaii", etc.
TYPE:
|
do_coldstart |
Causes coldstart to be ran before forecast.
TYPE:
|
fcst_run_name |
Name of the forecast realization run. Affects a directory name.
TYPE:
|
noop |
Causes a noop to occur (for confirming that Python packages are importable).
TYPE:
|
restart |
Causes the test to be restarted by reading the existing c.TEST_RESULTS_FILE and skipping configurations which had completed earlier. Can be used when long-running tests are interrupted. Use with caution.
TYPE:
|
Source code in bin_mounted/ngen_rte/configs.py
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 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 | |
get_calib_permutations
#
Returns the permutations of objective function and optimization algorithm specified in the config, as well as a TestPaths instance for each. If only_first, then only the first permutation will be returned. Else all permutations will be returned.
Source code in bin_mounted/ngen_rte/configs.py
make_parallel_config
#
MSWM ParallelConfig instance.
Source code in bin_mounted/ngen_rte/configs.py
Regionalization Workflows#
The regionalization workflows run via command-line interface (CLI) Scripts.
Here is the argparse help menu of run_regionalization.py:
run_regionalization is called by run_region.sh
For more information, see the nwm-region-mgr repository.
ngen_rte.run_regionalization
#
RTE regionalization workflow runner script.