APSIMInitiative / ApsimX

ApsimX is the next generation of APSIM
http://www.apsim.info
Other
132 stars 161 forks source link

Implementing heat stress in maize using manager scripts #8513

Open LenLon opened 9 months ago

LenLon commented 9 months ago

What is your question?

Hello everyone,

I am trying to make the switch to ApsimX from Classic due to the relative ease with which it can be used on HPCs for parallel and remote operationalisation compared to Classic, and would like to investigate heat stress in maize under future climate change.

As the heat stress formulation in Classic has not yet been implemented in ApsimX, I wanted to do it myself, which seems to be at least possible for wheat.

I'd like to "port over" the heat stress response of grain number that is implemented in Classic as described here, which is an accumulative average weighted by thermal time under stress in maize's flowering phase.

Now the issue I see is that the maize model parameters are now embedded in ApsimX's source code (whic I base on this thread instead of a model-specific .xml file, so can I even change any parameters using the manager? [Maize].Grain is not available in the manager script window. I have found a PotentialGrainNumber variable in the maize model structure, at least, pointing to a [MaximumGrainsPerCob] which seems to be settable in the cultivar parameters [Grain].MaximumGrainsPerCob.FixedValue = xxx

Another issue is that I have never written a manager script, and the required syntax of C# in general (which ChatGPT might be able to help me with) and ApsimX specifically is new to me. Without a console it is quite difficult to poke at objects to see what they contain and what methods do (such as DateUtilities and such). What I am doing at the moment is looking at the scripts available through the manager toolbox and Frankensteining whatever works together. I have not figured out a way to report the variables in my manager script either which would greatly help with testing

I'd be glad for any pointers (should I even do this / stay with Classic?) or code snippets I can use. This is what I have so far:

using Models.Core;
using Models.Functions;
using Models.Interfaces;
using Models.PMF;
using APSIM.Shared.Utilities;

  namespace Models
  {
      [Serializable]
      public class Script : Model
      {
          [Link] Plant maize;
          [Link] IWeather weather;

          [EventSubscribe("DoManagement")]
          private void DailyTimestep(object sender, EventArgs args)
          {
            string stage = maize.Phenology.CurrentStageName;

              if (stage == "Flowering" && weather.MaxT >= 32)
              {
                  double heatMultiplier = -435.86 + 37.87 * weather.MaxT - 1.10 * Math.Pow(weather.MaxT, 2) + 0.01 * Math.Pow(weather.MaxT, 3);  // interpolated cubic response function  of heat stress response table 

                  Constant grain_number = (Constant)FindByPath("[Maize].Grain.MaximumGrainsPerCob").Value;
                  grain_number.FixedValue = grain_number.FixedValue * heatMultiplier;

                  // how to get grain_number to show up in report?

                  // how to change MaximumGrainsPerCob? I feel like I am just reading it and then changing my own declared variable instead
              } 
          }
      }
  }
BrianCollinss commented 9 months ago

If you are interested in porting the heat-stress manager script that was developed for wheat/sorghum in APSIM Classic (https://www.sciencedirect.com/science/article/pii/S0168192319305052), I may be of help. I have done some preliminary work but did not get the chance to finish it.

LenLon commented 8 months ago

Hello Brian,

I'd be super glad! I have also found this thread where @par456 provided some I think really useful info for changing cultivar parameters on the fly.

If you have any preliminary code we can use to implemement the cumulative averaging I'd be happy to use it!

Best, Lennart

BrianCollinss commented 8 months ago

Hello Lennart. The heat-shock module that was developed for wheat and sorghum in APSIM Classic has a different approach. You can find the details in the paper I shared the link of. Happy to help if you have decided this is what you need.

LenLon commented 8 months ago

Thanks, I will have a deep look! I heard that the values for the maize temperature response table are sourced from a study on Sorghum anyway, namely this one: Singh et al 2017

LenLon commented 8 months ago

Hello @BrianCollinss , I finally read through the paper and the approach seems quite similar, so I'd be happy to implement it as best as we can and adapt it for maize!

I assume this is the equation we are talking about:

image

Summing over tillers for maize is not necessary so could be scrapped. The rest seems very close to an accumulative (summing Fstage over days) weighted (which is what Fstage is, a weighing or sensitivity factor around anthesis) "average" (dividing fTmax by number of days of exposure, in this case fixed at 7). The response function we could adapt using values for the heat stress implemented in Apsim Classic Maize.

Does this seem sensible?

BrianCollinss commented 8 months ago

Yes. I have done most of the work but it was a while ago so I might not be able to ooen the file using the latest version of GUI. I has to make some adjustments to adapt the algorithm to how NextGen works. In Classic, the impact on Seed Weight was calculated at the end. That needed to be changed as its not possible to do without using a manager script.

Please do remind me if I forgot to send you my file.

LenLon commented 8 months ago

Great!

Did you mean to send it already? If so, then you did forget, if not, when should I remind you?

LenLon commented 8 months ago

Hey @BrianCollinss, how is it coming along?

I'd be happy to help and try implement whatever is present at the moment :-)

I had a cursory read through the github forum and the Holzworth 2021 paper on ApsimX, and I found out that you apparently can replace the Maize model and adapt it using the PMF framework (like here ). Might this be a valid approach? Or should one rather use the approach by @par456 where one modifies a heat-sensitive cultivar using a manager script?

I really don't have any idea what happens WHEN in the maize model though, so modifying the [MaximumGrainsPerCob] value might be overwritten by some other process, though it currently seems it is only used in the NFillingRate function:

image

BrianCollinss commented 8 months ago

Sorry for my late reply. Could you please send me an email so I can send you a file in private? brian.collins@unisq.edu.au

stale[bot] commented 6 months ago

This issue has been automatically marked as stale because it has not had any activity in the last 30 days. It will be closed in one week if no further activity occurs. Thank you for your contributions.

BrianCollinss commented 5 months ago

Hey @LenLon . Wondering how your work is going.