tdeswaef / aquacroponr

R package with wrapper functions for AquaCrop
https://tdeswaef.github.io/aquacroponr/
Other
2 stars 1 forks source link

Issue simulating perennial crops #1

Open emdigman opened 1 year ago

emdigman commented 1 year ago

Firstly, I wanted to express my gratitude to you for making this R package, as I have been learning how to run simulations in AquaCrop, but I do not have the familiarity with Python needed to easily learn how to use the AquaCrop python package. Thank you very much for your work!

I have been trying to use the package to run a simulation for perennials. I have tried to use this package with the test dataset provided by the FAO AquaCrop repository here for simulating the cultivation of Alfalfa in Ottowa, Canada.

I have tried changing different variables, and the problem appears to be with the crop file used in this case. When I run the aquacrop_wrapper function using the original CRO file for alfalfa from the FAO repository, I recieve the following error:

test_ottowa_01 <- aquacrop_wrapper(param_values = list(),
+                             situation = "S_ottowa",
+                             cycle_length = 180,
+                             model_options = list(AQ = AQ, defaultpar = crop_alfalfa_ottowa, output = "def"))
Error in `dplyr::mutate()`:
ℹ In argument: `digitvalues = format(values, digits = 1, nsmall = digits, scientific = F, quote = F)`.
ℹ In row 84.
Caused by error in `prettyNum()`:
! invalid 'nsmall' argument

I have checked the crop file, and the 'row 84' the error is referring to is the first set of values for the 'internal crop calendar' section of the CRO file, which the read_CRO function does not appear to recognise correctly. If I delete the 'internal crop calendar' section of the crop file (so that row 83 is the final row of data), I instead recieve this error:

> test_ottowa_01 <- aquacrop_wrapper(param_values = list(),
+                             situation = "S_ottowa",
+                             cycle_length = 180,
+                             model_options = list(AQ = AQ, defaultpar = crop_alfalfa_ottowa_2, output = "def"))
Error in `map()`:
ℹ In index: 1.
Caused by error in `dplyr::mutate()`:
ℹ In argument: `CRa = CR_fun(SAT, FC, WP, Ksat) %>% .$CRa`.
Caused by error in `if (PWP >= 20) ...`:
! argument is of length zero

I wanted to ask, is there a way to solve this error in the package? Does the package currently support simulation of perennial crops such as alfalfa? And does the package automatically simulate using growing degree-days if this value is marked on the CRO file? Any support you could provide with this error would be much appreciated - sorry if I have not documented something clearly enough, I am a beginner to using R.

Many thanks,

Edward D.

tdeswaef commented 1 year ago

Hi Edward,

Thanks for your question. It is true that the package is not yet able to cope with perennial crops that are harvested multiple times. I should dive into the specificities of how AquaCrop deals with this type of crop. At the moment, I don't have much time to work on this, although it should be included in the future. Would you like to contribute on this specific aspect of the package?

Cheers, Tom