femiguez / apsimx

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

How to only extracte water stress from APSIM? #84

Closed lyfranki closed 2 years ago

lyfranki commented 2 years ago

Hi @femiguez ,

In my research, I would only care about the stage before the end of juvenile, which is dominated by temperature and water stress. In that way, I can simulate phenology only if I have daily temperature data and water stress data from my understanding. However, water stress is related to different components in APSIM. If I want to calculate daily water stress, I might need to have a high-level understanding of APSIM. In your opinion, do you think whether it is feasible to calculate water stress by myself using python through understanding the source code of APSIM? Or it may be a better and easier way to simulate phenology before the end of juvenile using APSIM directly?

Thanks, Yin

lyfranki commented 2 years ago

Or is there any way that we can only extract daily water stress, just like your designed function tt_apsim_met ?

femiguez commented 2 years ago

Before the end of juvenile I would not expect for a crop to experience much water stress. Unless this is a very dry environment in which you are dependent on rainfall for germination and emergence. Depending on your objective, emulating APSIM is possible, but not my first choice in general. You could re-write the development routines from APSIM in a different language or environment, but that is not what this package is about. The goal of this package is to be able to run APSIM from R and perform a large number of potential operations and manipulations. APSIM is suitable for fairly complex farming management, if you need something simple, there are many alternatives that might suit your needs better.

lyfranki commented 2 years ago

Yes, you are right. Although a crop won't experience much water stress before the end of juvenile, we hope that we can achieve our objective with higher accuracy and more robust context support. Emulating APSIM is not my first choice in general, either. I have to rewrite many related subroutines to calculate water stress. It is time-consuming. My goal is to estimate duration between planting date and end of juvenile. Do you think whether it is a good idea if I only edit the MET data and soil profile data for each pixel over a large scale (Like a state) and simulate the duration from fixed sowing date to end of juvenile for each pixel using APSIM? I won't use the manager's sowing rule to find the sowing date but use the fixed sowing date as input. Thanks for your suggestion and patience! Yin

femiguez commented 2 years ago

There are almost always trade-offs with different decisions. Creating a loop over a grid (as long as it is relatively small) will get the job done and you could even consider different parallelization strategies if it takes too long. Have you seen this tutorial about changing the APSIM inputs? https://femiguez.github.io/weather_soil_databases/Weather_Soil_Inputs_APSIM.html This strategy would allow for a fairly simple run of APSIM "on a grid", but simply rewriting that code inside a loop. I would give this idea a try and let me know if you have any feedback about the package.

lyfranki commented 2 years ago

Thanks a lot! I have not seen this tutorial before. It seems very efficient to my objective! One more question, do you have any idea about how to edit the EndofJuvenile thermal time parameter? Like, set it as 185 degree days.

femiguez commented 2 years ago

You can edit crop parameters by changing the corresponding xml file in Classic or the replacement in Next Gen. There are functions in the package to do that. 'edit_apsim_xml' for Classic and 'edit_apsimx_replacement' for Next Gen.

lyfranki commented 2 years ago

It works! But I am still struggling with the .apsimx files. I am not sure whether maize-manager-edited.apsimx considers water stress when simulating phenology. Or all simulation in apsim/apsimx will consider the influence of water stress? Do you have any idea about that? And do you know where to find the look-up table for VariableNames. Like if I want to get daily soil-water information, I can add "[Soil].SoilWater.SWmm" into the following part? But I have no idea about the other variable names.

"VariableNames": [ "[Clock].Today", "[Weather].Rain", "[Maize].Phenology.CurrentStageName", "[Maize].AboveGround.Wt", "[Maize].AboveGround.N", "[Maize].Grain.Wt", "[Maize].Grain.Size", "[Maize].Grain.N", "[Maize].Leaf.Transpiration", "[Maize].Leaf.LAI", "[Maize].Leaf.LAITotal", "[Maize].Phenology.FloweringDAS", ]

Thanks for your patience! Thank you, Fernando!

femiguez commented 2 years ago

APSIM will always estimate water stress when there is a crop. If you open the file using the GUI you get some guidance related to the available output variables. There is more information in the documentation for each individual model. https://apsimnextgeneration.netlify.app/modeldocumentation/ . The variable for leaf water stress is [Maize].Leaf.Fw for example. I don't know why you started with the 'maize-manager.apsimx' as your template, but if it works...

lyfranki commented 2 years ago

Thanks, Fernando! Thanks for your help these two days!

lyfranki commented 2 years ago

Hi Fernando,

I got another question. Do you have any idea how to simulate BBCH, just like the phenology simulation, May 1st = germination? I noticed there is a part which is about BBCH. Can I just add a variable into the second code and show the simulation of BBCH? I am working on the example of MaizeSoybean.apsimx.

  {
                  "$type": "Models.PMF.Phen.BBCH, Models",
                  "Name": "BBCH",
                  "Children": [],
                  "Enabled": true,
                  "ReadOnly": false
}
"VariableNames": [
                "[Clock].Today",
                "[Maize].Phenology.CurrentStageName",
                "[Maize].AboveGround.Wt",
                "[Weather].Rain",
                "[Maize].Total.Wt",
                "[Maize].Leaf.Fw",
                "[Soil].SoilWater.ESW",
                "[Soil].SoilWater.SWmm"
              ],
              "EventNames": [
                "[Clock].EndOfDay"
              ],

Thanks, Yin

femiguez commented 2 years ago

I think you want

[Maize].Phenology.BBCH.Stage