femiguez / apsimx

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

Error when using edit_apsim_replace_soil_profile with ISRIC soils #127

Open mkGoe opened 11 months ago

mkGoe commented 11 months ago

Hi there,

I used the get_isric_soil_profile function to retrieve soil profiles for multiple locations. When I then try running the function 'edit_apsim_replace_soil_profile' for a '.apsim' file by using:

edit_apsim_replace_soil_profile(file = "ISCRIC.apsim", soil.profile = soil_AB, overwrite = TRUE, verbose = FALSE)

I get :
Error in !missing(soilwat) || !is.na(soil.profile$soilwat) : 'length = 18' in coercion to 'logical(1)'

This is how the soil looks like: grafik

I dont know how to fix this error. Thank you very much for your help.

Kind regards, Mareike

femiguez commented 11 months ago

Can you please provide a reproducible example? Have you looked at this:

https://femiguez.github.io/weather_soil_databases/Weather_Soil_Inputs_APSIM.html

mkGoe commented 11 months ago

Hi, Yes I looked at the package documentation, but I couldnt find a hint to the problem. Please find below the zipped R script and the .apsim file

ISCRIC soil sim.zip

Thanks a lot!

gabrielhintz commented 11 months ago

@femiguez I am having the same problem.

femiguez commented 11 months ago

I will look at this next week :)

femiguez commented 11 months ago

@gabrielhintz The error message is confusing and I will look into improving this. The package tries to make it easy to edit APSIM files from R, but it can't do magic. :)

This code works for me, but I would be careful about the resulting APSIM simulation. Soil Grids does provide some parameters but others are just used as defaults, which is not ideal if you are trying to create point simulations.

### Get soil 
x <- 3.1
y<- 45.8

soil <- get_isric_soil_profile(lonlat = c(x,y),             
                               find.location.name = FALSE)  

 # Replace soil profile

swat <- soilwat_parms()
## We need to add the crop names
soil$crops <- c("wheat", "barley", "oats", "canola", "chickpea")

edit_apsim_replace_soil_profile(file = "ISCRIC.apsim",
                                                       soil.profile = soil,
                                                      soilwat = swat,
                                                     overwrite = TRUE, verbose = FALSE)

I don't know if this runs as I can't test it right now.

Also, another comment is that you should not have spaces in your paths. In the R script you sent me there are, so rename your folders to eliminate spaces. This will not allow you to run APSIM Classic simulations from R.

mkGoe commented 10 months ago

Thank you for the tip with the spaces in the folders.

When runnig this code I get this error: _Error in readapsim(file = output.names, src.dir = src.dir, value = value) : object 'skip.out.lines' not found

femiguez commented 1 month ago

I'm coming back to this example. Since I don't do much work with Classic, I neglected it. The example provided does not run on APSIM 7.10-r4221. If either of you can provide an example and let me know which version of APSIM you are running I should be able to test it. Thanks!