January 26, 2017 at 9:53 am #7850
I would like to know how to refer to a channel just for the output integration time. I was trying to print the sum of a channel. However, it returns the sum including the standard. I only want the sum for my output.
Thanks for your help!
February 15, 2017 at 2:12 am #7983
Dr Bence PaulKeymaster
Sorry for taking so long to reply. I have just returned from leave, and it took a little coding to produce what you’re after. To return the sum of values in a channel only for your samples requires to you make selections within a selection group. For example, if you wanted the sum of all values for your samples for the channel Na23, you would put your selections for your samples in Output_1. Then you would sum all the values that occur during the time intervals defined by the selections. We have some code to return the avg and 2SD/2SE, but I had to alter our code to return the sum. Below is some code that you can copy and paste into a procedure window in Igor Pro (Windows -> Procedure Window). You can then type into the Command Window (Cmd + H, Ctrl + H on PC):
print ExtractIntegTypeValuesOnly(“Output_1”, “Na23”, “sum”)
As described above, this will print the sum of all values in channel Na23 within the time defined by selections in Output_1.
Please note that this bit of code should be included with the next release of iolite, so you won’t have to copy and past the code below when it is released.
Please let us know if you have any troubles.
//This function extracts the mean value, sum or standard deviations of a particular selection group and returns it as a number Function ExtractIntegTypeValuesOnly(Integ_Name,Wave_Name,Mode) String Integ_Name //Name of Integration, e.g. Baseline_1 String Wave_Name //This is the Name of the wave that the function will return stats for String Mode //Set to "Avg" to return the average, set to "2sd" to return 2 standard deviations, "2SE" to return 2 standard error, "sum" to return sum of all selections String DatafolderName = WhereIsWave(Wave_Name) //This is the data folder to look for the wave in wave YAxisSource = $ioliteDFpath(DatafolderName,Wave_Name) //Now we can reference the wave //the next 5 lines reference all of the global strings and variables in the header of this file for use in the main code of the DRS that follows. string currentdatafolder = GetDataFolder(1) setdatafolder $ioliteDFpath("DRSGlobals","") SVar IndexChannel, ReferenceStandard, DefaultIntensityUnits NVar MaskThreshold, MaskEdgeDiscardSeconds setdatafolder $ioliteDFpath("Temp","") wave SourceMatrix = $IoliteDFpath("integration","m_" + Integ_Name) if(!waveexists(SourceMatrix)) PrintAbort ("Could not find the integration matrix selected. Process has been aborted.") endif wave Index_time = $IoliteDFpath("CurrentDRS","Index_Time") if(!waveexists(Index_time)) PrintAbort ("Could not find Index Time in CurrentDRS folder. Process has been aborted.") endif variable thisinteg=0, NoOfIntegs=dimsize(SourceMatrix,0) variable thisstartpoint,thisendpoint,thisstarttime,thisendtime // per-integration start and end points and times wave StdSegments = $MakeIoliteWave("temp",Wave_Name+"_m",N = 0) //Create a temporary wave with no points in it to hold all the values. Don't worry, points will be added during the loop StdSegments = NaN Variable NoOfPoints //This is the number of points in each integration Variable RowNumber //This is the row number of the last entry in the StdSegments wave, where we'll add the points Do //loop through the integrations of the standard integration and make a separate wave for each one if(thisinteg>NoOfIntegs-1) //if there are no integrations left break //then break the loop endif thisstarttime=SourceMatrix[thisinteg][%$"Median Time"]-SourceMatrix[thisinteg][%$"Time Range"]//get start, and thisendtime=SourceMatrix[thisinteg][%$"Median Time"]+SourceMatrix[thisinteg][%$"Time Range"]//end times for this integration thisstartpoint=ForBinarySearch(index_time, thisstarttime) thisendpoint=ForBinarySearch(index_time, thisendtime) //find point indices for requested start and end points if(thisstartpoint==thisendpoint) //if start and end points the same, then both times precede or postdate entire wave, wave is only 0 points long, or start and end times do not bracket any point in the wave. thisinteg+=1 //set pointer to next sample continue //and return to start of loop endif //otherwise, have bracketed at least a single point Duplicate/O/R=[thisstartpoint,thisendpoint] YAxisSource temporyExtract //Copy the values out of the source wave into a temporary wave Duplicate/O StdSegments TempOrig //Can't concatenate two waves into one, muct concatenate two waves into a new wave, so we create a temporary copy of the original, then concentate that with the new data Wave temporyExtract, TempOrig Concatenate/NP/O "TempOrig;temporyExtract;", StdSegments //Then join the two together thisinteg+=1 //next integration while(thisinteg<NoOfIntegs) //until all integrations added Variable ReturnValue If (cmpstr(Mode, "avg", 0)==0) Wavestats/Q /M=1 StdSegments ReturnValue=V_avg SetDataFolder currentdatafolder Return ReturnValue ElseIf(cmpstr(Mode, "2sd", 0)==0) Wavestats/Q StdSegments ReturnValue = 2 * V_sdev SetDataFolder currentdatafolder Return ReturnValue ElseIf(cmpstr(Mode, "2se", 0)==0) Wavestats/Q StdSegments ReturnValue = 2 * V_sdev / sqrt(V_npnts) SetDataFolder currentdatafolder Return ReturnValue ElseIf(cmpstr(Mode, "sum", 0)==0) Wavestats/Q StdSegments ReturnValue = V_sum SetDataFolder currentdatafolder Return ReturnValue Endif endFebruary 27, 2017 at 7:45 pm #8080
Thanks Bence, it’s working nicely!
You must be logged in to reply to this topic.