kevinwolz / hisafer

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

add filter to plot_hisafe_xxx when variable is not present in cropType #149

Open ThomasGendron opened 4 years ago

ThomasGendron commented 4 years ago

Hey,

I don't know if my message will be useful but we never know.

In the case of using plot_hisafe_ts() with cells profile, some variables calculated for interCrop.

When using the function without using facet.crop = TRUE, the mean of selected variable on the scene lead to difference between agroforestry and monocrop situation.

For example :

image

image

This two figures don't lead to the same interpretation but just the second is correct.

I don't know if the issue come from hisafe who don't calculate nitrogenMicrobe of the soil in intercrop (that's strange for all the mineralisation process...).

What's your opinion on it ?

kevinwolz commented 4 years ago

Can you share the simulation folders of a reprex?

ThomasGendron commented 4 years ago

Sorry , a reprex ?

I can share the three simulation folder corresponding to monocrop, agroforestry and forestry simulation.

Guillaume-Blanchet commented 4 years ago

reprex = REPRoducible EXample

So ideally a folder with a minimal structure with a piece of code that will reproduce the bug you are facing. This way, Kevin can directly face the issue as well. Look here if you want an example.

ThomasGendron commented 4 years ago

It's not a bug rather a mistake in calculating mean for some variables. Mistake induce by no calculation of hisafe on InterCrop cells for that variables

read_hisafe_example is a reprex ? they are "example" in this name

`` face <- read_hisafe_example()

plot_hisafe_ts(hop = face, variables = "nitrogenMicrobes", profile = "cells") plot_hisafe_ts(hop = face, variables = "nitrogenMicrobes", profile = "cells", facet.crop = TRUE) plot_hisafe_ts(hop = face, variables = "nitrogenMicrobes", profile = "cells", facet.simu = TRUE)

face_cell_filter <- face$cells %>% filter( cropType == "interCrop" & SimulationName == "agroforestry" ) plot( x = face_cell_filter$Date, y = face_cell_filter$nitrogenMicrobes )

face_cell_filter <- face$cells %>% filter( cropType == "mainCrop" & SimulationName == "agroforestry" ) plot( x = face_cell_filter$Date, y = face_cell_filter$nitrogenMicrobes ) ``

kevinwolz commented 3 years ago

@ThomasGendron maybe I do not understand the mistake you are describing, but I do not see a problem here. Here is my check to see if facet_simu = TRUE is working as expected:

face <- read_hisafe_example()
af <- hop_filter(hop = face, simu.names = "agroforestry")

together <- plot_hisafe_ts(hop = af, variables = "nitrogenMicrobes", profile = "cells", plot = FALSE) %>%
  dplyr::mutate(cropType = "Scene mean")

separate <- plot_hisafe_ts(hop = af, variables = "nitrogenMicrobes", profile = "cells", facet.crop = TRUE, plot = FALSE)

dat <- dplyr::bind_rows(together, separate)

ggplot(dat, aes(x = Date, y = nitrogenMicrobes, color = cropType)) +
  geom_line() +
  theme_hisafe_ts()

image

To me, this looks correct. The mean of nitrogenMicrobes across the scene (facet.simu = FALSE) is slightly lower than the value for mainCrop alone because of the interCrop cells that have 0 values bringing down the mean.

Now, all that said, I agree that nitrogenMicrobes = 0 in the interCrop seems weird, but that's not a problem of hisafer.

What do you think?