femiguez / apsimx

R package for APSIM-X

Home Page:https://femiguez.github.io/apsimx-docs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when using edit_apsim_replace_soil_profile with ISRIC soils

mkGoe opened this issue · comments

commented

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

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

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

commented

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!

@femiguez I am having the same problem.

I will look at this next week :)

@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.

commented

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

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

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!

I'm closing this due to inactivity. Please submit another issue and I can test it. Thanks!