It is sometimes useful to analyze the fitting process by simple visualization tools. This is possible by the RTModel.plotmodel subpackage, which also includes the possibility to show an animation of the fitting process.
Note that the functions in this section access the PreModels/ directory. It is not possible to see the animation of the fit if you have not decided to keep this directory by the cleanup = False option and turned on step chain saving by stepchainsave = Trueas explained in Preliminary Models.
Suppose you want to see how the binary-lens fit from the initial condition 190 works for the event /event001. The following code will visualize the step chain of the Levenberg-Marquardt fits in the (s,q) plane:
import RTModel.plotmodel as plm
eventname = '/event001'
model = 'LS0190'
parameter1 = 0
parameter2 = 1
plm.plotchain(eventname,model,parameter1,parameter2)
The output will look like this
The plotchain() function shows the chains of steps taken by the Levenberg-Marquardt fit from the initial condition to the minima found. The blue line is the first fit, while the following fits after the bumping mechanism described in Fitting are shown with different colors. Each minimum is marked by a filled circle. The parameter space is identified by the two values given as parameter1,parameter2. The order of parameters is the one specified in Model categories.
The fit process can be animated by the following code
stepchainfile = 'PreModels/LS0190-stepchain0.dat'
plm.plotmodel(eventname = eventname, modelfile = stepchainfile, printpars = False, animate = 1,interval = 800)
The output is a gif file ani.gif generated in the directory /event001 which looks like this
The individual frames are contained in a subdirectory /tmpssteps.
The plotmodel() function works in the same way as illustrated in Plot model. The additional options we see here with their default values are the following:
animate = 0: If non-zero, an animated gif is generated. This only works with files containing a sequence of models line by line, as the step chains generated by theLevMarmodule described in Fitting.interval = 1000: The time interval in milliseconds between frames in the generated gif.
If you want to show the gif file in a Jupyter notebook you may use the following lines:
from IPython.display import Image
Image(filename = 'figs/ani.gif')

