Jscript Tutorial Wolfgang Unger and Tobias Sommer



Yüklə 0,62 Mb.
Pdf görüntüsü
səhifə14/21
tarix07.11.2018
ölçüsü0,62 Mb.
#78679
1   ...   10   11   12   13   14   15   16   17   ...   21

Chapter 11

Evaluating spectra

11.1

Offset and Dark Current Correction



Open the spectrum, that you want to correct and make sure, that you have an offset and a

dark current spectrum in the folder that is specified in the code.

import Systme;

import DoasCore.Spectra;

import DoasCore.Math;

// store active spectrum in the variable Meas

var Meas :

ISpectrum = Specbar.CurrentSpectrum;

// Open two empty spectra sheets called Offset and DarkCurrent

var Offset:

ISpectrum = Specbar.GetSpectrum("Offset");

var DC: ISpectrum = Specbar.GetSpectrum("Darkcurrent");

// Load the two spectra in the empty spectra sheets

Offset.Open("C:

\\scripttest\\offset.sp2");

DC.Open("C:

\\scripttest\\darkcurrent.sp2");

// Do the Offset and DarkCurrent correction

SpecMath.CorrectOffset(Meas,Offset);

SpecMath.CorrectDarkCurrent(Meas,DC);

Remarks

• The offset correction will be done by subtracting the offset spectrum scan weighted.



The dark current correction will be done by subtracting the dark current spectrum

scan time weighted.

What is actually done in mathematical sense when calling the correction routines is

explained in detail in the DOASIS Tutorial, section 8.1.2: Spectrum Operations.

• Make sure that the dark current spectrum you use has already been offset corrected!

55



11.2

Offset and Dark Current Correction with a “JScript

project file”

In 9 it was strongly recommended to structure JScript programs by using so called JScript

project files. A concrete example will be given here. The functionality will be exactly the

same as 11.1.

11.2.1

Preparation



Create the three folders C:\scripttest\generally, C:\scripttest\correct and C:\scripttest\darkspectra.

In C:\scripttest\darkspectra, save a dark current spectrum as darkcur.sp2 and an offset

spectrum as offset.sp2.

11.2.2


The “project file“

The project file looks like this:

C:

\\scripttest\\generally\\variables.js



C:

\\scripttest\\generally\\functions.js

C:

\\scripttest\\correct\\maincorrect.js



Save the project file as C:\scripttest\correct\correct.jsp.

The three JScript files variables.js, functions.js and maincorrect.js have to be defined now.

11.2.3

The file variables.js



The file variables.js includes all “namespaces”, that have to be imported, all variables, which

are used and it is recommended to specify the different locations, where spectra can be found,

too.

import System;



import DoasCore.Spectra;

import DoasCore.Math;

var darkpath = "C:

\\scripttest\\darkspectra\\";

var DarkCurrentName = "darkcur.sp2";

var OffsetName = "offset.sp2";

var Meas :

ISpectrum;

var Offset:

ISpectrum;

var DC: ISpectrum;

var Spectr:

ISpectrum;

As mentioned already in 8.11, the declaration of the type “ISpectrum” is not absolutely

necessary.

Save variables.js as C:\scripttest\generally\variables.js.

56



11.2.4

The file functions.js

All common functions are defined in the file functions.js. Offset and Dark Current Correc-

tion are one of the most frequent functions and will therefore be specified here.

function CorrectOffset(Spectr)

{

SpecMath.CorrectOffset(Spectr,Offset);



}

function CorrectDC(Spectr)

{

SpecMath.CorrectDarkCurrent(Spectr,DC);



}

Object orientated programming:

The content of the file functions.js is a typical example for object orientated programing.

Functions are defined, than can be called later in the main routine. The theory of object

orientation is quite complex, but the basic meaning should already become clear by studying

the file maincorrect.js.

Save functions.js as C:\scripttest\generally\functions.js.

11.2.5


The file maincorrect.js

Meas = Specbar.CurrentSpectrum;

Offset = Specbar.GetSpectrum("Offset");

DC = Specbar.GetSpectrum("Darkcurrent");

Offset.Open(darkpath+OffsetName);

DC.Open(darkpath+DarkCurrentName);

CorrectOffset(Meas);

CorrectDC(Meas);

In the lines

CorrectOffset(Meas);

CorrectDC(Meas);

the functions from the file functions.js are called. The argument, which is passed, is a spec-

trum, in this case, the spectrum “Meas”.

Save maincorrect.js as C:\scripttest\correct\maincorrect.js.

Now, in the “Script”-window of DOASIS, correct.jsp can be called from the folder C:\scripttest\correct

and the script will be executed.

57



11.3

Fitting with JScript

This example does the same, as if you opened a spectrum and a fit scenario in DOASIS and

then executed the fit. All properties of the fit, like fit range and reference spectra are stored

in the fit scenario. So all you need to run the script is to open a spectrum manually in

DOASIS and make it the active spectrum (see Fig. 1.1). This will be the spectrum against

which will be fitted. Make sure that it is offset and dark current corrected (see section 11.1)

and that the logarithm has been taken. Apart from that, a fit scenario file has to be stored

as c:\scripttest\fitscenario.fs.

The program runs the fit, shows the fit result and displays the fit coefficient of the first

spectrum in the fit scenario in the Output window. Another example for fitting is presented

in section 7.2.3.

import System;

import DoasCore.Spectra;

// necessary for the DoasFit class

import DoasCore.Math;

// store active spectrum in variable MeasSpec

var MeasSpec :

ISpectrum = Specbar.CurrentSpectrum;

// open an empty spectrum sheet with the title "FitResult"

// in which the fit result will be shown later

var ResultSpec :

ISpectrum = Specbar.GetSpectrum("FitResult");

var fitfile = "c:

\\scripttest\\fitscenario.fs";

// open fit scenario

var fit:DoasFit = new DoasFit;

fit=DoasFit.Open(fitfile);

// execute the fit, DoFit returns "true" if the fit was succesfull

if(fit.DoFit(MeasSpec))

{

// display message for successful fit



Console.WriteLine("Fit successful!");

// display the fit result windows in the spectrum "ResultSpec"

fit.PrepareFitResultSpectrum(ResultSpec);

// display the fit results an the active spectrum sheet

Specbar.CurrentSpectrum = ResultSpec;

// display the fit coefficient of the first reference spectrum

Console.WriteLine("Fit Coefficient:

"+fit.ReferencesInfo[0].FitCoefficient)

// write fit results into file

fit.AppendResultToFile("c:

\\scripttest\\result.dat");

}

else



{

System.Console.WriteLine("Error while fitting!");

}

58



Yüklə 0,62 Mb.

Dostları ilə paylaş:
1   ...   10   11   12   13   14   15   16   17   ...   21




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə