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

Support catchment {{id}} substitution in init_config field of global single module formulations #850

Open
aaraney opened this issue Jul 3, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@aaraney
Copy link
Member

aaraney commented Jul 3, 2024

{{id}} is not substituted with the modeled catchment id in global single module formulations (e.g. init_config: "some_config_{{id}}.format") like they are in a multi-bmi formulation. It is desirable that this behavior is replicated in the single module formulation variant.

Substitution occurs in the multi-bmi case here:

// Since this is a nested formulation, support usage of the '{{id}}' syntax for init config file paths.
Catchment_Formulation::config_pattern_substitution(properties, BMI_REALIZATION_CFG_PARAM_REQ__INIT_CONFIG,
"{{id}}", id);

Example:

{
    "global": {
      "formulations": [
        {
          "name": "bmi_c++",
          "params": {
            "model_type_name": "test_bmi_cpp",
            "library_file": "./extern/test_bmi_cpp/cmake_build/libtestbmicppmodel",
            "init_config": "./data/bmi/c/test/test_bmi_c_config_{{id}}.ini",
            "main_output_variable": "OUTPUT_VAR_2",
            "variables_names_map" : {
              "INPUT_VAR_2": "TMP_2maboveground",
              "INPUT_VAR_1": "precip_rate"
            },
            "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
    }
}

This will throw the following error:

Cannot create and initialize libtestbmicppmodel using unreadable file './data/bmi/c/test/test_bmi_c_config_{{id}}.ini'. Error: No such file or directory

Current workaround:

Wrap the single module in a multi-bmi formulation.

Example
{
  "global": {
    "formulations": [
      {
        "name": "bmi_multi",
        "params": {
          "model_type_name": "work_around",
          "forcing_file": "",
          "init_config": "",
          "allow_exceed_end_time": true,
          "main_output_variable": "OUTPUT_VAR_2",
          "uses_forcing_file": false,
          "modules": [
            {
              "name": "bmi_c++",
              "params": {
                "model_type_name": "test_bmi_cpp",
                "library_file": "./extern/test_bmi_cpp/cmake_build/libtestbmicppmodel",
                "init_config": "./data/bmi/c/test/test_bmi_c_config_{{id}}.ini",
                "main_output_variable": "OUTPUT_VAR_2",
                "variables_names_map": {
                  "INPUT_VAR_2": "TMP_2maboveground",
                  "INPUT_VAR_1": "precip_rate"
                },
                "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
  }
}
@aaraney aaraney added the bug Something isn't working label Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant