Closed hcorson-dosch-usgs closed 2 years ago
Also wanted to note that I tested the mapping by doing the following:
p1_lake_cell_tile_xwalk
to 5 lakes:
tar_target(p1_lake_cell_tile_xwalk_df,
readr::read_csv(p1_lake_cell_tile_xwalk_csv, col_types=cols()) %>%
filter(site_id %in% p1_nml_site_ids) %>%
arrange(site_id) %>%
filter(site_id %in% c('nhdhr_105567868','nhdhr_105569520', 'nhdhr_114336097',
'nhdhr_120019185','nhdhr_114544667'))),
p1_gcm_names
and p1_gcm_dates
to the run_glm3_model()
command:
tar_target(
p2_glm_uncalibrated_runs,
run_glm3_model(
sim_dir = '2_run/tmp/simulations',
nml_obj = p1_nml_objects,
gcm_name = p1_gcm_names,
gcm_date = p1_gcm_dates,
model_config = p1_model_config,
burn_in = 300,
burn_out = 190,
export_fl_template = '2_run/tmp/GLM_%s_%s_%s.feather'),
packages = c('retry','glmtools', 'GLM3r'),
pattern = map(p1_model_config, cross(p1_nml_objects, p1_gcm_names, p1_gcm_dates))),
Modifying run_glm3_model
to return a tibble to check that the pertinent parameters match:
run_glm3_model <- function(sim_dir, nml_obj, gcm_name, gcm_date, model_config, burn_in, burn_out, export_fl_template) {
# pull parameters from model_config
site_id <- model_config$site_id
time_period <- model_config$time_period
gcm <- model_config$gcm
raw_meteo_fl <- model_config$meteo_fl
mapping_check <- tibble(
config_site_id = site_id,
nml_site_id = nml_obj$morphometry$lake_name,
config_gcm = gcm,
mapped_gcm = gcm_name,
config_time_period = time_period,
mapped_time_period = gcm_date
)
return(mapping_check)
In the resulting tibble, you can see that the mapping set up by cross(p1_nml_objects, p1_gcm_names, p1_gcm_dates)
matches the order of p1_model_config
:
Fixes #22
When I started to dig into #22, I realized that it was possible to make this fix without writing each of the nml objects to file, so I instead implemented an objects-based fix here.
This PR:
p1_nml_objects
list of nml objectsp1_nml_objects
in the target recipe forp2_glm_uncalibrated_runs
, but does so as part of across()
withp1_gcm_names
andp1_gcm_dates
, which means that each nml object is repeated 18 times - once for each gcm-time-period combination. That matches the construction ofp1_model_config
, which means that the nml object passed to each branch ofp2_glm_uncalibrated_runs
is the correct nml object for that model run.I tested this out for a subset of 5 lakes. If I first run the model for 4 of the lakes, and then add another site_id for a 5th lake, only the models for that 5th lake are built. Similarly if I run the model for 4 of the lakes and then remove one of those site_ids, none of the models are rebuilt. That's the behavior we want, and corrects the issue noted in #22.