APSIMInitiative / ApsimX

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

Is it possible to update state variables daily and contine the simulation? #4028

Closed ShiruiH closed 4 years ago

ShiruiH commented 5 years ago

I'm trying to assimilate remote sensing data into APSIM model. Basically, the outputs of the model (like LAI, soil moisture) will be updated at the end of a day with some external observations, and the updated variables will be used as the initial values for the simulation of the next day.
Is it possible to modify the source code to pause the simulation, update some variables and continue the simulation? If it is, should I write a module to implement it? Or if this can be realised with writing some manager scripts in ApsimX? Or is there any other possible ways?

hol353 commented 5 years ago

I think you could do this quite easily from a manager script. To update variables on a particular day:

if (clock.Today == new DateTime(2019,31,1)) { update the variables you want. }

This will work with some variables e.g. soil water but not others. For some crops, LAI is a calculated variable and is not settable. Some crops use a cohorting leaf model where leaves are tracked through time. In this case, LAI is calculated from leaf area of each leaf cohort. Not really possible to set a value of LAI.

ShiruiH commented 5 years ago

@hol353 Thanks for you suggestions. Updating variables with manager script is the best way to deal with a single model running. But data assimilation has a different situation. It requires to run the model ensembly.
Let's take soil moisture (SM) as an example here. Ensemble running means the model runs for hundreds of times simultaneously (with some parameters perturbed). And when the observations available, the ensemble SM (hundreds of SM values as a whole) is taken out and adjusted with the observations (through some assimilation methods). Then we will get the updated ensemble SM (each of the SM value may have changed), and these new SM values need to be put back to the ensemble models (each SM back to the model where they came from respectively). The whole process is a little bit different from updating state variables for a single model running, and I will have a bunch of available observations, updating the model one by one is not a good way.
For this situation, could you enlight me with some other suggestions? I know we can batch run the models using command line, and I know how to set the factorial when initialising APSIM. But I have no idea if we can dynamically update the ensemble models while they are running (especially we have to calculate the updated values during the model runs). Thanks in advance.

hol353 commented 5 years ago

Sorry I don't understand your middle paragraph. Your terminology appears different to my understanding. e.g. What is 'ensemble SM' and 'put back to the ensemble models' mean?

A single APSIM simulation reads inputs, runs a simulation and writes outputs. The inputs can be soil moisture observations for 1 or more days and they can be in an input file that APSIM reads and updates its state on those days. Lots of people write Python or R scripts to run an ensemble of APSIM simulations (millions of simulations) asynchronously, perturbing the inputs based on previous model outputs.