femiguez / apsimx

R package for APSIM-X
https://femiguez.github.io/apsimx-docs/
45 stars 19 forks source link

Error running APSIMx files #117

Closed Janewanguimugo closed 6 months ago

Janewanguimugo commented 1 year ago

I am no longer able to run any apsimx simulations even those that come with package. What could be the error? For example this returns an error extd.dir <- system.file("extdata", package = "apsimx") sim <- apsimx("Wheat.apsimx", src.dir = extd.dir, value = "report")

Error in read_apsimx(file = sub("apsimx$", "db", file), src.dir = src.dir, : There are no .db files in the specified directory to read. In addition: Warning message: In system(cmd, intern = intern, wait = wait | intern, show.output.on.console = wait, : running command 'C:\WINDOWS\system32\cmd.exe /c C:\PROGRA~1\APSIM2023.2.7166.0\bin\Models.exe C:\Users\Admin\AppData\Local\R\win-library\4.2\apsimx\extdata\Wheat.apsimx' had status 32908

femiguez commented 1 year ago

@Janewanguimugo Did you update APSIM? There are some problems with versions from 2023. I have no problems running the latest versions from 2022

Janewanguimugo commented 1 year ago

The error occurred today, everything was alright before. How can I install an older version?

On Mon, 27 Feb 2023, 5:09 pm Fernando Miguez, @.***> wrote:

@Janewanguimugo https://github.com/Janewanguimugo Did you update APSIM? There are some problems with versions from 2023. I have no problems running the latest versions from 2022

— Reply to this email directly, view it on GitHub https://github.com/femiguez/apsimx/issues/117#issuecomment-1446387859, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYYCGN4HHHXMW4VBYTMZ7Z3WZSYTLANCNFSM6AAAAAAVJMQZD4 . You are receiving this because you were mentioned.Message ID: @.***>

femiguez commented 1 year ago

From the APSIM download page select an older version of the software. You might need to increase the number of entries shown

Janewanguimugo commented 1 year ago

Thank you it worked. On a different matter is there an issue with the soil download (get_isric_soil_profile())? I am trying to download soils for 800 points to do a spatial simulation. I get results of my simulation in some points and errors in others. eg. an issue with soil LL in one site and maybe soil SAT in another. Is there any way to get the correct soil without errors?

femiguez commented 1 year ago

The version in github has an option 'fix' that will try to correct these errors before they are detected by APSIM. Set 'fix' to TRUE (default is FALSE). Let me know if that works

Janewanguimugo commented 1 year ago

Which command do I use/add the fix = TRUE?

On Tue, 28 Feb 2023, 5:39 pm Fernando Miguez, @.***> wrote:

The version in github has an option 'fix' that will try to correct these errors before they are detected by APSIM. Set 'fix' to TRUE (default is FALSE). Let me know if that works

— Reply to this email directly, view it on GitHub https://github.com/femiguez/apsimx/issues/117#issuecomment-1448299461, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYYCGN4KEJMNCBQYAJ5ASU3WZYEYTANCNFSM6AAAAAAVJMQZD4 . You are receiving this because you were mentioned.Message ID: @.***>

Janewanguimugo commented 1 year ago

When I used fix = TRUE, I am running potato simulations btw...I got results for approximately 500 locations, the others still have soil issues. Does it mean I now have to fix the unique issues one by one? Or is there any way to get the correct soil for the 800 points at once.

femiguez commented 1 year ago

What does the error message look like? I could include code that addresses this issue before you run the simulations

Janewanguimugo commented 1 year ago

It's a soil issue when I check in the GUI. I have attached the file for the location with an error...most locations have no issues. The error when running in R is the one below.

Error in read_apsimx(file = sub("apsimx$", "db", file), src.dir = src.dir, : No report tables found In addition: Warning message: In system(cmd, intern = intern, wait = wait | intern, show.output.on.console = wait, : running command 'C:\WINDOWS\system32\cmd.exe /c C:\PROGRA~1\APSIM2022.12.7129.0\bin\Models.exe .\PotatoFactorialFebMAr.apsimx' had status 1

PotatoFactorialFebMAr.zip

femiguez commented 1 year ago

The problem is that LL can't be lower than AirDry. I have made this change to my 'fix' function, but it is not public yet. You can try using it

fix_apsimx_soil_profile <- function(x, soil.var = c("SAT", "BD"), particle.density = 2.65, verbose = TRUE){

  if(!inherits(x, "soil_profile"))
    stop("object should be of class 'soil_profile'", call. = FALSE)
  ## Heuristics for fixing soil profiles

  soil.var <- match.arg(soil.var)

  ## Bulk density and saturation issue
  max_bd <- (1 - x$soil$SAT) * 2.65
  bd_diff <- max_bd - x$soil$BD

  for(j in seq_along(max_bd)){
    if(bd_diff[j] <= 0){
      x$soil$SAT[j] <- 1 - x$soil$BD[j] / 2.65 - 0.001
      if(verbose && soil.var == "SAT"){
        cat("Saturation of:", x$soil$SAT[j], "in layer:", j, "was above acceptable value of:", 1 - x$soil$BD[j] / 2.65, ".",
            "It was adjusted to:", 1 - x$soil$BD[j] / 2.65 - 0.001, "\n")              
      }
      ## Fixing LL and air dry issue
      if(x$soil$LL15 < x$soil$AirDry){
        if(verbose){
          cat("LL15 cannot be lower than AirDry in layer:", j,".\n",
              "It was adjusted to the value of AirDry.\n")
        }
        x$soil$LL15[j] <- x$soil$AirDry[j]
      }
    }
  }
  return(x)
}
Janewanguimugo commented 1 year ago

Thank you, I shall give it a try

On Thu, 30 Mar 2023, 8:27 pm Fernando Miguez, @.***> wrote:

The problem is that LL can't be lower than AirDry. I have made this change to my 'fix' function, but it is not public yet. You can try using it

fix_apsimx_soil_profile <- function(x, soil.var = c("SAT", "BD"), particle.density = 2.65, verbose = TRUE){

if(!inherits(x, "soil_profile")) stop("object should be of class 'soil_profile'", call. = FALSE)

Heuristics for fixing soil profiles

soil.var <- match.arg(soil.var)

Bulk density and saturation issue

max_bd <- (1 - x$soil$SAT) * 2.65 bd_diff <- max_bd - x$soil$BD

for(j in seq_along(max_bd)){ if(bd_diff[j] <= 0){ x$soil$SAT[j] <- 1 - x$soil$BD[j] / 2.65 - 0.001 if(verbose && soil.var == "SAT"){ cat("Saturation of:", x$soil$SAT[j], "in layer:", j, "was above acceptable value of:", 1 - x$soil$BD[j] / 2.65, ".", "It was adjusted to:", 1 - x$soil$BD[j] / 2.65 - 0.001, "\n") }

Fixing LL and air dry issue

  if(x$soil$LL15 < x$soil$AirDry){
    if(verbose){
      cat("LL15 cannot be lower than AirDry in layer:", j,".\n",
          "It was adjusted to the value of AirDry.\n")
    }
    x$soil$LL15[j] <- x$soil$AirDry[j]
  }
}

} return(x) }

— Reply to this email directly, view it on GitHub https://github.com/femiguez/apsimx/issues/117#issuecomment-1490668761, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYYCGN6EEHHE4LXMPV4SRU3W6W7BTANCNFSM6AAAAAAVJMQZD4 . You are receiving this because you modified the open/close state.Message ID: @.***>

Janewanguimugo commented 1 year ago

Hello, So I used the fix function and now I am encountering new issues. Kindly see the attached file, it is a soil issue as well. The issue keeps changing depending on the site.

example_file.zip

femiguez commented 6 months ago

@Janewanguimugo Have you been able to figure this out? There are some issues which pertain to APSIM Next Gen, which are not related to the apsimx R package. I know there is an issue with initial water. I'm going to close this to concentrate on other issues. Let me know if you still need help