Implement functions and classes in ngen to produce Catchment output netcdfs [NGWPC-10597]#177
Conversation
cae217c to
61be6c6
Compare
1f1199b to
f84be25
Compare
7d99ade to
b42b585
Compare
944da40 to
61e9454
Compare
| std::string output = std::to_string(output_time_index)+","+current_timestamp+","+ | ||
| r_c->get_output_line_for_timestep(output_time_index)+"\n"; | ||
| r_c->write_output(output); | ||
|
|
||
| for (const auto& fmt : output_formats) | ||
| { | ||
| if (fmt == "csv"){ | ||
| r_c->write_output(output); | ||
| } | ||
| if(fmt == "netcdf"){ | ||
| //capture all the output values for this timestep to write to netcdf | ||
| #if NGEN_WITH_NETCDF | ||
| catchment_output_values[id] = r_c->get_output_line_for_timestep(output_time_index); | ||
| #endif //NGEN_WITH_NETCDF | ||
| } | ||
| } |
There was a problem hiding this comment.
Work can be reduced here. Call just r_c->get_output_line_for_timestep on line 63. Line 69 can add the other information, and line 74 doesn't have to recreate the string.
| #include <NGenConfig.h> | ||
|
|
||
| NetCDFManager::NetCDFManager(std::shared_ptr<realization::Formulation_Manager> manager, | ||
| const std::string& output_name, Simulation_Time const& sim_time, int mpi_rank, int mpi_num_procs) |
There was a problem hiding this comment.
| const std::string& output_name, Simulation_Time const& sim_time, int mpi_rank, int mpi_num_procs) | |
| const std::string& output_name, Simulation_Time const& sim_time, int mpi_rank, int mpi_num_procs) : rank_(mpi_rank), num_procs_(mpi_num_procs) |
There was a problem hiding this comment.
The workflow should ensure that rank is 0 and num procs is 1 when NGEN is compiled without MPI, so it's safe to just always initialize them at the start instead of in the constructor.
There was a problem hiding this comment.
Fixed. Removed initialization of rank_ and num_procs_ in the header. Assigning values as suggested.
| std::vector<int> catchments_in_proc; | ||
| catchments_in_proc.reserve(num_catchments); | ||
| for (auto const& formulation_info : manager_->get_all_formulations()) | ||
| { | ||
| int catchment_id; | ||
| std::string catchm = formulation_info.first; | ||
| if (catchm.rfind("cat-", 0) == 0){ | ||
| catchment_id = std::stoi(catchm.substr(4)); | ||
| } | ||
| else{ | ||
| catchment_id = std::stoi(formulation_info.first); | ||
| } | ||
| catchments_in_proc.push_back(catchment_id); | ||
| } | ||
| gather_all_catchments(catchments_in_proc); |
There was a problem hiding this comment.
Catchment IDs now need to be int_64_t for NHF 1.2. All conversions of catchment IDs to numbers need to us atoll, stoll, etc. I'm just marking this first place I noticed using int for catchment IDs, but please review the rest of where this type of conversion happens and update accordingly.
One note is that the IDs should never be less than or equal to 0.
There was a problem hiding this comment.
Changed all int to int64_t for catchments. All NetCDF operations related to catchments now use long long. Tested the changes and everything works.
|
|
||
| # Uncomment when building locally | ||
| # FROM ngen-bmi-forcing AS base | ||
| # FROM forcing:local AS base |
There was a problem hiding this comment.
This is likely an unintended change.
There was a problem hiding this comment.
This has been refactored out in favor of a command line build argument in the latest version of the Dockerfile.
Likely need to rebase this branch to development
There was a problem hiding this comment.
I added it for testing purposes. It has been replaced and updated after rebase.
commit 971c830 Author: siva.selvanathan Added checks for MPI and output variables in realization to prevent NetCDF creation. Added appropriate log messages. commit b82797b Author: siva.selvanathan Date: Mon Jan 26 21:46:41 2026 -0500 Added a couple of macro If blocks to prevent attempts to write to a single NetCDF in parallel fashion. commit cf5e694 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Mon Jan 26 14:52:17 2026 -0500 Included num_proc if clause to prevent MPI Barrier being called for a single process. Also, removed an unused function from the test class. commit f4b8819 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Mon Jan 26 11:29:36 2026 -0500 Unit tests for netcdf creators. This build does not support MPI functionality. commit fff50aa Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Tue Jan 13 21:18:32 2026 -0500 Added dependent libraries to test_ngen_simulation for a successful build. commit 915c0c3 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Tue Jan 13 17:24:56 2026 -0500 Changes made to enable MPI for netcdf writing. commit fc5eec5 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Mon Jan 12 09:19:57 2026 -0500 Made changes to enable MPI for catchment NetCDF creation. Build is still failing. commit 43fb963 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Sun Jan 11 21:11:14 2026 -0500 Added pybind include directory to check pipeline build commit 53f7022 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Sun Jan 11 17:14:34 2026 -0500 NetCDF for catchment outputs funcitonality implemented. commit 74a624a Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Wed Dec 24 09:17:12 2025 -0500 Included proper headers and target directories to CMakeFile to make the program compilable. commit 3dcac1a Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Tue Dec 23 14:26:04 2025 -0500 Removed all class variables and constructor implementation for NetCDFCreator. Currently, the code is skeletal with the focus on getting a successful compile. commit 4358f6a Merge: 6fcb180 b44c038 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Thu Dec 18 13:44:24 2025 -0500 Merge branch 'ssn_9011_netcdf_for_catchments' of https://github.com/NGWPC/ngen into ssn_9011_netcdf_for_catchments commit 6fcb180 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Thu Dec 18 12:26:03 2025 -0500 first commit with new netcdfcreator class commit b44c038 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Thu Dec 18 12:26:03 2025 -0500 first commit with new netcdfcreator class
…s updates with logger.
… changes to NgenSimulation and NetCDF Data provider. The old C++ class NetCDFCreator hasn't been removed yet.
…table fails due to shared library issue.
…r defined output formats.
…hould help in docker build as well.
commit 971c830 Author: siva.selvanathan Added checks for MPI and output variables in realization to prevent NetCDF creation. Added appropriate log messages. commit b82797b Author: siva.selvanathan Date: Mon Jan 26 21:46:41 2026 -0500 Added a couple of macro If blocks to prevent attempts to write to a single NetCDF in parallel fashion. commit cf5e694 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Mon Jan 26 14:52:17 2026 -0500 Included num_proc if clause to prevent MPI Barrier being called for a single process. Also, removed an unused function from the test class. commit f4b8819 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Mon Jan 26 11:29:36 2026 -0500 Unit tests for netcdf creators. This build does not support MPI functionality. commit fff50aa Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Tue Jan 13 21:18:32 2026 -0500 Added dependent libraries to test_ngen_simulation for a successful build. commit 915c0c3 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Tue Jan 13 17:24:56 2026 -0500 Changes made to enable MPI for netcdf writing. commit fc5eec5 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Mon Jan 12 09:19:57 2026 -0500 Made changes to enable MPI for catchment NetCDF creation. Build is still failing. commit 43fb963 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Sun Jan 11 21:11:14 2026 -0500 Added pybind include directory to check pipeline build commit 53f7022 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Sun Jan 11 17:14:34 2026 -0500 NetCDF for catchment outputs funcitonality implemented. commit 74a624a Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Wed Dec 24 09:17:12 2025 -0500 Included proper headers and target directories to CMakeFile to make the program compilable. commit 3dcac1a Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Tue Dec 23 14:26:04 2025 -0500 Removed all class variables and constructor implementation for NetCDFCreator. Currently, the code is skeletal with the focus on getting a successful compile. commit 4358f6a Merge: 6fcb180 b44c038 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Thu Dec 18 13:44:24 2025 -0500 Merge branch 'ssn_9011_netcdf_for_catchments' of https://github.com/NGWPC/ngen into ssn_9011_netcdf_for_catchments commit 6fcb180 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Thu Dec 18 12:26:03 2025 -0500 first commit with new netcdfcreator class commit b44c038 Author: siva.selvanathan <sselvanathan_IE@Dewberry.com> Date: Thu Dec 18 12:26:03 2025 -0500 first commit with new netcdfcreator class
…s updates with logger.
… changes to NgenSimulation and NetCDF Data provider. The old C++ class NetCDFCreator hasn't been removed yet.
…table fails due to shared library issue.
…r defined output formats.
…hould help in docker build as well.
…o use enums. Checked in with latest updates.
d2e042d to
45df04b
Compare
…h EWTS and other submodules).
…e output format requested.
…mmunicator is not null.
jswade-rtx
left a comment
There was a problem hiding this comment.
Changes look good. I performed many tests for calibration/validation/forecast/regionalization/default run types to produce CSV, NetCDF/CSV, and NetCDF outputs using both single and multiple processors.
|
Related PRS: |
Enable functionality in ngen to write all catchment outputs to a netcdf file for non-MPI ngen runs. This PR is created following NGWPC-9011 PR (#106). However, that didn't make it into development because it remained in draft. We squashed all earlier commits and rebased with ngen development for this PR. This PR might show more changes than what is needed for NetCDF operations. The changes listed below are specific to NetCDF related changes. This works only with NHF geopackage schema.
Additions
Removals
Changes
get_output_variable_unitsandset_output_variable_unitsfunction to obtain the output variable units to write to netcdf attributes.Updatefunction.Testing
Screenshots
Notes
Todos
Checklist
Testing checklist (automated report can be put here)
Target Environment support