-
Notifications
You must be signed in to change notification settings - Fork 63
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 using the forcing file header error. #624
Conversation
Please fill in a description of the problem and its resolution in the PR notes, and correct the checklist formatting. |
@@ -245,6 +245,10 @@ namespace realization { | |||
for(std::map<std::string,std::shared_ptr<data_access::GenericDataProvider>>::iterator iter = availableData.begin(); iter != availableData.end(); ++iter) | |||
{ | |||
var_name = iter->first; | |||
auto it = std::find(forcing->get_available_variable_names().begin(), forcing->get_available_variable_names().end(), var_name); | |||
if (it == forcing->get_available_variable_names().end()) { | |||
var_name = forcing->get_available_variable_names()[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.
The whole loop now boils down to this line. Just eliminate the for
loop and set var_name
to this... even the try
block below is probably not useful now, because (I'm pretty sure) if availableData[var_name]->get_data_start_time();
fails on a forcing var_name, something has gone wrong (in the current code, at least).
Actually... I think the whole use of a variable name is redundant in this code path (where var_name == "*" || var_name = ""
... I think this whole section can be reduced to:
// Find one that successfully returns...
if(var_name == "*" || var_name == ""){
return forcing->get_data_start_time();
}
// If not found ...
Can you try that?
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.
Actually the comment above that if
is now not really correct either, probably just make it // If no var_name, use forcing
... if the above 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.
Just tried. It seems to work.
The details are described in Issue #504. Briefly, when a forcing file with the following format:
Time,RAINRATE,T2D,Q2D,U2D,V2D,PSFC,SWDOWN,LWDOWN
2015-12-01 00:00:00,0,285.8000183,0.0093,-2.299999952,0.100000001,100310,0,361.3000183
is used, ngen throw a runtime " out of range" error.
The usually used header is as follows.
time,APCP_surface,DLWRF_surface,DSWRF_surface,PRES_surface,SPFH_2maboveground,TMP_2maboveground,UGRD_10maboveground,VGRD_10maboveground,precip_rate
2015-12-01 00:00:00,0.0,360.8000183105469,0.0,100220.0,0.009399999864399433,285.8999938964844,-2.299999952316284,0.10000000149011612,0.0
Additions
Removals
Changes
include/realizations/catchment/Bmi_Multi_Formulation.hpp
Testing
Run ngen test
Screenshots
Notes
It is found the error was caused by setting
init_time
to0
inCsvPerFeatureForcingProvider.hpp
. This was ultimately traced toget_data_start_time()
which callget_variable_time_begin(const std::string &variable_name)
inBmi_Multi_Formulation.hpp
. This function usesavailableData
to extract the start time. Ifvar_name
inavailableData
is not inforcing
data, then it returns0
as start time. The solution makes sure if avar_name
chosen fromavailableData
is not a forcing variable name, we use the first forcing variable name asvar_name
to choose start time, which is always a valid time. We could actually use any of the forcing variable names to choose the start time, here we just uses the first one for convenience.Also note that the fix works for both CSV and netCDF data.
Todos
Checklist
Testing checklist (automated report can be put here)
Target Environment support