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
 Forum for Origin C
 Integrate Columns from the minimum value

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
masterd Posted - 05/01/2008 : 11:46:01 PM
Origin Version (Select Help-->About Origin): OriginPro 7.5
Operating System: XP

I use the the below code to integrate data (area, height and timing) and then create a worksheet of results. Code is sligtly modified version from Origin example code http://www.originlab.com/pdfs/programming/IntegrateColumnsAndCreateReport.pdf

The problem I have is that both Origin example and my code integrate data from Y=0. Essentially, peak height is just a maximum value, regardless if the baseline is above or below zero, hence not a true height. I would like a code that gives me peak height as difference between max and min so it compensates for the baseline position. Again, with peak area, code that integrates between min and max is what I would like.

I hope someone can help! Thanks,

Darko

void integrate2()
{
// Declare worksheet using active layer and check validity
Worksheet wksData = Project.ActiveLayer();
if(!wksData){
out_str("Active layer is not a worksheet!");
return;
}
// Bring up wait cursor to indicate computation in progress
waitCursor wCur;
// Create a results worksheet
Worksheet wksResult;
wksResult.Create();
// Get the page for this worksheet and set its label and show the label
WorksheetPage wpg = wksResult.GetPage();
wpg.Label = "Integration results for '" + wksData.GetPage().GetName() + "' worksheet";
wpg.TitleShow = WIN_TITLE_SHOW_BOTH;

//Declare datasets in results worksheet and set column names and widths
// First delete all columns in result worksheet and start adding new columns
while(wksResult.DeleteCol(0));
int nIndex;
int nWidth = 15;
// 1st column: name of Y column from data worksheet
nIndex = wksResult.AddCol();
wksResult.Columns(nIndex).SetLabel("Label");
wksResult.Columns(nIndex).SetWidth(nWidth);
// 2nd column: peak x location
nIndex = wksResult.AddCol();
wksResult.Columns(nIndex).SetLabel("Peak Time");
wksResult.Columns(nIndex).SetWidth(nWidth);
// 3rd column: peak y value
nIndex = wksResult.AddCol();
wksResult.Columns(nIndex).SetLabel("Peak Height");
wksResult.Columns(nIndex).SetWidth(nWidth);
// 4th column: integrated area
nIndex = wksResult.AddCol();
wksResult.Columns(nIndex).SetLabel("Peak Area");
wksResult.Columns(nIndex).SetWidth(nWidth);
// Turn on column label display
wksResult.ShowLabels();
// Set designation of 1st col to label
wksResult.Columns(0).SetType(OKDATAOBJ_DESIGNATION_L);

// Loop over all columns of data worksheet and integrate y columns
int nCount = 0;
foreach(Column ColData in wksData.Columns)
{
if( OKDATAOBJ_DESIGNATION_Y == ColData.GetType() )
{
// Get label of data column and store in result wks at current row, 1st col
wksResult.SetCell(nCount, 0, ColData.GetLabel());

// Declare curve object from data column
Curve crvData(wksData, ColData.GetIndex());

// Perform integration and store results at current row in subsequent cols
IntegrationResult irResult;
BOOL bRet = Curve_integrate(&crvData, &irResult);
if(bRet)
{
wksResult.SetCell(nCount, 1, irResult.xPeak);
wksResult.SetCell(nCount, 2, irResult.yPeak);
wksResult.SetCell(nCount, 3, irResult.Area);
}
nCount++;
}
}

// If no y columns were processed, delete the report worksheet and quit
if( 0 == nCount )
{
out_str("Did not find any Y columns in data worksheet!");
wksResult.Destroy();
return;
}
else
printf("%d columns were processed\n", nCount);
}
/*int iCol = 0; iCol < iNumCols; iCol++)
{
Dataset dsData(wksData, iCol + iBegin - 1);
if(!dsData)
{
printf("invalid data column!\n");
return;
}
// Get name of data column and store in result wks
string strColName = dsData.GetName();
dsLabel.SetText(iCol, strColName);
// Loop thru each element in data column and do the math
int iSize = dsData.GetSize();
for(int iRow = 0; iRow < iSize; iRow++)
{
dsData[iRow] = ( 10^( dsData[iRow] / 10.0 ) * 0.001) ^ 0.5;
}

// Perform integration and store result
Curve crvMyCurve(strColName); // Create Curve object to integrate
if(!crvMyCurve)
{
printf("invalid curve object!\n");
return;
}
IntegrationResult irMyResults; // Origin C structure to store integration results
bool bErr = Curve_integrate( &crvMyCurve, &irMyResults ); // Perform integration
dsValue[iCol] = irMyResults.Area;
}
// Set 1st col of result worksheet to type label
wksResult.Columns(0).SetType(OKDATAOBJ_DESIGNATION_L);
}

4   L A T E S T    R E P L I E S    (Newest First)
masterd Posted - 05/07/2008 : 02:15:40 AM
Hi Easwar,

Your method definitely gave me an idea on a rather easy way of baselining and integrating. I cant belive I didnt think of it earlier!

In the end I ended up using few different scripts in succession. Firstly I would clone the raw data wks, then use below script which finds a min value of each y column in a worksheet then subtracts it. Then I would integrate data the same way as before! Problem solved!

Thanks!

Darko




void base()
{
Worksheet wks = Project.ActiveLayer();


foreach( Column col in wks.Columns )
{
if( OKDATAOBJ_DESIGNATION_Y == col.GetType() )
{
Dataset ds(col);
double dMin, dMax;
ds.GetMinMax(dMin, dMax);
ds -= dMin;
}
}
}

easwar Posted - 05/05/2008 : 2:22:31 PM
Hi Darko,

You can set up another temporary worksheet where you make a flat baseline with min value each time and use that.....or you could take the data and subtract the min value and put the result in a temp sheet and integrate from the temp sheet...

The code below takes data, puts into a temp sheet by subtracting min, and then integrates the curve from temp sheet with no baseline (which is basically the same as integrating with flat min baseline) and in the end you can just destroy the temp sheet...

Easwar
OriginLab


void test()
{
Worksheet wksData = Project.ActiveLayer();
if( !wksData ) return;

// Create a temp worksheet
WorksheetPage wpgTemp;
wpgTemp.Create("Origin", CREATE_HIDDEN);
Worksheet wksTemp = wpgTemp.Layers(0);
if( !wksTemp ) return;
// Assuming here that temp sheet has two cols, first set as type X
Dataset dsXTemp(wksTemp, 0);
Dataset dsYTemp(wksTemp, 1);

// Change to loop over all Y cols etc - here I am doing only one col
Dataset dsXData(wksData, 0);
// get min value of y col
Dataset dsYData(wksData, 1);
double dMin, dMax;
dsYData.GetMinMax(dMin, dMax);
// Set temp sheet y by subtracting min from y, and copy x
dsYTemp = dsYData - dMin;
// Copy over X
dsXTemp = dsXData;

// Now make curve from temp sheet and integrate
Curve crvTemp(wksTemp, 0, 1);
IntegrationResult irResult;
BOOL bRet = Curve_integrate(&crvTemp, &irResult);
printf("%f\n", irResult.Area);
// put the integ result in report sheet etc

// after you are done with all cols, delete temp sheet
wpgTemp.Destroy();
}


masterd Posted - 05/04/2008 : 9:53:05 PM
Hi Easwar,

I can see that Curve_integrate() can do exactly what I am after by utilising baseline dataset but I am failing to execute it! :( I can get the script to work on a single set of data where I manually define additional Y column with min values. Unfortunately, anything other than that is getting bit beyond my programming skills. :(

My worksheet with raw data can have anywhere up to several hundred datasets (XY), all with the same X axis and I do have a script to delete X columns so data takes XYYYY form.

Could you please help me modify the code above so it creates a baseline based on a min value for EACH Y column of the raw data and uses it for integrations. Baseline data needs to be deleted afterwards leaving raw data only plus results worksheet.

Your help would be very much appreciated,

Darko

easwar Posted - 05/02/2008 : 09:31:51 AM
Hi Darko,

If you look up Curve_integrate() function in OC language reference, you will see it has option for also passing a baseline curve. So you can create another x,y column pair that holds your baseline. If you want a constant baseline, you could make the y values of the baseline to be same as min value of the dataset and then pass it.

Easwar
OriginLab


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