How to save a .tract 3D snapshot from command line

Dear all,
I would like to save a .niml.tract 3D image (like is possible to see in suma -tract) directly by command line in a pipeline script, for QC and documentation purposes. Is it possible with a suma command line? Or may be exist another .niml.tract viewer that can be used instead?
Cheers,
Giuseppe

A possible trick is to generate traces with 3dTrackID with the -do_trk_out option and use the track_vis command:
track_vis MINIP_000.trk -l 20 -camera azimuth 0 elevation 270 -sc MINIP_000.axi.png
rm tmp.cam

is it possible to use suma in command line in a similar way?

Hi, Giuseppe-

I will write more shortly from work (and after coffee).

However, by all means exporting to trackvis is not necessary; you can “drive” suma and provide it commands to load tracks (+ slices or surfaces, if those are useful its to include), rotate and/or zoom, and save PNGs. I will send a code example for doing so.

A presto,
pt

Hi again-

Well, I got distracted by other things at work first, but here is a script that should take 4 snapshots (frontal-coronal, left- and right-sagittal, superior-axial) of a tract file, with an FA file (or any other useful volume) added for good measure-- you can excise the latter, if you prefer.

Please let me know how that goes.


#!/bin/tcsh

########################################################################
#
# How to: view DTI tracking results with automatic snapshots; right
# now, takes two arguments:  the *.niml.tract file and an FA volume
#
# For example, you can run as:
#
# tcsh -ef do_suma-tract_example.tcsh TRACTFILE_000.niml.tract FA.nii.gz
#
########################################################################

# For path stuff
set here     = $PWD

# Input tract name
set itract   = $1
# Input FA volume
set ifa      = $2

# Some small(ish) pauses are needed to let SUMA complete things and
# not crash...  *If* things crash, you might need more sheep here:
set sheep_count = 3  

# Size of the image window (bigger -> higher res), given as:
#       leftcorner_X  leftcorner_Y  windowwidth_X  windowwith_Y
# You can also use this to set the dimensions of the viewing windows
setenv SUMA_Position_Original "50 50 500 500" #"50 50 3500 3500"

# -------------------- image file parameters -----------------------

# Saved image naming props: directory and file prefix (latter, taken
# from input tract filename)
set image_dir = "$here/MY_TRACT_IMAGES"        
set image_pre = `basename "$itract" ".niml.tract"`

# size of the image window (bigger -> higher res), given as:
#       leftcorner_X  leftcorner_Y  windowwidth_X  windowwith_Y
setenv SUMA_Position_Original "50 50 500 500" #"50 50 3500 3500"

# --------------------- preliminary settings -----------------------

### If you wanted to open AFNI at the same time and drive it, you
### could.  In such a case, you'd want the portnum stuff set.  Here,
### it is probably just overkill.
# port number for AFNI+SUMA to talk to each other
set portnum = `afni -available_npb_quiet`

# boring stuff.
setenv AFNI_ENVIRON_WARNINGS       NO
setenv AFNI_PBAR_FULLRANGE         NO
setenv SUMA_DriveSumaMaxCloseWait  20
setenv SUMA_DriveSumaMaxWait       10

setenv SUMA_AutoRecordPrefix "${image_dir}/${image_pre}"
#setenv SUMA_SnapshotOverSampling $OVERSAMP

# ========================= run SUMA ============================

# --------------------- SUMA setup------------------------------

# The "-npb $portnum -niml" are a bit unnecessary, but you might want
# to drive AFNI at the same time, in which case they become useful
suma                                                            \
    -echo_edu                                                   \
    -npb $portnum                                               \
    -niml                                                       \
    -tract  $itract                                             \
    -vol    $ifa  &

echo "++ sleepy time..."
sleep $sheep_count

### With these, you can turn *OFF* visibility of the following things 
### (respectively):  
###    crosshair, selector node, selector faceset, and label
DriveSuma                                              \
    -echo_edu                                          \
    -npb $portnum                                      \
    -com viewer_cont -key 'F3' -key 'F4' -key 'F5' -key 'F9'
# You can leave this in or not, as desired.

# these are just some of the view angles I thought would be most useful
foreach pose ('Ctrl+Shift+up'  'Ctrl+up' 'Ctrl+left' 'Ctrl+right' )

    # get view and SNAP
    DriveSuma                                        \
        -npb $portnum                                \
        -com viewer_cont -key "$pose"                \
        -com viewer_cont -key 'Ctrl+r'

    echo "++ Pose: $pose..."
    sleep $sheep_count

end

### Uncomment the '@Quiet* ...' line if you want to automatically
### close everything down!  Optionally, can leave SUMA (and AFNI, if
### used) running, if you preferred.
#@Quiet_Talkers -npb_val $portnum

echo "++ DONE!"

–pt

… and an additional note on this driving of SUMA: it cannot be driven in a virtual environment, unlike AFNI which can be. Thus, there are some auto-QC snapshotting features in AFNI scripts (such as @snapshot_volreg and the fat_proc* scripts) that can make images even when running on a remote server where a graphical interface cannot be opened up. However, SUMA and its OpenGL-osity don’t permit for this; so this kind of script could only be run somewhere where SUMA can open up its viewer window. For example, if ssh’ed into a cluster for processing, you would have to use “ssh -X …” or something to allow this to run.

We have looked into generating a virtual environment for things like this to run, but to date that has not been successfully accomplished.

–pt

Thanks a lot Paul,
I’ll try tomorrow in office …on the localhost and after coffee :wink:
cheers,
g.c

Thanks Paul,
I’ve tried your script and it works on my environment. Just I have few more questions:
1- can I chenge the default output format: png instead of jpg? … may be a setenv SUMA_something?
2- what does the final part of the name refer to? (e.g. MINIP_000.A.180410_114402.012.jpg)
3- can you suggest a good starting point tutorial to use AFNI+SUMA from command line… it seems very powerful but not intuitive for beginners.

Cheers,
Giuseppe

Hi, Giuseppe:

Re:

1- can I chenge the default output format: png instead of jpg? … may be a setenv SUMA_something?
Yes, both AFNI and SUMA have “rc” files, which should be in your home directory, as described in the install instructions, such as here:
https://afni.nimh.nih.gov/pub/dist/doc/htmldoc/background_install/install_instructs/steps_linux_Fed_RH.html#make-afni-suma-profiles
(it’s basically the same method for copying/creating them on any OS system where you are installing AFNI binaries.)

Basically, AFNI and SUMA GUIs have a looooot of settings; many of these are arbitrary: for example, do you want left=left or left=right convention? What should the background color of an image be? How many degrees should the SUMA image rotate with an arrow key press? Many things like this (“environment variable” settings) can be controlled by you, The User. Many of these can be done by changing values in the ~/.afnirc and ~/.sumarc files.

In this question’s case, if you search your ~/.sumarc file for “jpg”, you should fine the following:


// 058-SUMA_AutoRecordPrefix:
//     Prefix for autorecord (suma's Ctrl+R) files. 
//      FreeSurfer states should not be sent to AFNI.
//      Add a path if you want the files to endup in a particular directory.
//      You can also add an extension to prefix to specify the output type.
//      Choose from .jpg, .ppm, or .1D . The fallback type is .jpg
//      
//     default:   SUMA_AutoRecordPrefix = ./SUMA_Recordings/autorecord.jpg
   SUMA_AutoRecordPrefix = ./SUMA_Recordings/autorecord.jpg

You can adjust the file extension to be “png”.

You can also set the values for these environment variables in your ~/.bashrc or ~/.cshrc files, with appropriate syntax for that shell (i.e., “export …” or “setenv …”, respectively). More about the environment variables for AFNI are described in the following:
https://afni.nimh.nih.gov/pub/dist/doc/program_help/README.environment.html

2- what does the final part of the name refer to? (e.g. MINIP_000.A.180410_114402.012.jpg)
Date and time that you ran things; in your example, in order:
18=year
04=month
10=day
_
11=hour (24-hour format)
44=min
02=sec
.
012=milliseconds (I think…)

3- can you suggest a good starting point tutorial to use AFNI+SUMA from command line… it seems very powerful but not intuitive for beginners.
We refer to these command line “button clicking” of the AFNI and SUMA GUIs as “driving”. Descriptions of AFNI and SUMA driving are provided in:
https://afni.nimh.nih.gov/pub/dist/doc/program_help/DriveSuma.html
https://afni.nimh.nih.gov/pub/dist/doc/program_help/README.driver.html
There are also demos for each, @DriveAfni and @DriveSuma.
Note that @DriveAfni requires that you have the Bootcamp demo downloaded on you computer; type “@DriveAfni” to get a blurb about that and where to run it from.

A really good place for examples of Driving AFNI and SUMA are some of the AFNI Bootcamp materials; in the FATCAT Demo, for example, the Do_06* and Do_09* scripts have (fairly fancy) examples of driving each of AFNI and SUMA, and, importantly, of driving them together (while they are “talking” to each other, sending information back and forth).

Those are the best places to start with, I think. And, of course, please ask any more specific questions, too. Driving capabilities may be quite “simple” to do things you want (that is, doing something in a short number of commands, not “simple” in the sense of obvious!); other times, things can be surprisingly complicated or just not possible… Such is life, but that is why the Message Board exists.

–pt