Author |
Topic  |
|
g.aliev@ba1
UK
7 Posts |
Posted - 01/04/2003 : 01:02:20 AM
|
Hi everybody,
Happy New Year!
I am trying to fit a multi-peak curve using a user-defined function as a sum of two (or more) standard functions: Lorentz and Gauss, for example.
Fitting is going on very well but I cannot provide automatic plotting of decomposed graphs of these functions with current parameters during iteration procedure (or finally) like in the case of usual multi-peak fitting procedure.
I tried to solve the problem using before-fitting and after-fitting scripts in NLSF but still with partial success. Is there NLSF object like nlsf.fitWksName$ that returns name of current Graph (or Layer) where fitting procedure is going on?
I am using Origin 6.1 sr4.
Thanks,
Gazi
|
|
easwar
USA
1965 Posts |
Posted - 01/04/2003 : 10:32:52 PM
|
Hi Gazi,
The LabTalk string variable %h (name of the active window) points to the graph window when NLSF is performing fitting. For example, even if you had a worksheet window active, once you start the fitting process, NLSF sets the active window to be the graph window (it creates a graph of the fitting data if there was no graph to start with).
Now, if your graph has multiple layers and you are fitting in one of the layers, you can get the specific layer number using a script statement such as il = %h!page.active which will put the layer number into the variable il.
Easwar OriginLab.
Edited by - easwar on 01/04/2003 10:37:34 PM |
 |
|
g.aliev@ba1
UK
7 Posts |
Posted - 01/07/2003 : 07:29:38 AM
|
Hi Easwar,
thank you for your answer. Now I am using the following after-fitting script:
%R=%H; /*remember the graph's name*/ %Q=nlsf.fitWksName$; /*remember the worksheet's name*/ %X=nlsf.x$; /*remember the X-column's name*/ win -a %Q; /*activate worksheet*/ worksheet -v lorentz1; /*create a new column in the active wks*/ col(lorentz1)=y0+(2*A1/PI)*(w1/(4*(%X-xc1)^2 + w1^2)); /*calculate lorentz*/ worksheet -v gauss2; col(gauss2) = y0+(A2/(w2*sqrt(PI/2)))*exp(-2*((%X-xc2)/w2)^2); /*calculate gauss*/ win -o %R {layer -i200 %Q_lorentz1; set %Q_lorentz1 -c 3;}; /*plot lorentz, line, green*/ win -o %R {layer -i200 %Q_gauss2; set %Q_gauss2 -c 4;}; /*plot gauss, line, blue*/ win -a %R; /*activate graph*/
Is there any possibility to execute the script in between iteration steps, before the end of fitting?
Thanks, Gazi
|
 |
|
Laurie
USA
404 Posts |
Posted - 01/07/2003 : 10:29:03 AM
|
Hi Gazi,
You could use part of your script in the function definition. In other words, you would need to set the Form drop-down list to Y-script.
You would want to use the rest of your script in the Before Fitting Scripts. (This will create the columns and include them in the layer...then during the fitting process the curves will be drawn in the graph and the data in these columns will update during the iterative process.)
I would use the following in the Before Fitting Scripts:
%Q=nlsf.fitWksName$; /*remember the worksheet's name*/ %X=nlsf.x$; /*remember the X-column's name*/ %Q!wks.addcol(lorentz1); %Q!wks.addcol(gauss2); layer -i200 %Q_lorentz1; set %Q_lorentz1 -c 3; layer -i200 %Q_gauss2; set %Q_gauss2 -c 4;
Add the following to the function definition:
%Q_lorentz1=y0+(2*A1/PI)*(w1/(4*(%X-xc1)^2 + w1^2)); /*calculate lorentz*/ %Q_gauss2 = y0+(A2/(w2*sqrt(PI/2)))*exp(-2*((%X-xc2)/w2)^2); /*calculate gauss*/
Try this and let us know how it works.
Thanks, Laurie
OriginLab Technical Support |
 |
|
g.aliev@ba1
UK
7 Posts |
Posted - 01/07/2003 : 2:51:13 PM
|
Hi Laurie,
thank you for your advice.
I have tried to follow your recommendations but still have got no success.
1)It seems to me that initialization script is executed only once. In this case we cannot expect any updating of the columns during iterative process.
2) If we wont replace the data in the columns it is better to my opinion to use win -o %Q {work -v lorentz1; work -v gauss2;}; instead %Q!wks.addcol(lorentz1); %Q!wks.addcol(gauss2);
3)I am not sure that expression %Q_lorentz1=y0+(2*A1/PI)*(w1/(4*(%X-xc1)^2 + w1^2)); in the function definition gives any result because, as I understand, at first, it must be x instead %X and, second, fitting process is resuling in the temporary worksheet YFIT. By the way, if I delete the x-column in the worksheet XFIT, the corresponding x-column in the %Q-worksheet disappears.
Gazi
|
 |
|
Laurie
USA
404 Posts |
Posted - 01/07/2003 : 4:59:21 PM
|
Hi Gazi,
Yes, the initialization script gets executed once, so it is here that we create the two new columns, gauss and lorentz, and add them to the layer. At this point, the datasets do not have any data, so you will not see anything plotted. During the iterative process, you will fill these columns as follows:
%Q_lorentz1=y0+(2*A1/PI)*(w1/(4*(X-xc1)^2 + w1^2)); /*calculate lorentz*/ %Q_gauss2 = y0+(A2/(w2*sqrt(PI/2)))*exp(-2*((X-xc2)/w2)^2); /*calculate gauss*/
And, yes, you're right - you use X and not %X.
Now you will see the two plots drawn on the graph. If it still does not work, then send me your fitting function FDF file.
Thanks.
OriginLab Technical Support |
 |
|
g.aliev@ba1
UK
7 Posts |
Posted - 01/08/2003 : 05:43:29 AM
|
Hi Lauri,
It does not work. I have sent you the working (after fitting) FDF file.
Gazi. |
 |
|
Laurie
USA
404 Posts |
Posted - 01/15/2003 : 3:30:16 PM
|
Hi Gazi,
Thanks for sending me your files. I've discussed this with others here and the correct way to calculate lorentz and gauss is in the After Fitting Script.
You should ignore my suggestion of moving this to the function definition. This significantly slows down the fitting since the definition gets executed twice per each data point per iteration.
What you're looking for is an "On Parameter Change" script for animation purpose. We do not yet have support for this.
Thanks, Laurie
OriginLab Technical Support |
 |
|
g.aliev@ba1
UK
7 Posts |
Posted - 01/16/2003 : 10:21:25 AM
|
Hi Laurie,
thanks for your reply. Now another problem (bug) arose. The "save project" option is not working properly after fitting procedure finished. Error message:
Origin could not back up the previous version of the file! The file was NOT saved! The problem may be due to disk being full. Would you like to continue with saving the file? This may fail unless you first free up some space on the disk. YES/NO
My disk is definitely not full. In the same time "Save project as..." option works properly.
I am working under Windows NT4.
Thanks, Gazi |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 01/16/2003 : 4:32:01 PM
|
Hi Gazi,
Just as a hunch, go to Tools...Options...Open/Close tab and uncheck the "Backup project before saving" box. Then try Save Project again.
Mike Buess Origin WebRing Member |
 |
|
g.aliev@ba1
UK
7 Posts |
Posted - 01/17/2003 : 11:52:40 AM
|
Hi Mike,
you are right. Now, of course, the "save project" button works properly because now Origin don't try to buck up any file. But why fitting procedure destroys this option?
Thanks, Gazi |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 01/17/2003 : 12:03:33 PM
|
Gazi,
I'll bet your project was saved the first time despite the error message (which only refers to the backup). I remember something like this happening to someone else over a year ago, but can't remember the details now.
Mike Buess Origin WebRing Member |
 |
|
g.aliev@ba1
UK
7 Posts |
Posted - 01/20/2003 : 08:13:29 AM
|
Mike,
you are right again. My project was saved but it was saved with another name and in another (Origin) folder, not in the folder where was the saving file. And every saving procedure creates a new file with a strange name.
Gazi |
 |
|
|
Topic  |
|