2dcalc?

Hello AFNI gurus,
I’m a die-hard shell scripter who makes frequent use of AFNI programs like 1deval and other shell scripting staples like ‘awk’ for doing basic mathematical operations within my scripts. A big reason I do this is because I hate having to switch to external analysis programs like MATLAB, R, or python for doing something as simple as averaging a column of numbers. For many simple tasks like these, I can rely on AFNI staples like 1d_tool.py, 1deval, or 3dTstat (with the 1D input options). However, one area that frequently gives me trouble is dealing with 2D arrays, like you might see in the regressor text files we input to 3dDeconvolve. For instance, let’s say I had a regressor file with onset times in milliseconds and I wanted to convert those times to seconds (I know, you don’t actually need to do this for 3dDeconvolve). All I’d need to do is divide all the columns within the text file by 1000. There are actually many ways of doing this using AFNI programs and shell commands, but most of them would require you to specify the operation on each column individually, and none of them are as straightforward as programs like 1deval or 3dcalc (and 1dmatcalc is especially difficult to use and limited in functionality). While I’m aware that you can actually use 3dcalc for operations just like this, the syntax is extremely hairy, and would generally look something like this:


1dcat input.txt\' | 3dcalc -a 1D:stdin\' -expr 'a/1000' -prefix - > output.txt

So instead of this, I personally would love to see a 2dcalc program (and I think many AFNI others users would also find this helpful), that had the basic functionality and syntax of the AFNI ‘calc’ programs, but worked on 2D arrays of numbers in text or ‘.csv’ files. What do you think?

P.S. If there are currently AFNI programs that do perform this function, other than the ones i’ve listed above, and I just haven’t stumbled across them before, please let me know. I’m certainly open to trying them out.

TL;DR: Would it be possible to create a simple function (perhaps named 2dcalc) which can deal with 2D arrays of numbers like 3dcalc does with 3D datasets?

I would do it close to the way you have done it:

3dcalc -a testnums.1D' -expr ‘a/1000’ -prefix stdout | 1dtranspose -

While this is a bit tricky, it’s fairly scriptable.