The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Need Help - Easy Situation

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
triley35 Posted - 09/11/2005 : 10:14:27 PM
Origin Version (Select Help-->About Origin): 7.0
Operating System: Windows XP

I am part of an IT group at a pharmaceutical. I have been asked by one of the scientists to find a solution to a dilemma for them, and I was wondering if I could get some help. The scientist would like to automate a process with Origin and although I have coding experience, it has never been with Origin C or labtalk. The scientist imports a spreadsheet with one X and lots of Y coordinates (their can be a different number of Y's so the macro needs to recognize how many are in this particular sheet). They then have to plot a line with the X coordinates with each of the Y's seperately and for each of these lines do a peak pick and find the negative peaks, and save all of this info into separate windows, and then cut and paste it into one common spreadsheet.

That is all. I have a good feeling it would be very simple to automate this but I dont know what direction to go in now. Should this be done with LabTalk or C.? Does code already exist that would help with this.? Please let me know what any of you gurus think..

Thanks so much for any help


9   L A T E S T    R E P L I E S    (Newest First)
jagdeeshRaman Posted - 09/20/2005 : 12:07:47 PM
That has worked, thank you all for helping.

easwar Posted - 09/20/2005 : 10:59:59 AM
Hi triley35 and jagdeeshRaman,

My apologies for not noticing that you had 7.0.

You need to get the SR4 patch for your Origin 7 from the following location:
http://www.originlab.com/index.aspx?s=9&lm=144

I tested in 7.0SR4 and with the code change specified by Mike Buess, the rest works fine.

Easwar
OriginLab

Mike Buess Posted - 09/20/2005 : 10:51:34 AM
Probably not in 7 SR2 because it compiles OK in 7 SR4.

Mike Buess
Origin WebRing Member
jagdeeshRaman Posted - 09/20/2005 : 10:48:48 AM
This worked. Now the error is on GetDataSetName(). Is this not a function of 7 SR2?

Where do I find these function lists.

Mike Buess Posted - 09/20/2005 : 01:30:48 AM
Find this line...

wpgResult.TitleShow = WIN_TITLE_SHOW_BOTH;

and replace it with this line...

wpgResult.LT_execute("page.title=3");

The original line only works in Origin 7.5.

Mike Buess
Origin WebRing Member
jagdeeshRaman Posted - 09/19/2005 : 5:57:55 PM
In an attempt to build the example program given, we are receiving the following error message:

Error, Variable "WIN_TITLE_SHOW_BOTH" not declared

Do you have any familiarity with this error?

Origin Version (Select Help-->About Origin): 7 SR2 (7.0383....)
Operating System: XP SP1
easwar Posted - 09/13/2005 : 11:57:10 AM
Hi triley35,

The Origin C code pasted below will find all negative peaks from all y data columns in active worksheet. It will create a report wks with x, y values of peak locations for each y data in your original wks.

The code has a separate function to find peaks, which is coded to use the LabTalk curve object. The parameters for peak serach correspond to what you will find in the Pick Peaks tool in the GUI.

The code does not create any result graphs, but that sort of thing can be easily added with more Origin C code.

Hope this helps you to get started.

Easwar
OriginLab


////////////////////////////////////////////////////////////////////////////////////
// This is the main function that can be called from Script Window
// or from custom toolbar buttons etc.
// To call from script window, make the worksheet with data active
// and type command in script window, such as:
// find_neg_peaks_all_y
// find_neg_peaks_all_y 0.05 0.05 0.8
// where in the second command above the default values of search parameters
// are changed. These search parameters are same as the ones you find in the
// Pick Peaks GUI tool (menu item Tools->Pick Peaks)
//
void find_neg_peaks_all_y(double dRectHeight = 0.05, double dRectWidth = 0.05, double dMinHeight = 0.05)
{
// Declare Worksheet object using active layer
Worksheet wksData = Project.ActiveLayer();
if( !wksData )
{
out_str("Active Layer is not a worksheet");
return;
}

// Create a new worksheet page for reporting
WorksheetPage wpgResult;
wpgResult.Create("Origin");
string str;
str.Format("Peak report for data from %s", wksData.GetPage().GetName());
wpgResult.Label = str;
wpgResult.TitleShow = WIN_TITLE_SHOW_BOTH;
// Point to worksheet
Worksheet wksResult = wpgResult.Layers(0);
// Delete all columns in default result sheet
while( wksResult.DeleteCol(0) );

// Loop thru all columns of data worksheet
int nYCols = 0;
foreach(Column colData in wksData.Columns)
{
// Check if it is a Y column
if( OKDATAOBJ_DESIGNATION_Y == colData.GetType() )
{
// Add a two new columns to result worksheet for each Y data column
int nIndexX = wksResult.AddCol();
// Set first one as type X
wksResult.Columns(nIndexX).SetType(OKDATAOBJ_DESIGNATION_X);
int nIndexY = wksResult.AddCol();
// Set column label of result cols using name of data col
string strDataColName = colData.GetDatasetName();
int nLabelLength = strDataColName.GetLength();
string strLabel = strDataColName + "\nPeak X";
wksResult.Columns(nIndexX).SetLabel(strLabel);
wksResult.Columns(nIndexX).SetWidth(nLabelLength);
strLabel = strDataColName + "\nPeak Y";
wksResult.Columns(nIndexY).SetLabel(strLabel);
wksResult.Columns(nIndexY).SetWidth(nLabelLength);

// Call function to find negative peaks
int nPeaks = find_neg_peaks(strDataColName, wksResult, nIndexX, dRectHeight, dRectWidth, dMinHeight);

// Increment column count
nYCols++;
}
}
// Turn on display of labels in result wks
wksResult.ShowLabels();

// If no Y cols found in data sheet
if( 0 == nYCols )
{
// Delete result sheet and quit
wpgResult.Destroy();
out_str("No Y columns found in data worksheet");
}

// Delete temp worksheet
//wpgTemp.Destroy();
}


////////////////////////////////////////////////////////////////////////////////////
// This function finds the X values of negative peak locations
// The width and height parameters determine how peaks are located
// See the PickPeaks tool documentation for more info.
static int find_neg_peaks(string strDataColName, Worksheet& wksResult, int nIndexX, double dRectHeight,
double dRectWidth, double dMinHeight)
{
// Declare curve using data column
Curve crvData(strDataColName);

// Multiply curve by -1 to detect negative peaks
crvData *= -1;

// Create a temp dataset to hold peak index values
Dataset dsPkIndex;
dsPkIndex.Create(crvData.GetSize());
dsPkIndex = NANUM;

// Use LabTalk curve object to find peaks
// Place peak results in temp wks
using LTCurve = LabTalk.curve;
// Reset curve object
LTCurve.Reset();
// Assign dataset name
LTCurve.Data$ = strDataColName;
// Assign column to hold peak index in temp wks
LTCurve.PeakIndex$ = dsPkIndex.GetName();
// Set peak search parameters
LTCurve.PickPeaks.RectHeight = dRectHeight;
LTCurve.PickPeaks.RectWidth = dRectWidth;
LTCurve.PickPeaks.MinHeight = dMinHeight;
// Find peaks assuming no baseline
LTCurve.PickPeaks(1);

// Set data curve back to original
crvData *= -1;

// For all peaks found, fill the X, Y values into temp wks cols 2, 3
Dataset dsPkX(wksResult, nIndexX);
Dataset dsPkY(wksResult, nIndexX + 1);
// Remove missing values from peak index dataset and then find size
dsPkIndex.TrimRight();
int nPeaks = dsPkIndex.GetSize();
dsPkX.SetSize(nPeaks);
dsPkY.SetSize(nPeaks);
// Get X data of original data curve
Dataset dsXData;
if( crvData.HasX() )
crvData.AttachX(dsXData);
for(int i = 0; i < nPeaks; i++)
{
// If X data exists, find X value of index
if( dsXData )
dsPkX[i] = dsXData[dsPkIndex[i ] - 1];
// else use index value as X
else
dsPkX[i] = dsPkIndex[i] - 1;
// Fill Y value
dsPkY[i] = crvData[dsPkIndex[i] - 1]
}

// Return number of negative peaks found
return nPeaks;
}



G.Bartsch Posted - 09/13/2005 : 06:49:23 AM
Hi,
this peak selection may be not as easy as expected. sometimes the pickpeak feature doesnt recognize peaks as expected (this was my problem some months ago). though people often smooth and fit curves in order to take the fit maximum as the peak location. but then it seems you have to know how many peaks the data contains, im afraid. I once wrote a script in labtalk as well as in originc to make an automated fit and peakdetection for two peaks. the code is not the best but nevertheless it may help (I can mail you if its needed). also you can try this http://www.originlab.com/fileexchange/details.aspx?fid=56
easwar Posted - 09/12/2005 : 09:44:41 AM
Hi,

If you are already familiar with C programming, you may find Origin C to be the more friendlier choice than LabTalk. Also for repetitive operations Origin C may be significantly faster than LabTalk script.

As for examples on how to access all Y columns in a worksheet and perform certain operation on them, you could look at examples in the following page:
http://www.originlab.com/index.aspx?s=9&lm=71&pid=268
particularly ones such as "Integrate Columns and Create Report" under Data Analysis.

As for peak analysis, there are functions in LabTalk such as pickpeaks() which can be accesed from Origin C. Are you looking just to find the position of the negative peaks? Is there any baseline subtration to be performed?

It may be worthwhile for you to send a sample Origin Project with a worksheet with many Y columns in it to tech@originlab.com and ask for help. If you do send the e-mail, please refer to this forum post.

Easwar
OriginLab


The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000