Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netcdf output #744

Draft
wants to merge 37 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ce2adad
Add missing files
donaldwj Feb 9, 2024
be9a79e
Create NetCDF from a list of dimensions and variables.
donaldwj Feb 14, 2024
1519e68
Add comments and netcdf write test.
donaldwj Feb 22, 2024
13a49c6
Rename variable 'tree' to 'config_ptree' in FormulationManager for cl…
donaldwj Mar 22, 2024
a3d93ed
Inital parsing code for listed netcdf variable and dimensions.
donaldwj Mar 22, 2024
1a425bc
Updates to integration code.
donaldwj Mar 27, 2024
e084523
Bug fixes from debuggin unit tests.
donaldwj Mar 27, 2024
c8222bd
Added example config file for nc output.
donaldwj Mar 27, 2024
6bd283f
fixes to sample data fire.
donaldwj Mar 27, 2024
589ecbd
Requested output file structure is now saved in the ConfigurationMana…
donaldwj Mar 28, 2024
1fd9001
Fixing rebase porblems and broken netcdf output unit test.
donaldwj Apr 10, 2024
34fdc72
Document requirments.txt fire in README.
donaldwj Apr 10, 2024
2bfae54
Updating CMakeList for easier configuration.
donaldwj Apr 10, 2024
7be97f8
Removing unnessessary namespace qualifiers.
donaldwj Apr 10, 2024
d383a0c
Add missing #define.
donaldwj Apr 10, 2024
ac7af5d
Adding feature guards for netcdf output code in FormulationManager.
donaldwj Apr 11, 2024
721e6e8
Provide default values of mpi_rank to test that use FormulationManager.
donaldwj Apr 11, 2024
2817f11
Add class_id() to layers.
donaldwj Apr 17, 2024
fa1187a
Start adding member functions to Forumulation for BMI queries
donaldwj Apr 17, 2024
34fe0b9
Remove attempt to force non copy of return vector with move.
donaldwj Apr 17, 2024
57ef614
Correcting typo in description of requirements.txt
donaldwj Apr 18, 2024
457a717
Added output interface to allow access to required BMI information fo…
donaldwj Apr 18, 2024
a7f2f25
Add inital interface for retireving bmi values for
donaldwj Apr 24, 2024
b497dc5
Basic definition of output interface for bmi_multi.
donaldwj Apr 25, 2024
8df2dc1
Added config based translation of BMI variable names.
donaldwj May 1, 2024
d356fee
Add logic for creation of netcdf file from layer
donaldwj May 30, 2024
5cd822a
Updating renamed files
donaldwj Jun 3, 2024
ee73d30
Create base class for output writers, this allows update_models() to …
donaldwj Jun 6, 2024
87c25bd
Update to main loop added outline of data export with BMI.
donaldwj Aug 14, 2024
3ce0bf0
formating fix
donaldwj Aug 14, 2024
965d9e8
Proto type code for building netcdf output arrays added to layers.
donaldwj Aug 21, 2024
ae86a05
Added code for string variables
donaldwj Aug 21, 2024
276c566
Added the first part of netcdf output to file in layers.
donaldwj Sep 13, 2024
47a5924
update layer output code to write all buffers.
donaldwj Sep 13, 2024
364bb24
Clean up of NetcdfOutputWriterUtils.cpp
donaldwj Sep 13, 2024
c6f5bd9
Recorded data needed for offsets with mpi.
donaldwj Sep 13, 2024
93df131
Delete comment for unneeded function.
donaldwj Sep 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ if(NGEN_WITH_NETCDF)
endif()

add_compile_definitions(NETCDF_ACTIVE)
add_compile_definitions(NGEN_WITH_NETCDF)
endif()

if(NGEN_WITH_EXTERN_SLOTH)
Expand Down Expand Up @@ -330,6 +331,7 @@ add_subdirectory("src/forcing")
add_subdirectory("src/utilities/mdarray")
add_subdirectory("src/utilities/mdframe")
add_subdirectory("src/utilities/logging")
add_subdirectory("src/output")

target_link_libraries(ngen
PUBLIC
Expand All @@ -342,6 +344,7 @@ target_link_libraries(ngen
NGen::forcing
NGen::core_mediator
NGen::logging
NGen::output
)

if(NGEN_WITH_SQLITE)
Expand All @@ -354,6 +357,11 @@ if(NGEN_WITH_ROUTING)
target_link_libraries(ngen PUBLIC NGen::routing)
endif()

if(NGEN_WITH_NETCDF)
add_subdirectory("src/utilities/netcdf")
target_link_libraries(ngen PUBLIC NGen::netcdf_utils)
endif()

add_executable(partitionGenerator src/partitionGenerator.cpp)
target_include_directories(partitionGenerator PUBLIC "${PROJECT_BINARY_DIR}/include")
if(NGEN_WITH_SQLITE)
Expand Down
165 changes: 165 additions & 0 deletions data/example_ncout_realization_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
{
"global": {
"formulations": [
{
"name": "bmi_c++",
"params": {
"model_type_name": "test_bmi_cpp",
"library_file": "./extern/test_bmi_cpp/cmake_build/libtestbmicppmodel.so",
"init_config": "./data/bmi/c/test/test_bmi_c_config.ini",
"main_output_variable": "OUTPUT_VAR_2",
"variables_names_map" : {
"INPUT_VAR_2": "TMP_2maboveground",
"INPUT_VAR_1": "precip_rate"
},
"create_function": "bmi_model_create",
"destroy_function": "bmi_model_destroy",
"uses_forcing_file": false
}
}
],
"forcing": {
"file_pattern": ".*{{id}}.*.csv",
"path": "./data/forcing/"
}
},
"time": {
"start_time": "2015-12-01 00:00:00",
"end_time": "2015-12-30 23:00:00",
"output_interval": 3600
},
"outputs" : {
"nc_file1" : {
"name" : "netcdf_output_1.nc",
"type" : "NetCDF4",
"dimensions" : {
"X" : {
"size" : 1000
},
"Y" : {
"size" : 500
},
"Z" : {
"size" : 100
}
},
"variables" : {
"inflitration_excess" : {
"type" : "float",
"dimensions" : "X, Y"
},
"soil_moisture_content" : {
"type" : "float",
"dimensions" : "X, Y"
}
}
},
"nc_file2" : {
"name" : "netcdf_output_2.nc",
"type" : "NetCDF4",
"dimensions" : {
"D1" : {
"size" : 10
},
"D2" : {
"size" : 100
},
"D3" : {
"size" : 1000
},
"D4" : {
"size" : 10000
}
},
"variables" : {
"var1" : {
"type" : "float",
"dimensions" : "D1"
},
"var2" : {
"type" : "int",
"dimensions" : "D2"
},
"var3" : {
"type" : "char",
"dimensions" : "D3"
},
"var4" : {
"type" : "int64",
"dimensions" : "D4"
}
}
}
},
"catchments": {
"cat-27": {
"formulations": [
{
"name": "bmi_c++",
"params": {
"model_type_name": "test_bmi_cpp",
"library_file": "./extern/test_bmi_cpp/cmake_build/libtestbmicppmodel.so",
"init_config": "./data/bmi/c/test/test_bmi_c_config.ini",
"main_output_variable": "OUTPUT_VAR_2",
"variables_names_map" : {
"INPUT_VAR_2": "TMP_2maboveground",
"INPUT_VAR_1": "precip_rate"
},
"create_function": "bmi_model_create",
"destroy_function": "bmi_model_destroy",
"uses_forcing_file": false
}
}
],
"forcing": {
"path": "./data/forcing/cat-27_2015-12-01 00_00_00_2015-12-30 23_00_00.csv"
}
},
"cat-52": {
"formulations": [
{
"name": "bmi_c++",
"params": {
"model_type_name": "test_bmi_cpp",
"library_file": "./extern/test_bmi_cpp/cmake_build/libtestbmicppmodel.so",
"init_config": "./data/bmi/c/test/test_bmi_c_config.ini",
"main_output_variable": "OUTPUT_VAR_2",
"variables_names_map" : {
"INPUT_VAR_2": "TMP_2maboveground",
"INPUT_VAR_1": "precip_rate"
},
"create_function": "bmi_model_create",
"destroy_function": "bmi_model_destroy",
"uses_forcing_file": false
}
}
],
"forcing": {
"path": "./data/forcing/cat-52_2015-12-01 00_00_00_2015-12-30 23_00_00.csv"
}
},
"cat-67": {
"formulations": [
{
"name": "bmi_c++",
"params": {
"model_type_name": "test_bmi_cpp",
"library_file": "./extern/test_bmi_cpp/cmake_build/libtestbmicppmodel.so",
"init_config": "./data/bmi/c/test/test_bmi_c_config.ini",
"main_output_variable": "OUTPUT_VAR_2",
"variables_names_map" : {
"INPUT_VAR_2": "TMP_2maboveground",
"INPUT_VAR_1": "precip_rate"
},
"create_function": "bmi_model_create",
"destroy_function": "bmi_model_destroy",
"uses_forcing_file": false
}
}
],
"forcing": {
"path": "./data/forcing/cat-67_2015-12-01 00_00_00_2015-12-30 23_00_00.csv"
}
}
}
}
2 changes: 1 addition & 1 deletion extern/SoilMoistureProfiles/SoilMoistureProfiles
Submodule SoilMoistureProfiles updated 47 files
+9 −0 .gitignore
+42 −0 CMakeLists.txt
+42 −45 README.md
+6 −6 config/config_layered.txt
+0 −6 config/config_mapping.txt
+7 −0 config/config_topmodel.txt
+8 −3 config/realization_config_smp.json
+0 −69 config/realization_config_smp_macos.json
+110 −0 config/realization_config_smp_topmodel.json
+7 −0 config/topmod.run
+99 −82 include/bmi_soil_moisture_profile.hxx
+74 −88 include/soil_moisture_profile.hxx
+0 −3 make_bmi_mapper.sh
+0 −3 make_bmi_smp.sh
+27 −0 regridder/README.md
+84 −0 regridder/bmi/bmi.hxx
+11 −0 regridder/config/config_mapping.txt
+2 −0 regridder/config/config_syn.txt
+21,999 −0 regridder/data/cat_params.dat
+0 −0 regridder/data/grid_mapping.csv
+21,999 −0 regridder/data/grid_mapping_nextgen_01_ext.dat
+17 −0 regridder/data/synthetic/grid_mapping_syn2x2_case0.csv
+15 −0 regridder/data/synthetic/grid_mapping_syn2x2_case1.csv
+44 −0 regridder/data/synthetic/grid_mapping_syn2x2_case2.csv
+44 −0 regridder/data/synthetic/grid_mapping_syn2x2_case3.csv
+ regridder/data/synthetic_data_example.xlsx
+22,000 −0 regridder/data/twi-nextgen_01_ext.dat
+0 −0 regridder/data/twi_data.csv
+1 −1 regridder/include/bmi_regridder.hxx
+27 −7 regridder/include/soil_moisture_regridding.hxx
+3 −0 regridder/make_bmi_mapper.sh
+ regridder/run_bmi_mapper
+4 −2 regridder/src/bmi_main_regridder.cxx
+2 −2 regridder/src/bmi_regridder.cxx
+815 −0 regridder/src/soil_moisture_regridding.cxx
+29 −0 run_smp.sh
+120 −45 src/bmi_soil_moisture_profile.cxx
+171 −0 src/main_smp_topmodel.cxx
+14 −11 src/main_soil_moisture.cxx
+0 −485 src/soil_moisture_mapping.cxx
+621 −208 src/soil_moisture_profile.cxx
+1 −1 test/configs/unittest_conceptual.txt
+9 −0 test/configs/unittest_layered_constant.txt
+9 −0 test/configs/unittest_layered_linear.txt
+0 −461 test/main_unit_test_bmi.cxx
+695 −0 test/main_unittest.cxx
+2 −2 test/run_unittest.sh
3 changes: 2 additions & 1 deletion extern/test_bmi_py/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- run_bmi_unit_test.py: This is a file that runs each BMI unit test to make sure that the BMI is complete and functioning as expected.
- config.yml: This is a configuration file that the BMI reads to set inital_time (initial value of current_model_time) and time_step_seconds (time_step_size).
- environment.yml: Environment file with the required Python libraries needed to run the model with BMI. Create the environment with this command: `conda env create -f environment.yml`, then activate it with `conda activate bmi_test`
- requirements.txt: This file is used to install needed packages into system or venv directories using the command 'pip install -r requirements.txt'

# About
This is an implementation of a Python-based model that fulfills the Python language BMI interface and can be used in the Framework. It is intended to serve as a control for testing purposes, freeing the framework from dependency on any real-world model in order to test BMI related functionality.
Expand All @@ -28,4 +29,4 @@ model time, input_1, input_2, output_1, output_2, output_3
457200.00, 3.57, 1.31, 228.50, 167.46, 0.00
918000.00, 5.18, 1.77, 662.80, 453.24, 0.00
1839600.00, 3.68, 3.75, 943.04, 1919.17, 0.00
3682800.00, 8.62, 1.63, 4412.11, 1668.66, 0.00
3682800.00, 8.62, 1.63, 4412.11, 1668.66, 0.00
15 changes: 14 additions & 1 deletion include/core/DomainLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ namespace ngen
formulation->write_output("Time Step,""Time,"+formulation->get_output_header_line(",")+"\n");
}

/**
* @brief Get a list of output variables names for this layer
*
* @return vector of output variable names
*/

/***
* @brief Run one simulation timestep for this model associated with the domain
*
Expand All @@ -56,7 +62,7 @@ namespace ngen
* Any required connection to other components, e.g. providing inputs to a catchment feature,
* is not yet implemented in this class.
*/
void update_models() override{
void update_models(std::shared_ptr<data_output::OutputWriter> writer) override{
std::string current_timestamp = simulation_time.get_timestamp(output_time_index);
try{
formulation->get_response(output_time_index, simulation_time.get_output_interval_seconds());
Expand All @@ -80,6 +86,13 @@ namespace ngen

}

/**
* @brief Get a class id for this layer object
*
* @return int
*/
int class_id() { return LayerClass::kDomainLayer; }

private:
std::shared_ptr<realization::Catchment_Formulation> formulation;
};
Expand Down
Loading