
extracting data from a wave to make a new wave

appaloosahotdog
Here are the functions I'm writing in total. The first loads peak areas from several chromatograms and the second loads the concentrations used for instrument calibration purposes. The idea is to match the correct peak areas with concentration values for each ion by wave name and ultimately generate linear calibration curves for them all - of which i am only interested in the fitted curve's equation.
Thanks in advance for any help.
#pragma rtGlobals=3 // Use modern global access method and strict wave access. Function load(pathName, filePath) string pathName, filePath if (strlen(filePath) == 0) Open/D/R/P=$pathName refNum as filePath if (strlen(S_fileName) == 0) return -1 endif filePath = S_fileName endif LoadWave/J/D/O/K=0/A/B="N='_skip_'; N='_skip_'; N='_skip_'; N='Sig1';"/P=$pathName filePath wave/T Sig1 make/o/N=(numPnts(Sig1)) PeakArea PeakArea = str2num(Sig1[p]) MatrixOp/o PeakArea = replace(PeakArea, NaN, 0) edit PeakArea variable index string name make/o/N=10 tempwave for(index = 0; index<12; index+=1) name = "PA" + num2str(index) extract/o PeakArea, tempwave, p>=14*index && p<=14*index + 13 duplicate tempwave, $name endfor killwaves tempwave make/o/N=10 PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PA8, PA9, PA10, PA11 appendtotable PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PA8, PA9, PA10, PA11 load2("","") End Function load2(pathName, filePath) string pathName, filePath if (strlen(filePath) == 0) Open/D/R/P=$pathName refNumas filePath if (strlen(S_fileName) == 0) return -1 endif filePath = S_fileName endif LoadWave/J/D/O/K=1/A/B="N='Concentration';"/P=$pathName filePath wave Concentration appendtotable Concentration variable index string name make/o/N=10 tempwave for(index=0; index<12; index+=1) name = "Conc" + num2str(index) extract/o Concentration, tempwave, p>=10*index && p<= 10*index + 9 duplicate tempwave, $name appendtotable $name endfor killwaves tempwave End
Also, bracket your code with <igor> and </igor> tags.
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
June 30, 2014 at 01:10 pm - Permalink
June 30, 2014 at 03:33 pm - Permalink
1 water n.a. n.a. 2 water n.a. n.a. 3 A1 4.794 0.0080 4 A2 4.797 0.0308 5 A3 4.800 0.0620 6 A4 4.800 0.1190 7 A5 4.800 0.1454 8 A6 4.800 0.5873 9 A7 4.797 1.2083 10 A8 4.797 2.5246 11 snow 4.800 0.3649 12 snow 4.800 0.3662 13 water n.a. n.a. 14 water n.a. n.a. 1 water n.a. n.a. 2 water n.a. n.a. etc...
Loading the wave as text is reasonable given the unusual file formatting.
Loading only column 4 seems to work fine:
You then replace the n.a. values with 0 (which is a little questionable).
These questions:
do not make any sense to me. I may need more coffee.
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
June 30, 2014 at 04:07 pm - Permalink
however, while playing with the data in a table, i realized that some of the values were not being loaded. for example,
10 C8 9.940 15.7039
In that line of data, the fourth column remains blank when loaded by my program.
Since i can't be sure if the spacing in the txt files will be uniform and can't double check for errors when the deluge of data arrives, this problem seems to be a serious concern.
I did some backtracking by loading the waves in a different manner, and found that loading the txt into one wave works. all the data is there.
That's why I'm asking how to pull a wave from a wave. Does that make my problem clearer?
Thanks!
June 30, 2014 at 09:25 pm - Permalink
If you are asking how to extract the 4th column from a 2D text wave into a 1-column ("1-D") numeric wave, then that I can answer:
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
June 30, 2014 at 11:21 pm - Permalink
The 'problem' with your data is that some lines contain a fourth tab character, making these lines essentially 5 columns in width. The loading command interprets the data as four columns (probably concluding from the structure of the first line) and then never looks again and just loads the "emptiness" after the 1st tab character, ignoring the data which comes afterwards. That's why loading into one column works (I guess you use something like
LoadWave/J/O/K=2/A/V={"", "",0,0}
). If you come that far, all that's left to do is to get rid of the additional tab character and reinterpret the data, like this:Hope that helps.
July 1, 2014 at 03:18 am - Permalink
July 1, 2014 at 07:47 am - Permalink
I've succeeded in loading the txt file into a single wave with this code:
But neither of the functions you've suggested extract the fourth column of data from wave0.
attached is the full code using jim's suggestion:
July 1, 2014 at 09:02 am - Permalink
July 1, 2014 at 09:05 am - Permalink
I had to remove the /K flag and add ",T=4" to the /B flag.
I also added an extra "skip" at the end so LoadWave will ignore the extra tabs found on some lines.
This gives you a numeric output wave.
The "n.a" entries load as NaN. If you want to replace NaN with zero, add this:
July 1, 2014 at 09:38 am - Permalink
July 1, 2014 at 10:24 am - Permalink
That's because that line of text in the file has two tabs before column 3 instead of 1. I thought the extra tabs were all at the end of a given line.
In this case I would create a filtered version of the file by replacing tab-tab with tab. For an example of creating a filtered file and loading the filtered file, see:
http://www.igorexchange.com/node/1221
Your FixText routine would look like this:
While you are at it you might as well remove the stray tabs at the end of some lines:
July 1, 2014 at 10:36 am - Permalink
I took your data and used the loading command, then applied my function and it is working just fine. I guess there is something not working with the implementation. For example, here:
Note also that the 'n.a.' rows turn out as NaNs in the numerical wave obviously. You can convert these later to zeros if you wish.
July 1, 2014 at 09:42 pm - Permalink
July 2, 2014 at 09:51 am - Permalink