Closed Clzuy closed 1 year ago
The sugarcane model doesn't have a structure to show because it isn't written the same way as the other plant models. It is a direct port of the sugarcane model from the older APSIM 7.10.
Considering we've had this question a few times now, it might be worth having some sort of feedback when expanding sugercane that explains this.
The sugarcane model doesn't have a structure to show because it isn't written the same way as the other plant models. It is a direct port of the sugarcane model from the older APSIM 7.10. So if I want to change the sugarcane crop parameters, can I only use APSIM classic, or are there other ways to achieve this in APSIM NEXT GENERATION?
You can do this from an operations model like this:
2023-01-01 [sugarcane].PARAMNAME = xxx
Where PARAMNAME is the name of the variable and the date should be the date (yyyy-mm-dd) of the start of your simulation. After you press the '.' character it should bring up an intellisense menu that lists the available variables you can access. I suspect though that most variables are NOT accessible because the sugarcane model was ported a while ago and hasn't had a lot of use in Next Gen. The model needs a bit of refactoring to make it more usable.
Q: What crop parameters do you want to change?
You can do this from an operations model like this:
2023-01-01 [sugarcane].PARAMNAME = xxx
Where PARAMNAME is the name of the variable and the date should be the date (yyyy-mm-dd) of the start of your simulation. After you press the '.' character it should bring up an intellisense menu that lists the available variables you can access. I suspect though that most variables are NOT accessible because the sugarcane model was ported a while ago and hasn't had a lot of use in Next Gen. The model needs a bit of refactoring to make it more usable.
Q: What crop parameters do you want to change?
The parameters are shown in the following figure, and I want to modify those parameters. Then I have another question, where is the input position of this parameter? Thank you for your reply.
RUE is a parameter that we don't normally change. It isn't a cultivar parameter. The value of RUE is considered a constant that should work across genetics, environments and managements.
I've had a quick look at the code. Changing these isn't currently possible. We will need to make some changes in APSIM before you can continue. Notes for us:
c# private CropConstants crop;
c# private CultivarConstants cult;
Next week we will be back on APSIM maintenance so we'll see if we can find time to fix this.
RUE is a parameter that we don't normally change. It isn't a cultivar parameter. The value of RUE is considered a constant that should work across genetics, environments and managements.
I've had a quick look at the code. Changing these isn't currently possible. We will need to make some changes in APSIM before you can continue. Notes for us:
- [ ] Make line 1154 public:
c# private CropConstants crop;
- [ ] Make line 1175 public:
c# private CultivarConstants cult;
- [ ] Write an example manager script to show how to change the variables.
Next week we will be back on APSIM maintenance so we'll see if we can find time to fix this.
Thank you very much for taking the time to answer me. I look forward to hearing the good news that you have fixed the issue.
Once the pull request #8427 has been merged the attached example has a manager script called "Change Sugarcane Params" that can be used. The manager script shows how to change the parameters at the start of the simulation. sugarCaneExample.zip
Once the pull request #8427 has been merged the attached example has a manager script called "Change Sugarcane Params" that can be used. The manager script shows how to change the parameters at the start of the simulation. sugarCaneExample.zip
Hi, I have opened it in my APSIM desktop, but I do not know how to use it. I does not show the current parameter values for the varieties available in the model or a list of possible parameters. How do I know the full list of possible parameters and how to I actually use this script for changing values? Is there a specific position that this management script should be on the tree? Should the parameters tab be blank like this?
I do not have parameters that I am interested in changing. I would like to be able to reproduce workflows from previous studies done using APSIM and to learn from them. Parameters I have seen previous authors changed were: shoot_lag, tt_emerg_to_begcane, Tb and leaf area profile.
Kind regards, Isis
@daSilva5
You need to paste the script down below, other parameters also like this: using System; using Models.Core; using Models.Interfaces; using Models.PMF;
namespace Models { [Serializable] [System.Xml.Serialization.XmlInclude(typeof(Model))] public class Script : Model { [Link] private IClock Clock; [Link] private Sugarcane Sugarcane; [Link] private ISummary Summary;
[Description("rue:")]
public double[] rue { get; set; } = new double[] { 0.0, 0.0, 1.8, 1.8, 1.8, 0.0 }; // 初始化为指定数值的数组
[EventSubscribe("StartOfSimulation")]
private void OnStartOfSimulation(object sender, EventArgs e)
{
Summary.WriteMessage(this, "StartOfSimulation event triggered.", MessageType.Information);
var plant = Sugarcane.plant as SugarcaneSpeciesConstants;
plant.rue = rue;
Summary.WriteMessage(this, $"rue values set at start: {string.Join(", ", plant.rue)}", MessageType.Information);
}
[EventSubscribe("DoManagement")]
private void OnDoManagement(object sender, EventArgs e)
{
var plant = Sugarcane.plant as SugarcaneSpeciesConstants;
Summary.WriteMessage(this, $"rue values during simulation: {string.Join(", ", plant.rue)}", MessageType.Information);
}
[EventSubscribe("EndOfSimulation")]
private void OnEndOfSimulation(object sender, EventArgs e)
{
var plant = Sugarcane.plant as SugarcaneSpeciesConstants;
Summary.WriteMessage(this, $"rue values at end of simulation: {string.Join(", ", plant.rue)}", MessageType.Information);
}
}
}
@daSilva5
You need to paste the script down below, other parameters also like this: using System; using Models.Core; using Models.Interfaces; using Models.PMF;
namespace Models { [Serializable] [System.Xml.Serialization.XmlInclude(typeof(Model))] public class Script : Model { [Link] private IClock Clock; [Link] private Sugarcane Sugarcane; [Link] private ISummary Summary;
[Description("rue:")] public double[] rue { get; set; } = new double[] { 0.0, 0.0, 1.8, 1.8, 1.8, 0.0 }; // 初始化为指定数值的数组 [EventSubscribe("StartOfSimulation")] private void OnStartOfSimulation(object sender, EventArgs e) { Summary.WriteMessage(this, "StartOfSimulation event triggered.", MessageType.Information); var plant = Sugarcane.plant as SugarcaneSpeciesConstants; plant.rue = rue; Summary.WriteMessage(this, $"rue values set at start: {string.Join(", ", plant.rue)}", MessageType.Information); } [EventSubscribe("DoManagement")] private void OnDoManagement(object sender, EventArgs e) { var plant = Sugarcane.plant as SugarcaneSpeciesConstants; Summary.WriteMessage(this, $"rue values during simulation: {string.Join(", ", plant.rue)}", MessageType.Information); } [EventSubscribe("EndOfSimulation")] private void OnEndOfSimulation(object sender, EventArgs e) { var plant = Sugarcane.plant as SugarcaneSpeciesConstants; Summary.WriteMessage(this, $"rue values at end of simulation: {string.Join(", ", plant.rue)}", MessageType.Information); } }
}
Thank for your answer. I think you understood what I would like to do. I have some further questions.
Where within Apsim next gen should I paste this script?
If I want to change parameters in other modules, do I just replace "[Link] private Sugarcane Sugarcane" by "[Link] private Surface Organic Matter Surface Organic Matter" or "[Link] private Soil Soil"?
I can see that this coding does not follow the same variable names that there were in APSIM classic XML files. I think Sugarcane.plant is referring to plant crop? Do you know how I expose these variable names for APSIMNext gen, so I can identify variable names correctly?
Also, if I can run this script within a given simulation in APSIMNext gen, does it mean I confine these configurations just to that simulation, and it would not affect others? Because it would be really great!
Kind regards
@daSilva5 Hello, here's how it works:
You can paste the script into the "Script" section of the example above, similar to the screenshot shown. Then, you can copy and paste this management plugin into your APSIM-Sugarcane model for use.
APSIMX can be accessed through this link, where you can view the Models-Resources-Sugarcane.json
file. You can also download it for easier access.
As far as I know, modifying the parameters of the management plugin will only affect the current file you're using and won't impact the system files. If you have experience, you can open the model file with software like VS Code to view the modified parameters and code.
If you want to modify other parameters, using R can be more effective, or you can use Factorial. Modifying RUE in this way is necessary because RUE is not a crop variety parameter in the APSIM-Sugarcane module, so it cannot be directly modified.
Hi, @Clzuy
I was really lost about how to do the connection between that json files and the manager scripts. I still need to understand this coding language better. But now I can see the way. Understanding how to do the modifications, I can paste it in any manager script tab and just rename the manager. The ultimate goal is to run these simulations with the new manager scripts in R.
Really, thank you so much for all of it!
Hi,@daSilva5 In fact, soil parameters and normal adjustable sugarcane variety parameters can be controlled through the Factorial module in APSIM or using the rapsimng and apsimx R packages. Parameters like RUE and shoot_lag that you're using need to be controlled via Script, while others like tt_emerg_to_begcane can be directly adjusted without using Script. The genetic parameters of the sugarcane module are directly transplanted from APSIM Classic, so they're quite different from other crops. It took me nearly a month of exploration to partially understand it. If you have any questions or confusion, please feel free to ask me, and I'll share everything I know.
Hi,@daSilva5 In fact, soil parameters and normal adjustable sugarcane variety parameters can be controlled through the Factorial module in APSIM or using the rapsimng and apsimx R packages. Parameters like RUE and shoot_lag that you're using need to be controlled via Script, while others like tt_emerg_to_begcane can be directly adjusted without using Script. The genetic parameters of the sugarcane module are directly transplanted from APSIM Classic, so they're quite different from other crops. It took me nearly a month of exploration to partially understand it. If you have any questions or confusion, please feel free to ask me, and I'll share everything I know.
Hi @Clzuy , how do you access the cultivars parameters to edit in R? Despite being able to expose them and edit in the desktop, I have tried variations of inspect_apsimx("Sugarcane.apsimx", src.dir = ex_dir, node = "Other", parm = list("Crop", "Sugarcane")) in R, but no success to expose the node.
Cheers, Isis
@daSilva5 Hi, it is a little complicated. I would share the R code and the apsimx.exe to you. The root is inspect_apsimx_replacement("sugarRuan1004Opt.apsimx", src.dir = extd.dir,
node = "Sugarcane",
node.child = "Cultivars",
node.subchild = "clzuy",
root = list("Models.Core.Folder", 1),
verbose = FALSE)
The cultivar must be set in the replacement module. Please note that I have add a cultivar which is named clzuy. You can change it to the regular cultivar.
Besides the root to parameter is very interesting. Some must add a blank space. while others must add the cult. xx. I will provide you with the specific paths of the parameters I have used. Please pay attention to their differences. Additionally, please do not directly open apsimx.exe, as this will automatically overwrite the various sugarcane variety files that I have pasted from elsewhere. Instead, please open, review, and modify the content using VS Code or similar text editors. Otherwise. you can see the document for some help. https://femiguez.github.io/apsimx-docs/
exam.zip
@daSilva5 Hi, it is a little complicated. I would share the R code and the apsimx.exe to you. The root is inspect_apsimx_replacement("sugarRuan1004Opt.apsimx", src.dir = extd.dir, node = "Sugarcane", node.child = "Cultivars", node.subchild = "clzuy", root = list("Models.Core.Folder", 1), verbose = FALSE) The cultivar must be set in the replacement module. Please note that I have add a cultivar which is named clzuy. You can change it to the regular cultivar. Besides the root to parameter is very interesting. Some must add a blank space. while others must add the cult. xx. I will provide you with the specific paths of the parameters I have used. Please pay attention to their differences. Additionally, please do not directly open apsimx.exe, as this will automatically overwrite the various sugarcane variety files that I have pasted from elsewhere. Instead, please open, review, and modify the content using VS Code or similar text editors. Otherwise. you can see the document for some help. https://femiguez.github.io/apsimx-docs/ exam.zip
Hi,
I really appreciate it. I did not think that the .apsimx needed to be modified in this way. Just going through https://femiguez.github.io/apsimx-docs/ I did not have this impression, and I did not try to open the .apsimx file in the example to see the code. But now I realize that inspect_apsimx_replacement does not work with the common .apsimx examples.
I also realize now that by opening some of the available .apsimx from other users with apsimx.exe to try to see what the modifications were, I might be overwriting their useful modifications.
Thank you so much for sharing all that!
What is your question?
I haven’t clicked on “Show model structure” yet, but it is already in the open mode by default, but there is no corresponding module below.