-
Notifications
You must be signed in to change notification settings - Fork 64
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
Gridded output formulations #532
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review is incomplete but there are some things to start on here.
In addition to the inline comments, we need all the unrelated content removed from the PR to consider merging (e.g. the AORC modules)--there's no need to have data sources for gridded data beyond the existing test models (I don't think), though yes we will need some tests for this the data can probably be either provided by the test models or hard-coded into the unit tests (I haven't reviewed the test code yet).
long nested_module_time = nested_module->get_data_start_time() + ( this->get_model_current_time() - this->get_model_start_time() ); | ||
auto selector = CatchmentAggrDataSelector(this->get_catchment_id(),var_name,nested_module_time,this->record_duration(),"1"); | ||
//TODO: After merge PR#405, try re-adding support for index | ||
return nested_module->get_values(selector); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this resulted in a copy of the function get_var_value_as_double
with exactly one character changed (aside from the signature). Since this is a moderately complex function, this duplication is not good. Once this function is implemented, get_var_value_as_double
is a special case of get_var_vec_as_double
, which is to get a specific index (default 0
). Also note the //TODO:
above. All of this to say the following:
When adding this function, the function get_var_value_as_double
should probably call get_var_vec_as_double
instead of duplicating its contents. Also, this function (get_var_vec_as_double
) does not use the index
parameter, it should be removed from the signature here. However, get_var_value_as_double
used to use the index
parameter but it was removed in #405; and if get_var_value_as_double
calls get_var_vec_as_double
, it can probably easily re-implement the index
parameter now, so this should probably be done.
The above change (and re-implementation of the index
parameter) probably makes sense to do in the other Bmi_*_Formulation
classes as well, though their get_var_vec_as_double
methods are probably much less complex.
Another approach to remove the duplication might be to implement get_data_provider_for_var_name
, which would return a pointer to a data provider (which is what most of this function does), but even if doing that, get_var_value_as_double
should probably be made to call get_var_vec_as_double
in order to implement the index
parameter... so this decomposition could easily be accomplished later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another note here, it is probably possible to get get_var_value_as_double
to return const &
to avoid additional copies, but I'm not 100% sure...but think about avoiding additional copies in this PR where possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the first comment, I agree that it does seem out of place for that AORC code to be there. I'll remove it from this PR. On the other hand, the code is needed at present to be able to run the gridded python module. Maybe we can put that code in ngen-forcing repo and download it whenever we want to run the Bmi-Python module in ngen?
The comments about the get_var_vec_as_double are well taken. I'll simplify the implementation along the line suggested in the comment.
@@ -97,12 +97,20 @@ namespace realization { | |||
|
|||
shared_ptr<models::bmi::Bmi_Py_Adapter> construct_model(const geojson::PropertyMap &properties) override; | |||
|
|||
template<class T, class O> | |||
T get_var_value_as(int t_index, const std::string& var_name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is declared in several classes but never used... please remove it from this PR if it isn't part of the solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it was an earlier implementation but not get used in the final version. One version of the template function itself probably is in the master repo. I'll check.
for (const std::string& name : get_output_variable_names()) { | ||
output_str += (output_str.empty() ? "" : ",") + std::to_string(get_var_value_as_double(name)); | ||
//output_str += (output_str.empty() ? "" : ",") + std::to_string(get_var_value_as_double(name)); | ||
output_str += (output_str.empty() ? "" : ",") + std::to_string(get_var_vec_as_double(t_delta, name)[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A simple solution for scalar values would be to check the vector length and if it's = 1 then output only element 0 .... I think that get_var_vec_as_double
should work for scalar values returning a vector of size 1. But yes, this should be addressed before we consider merging.
I'm also not sure we actually want to put this to_string
representation into a column in the CSV... what does it look like? If it has commas that won't do at all, just for instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is an example output:
cat-298118.csv
or as follows from direct copy/paste. In the displayed data, each variable has 9 consecutive values. I think the comas within each variable can be easily removed if that's what we want.
TimeStep,Time,APCP_surface,TMP_2maboveground,SPFH_2maboveground,UGRD_10maboveground,VGRD_10maboveground,PRES_surface,DSWRF_surface,DLWRF_surface
0,2015-12-01 00:00:00,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,278.399993896,278.600006104,278.600006104,278.399993896,278.500000000,278.600006104,278.399993896,278.399993896,-0.123450004,0.004700000,0.004800000,0.004800000,0.004700000,0.004700000,0.004800000,0.004700000,0.004700000,-0.123450004,5.700000286,5.700000286,5.700000286,5.700000286,5.700000286,5.700000286,5.700000286,5.700000286,-0.123450004,1.500000000,1.500000000,1.600000024,1.500000000,1.500000000,1.500000000,1.500000000,1.500000000,-0.123450004,98070.000000000,98020.000000000,97970.000000000,98130.000000000,98070.000000000,98020.000000000,98080.000000000,98050.000000000,-0.123450004,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,-0.123450004,247.500000000,248.100006104,248.300003052,247.300003052,247.600006104,248.100006104,247.100006104,247.199996948,-0.123450004
1,2015-12-01 01:00:00,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,276.899993896,276.899993896,277.000000000,276.899993896,276.899993896,277.000000000,276.899993896,276.899993896,-0.123450004,0.004400000,0.004400000,0.004500000,0.004400000,0.004400000,0.004400000,0.004400000,0.004400000,-0.123450004,4.900000095,4.900000095,4.900000095,4.900000095,4.900000095,4.900000095,4.900000095,4.900000095,-0.123450004,0.699999988,0.699999988,0.800000012,0.699999988,0.699999988,0.699999988,0.699999988,0.699999988,-0.123450004,98020.000000000,97970.000000000,97920.000000000,98080.000000000,98000.000000000,97970.000000000,98040.000000000,98000.000000000,-0.123450004,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,-0.123450004,248.600006104,248.600006104,249.100006104,248.300003052,248.500000000,248.800003052,248.100006104,248.100006104,-0.123450004
2,2015-12-01 02:00:00,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,275.500000000,275.500000000,275.500000000,275.399993896,275.500000000,275.500000000,275.399993896,275.399993896,-0.123450004,0.004200000,0.004200000,0.004200000,0.004100000,0.004200000,0.004200000,0.004100000,0.004100000,-0.123450004,4.099999905,4.099999905,4.099999905,4.099999905,4.099999905,4.099999905,4.099999905,4.099999905,-0.123450004,-0.100000001,-0.100000001,-0.100000001,-0.100000001,-0.100000001,-0.100000001,-0.100000001,-0.100000001,-0.123450004,97960.000000000,97910.000000000,97860.000000000,98020.000000000,97960.000000000,97910.000000000,97980.000000000,97940.000000000,-0.123450004,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,-0.123450004,249.900009155,249.900009155,250.300003052,249.699996948,249.800003052,250.000000000,249.400009155,249.500000000,-0.123450004
3,2015-12-01 03:00:00,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,274.100006104,274.000000000,274.100006104,274.000000000,274.000000000,274.100006104,274.000000000,274.000000000,-0.123450004,0.003900000,0.003900000,0.003900000,0.003900000,0.003900000,0.003900000,0.003900000,0.003900000,-0.123450004,3.299999952,3.299999952,3.400000095,3.299999952,3.299999952,3.299999952,3.299999952,3.299999952,-0.123450004,-0.900000036,-0.900000036,-0.900000036,-0.900000036,-0.900000036,-0.900000036,-0.900000036,-0.900000036,-0.123450004,97910.000000000,97870.000000000,97800.000000000,97960.000000000,97900.000000000,97850.000000000,97910.000000000,97880.000000000,-0.123450004,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,-0.123450004,219.000000000,218.800003052,219.000000000,218.800003052,218.800003052,218.800003052,219.000000000,218.800003052,-0.123450004
4,2015-12-01 04:00:00,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,273.399993896,273.300018311,273.399993896,273.399993896,273.399993896,273.399993896,273.399993896,273.300018311,-0.123450004,0.003700000,0.003700000,0.003700000,0.003700000,0.003700000,0.003700000,0.003700000,0.003700000,-0.123450004,3.200000048,3.200000048,3.200000048,3.200000048,3.200000048,3.200000048,3.200000048,3.200000048,-0.123450004,-0.600000024,-0.600000024,-0.600000024,-0.600000024,-0.600000024,-0.600000024,-0.600000024,-0.600000024,-0.123450004,97910.000000000,97870.000000000,97800.000000000,97960.000000000,97900.000000000,97850.000000000,97910.000000000,97880.000000000,-0.123450004,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,-0.123450004,219.400009155,219.100006104,219.300003052,219.300003052,219.300003052,219.300003052,219.300003052,219.100006104,-0.123450004
5,2015-12-01 05:00:00,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,272.700012207,272.600006104,272.700012207,272.700012207,272.700012207,272.600006104,272.700012207,272.600006104,-0.123450004,0.003600000,0.003600000,0.003600000,0.003600000,0.003600000,0.003600000,0.003600000,0.003600000,-0.123450004,3.000000000,3.000000000,3.100000143,3.000000000,3.000000000,3.000000000,3.000000000,3.000000000,-0.123450004,-0.300000012,-0.300000012,-0.300000012,-0.300000012,-0.300000012,-0.300000012,-0.200000003,-0.200000003,-0.123450004,97910.000000000,97870.000000000,97800.000000000,97980.000000000,97900.000000000,97850.000000000,97930.000000000,97880.000000000,-0.123450004,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,-0.123450004,219.800003052,219.500000000,219.699996948,219.699996948,219.699996948,219.699996948,219.800003052,219.500000000,-0.123450004
6,2015-12-01 06:00:00,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,272.000000000,271.899993896,271.899993896,272.000000000,272.000000000,271.899993896,272.000000000,272.000000000,-0.123450004,0.003400000,0.003400000,0.003400000,0.003400000,0.003400000,0.003400000,0.003400000,0.003400000,-0.123450004,2.900000095,2.900000095,2.900000095,2.900000095,2.900000095,2.900000095,2.900000095,2.900000095,-0.123450004,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.100000001,0.100000001,-0.123450004,97910.000000000,97870.000000000,97800.000000000,97980.000000000,97900.000000000,97870.000000000,97930.000000000,97900.000000000,-0.123450004,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,-0.123450004,215.600006104,215.199996948,215.199996948,215.500000000,215.400009155,215.199996948,215.600006104,215.400009155,-0.123450004
7,2015-12-01 07:00:00,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,271.899993896,271.800018311,271.800018311,271.899993896,271.899993896,271.800018311,271.899993896,271.899993896,-0.123450004,0.003400000,0.003400000,0.003400000,0.003400000,0.003400000,0.003400000,0.003400000,0.003400000,-0.123450004,2.500000000,2.500000000,2.500000000,2.500000000,2.500000000,2.500000000,2.500000000,2.500000000,-0.123450004,0.900000036,0.900000036,0.900000036,0.900000036,0.900000036,0.900000036,0.900000036,0.900000036,-0.123450004,97930.000000000,97880.000000000,97830.000000000,97990.000000000,97930.000000000,97880.000000000,97950.000000000,97910.000000000,-0.123450004,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,-0.123450004,215.500000000,215.300003052,215.300003052,215.400009155,215.400009155,215.300003052,215.500000000,215.300003052,-0.123450004
8,2015-12-01 08:00:00,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,271.800018311,271.700012207,271.800018311,271.800018311,271.800018311,271.800018311,271.800018311,271.800018311,-0.123450004,0.003400000,0.003400000,0.003400000,0.003400000,0.003400000,0.003400000,0.003400000,0.003400000,-0.123450004,2.100000143,2.100000143,2.100000143,2.100000143,2.100000143,2.100000143,2.100000143,2.100000143,-0.123450004,1.700000048,1.700000048,1.700000048,1.700000048,1.700000048,1.700000048,1.700000048,1.700000048,-0.123450004,97950.000000000,97900.000000000,97850.000000000,98010.000000000,97950.000000000,97900.000000000,97960.000000000,97930.000000000,-0.123450004,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,-0.123450004,215.400009155,215.100006104,215.100006104,215.400009155,215.300003052,215.100006104,215.500000000,215.300003052,-0.123450004
9,2015-12-01 09:00:00,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,271.700012207,271.600006104,271.700012207,271.700012207,271.700012207,271.700012207,271.700012207,271.700012207,-0.123450004,0.003400000,0.003300000,0.003400000,0.003400000,0.003400000,0.003300000,0.003400000,0.003400000,-0.123450004,1.800000072,1.800000072,1.800000072,1.800000072,1.800000072,1.800000072,1.800000072,1.800000072,-0.123450004,2.600000143,2.600000143,2.600000143,2.600000143,2.600000143,2.600000143,2.600000143,2.600000143,-0.123450004,97960.000000000,97930.000000000,97870.000000000,98030.000000000,97960.000000000,97910.000000000,97980.000000000,97950.000000000,-0.123450004,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,-0.123450004,213.199996948,212.800003052,212.900009155,213.100006104,212.900009155,212.800003052,213.100006104,212.900009155,-0.123450004
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On scalar vs. vector, the get_output_line_for_timestep() function should be made to be able to output scalar and vector values too.
// Do the first separately, without the leading comma | ||
*output_text_stream << get_var_value_as_double(output_var_names[0]); | ||
//*output_text_stream << "," << get_var_value_as_double(output_var_names[0]); | ||
*output_text_stream << get_var_vec_as_double(t_delta, output_var_names[0])[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments on [Bmi_Cpp_Formulation.cpp] apply to all get_output_line_for_timestep
implementations... unifying the code in these would also be beneficial (and in scope since they all have to be touched).... consider, is there a way to make this a superclass method or share some code between these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed this comment before I wrote mine. Agree.
//*output_text_stream <<"," << get_var_vec_as_double(t_delta, output_var_names[0])[17646500]; | ||
|
||
// Using array to select indices of grid points for output data | ||
int array[5] = {0,1,17646300,17646500,17646000}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove test data... lets keep subsetting of output out of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. It is a validation that vectorized/gridded version works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review is incomplete but there are some things to start on here.
In addition to the inline comments, we need all the unrelated content removed from the PR to consider merging (e.g. the AORC modules)--there's no need to have data sources for gridded data beyond the existing test models (I don't think), though yes we will need some tests for this the data can probably be either provided by the test models or hard-coded into the unit tests (I haven't reviewed the test code yet).
I have replied to your comments in the PR page. Regarding to the template
function T get_var_value_as(time_step_t t_index, const std::string&
var_name), the codes exist in the Bmi_C_Formulation.hpp
and Bmi_Cpp_Formulation.hpp in the master repo, do you want to leave them
in there as they are?
…On Mon, Jun 5, 2023 at 12:59 PM Matt Williamson ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In include/realizations/catchment/Bmi_Multi_Formulation.hpp
<#532 (comment)>:
> + * Get value vector for some BMI model variable.
+ */
+ std::vector<double> get_var_vec_as_double(const int& index, const std::string& var_name) {
+ auto data_provider_iter = availableData.find(var_name);
+ if (data_provider_iter == availableData.end()) {
+ throw external::ExternalIntegrationException(
+ "Multi BMI formulation can't find correct nested module for BMI variable " + var_name + SOURCE_LOC);
+ }
+ // Otherwise, we have a provider, and we can cast it based on the documented assumptions
+ try {
+ std::shared_ptr <data_access::GenericDataProvider> nested_module =
+ std::dynamic_pointer_cast<data_access::GenericDataProvider>(data_provider_iter->second);
+ long nested_module_time = nested_module->get_data_start_time() + ( this->get_model_current_time() - this->get_model_start_time() );
+ auto selector = CatchmentAggrDataSelector(this->get_catchment_id(),var_name,nested_module_time,this->record_duration(),"1");
+ //TODO: After merge PR#405, try re-adding support for index
+ return nested_module->get_values(selector);
Another note here, it is probably possible to get get_var_value_as_double
to return const & to avoid additional copies, but I'm not 100% sure...but
think about avoiding additional copies in this PR where possible.
—
Reply to this email directly, view it on GitHub
<#532 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACA4SRO5WTCWPA7Y3BXW2A3XJYM7HANCNFSM6AAAAAAYQU4GVU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Superseded by #534 |
Output variables on selected grid points
Additions
Removals
Changes
gridded_bmi_aorc_python/config.yml
include/realizations/catchment/Bmi_C_Formulation.hpp
include/realizations/catchment/Bmi_Cpp_Formulation.hpp
include/realizations/catchment/Bmi_Fortran_Formulation.hpp
include/realizations/catchment/Bmi_Module_Formulation.hpp
include/realizations/catchment/Bmi_Multi_Formulation.hpp
include/realizations/catchment/Bmi_Py_Adapter.hpp
include/realizations/catchment/Bmi_Py_Formulation.hpp
src/realizations/catchment/Bmi_C_Formulation.cpp
src/realizations/catchment/Bmi_Cpp_Formulation.cpp
src/realizations/catchment/Bmi_Fortran_Formulation.cpp
src/realizations/catchment/Bmi_Multi_Formulation.cpp
src/realizations/catchment/Bmi_Py_Formulation.cpp
test/realizations/catchments/Bmi_Multi_Formulation_Test.cpp
test/realizations/catchments/Bmi_Py_Formulation_Test.cpp
Testing
Screenshots
Notes
Todos
Checklist
Testing checklist (automated report can be put here)
Target Environment support