kevinwolz / hisafer

An R toolbox for the Hi-sAFe biophysical agroforestry model
6 stars 4 forks source link

Trouble modifying exportFrequencies using define_hisafe() #142

Closed kevinwolz closed 4 years ago

kevinwolz commented 4 years ago

FROM THOMAS GENDRON:

I have some difficulties to define hisafe simulation with hisafer. I want to write directly from the script, the exportFrequencies of output profile.

BUT this doesn't work well ... "Use 'profiles' argument of build_hisafe()" but there is no 'profiles' argument in build_hisafe function.

"Run rlang::last_error() to see where the error occurred." I understand nothing ...

The solution ? Directly from the template ? other ways ?

The code is just below.

Merci d'avance, even if you don't know.

Bonne journée.

Thomas Gendron

hip_AF_test <- define_hisafe(path = Dossier_local,

  • template = paste(way_template,Nom_template, sep = ""),
  • profile = output_list[c(1,3)],
  • exp.name = Nom_simu,
  • SimulationName = Nom_simu,
  • nbSimulations = 20,
  • exportFrequencies = list(c(10,10)),
  • profileNames = list(c("trees","plot")) ) Error: Hi-sAFe definition errors: -- profileNames and exportFrequencies cannot be defined using define_hisafe(). Use the 'profiles' argument of build_hisafe().

hip_AF_test <- define_hisafe(path = Dossier_local,

  • template = paste(way_template,Nom_template, sep = ""),
  • profile = output_list[c(1,3)],
  • exp.name = Nom_simu,
  • SimulationName = Nom_simu,
  • nbSimulations = 20,
  • ... = list(exportFrequencies = list(c(10,10)),
  • profileNames = list(c("trees","plot")) ) ) Error: Column 3 must not have names of the form ... or ..j. Use .name_repair to specify repair. Run rlang::last_error() to see where the error occurred.

rlang::last_error() <error/rlang_error> Column 3 must not have names of the form ... or ..j. Use .name_repair to specify repair. Backtrace:

  1. hisafer::define_hisafe(...)
  2. tibble:::as_tibble.list(param.list.filled)
  3. tibble:::lst_to_tibble(x, .rows, .name_repair, col_lengths(x))
  4. tibble:::set_repaired_names(x, .name_repair)
  5. tibble:::repaired_names(names(x), .name_repair = .name_repair)
  6. tibble:::check_unique(new_name) Run rlang::last_trace() to see the full context. rlang::last_trace() <error/rlang_error> Column 3 must not have names of the form ... or ..j. Use .name_repair to specify repair. Backtrace: x
  7. -hisafer::define_hisafe(...)
  8. +-dplyr::as_tibble(param.list.filled)
  9. -tibble:::as_tibble.list(param.list.filled)
  10. -tibble:::lst_to_tibble(x, .rows, .name_repair, col_lengths(x))
  11. -tibble:::set_repaired_names(x, .name_repair)
  12. +-rlang::set_names(x, repaired_names(names(x), .name_repair = .name_repair))
  13. | -rlang:::set_names_impl(x, x, nm, ...)
  14. | -rlang::is_function(nm)
  15. | -rlang::is_closure(x)
  16. -tibble:::repaired_names(names(x), .name_repair = .name_repair)
  17. -tibble:::check_unique(new_name)

hip_AF_test <- define_hisafe(path = Dossier_local,

  • template = paste(way_template,Nom_template, sep = ""),
  • profile = output_list[c(1,3)],
  • exp.name = Nom_simu,
  • SimulationName = Nom_simu,
  • nbSimulations = 20,
  • bulk.pass = list(exportFrequencies = list(c(10,10)),
  • profileNames = list(c("trees","plot")) ) ) Error: Hi-sAFe definition errors: -- profileNames and exportFrequencies cannot be defined using define_hisafe(). Use the 'profiles' argument of build_hisafe().

build_hisafe( hip = hip_AF_test, profiles = c(10,10) ) Error in build_hisafe(hip = hip_AF_test, profiles = c(10, 10)) : unused argument (profiles = c(10, 10))

kevinwolz commented 4 years ago

Unfortunately, hisafer does not yet support direct modification of exportFrequencies. You can only specify the output profile names you want to include via the profiles argument of define_hisafe(), and then the defaults are applied. That's what the error message was trying to tell you, but it seems that there is a typo it in so it says build_hisafe() instead - sorry about that! I have updated the error message to fix this typo. It now reads: "-- profileNames and exportFrequencies cannot be defined using define_hisafe(). Use the 'profiles' argument of define_hisafe()."

I have added issue https://github.com/kevinwolz/hisafer/issues/143 for us to explore how to integrate this functionality, as it has been something that I have also wanted for a long time. In the meantime, however, here is what you need to do:

(1) Use copy_hisafe_template() to copy one of the hisafer templates to a new folder on your computer. All of the export profiles that hisafer has will be included.

(2) Edit the profileNames and exportFrequencies lines of the .sim file yourself in a text editor and save the file.

(3) Use this template directory as your template in define_hisafe() rather than one of the built-in templates.

ThomasGendron commented 4 years ago

I test this solution before but it doesn't work. I will do it handmade for the moment.

Even if you specified, in your own template (after using copy_hisafe_template() ), the profileNames and exportFrequencies define_hisafe() will overwrite it.

If you specified the argument profiles in define_hisafe(), it will use the default values of exportFrequencies for that profiles.

In the template use :

EXPORTS

profileNames = cells,plot,voxels exportFrequencies = 10,10,10

hip_CC <- define_hisafe(path = Dossier_local, template = paste(way_template,Nom_template[i], sep = ""), profiles = c("cells","plot","voxels"), SimulationName = Nom_simu[i], nbSimulations = 5 ) Result :

EXPORTS

profileNames = cells,plot,voxels exportFrequencies = 1,1,1

If you didn't specifie the argument profiles in define_hisafe(), it will use the default values of profiles and exportFrequencies for that simulation.

` hip_CC <- define_hisafe(path = Dossier_local, template = paste(way_template,Nom_template[i], sep = ""), SimulationName = Nom_simu[i], nbSimulations = 5 ) '

Result in .sim of the simulation folder

EXPORTS

profileNames = cells,climate,plot,trees,voxelsMonth exportFrequencies = 1,1,1,1,30

kevinwolz commented 4 years ago

Ah, yes, I see now where it is overwritten. See #143 for the beginnings of a solution to this.