Author |
Topic  |
|
antar
Posts |
Posted - 04/16/2006 : 09:45:58 AM
|
Origin Version: OriginPro Student 7.5 Operating System: Windows XP
I've automated some code to create scatter plots of displacements due to Brownian motion for eight separate timesteps, fit these plots with Gaussean curves, and then plot their widths squared versus the timestep.
When it works, it's great, since it saves me between 15 minutes and half an hour of analysis time per trial.
Unfortunately, it keeps crashing on me, usually around plot 4 or 5. My guess is it's the nonlinear fitting, and I've tried everything, from restarting the fitting session each time to just giving the system time to breathe (as in, putting in a pause).
The pausing seems to help, but even extending it to five seconds between plottings, Origin STILL crashes on exit.
I updated to Service Patch 6--still no help.
I can post the code, if it would be helpful. |
|
easwar
USA
1965 Posts |
Posted - 04/16/2006 : 10:20:21 PM
|
Hi,
Please send your data/OPJ and code to tech support so they can trace the problem.
Easwar OriginLab
|
 |
|
antar
Posts |
Posted - 04/16/2006 : 11:19:49 PM
|
How do I get in touch with TechSupport?
And, technically, I don't even know if they can help me yet, since I just installed the Student version and haven't emailed them my student ID yet.
So how about if I post the code?
quote:
void binsAnalysis() { //declare worksheet stuff Worksheet wks; WorksheetPage wp; PageBase pb; //declare more variables double width ; double werr ; using NLSF = LabTalk.NLSF; // Point to the NLSF object //get active window pb = Project.Pages(); wp = (WorksheetPage) pb; wks = (Worksheet) wp.Layers(0); string wksName = wp.GetName();
//declare graph stuff GraphPage grphData ; GraphLayer grphLayer ; string strYDataName ; //declare curves Curve curve0(wks, 0, 1); curve0.GetName(strYDataName[0]); Curve curve1(wks, 0, 2); curve1.GetName(strYDataName[1]); Curve curve2(wks, 0, 3); curve2.GetName(strYDataName[2]); Curve curve3(wks, 0, 4); curve3.GetName(strYDataName[3]); Curve curve4(wks, 0, 5); curve4.GetName(strYDataName[4]); Curve curve5(wks, 0, 6); curve5.GetName(strYDataName[5]); Curve curve6(wks, 0, 7); curve6.GetName(strYDataName[6]); Curve curve7(wks, 0, 8); curve7.GetName(strYDataName[7]); NLSF.init(); // Initialize the fitter for (int i=0; i<8; i++) {//plot scatters, fit gauss curve and take note of widths //plot scatters grphData[i].Create("Origin"); grphLayer[i] = grphData[i].Layers(); if (i == 0) grphLayer[i].AddPlot(curve0, IDM_PLOT_SCATTER); if (i == 1) grphLayer[i].AddPlot(curve1, IDM_PLOT_SCATTER); if (i == 2) grphLayer[i].AddPlot(curve2, IDM_PLOT_SCATTER); if (i == 3) grphLayer[i].AddPlot(curve3, IDM_PLOT_SCATTER); if (i == 4) grphLayer[i].AddPlot(curve4, IDM_PLOT_SCATTER); if (i == 5) grphLayer[i].AddPlot(curve5, IDM_PLOT_SCATTER); if (i == 6) grphLayer[i].AddPlot(curve6, IDM_PLOT_SCATTER); if (i == 7) grphLayer[i].AddPlot(curve7, IDM_PLOT_SCATTER); grphLayer[i].Rescale(); //fit gauss NLSF.Func$ = "gauss"; NLSF.begin(); NLSF.FitData$ = strYDataName[i]; NLSF.Execute("parainit"); NLSF.fit(100); //take note of width (and error) width[i] = NLSF.p3; werr[i] = NLSF.e3; NLSF.end(0); LT_execute("second -p 5"); //debug - give the system time to "breathe" } //create w^2 vs tau worksheet //declare worksheet stuff Worksheet wksWidths; wksWidths.Create("widths"); Dataset DataTau(wksWidths,0); DataTau.SetSize(8); Dataset DataWidths(wksWidths,1); DataWidths.SetSize(8); Dataset DataErr(wksWidths,2); DataErr.SetSize(8); Dataset Dataw2(wksWidths,3); Dataw2.SetSize(8); Dataset DataErr2(wksWidths,4); DataErr2.SetSize(8); double k; for (int j=0; j<8; j++) {//get and compute data k = j; DataTau[j] = (k+1)/30; DataWidths[j]=width[j]; DataErr[j]=werr[j]; Dataw2[j] = width[j]*width[j]; DataErr2[j] = 2*(werr[j]/width[j])*(width[j]*width[j]); } //declare graph stuff GraphPage grphWidths; GraphLayer widthLayer; Curve widthCurve(wksWidths,0,3); Column errBar(wksWidths, 4); //graph w^2 vs tau grphWidths.Create("WidthGraph"); widthLayer = grphWidths.Layers(); widthLayer.AddPlot(widthCurve, IDM_PLOT_SCATTER); widthLayer.AddErrBar(widthCurve, errBar); widthLayer.Rescale(); //linear fitting needs to be done by hand }
|
 |
|
zachary_origin
China
Posts |
Posted - 04/18/2006 : 04:19:32 AM
|
Hi,antar: I have rewritten the code as follows, and I have tested it with a worksheet that the data is imported from ..Origin$\Samples\Data\Gaussian.dat.(..Origin$ is the install folder of the Origin) and then copied it to eight columns. It works well.
For your fitting data, I cann't be sure whether this function also works well because if the data don't conform to the Gaussian model, it will throw out errors during the fitting. You'd better send your data to us and we can test on it. (send mail to: tech@originlab.com ).
Zachary Huang OriginLab GZ office.
--------------------------------------------------------------------
void binsAnalysis_2() { WorksheetPage wp = Project.Pages(); Worksheet wks = wp.Layers(0); Dataset ds; if( !wks ) return; using NLSF = LabTalk.NLSF; vector vWidths; vWidths.SetSize(8); vector vErrors; vErrors.SetSize(8); string strName;
for(int ii = 0; ii < 8; ii ++) { ds.Attach(wks, ii); ds.GetName(strName); Curve cvData; cvData.Attach(wks, ii); GraphPage gp;//create a new graph page to plot the original data gp.Create(); GraphLayer glData = gp.Layers(); glData.AddPlot(cvData, IDM_PLOT_SCATTER); NLSF.begin(); NLSF.init(); NLSF.cleanupfitdata(); NLSF.Func$ = "gauss"; NLSF.fitdata$ = strName; NLSF.Execute("parainit"); NLSF.p1=0; // NLSF.p2=25; // NLSF.fit(100); LT_execute("rescale()"); vWidths[ii] = NLSF.p3; vErrors[ii] = NLSF.e3; NLSF.end(); ds.Detach(); } int nW = wks.AddCol();//Here, add two columns to the original worksheet to store the widths int nE = wks.AddCol();// and errors Dataset dsW2( wks, nW ); Dataset dsE2( wks, nE ); dsW2 = vWidths ^2; dsE2 = vErrors ^2; GraphPage gp;//create a new graph page to plot the widths gp.Create(); GraphLayer gl = gp.Layers(); Curve cvW2(wks, nW); gl.AddPlot(cvW2, IDM_PLOT_SCATTER); gl.AddErrBar(cvW2, wks.Columns(nE) ); gl.Rescale(); }
quote:
How do I get in touch with TechSupport?
And, technically, I don't even know if they can help me yet, since I just installed the Student version and haven't emailed them my student ID yet.
So how about if I post the code?
quote:
void binsAnalysis() { //declare worksheet stuff Worksheet wks; WorksheetPage wp; PageBase pb; //declare more variables double width ; double werr ; using NLSF = LabTalk.NLSF; // Point to the NLSF object //get active window pb = Project.Pages(); wp = (WorksheetPage) pb; wks = (Worksheet) wp.Layers(0); string wksName = wp.GetName();
//declare graph stuff GraphPage grphData ; GraphLayer grphLayer ; string strYDataName ; //declare curves Curve curve0(wks, 0, 1); curve0.GetName(strYDataName[0]); Curve curve1(wks, 0, 2); curve1.GetName(strYDataName[1]); Curve curve2(wks, 0, 3); curve2.GetName(strYDataName[2]); Curve curve3(wks, 0, 4); curve3.GetName(strYDataName[3]); Curve curve4(wks, 0, 5); curve4.GetName(strYDataName[4]); Curve curve5(wks, 0, 6); curve5.GetName(strYDataName[5]); Curve curve6(wks, 0, 7); curve6.GetName(strYDataName[6]); Curve curve7(wks, 0, 8); curve7.GetName(strYDataName[7]); NLSF.init(); // Initialize the fitter for (int i=0; i<8; i++) {//plot scatters, fit gauss curve and take note of widths //plot scatters grphData[i].Create("Origin"); grphLayer[i] = grphData[i].Layers(); if (i == 0) grphLayer[i].AddPlot(curve0, IDM_PLOT_SCATTER); if (i == 1) grphLayer[i].AddPlot(curve1, IDM_PLOT_SCATTER); if (i == 2) grphLayer[i].AddPlot(curve2, IDM_PLOT_SCATTER); if (i == 3) grphLayer[i].AddPlot(curve3, IDM_PLOT_SCATTER); if (i == 4) grphLayer[i].AddPlot(curve4, IDM_PLOT_SCATTER); if (i == 5) grphLayer[i].AddPlot(curve5, IDM_PLOT_SCATTER); if (i == 6) grphLayer[i].AddPlot(curve6, IDM_PLOT_SCATTER); if (i == 7) grphLayer[i].AddPlot(curve7, IDM_PLOT_SCATTER); grphLayer[i].Rescale(); //fit gauss NLSF.Func$ = "gauss"; NLSF.begin(); NLSF.FitData$ = strYDataName[i]; NLSF.Execute("parainit"); NLSF.fit(100); //take note of width (and error) width[i] = NLSF.p3; werr[i] = NLSF.e3; NLSF.end(0); LT_execute("second -p 5"); //debug - give the system time to "breathe" } //create w^2 vs tau worksheet //declare worksheet stuff Worksheet wksWidths; wksWidths.Create("widths"); Dataset DataTau(wksWidths,0); DataTau.SetSize(8); Dataset DataWidths(wksWidths,1); DataWidths.SetSize(8); Dataset DataErr(wksWidths,2); DataErr.SetSize(8); Dataset Dataw2(wksWidths,3); Dataw2.SetSize(8); Dataset DataErr2(wksWidths,4); DataErr2.SetSize(8); double k; for (int j=0; j<8; j++) {//get and compute data k = j; DataTau[j] = (k+1)/30; DataWidths[j]=width[j]; DataErr[j]=werr[j]; Dataw2[j] = width[j]*width[j]; DataErr2[j] = 2*(werr[j]/width[j])*(width[j]*width[j]); } //declare graph stuff GraphPage grphWidths; GraphLayer widthLayer; Curve widthCurve(wksWidths,0,3); Column errBar(wksWidths, 4); //graph w^2 vs tau grphWidths.Create("WidthGraph"); widthLayer = grphWidths.Layers(); widthLayer.AddPlot(widthCurve, IDM_PLOT_SCATTER); widthLayer.AddErrBar(widthCurve, errBar); widthLayer.Rescale(); //linear fitting needs to be done by hand }
|
 |
|
antar
Posts |
Posted - 04/18/2006 : 08:14:38 AM
|
Sorry. It probably would've helped if you'd known what kind of data this was fitting. Essentially, I have a C++ program that runs a Brownian motion simulation for a certain number of seconds, writing the position data to file. It also writes to a separate file the displacement values over eight different timesteps. Finally, it sorts the data from both into histogram datafiles. binsAnalysis() would take the histogram values for displacement, plot eight graphs of frequency vs. displacement in a given timestep, then fit these curves, which should be normally distributed, with a gauss curve. The widths of these gauss curves squared is then plotted versus the timestep to yield D_0, the diffusion coefficient.
So, the first column of the datafile binsAnalysis() works with contains the displacement values into which the delta dataset was binned into. The other eight contain frequency (counts / total counts) values for that displacement. Each of those eight columns corresponds to an ever-increasing timestep (tau = 1/30s, tau = 2/30s, etc.)
But thanks for the code, it at least will give me new ideas to try.
For instance, just putting in NLSF.cleanupfitdata() seems to have prolonged how long the automation goes before crashing (though it still crashes when I try to exit Origin).
|
 |
|
antar
Posts |
Posted - 04/18/2006 : 11:12:17 AM
|
Hmmm...
Very strange. I modified the code slightly, realizing that I didn't need arrays for grphData and grphLayer... and that change alone seems to have made the automation more, if not perfectly, stable. Which is making me doubt that it's NLSF that's causing the problem in the first place.
More testing is needed. |
 |
|
Deanna
China
Posts |
Posted - 04/18/2006 : 9:26:28 PM
|
Hi, antar.
Why don't you send your data to us via email (tech@originlab.com)? We may try to find a solution together. :)
Deanna OriginLab GZ Office |
 |
|
antar
Posts |
Posted - 04/19/2006 : 12:23:20 AM
|
Well, it seems to be working now (knock on wood). |
 |
|
|
Topic  |
|
|
|