Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In which xml we can add organic amendment? #2262

Open
eelsaf opened this issue Nov 28, 2024 · 4 comments
Open

In which xml we can add organic amendment? #2262

eelsaf opened this issue Nov 28, 2024 · 4 comments

Comments

@eelsaf
Copy link

eelsaf commented Nov 28, 2024

I am simulating scenarios in APSIM classic for oil palm. I wonder which xml file contains the script for adding organic amendment or reducing surface residue from frond removal and litter.
I have explored some XML files, such as SOM, SoilN, PalmManagement, Management, and OilPalm, but I could not find them.
Please advice.

Thank you

@peter-devoil
Copy link
Collaborator

You can add material to the SOM pools with some manager code , and similarly, a tillage event will incorporate it. A tillage with depth=0 indicates to burn the material

@eelsaf
Copy link
Author

eelsaf commented Dec 10, 2024

Thank you peter-devoil for the guide.
I tried to modify as follow :

library(apsimr)

Define the APSIM file and working directory

apsimFile <- "Sim_mmda_ssp585_uksem1.apsim" # Replace with the actual path
apsimWd <- getwd() # Use the current working directory

Define the EFB application script

efb_script <- "
if year >= 5 and today = date('01-may') then
surfaceom add_surfaceom name=EFB, type=labile, mass=30000, cnr=30, cpr=80, standing_fraction=0.
endif
"

Add the EFB script under the 'Palm Management' manager's 'start_of_day' event

newFile <- edit_apsim(
file = apsimFile,
wd = apsimWd,
var = "manager[@name='Palm Management']/script[event='start_of_day']", # Corrected XPath
value = list(efb_script),
overwrite = FALSE # Save to a new file
)

Rename and save the modified file

Define the new file name (appending "_modif_EFB" to the original file name)

newApsimFile <- gsub(".apsim", "_modif_EFB.apsim", apsimFile)

Rename the modified APSIM file

Make sure the path to newFile is absolute or relative correctly to avoid errors

file.rename(newFile, newApsimFile)

Run the simulation with the modified file

apsimExe <- "C:/Program Files (x86)/APSIM710-r4221/Model/Apsim.exe" # Replace with the actual path to APSIM.exe
results <- apsim(
exe = apsimExe,
wd = apsimWd,
files = newApsimFile
)

Save results to a CSV file

resultsFile <- gsub(".apsim", "_results.csv", newApsimFile)
write.csv(results, resultsFile, row.names = FALSE)

Print the results to verify

print(results)
But seems, not working because I cannot find the exact "var" for manager code.

@peter-devoil
Copy link
Collaborator

Replacing the entire management text may be a bit heavy handed - perhaps there's a way to put some parameters on the script (eg dd-mmm for operation) and manipulate just those parameters?

@eelsaf
Copy link
Author

eelsaf commented Dec 11, 2024

Replacing the entire management text may be a bit heavy handed - perhaps there's a way to put some parameters on the script (eg dd-mmm for operation) and manipulate just those parameters?

Dear Peter-devoil, can you give some example, technically how can we do that using either edit the xml on inifile on APSIM classic or edit through apsimr in R. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants