Creating new 2D wave from multiple existing wave data

Hello,

I am quite new with Igor and somehow between beginner and intermediate level in coding/programming and need some help and suggestions.

I currently deal with mass spectrometry data of five different chemical species/components: NH4, NO3, SO4, Chl, and Org. It's a 2D wave, with +8000 rows representing time and 97 columns representing ion mass. I want to sum the data of each species in the corresponding time and mass in a new 2D wave. Here is what I code for the function:

Function SumAllSpecies()
    int rownum,colnum //Row number and column number
    int i,j //Index
    Wave NH4_data, Chl_data, NO3_data, SO4_data, Org_data //Data waves
    rownum=DimSize(NH4_data, 0)
    colnum=DimSize(NH4_data, 1)
    Make /O/N=(rownum,colnum) AllSpecies_data
    for(i=0;i<rownum;i=i+1)
        for(j=0;j<colnum;j=j+1)
            AllSpecies_data[i][j] = NH4_data[i][j]+Chl_data[i][j]+NO3_data[i][j]+SO4_data[i][j]+Org_data[i][j]
        endfor
    endfor
end

However, it doesn't do its job properly. Has anyone ever done something similar to this (not necessarily mass spectrometry data). Do you have any suggestions? Thank you very much!

Welcome to the forum. It is unclear what does not work properly for you. What should the result look like? Currently your code just sums up each respective point of all five samples. This disregards the (possibly present) time and ion mass scaling and also assumes that all data sets have exactly the same number of points. Do you want to sum the data for each (scaled) time and mass value? Then you would need to consider the x and y scaling, which might be different for each data set. But it is difficult to suggest something without knowing how your data looks exactly. Would it be possible to post a small example experiment file with a description of what you want to achieve? We could easily suggest small code then.

In reply to by chozo

Hello, thank you very much for the reply!

Each species wave contain the time data as row (which is the same across all species because they are collected from the same instrument at the same time) - no need to scale - and m/z values from 0 to 97 as column. The values are the signal obtained from each m/z and time of data acquisition on the instrument.

I am actually going to use "AllSpecies_data" to perform PMF analysis in Igor instead of doing each species separately, to see whether the combination of all species detected in each m/z would result in different profile or make sense.

OK, then summing the data like this should give you the sum of all data sets (actually including the time row). Is this then not what you want? If you want the average values then you should divide by 5 at the end. I am not well-versed in mass spectroscopy, so I do not know what a PMF analysis is. We can help you with the task if you can formulate how you want the data to turn out (again, having some example data would be much easier for everybody to test how things go).

By the way, just a small comment on your code: You do not need to have the for-loops since Igor is doing this for you automatically during wave assignment. Also, since all data sets seem to be the same size you can just write (even in the command line without the need for a function):

Make/O/N=(DimSize(NH4_data,0),DimSize(NH4_data,1)) AllSpecies_data
AllSpecies_data = NH4_data+Chl_data+NO3_data+SO4_data+Org_data

 

In reply to by chozo

Thank you for the suggestion! I am looking for the sum not the average.

The final graph looks like this but now since you mentioned about the time/date, I am convinced that the procedure messes up with the date value/format.

error.png

If you want to combine a bunch of 1D waves to create a 2D wave, you can use Concatenate:

Concatenate  {NH4_data, Chl_data, NO3_data, SO4_data, Org_data}, AllSpecies_data

Execute

DisplayHelpTopic "concatenate"

for details

Yes, I guess if you use the time row from the summed data for the plot this will not work. Either use the time row from one of the original data waves or have the time as a separate (x) wave in the first place. If you divide the time row by 5 after summing it might work, but I would not count on that. By the way, I have no idea how the plot is supposed to look, so I am a bit lost on what is wrong here.

Duplicate/O NH4_data, AllSpecies_data
AllSpecies_data = NH4_data+Chl_data+NO3_data+SO4_data+Org_data

using duplicate instead of make will preserve any scaling (for time, mass) in your 2D input waves

In reply to by tony

chozo wrote:

Yes, I guess if you use the time row from the summed data for the plot this will not work. Either use the time row from one of the original data waves or have the time as a separate (x) wave in the first place. If you divide the time row by 5 after summing it might work, but I would not count on that. By the way, I have no idea how the plot is supposed to look, so I am a bit lost on what is wrong here.

tony wrote:

Duplicate/O NH4_data, AllSpecies_data
AllSpecies_data = NH4_data+Chl_data+NO3_data+SO4_data+Org_data

using duplicate instead of make will preserve any scaling (for time, mass) in your 2D input waves

Thank you very much everyone for your help and suggestions! I will look everything up again :)

In reply to by tony

tony wrote:

If you want to combine a bunch of 1D waves to create a 2D wave, you can use Concatenate:

Concatenate  {NH4_data, Chl_data, NO3_data, SO4_data, Org_data}, AllSpecies_data

Execute

DisplayHelpTopic "concatenate"

for details

 

I believe the input waves are actually 2D (see DimSize definition of AllSpecies_Data above). In this case you could use

Concatenate/O/NP=2 {NH4_data, Chl_data, NO3_data, SO4_data, Org_data}, DataCube

to make a 3D wave, then apply MatrixOP to obtain the same result:

MatrixOP/O AllSpecies_Data = sumBeams(datacube)

Plenty of options ;-)