Remarks:
• Each time the fit is executed the fit results will be appended to the file result.dat. If
result.dat doesn’t exist yet it will be created.
• It is very important to create the fit object exactly in the way:
var fit:DoasFit = new DoasFit;
fit=DoasFit.Open(fitfile);
Otherwise, the fit coefficients can not be accessed. The reason is unclear.
• Each fit result (fit coefficient, shift, squeeze, chi square...) can be individually accessed.
The approach is similar to displaying the fit coefficient in the example above. For more
information about fit results of the different reference spectra search for “DoasFitRefer-
enceInfo” in the Programming Documentation of DOASIS (Help menu - Programming
Documentation). For properties of the fit itself (like fit range, polynomial...) search
for “DoasFit”.
• If you want to display e.g. the shift value of the second spectrum of the fit scenario
the command would be:
var shift;
shift = fit.ReferencesInfo[1].Shift;
Console.WriteLine(shift);
The entry “0” of the fit.ReferencesInfo-Array refers to the first spectrum from the top,
the entry “1” to the second...
Examples for other properties:
–
Squeeze:
fit.ReferencesInfo[1].Squeeze;
–
Fit coefficient error:
fit.ReferencesInfo[1].FitCoefficientError;
–
Chi Square:
fit.ChiSquare;
• If you don’t want to fit against the active spectrum but instead load a spectrum from
a file and fit against that spectrum, make use of the commands described in section
8.9.
11.4
Modifying a fit scenario with JScript
At first it has to be mentioned that so far it is not possible to create a fit scenario solely
with JScript. An existing fit scenario has to be loaded and can then be modified. Another
important aspect is, that the number of spectra in the fit scenario cannot be changed via
JScript. Hence, if a the loaded fit scenario consists of three spectra, it is neither possible
to delete one spectrum nor to add one spectrum. In the Fitting window of DOASIS it is
easily possible to activate and deactivate spectra manually from the fit scenario by ticking
the box in front of the according reference spectrum (see Fig. 11.1). This should be possible
in JScript as well, but in reality unfortunately it isn’t (so far).
The
example
presented
here
loads
an
existing
fit
scenario
from
C:
\scripttest\fitscenario.fs and overwrites the first spectrum of the fit scenario with
the spectrum from C:\scripttest\testspec.sp2. The file name of the this first spectrum
of the fit scenario is displayed in the Output window before and after the change to verify
that the new spectrum was actually implemented. Afterwards the limit parameters for the
shift (in channels) of the first spectrum of the fit scenario are set from 2 (Low) to 4 (High)
59
Figure 11.1: Fitting window of DOASIS. By ticking the boxes (marked by the red circle)
reference spectra can be activated and deactivated for the fit. This is not possible with
JScript.
Figure 11.2: Fit reference properties window. It can be activated by double clicking on
the reference spectrum in the Fitting window. The marked parameters are set within the
JScript. The default value of the shift parameter has to be in between the limit parameters.
It constitutes the starting value of the numerical calculations for the shift within the given
boundaries.
60
with 3 being the default value. See Fig. 11.2. The fit range is set from 300 to 600 channels.
Finally the fit scenario is saved as C:\scripttest\newfitscenario.fs. Before running
the script make sure that a fit scenario with at least one reference spectrum exists under
C:
\scripttest\fitscenario.fs and a spectrum is available from C:\scripttest\testspec.sp2.
import System;
import DoasCore.Spectra;
import DoasCore.Math;
// create an empty spectrum called "Spectrum"
var MeasSpec :
ISpectrum = Specbar.GetSpectrum("Spectrum");
var fitfile = "C:
\\scripttest\\fitscenario.fs";
var fit:
DoasFit = new DoasFit();
// open the spectrum
MeasSpec.Open("C:
\\scripttest\\testspec.sp2");
// open the fit scenario
fit = DoasFit.Open(fitfile);
// display the file name of the first spectrum of the fit scenario
Console.WriteLine("Old file name:
"+fit.ReferencesInfo[0].ReferenceSpectrum.FileName);
// replace the first spectrum of the fit scenario by the spectrum "MeasSpec"
fit.ReferencesInfo[0].ReferenceSpectrum = MeasSpec;
// display the new file name of the replaced spectrum
Console.WriteLine("New file name:
"+fit.ReferencesInfo[0].ReferenceSpectrum.FileName);
// set the low limit for the shift
fit.ReferencesInfo[0].SetCoefficientLowLimit(DoasFitReferenceInfo.Coefficients.Shift,2);
// set the default value for the shift
fit.ReferencesInfo[0].SetCoefficientDefault(DoasFitReferenceInfo.Coefficients.Shift,3);
// set the high limit for the shift
fit.ReferencesInfo[0].SetCoefficientHighLimit(DoasFitReferenceInfo.Coefficients.Shift,4);
// activate the hard limits for the shift, be aware that the command covers 3 lines
fit.ReferencesInfo[0].SetCoefficientMode
(DoasFitReferenceInfo.Coefficients.Shift,
DoasFitReferenceInfo.CoefficientMode.LimitHard);
// set the fit range
fit.FitRanges[0].LimitLow = 300;
fit.FitRanges[0].LimitHigh = 600;
// save the modified fit scenario, "DoasFit.Save()" returns "true", if saving
// was successful, if not, "false" is returned
if(DoasFit.Save(fit, "C:
\\scripttest\\newfitscenario.fs"))
{
Console.WriteLine("Fit scenario saved!");
}
else
{
Console.WriteLine("Error while saving!");
}
After the script is executed the modified fit scenario can be opened in DOASIS from
C:
\scripttest\newfitscenario.fs and the newly implemented spectrum will appear to-
61