How ajkhattak/nextgensandboxhub works
Project type and purpose
• This is an open-source workflow orchestration tool (NextGenSandboxHub) for setting up, configuring, and running hydrologic model simulations (NextGen, t-route) over sub-catchments.
• It ties together R scripts for hydrofabric processing, Python modules for configuration and execution, and external binaries/plugins (ngen, t-route, CIROH_DL_NextGen).
File structure
• Top-level orchestrator: sandbox.py (CLI entry point)
• Configuration directory: configs/ (YAML templates for basefiles, sandbox, calibration, workflows)
• R processing modules: src/R/ (data subsetting, parameter computation, plotting, main driver)
• Python orchestration modules: src/python/ (baseline, configuration, driver, forcing, generate, helper, realization, runner, schema, validation)
• External dependencies/plugins: extern/CIROH_DL_NextGen, extern/ngen-cal, extern/ngen_cal_plugins
• Utility scripts: utils/ (build sandbox, build models, S3 download, environment setup)
• Meta files: .gitignore, README.md, LICENSE, build scripts, submodule pointers
README insights
• Workflow steps (subset hydrofabric, download forcing, generate config/realization, run simulations)
• Relies on two environments: R (via Rscript or RStudio) and Python virtualenv (.venv_forcing, sandbox venv)
• External tool integrations: CIROH_DL_NextGen for atmospheric data, ngen + t-route for model execution
• Plugin pattern for calibration (ngen_cal_plugins)
Main components
a. CLI / Workflow Orchestrator
• sandbox.py (entry point handling flags: –subset, –forc, –conf, –run)
b. Configuration Management
• YAML files in configs/ drive every step
c. R Processing Engine
• Scripts in src/R/ invoked via Rscript or within RStudio
• Outputs: sub-catchment geopackages with computed parameters (TWI, GIUH, Nash cascade)
d. Python Processing Engine
• Modules in src/python/ manage forcing download, configuration generation, realization assembly, validation, and runner logic
e. External Tools & Plugins
• CIROH_DL_NextGen for forcing data (invoked in its own venv)
• ngen core library and t-route binary for simulation execution
• Calibration plugins under extern/ngen_cal_plugins (strategy/plugin pattern)
f. Data Storage & Flow
• Input: hydrofabric geopackages (local or S3), forcing archives
• Intermediate: generated config JSON/YAML, realization files
• Output: simulation results, calibrated parameter sets
Relationships & interactions
• CLI → reads configs/sandbox_config.yaml → invokes R stage (subsetting) → writes geopackages → invokes Python forcing module (CIROH_DL) → fetches data → Python config generator → writes model config & realization → Python runner module → calls external ngen + t-route → reads/writes output directories
• Plugin loader in Python runner discovers and applies calibration plugins from extern/ngen_cal_plugins
• Utility scripts (utils/) support environment and dependency setup but aren’t part of the runtime pipeline
Architectural patterns & design principles
• Modular pipeline stages (subsetting, forcing, config, run) separated by flag-driven CLI
• Strategy/plugin pattern for calibration (discoverable plugins under a common interface)
• Clear separation of concerns:
• Data preparation (R)
• Data ingestion & config (Python)
• Simulation execution (external binaries/libraries)
• Configuration-first design: all steps parameterized by YAML
Technologies & frameworks to annotate
• Python 3.x, virtualenv
• R (>=3.x) + Rscript
• CIROH_DL_NextGen (Python package)
• NGEN (Python library)
• t-route (Fortran/C++ binary)
• YAML, JSON for configs
• Plugin discovery (Python entry points or dynamic import)