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

Fix NetCDFPerFeatureDataProvider returning the same forcing for all catchments #437

Merged
merged 2 commits into from
Aug 26, 2022

Conversation

mattw-nws
Copy link
Contributor

The catchment ID was not being passed through to the selector. Rectified.

Additions

  • Made the value of Catchment_Formulation::get_catchment_id() be passed to selector constructors in Bmi_Module_Formulation and Bmi_Multi_Formulation

Removals

Changes

  • Made get_catchment_id() trim any .N suffix from the realization IDs in the case of nested formulations.

Testing

  1. Minimal test added for the change to get_catchment_id()... some more work tests would probably be good for the whole pipeline, but that's either an integration test or would require more mocks.

Screenshots

Notes

Todos

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows project standards (link if applicable)
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future todos are captured in comments
  • Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)
  • Reviewers requested with the Reviewers tool ➡️

Testing checklist (automated report can be put here)

  1. Additional test added as described above. All automated tests passing.

Target Environment support

  • Linux

@mattw-nws mattw-nws requested a review from robertbartel August 24, 2022 18:17
@mattw-nws mattw-nws changed the title Fix NetCDFPerFeaturDataProvider returning the same forcing for all catchments Fix NetCDFPerFeatureDataProvider returning the same forcing for all catchments Aug 24, 2022
@mattw-nws mattw-nws marked this pull request as ready for review August 24, 2022 18:51
Copy link
Contributor

@robertbartel robertbartel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed a few small things that I added inline review comments for, but nothing imperative.

I also noticed that the Simple_Lumped_Model_Realization::get_response function still makes some calls to the selector's constructor while passing in "" for id. Strictly speaking this looks like it could cause a problem, although it also seems reasonably safe to defer fixing it, given the class involved, as long as it gets tracked.

@mattw-nws I'll go ahead and approve, but let me know if you want to adjust any of those minor items and I'll come back to look at this again.

@@ -1118,7 +1118,7 @@ namespace realization {
varItemSize);
if (varItemSize != get_bmi_model()->GetVarNbytes(var_name)) {
//more than a single value needed for var_name
auto values = provider->get_values(CatchmentAggrDataSelector("",var_map_alias, model_epoch_time, t_delta,
auto values = provider->get_values(CatchmentAggrDataSelector(this->get_catchment_id(),var_map_alias, model_epoch_time, t_delta,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the risk of being a bit pedantic: the change probably shouldn't keep the bad spacing between the first two args.

I'm not going to keep pointing it out, but I did notice it in a few other places also.

@@ -644,7 +644,7 @@ namespace realization {
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("",var_name,nested_module_time,this->record_duration(),"1");
auto selector = CatchmentAggrDataSelector(this->get_catchment_id(),var_name,nested_module_time,this->record_duration(),"1");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to point out this exception, because the arg spacing here is already consistent, at least internally.

// Assume the catchment ID is equal to or embedded in the formulation `id`
size_t idx = id.find(".");
set_catchment_id( idx == std::string::npos ? id : id.substr(0, idx) );
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple things I notice, but that are by no means deal-breakers.

First, we may get slightly better performance using the find that accepts a char; e.g., size_t idx = id.find('.');.

Second, the code duplication is bugging me. No straightforward way of eliminating it entirely, but it might be better to move the parsing and substring logic here to set_catchment_id directly. I can't think of a reason why it makes sense to apply it at construction but not other times set_catchment_id is called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this bugged me a little... I'm willing to duplicate something (in this length/complexity neighborhood) twice but not three times. I did not want to put it in the getter... arguably, it shouldn't be in the setter because that should receive something that is already a catchment ID, while this is a formulation ID... this code (functionally speaking) translates a formulation ID into a catchment ID. So... yeah short of breaking it into a utility function (probably overkill for something this small) I don't see a great answer.

@mattw-nws
Copy link
Contributor Author

I also noticed that the Simple_Lumped_Model_Realization::get_response function still makes some calls to the selector's constructor while passing in "" for id.

Yes, this occurred to me, the two t-shirt models probably have the same. I was similarly on the fence about it... since you also identified it that is maybe tipping me off the fence toward resolving it. Or at least yeah I should file an issue for the remaining instances. Those formulations wouldn't work with NetCDFPerFeatureDataProvider... which is kindof the point of #432, for instance.

@mattw-nws
Copy link
Contributor Author

Okay, decided to add #439 to address legacy formulations.

@mattw-nws mattw-nws merged commit 13dcd18 into master Aug 26, 2022
@mattw-nws mattw-nws deleted the data-provider-selector-cat-id branch August 26, 2022 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants