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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Code to Baseline all spectra
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

masterd

Australia
Posts

Posted - 07/12/2005 :  10:50:57 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): OriginPro 7.5
Operating System: XP Home

My research involves plotting something like 15-30 spectra at the same time to start with. Then i have to baseline all my spectra followed by normalising of all y columns.

could someone PLEASE help me compile a code that would plot all my data in the worksheet and then baseline it with following settings:
-Automatic
- End Weighted with 250 points

I have a code that will normalise all my data after.

Thanks heaps in advance.

easwar

USA
1965 Posts

Posted - 07/12/2005 :  1:41:25 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi masterd,

Pasted below is a code example showing how to find baselines using the LabTalk curve object. You can look up the methods and properties of this object in the Progamming help file under LabTalk Language Reference.

This code segment assumes:
1> your various datasets are in separate worksheets
2> your x,y raw data are in cols 1, 2 of each worksheet
Then two more columns are added to each worksheet with the x,y values of 250 points of the baseline.

If your intention is to then subtract the baseline and then normalize the data, it may be better to generate the baseline to have exact same number of points as raw data so subtraction can be done easily.

Easwar
OriginLab


void find_bsln()
{
// Point to the LabTalk curve object
using LTCurve = LabTalk.curve;

// Loop over all pages in project
foreach(PageBase pgb in Project.Pages)
{
// If page is a worksheet page...
if( EXIST_WKS == pgb.GetType() )
{
WorksheetPage wpg = pgb;
Worksheet wks = wpg.Layers(0);
// If valid worksheet...
if( wks )
{
// Add two cols to hold bsln x, y
int nIndex = wks.AddCol("BslnX");
wks.Columns(nIndex).SetType(OKDATAOBJ_DESIGNATION_X);
wks.AddCol("BslnY");
// Use the LabTalk curve object
LTCurve.Reset();
// Assume y data is in 2nd col
LTCurve.Data$ = wks.Columns(1).GetDatasetName();
LTCurve.baselinePts = 250;
LTCurve.basex$ = wpg.GetName() + "_" + wks.Columns(2).GetName();
LTCurve.basey$ = wpg.GetName() + "_" + wks.Columns(3).GetName();
// Set baseline type to 0 - End weighted
LTCurve.baseline.fittype = 0;
// Compute baseline
LTCurve.baseline();
}
}
}
}



Go to Top of Page

masterd

Australia
Posts

Posted - 07/12/2005 :  8:55:15 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi easwar,

the code works well if i have only 2 columns per worksheet and it only creates baseline. What i really need is baseline created and then subtracted. Reading back over my initial post, i realised that i havent said that i want it subtracted as well.

Is there a possibility of creating new code that works with more than 2 columns in the worksheet because ideally i want up to 30 different datasets in one worksheet all sorted as XY XY. Also, rather than adding 2 new columns for baseline data can code create a new worksheet for baseline data that gets deleted after baseline gets subtracted ... just as if you do it all manually? at the bottom of it all, all i need is all my data to be baseline subtracted and normalised. i dont need baseline data.

...and as for number of points for the baseline, i tried with more point but it doesnt look it makes any difference at all. i will take your advice!

i tried to make it as clear as i can!

Thanks heaps.

Darko
Go to Top of Page

easwar

USA
1965 Posts

Posted - 07/13/2005 :  5:26:57 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Darko,

Try the code pasted below.

To learn more Origin C:
1> look at code examples in Programming Help file under Language reference as well as under Programming Guide
2> look at code examples from this page:
http://www.originlab.com/index.aspx?s=9&lm=71&pid=268
3> search the forum for code segments that OriginLab and other users may have posted

Easwar
OriginLab

void remove_bsln()
{
// Point to active worksheet and check validity
Worksheet wksData = Project.ActiveLayer();
if( !wksData ) return;

// Create a temp wks to hold baseline data
WorksheetPage wpgTemp;
wpgTemp.Create("Origin", CREATE_HIDDEN);
Worksheet wksTemp = wpgTemp.Layers(0);
while( wksTemp.DeleteCol(0) );
wksTemp.AddCol("BslnX");
wksTemp.Columns(0).SetType(OKDATAOBJ_DESIGNATION_X);
wksTemp.AddCol("BslnY");

// Point to the LabTalk curve object
using LTCurve = LabTalk.curve;

// Loop over wks assuming the data is organized as XYXYXY...
int nCols = wksData.GetNumCols();
for(int ic = 1; ic < nCols; ic += 2)
{
// Reset the LabTalk curve object
LTCurve.Reset();
// Point to the current Y dataset for input data
LTCurve.Data$ = wksData.Columns(ic).GetDatasetName();
// Get size of input data and set this as size for baseline
Dataset dsData(wksData, ic);
LTCurve.baselinePts = dsData.GetSize();
// Point to temp wks cols 1,2 for baseline output
LTCurve.basex$ = wpgTemp.GetName() + "_" + wksTemp.Columns(0).GetName();
LTCurve.basey$ = wpgTemp.GetName() + "_" + wksTemp.Columns(1).GetName();
// Set baseline type to 0 - End weighted
LTCurve.baseline.fittype = 0;
// Compute baseline
LTCurve.baseline();
// Subtract the baseline from the raw data
Dataset dsBsln(wksTemp, 1);
dsData -= dsBsln;
}

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



Go to Top of Page

masterd

Australia
Posts

Posted - 07/13/2005 :  7:20:48 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Beautiful!! Code works perfect! Its all smooth sailing now. Its saving me countless number of hours! Thanks again!
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000