how to do wave arithmetic in batch?

Hi guys, I have thousands of curve pairs and need to subtract one curve from another. There is a Wave Arithmetic Panel which allows me to do this. However, it is time consuming by placing cursor A and B on each curve to get subtraction one by one. I am wondering if there is a better way to do such work in batch? Thanks ahead.
Are all thousands of curves in one graph? Do the pairs all share X values, or do they need to be interpolated to common X values (which is one of the things Wave Arithmetic Panel does for you)? How do you identify which curves constitute a pair?

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote:
Are all thousands of curves in one graph? Do the pairs all share X values, or do they need to be interpolated to common X values (which is one of the things Wave Arithmetic Panel does for you)? How do you identify which curves constitute a pair?

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com


Thank you for your reply.
Each graph contains two curves as shown in the attached image. I am subtracting red curve from the black curve along X axis. Thousands of curves means that I have thousands of such graphs to treat.
Two curves are collected from instrument where there is an inherent time line. The red curve happens first from low force to high force while the black curve happens later from high force to low force. Two curves do not share either X (force) or Y (Extension) values. Both contain two columns of data and are independent to each other. I do not quite understand how the Wave Arithmetic Panel does the subtraction, however, the result seems reasonable to me.
That would be great if you could provide any thought to solve this work.
Thanks again.
FL.jpg (526.77 KB)
Yuzhongbo,

I can write a function to do the processing in batch mode, but it would be helpful to know what sort of processes you went through in the Wave Arithmetic Panel to get the X data to properly correspond. Can you send me an Igor experiment file with a representative sample of one of your wave pairs having been successfully lined up and subtracted? You can reply here or to the support email: support@wavemetrics.com.

Nate Hyde
WaveMetrics New Guy
support@wavemetrics.com
nhyde wrote:
Yuzhongbo,

I can write a function to do the processing in batch mode, but it would be helpful to know what sort of processes you went through in the Wave Arithmetic Panel to get the X data to properly correspond. Can you send me an Igor experiment file with a representative sample of one of your wave pairs having been successfully lined up and subtracted? You can reply here or to the support email: support@wavemetrics.com.

Nate Hyde
WaveMetrics New Guy
support@wavemetrics.com


Thank you, Nate Hyde. That is very kind of you.
I attached one Igor file. 10 graphs were included. Each graph contains two curves, one in black and another in red. Graph 9 shows the subtraction (Black - Red). The resulting curve is in blue color.
This is so great that you guys are here to help.
Thanks so much.
Subtraction.pxp (484.51 KB)
That experiment is perfect. I'll have to get to it in the morning, but it shouldn't take long.

Nate Hyde
WaveMetrics New Guy
Nate Hyde
All right, here it is. I've attached a .ipf file. Here's how to use it:

1) Download it, then in Igor go to File->Open File->Procedure, then navigate to subtract_on_all_windows.ipf

2) Compile the resulting procedure window.

3) From the command line run doSubtractOnAllWindows(). Each existing graph will then have a blue trace added to it representing A-B


The code is on the quick-n-dirty side. It does minimal error checking and I made a number of assumptions based on the experiment you sent me. Here's a list of the assumptions:

1) the "A" trace (of wave A-wave B) has a ".txtxR" suffix. When subtracting waves with distinct X coordinates one must be interpolated to the other (or, more generally, they must be interpolated to common X values). In this case wave B is interpolated to wave A's X coordinates

2) Assumes wave naming conventions in the sample experiment you sent are the same in all the waves (e.g. .txtxR, .txtfR, .txtxS and .txtfS suffixes, and liberal names).

3) Assumes there are only 2 waves on each graph, or that the first 2 waves are the ones on which you wish to operate. A more general solution would pass wave names (or near names that can be used to uniquely identify waves) to the subtract_1st2waves() function.

Another result of this processing is that a new wave is created for every subtraction. The new waves are named like the waves they are based on, and they share X values with the corresponding "A" wave (meaning currently their x points are the same as the corresponding .txtfR wave). Use the Data Browser after you run the function to see the results.

Let me know if this doesn't work for you or if you have any questions. And, of course, do back up your experiment before running any script from outside sources... Good Luck!


Nate Hyde
WaveMetrics New Guy
Nate Hyde
subtract_on_all_windows.ipf (2.01 KB)
This is such a beautiful procedure. It is exactly what I have been looking for. Thank you so much.