AFNI version info (afni -ver
):
Precompiled binary linux_ubuntu_24_64: Oct 1 2024 (Version AFNI_24.3.00 'Elagabalus')
Hi there,
I am trying to get the RAI coordinates of all the nodes in my ROI.
I am using Surf2VolCoord to do so, calling the function for each node in a loop (code below). However, some ROIs have 30,000 nodes, and the function call takes several seconds, so getting the RAI coordinates is taking several days.
Is there a faster way?
I also tried the below which gave me all the topographic facesets in a file, and the RAI coordinates in a file. But I wasn't sure if the RAI coordinates were for the middle of the faceset? and therefore how close they would be to the coordinates for the individual nodes in the facesets...
ConvertSurface -i ${sub_dir}/SUMA/lh.sphere.gii -sv ${sub_dir}/SUMA/${sv} -o_1D coords_sph mesh_sph
Thank you for your help!
H
#!/bin/bash
# Set sub details
sub_num="P002"
sub_init="HW"
# Get sub stuff from sub details
sv="${sub_init}_columns_SurfVol_Alnd_Exp+orig"
# Set other details
roi=fMap_Q001_postAl
# Change dir
cd ${working_dir}/${sub_init}
# Load afni
ml afni
# Get RAI cartesian coordinates for each node
input_dset="${roi}.1D.dset"
output_file="node_coordinates_spherical.txt"
# Clear or create output file
echo "Node R A I r theta phi" > "$output_file"
# Loop through each node in the input 1D.dset file
while read -r line; do
# Skip lines that start with '#'
if [[ "$line" == \#* ]]; then
continue
fi
# Read node number
node=$(echo "$line" | awk '{print $1}')
echo "node = ${node}"
# Extract RAI coordinates using Surf2VolCoord
output=$(Surf2VolCoord -i "$sub_dir/SUMA/lh.sphere.gii" -sv "$sub_dir/SUMA/$sv" -one_node "$node")
# Parse the output to get RAI values
RAI=$(echo "$output" | grep "RAImm" | awk -F 'RAImm ' '{print $2}' | awk -F ' :' '{print $1}')
# RAI=$(echo "$output" | grep "RAImm" | awk '{print $3, $4, $5}')
R=$(echo "$RAI" | awk '{print $1}')
A=$(echo "$RAI" | awk '{print $2}')
I=$(echo "$RAI" | awk '{print $3}')
# Check if we have valid RAI coordinates
if [[ -z "$R" || -z "$A" || -z "$I" ]]; then
echo "Skipping node $node (missing RAI values)"
continue
fi
# Compute spherical coordinates using bc
r=$(echo "scale=6; sqrt($R^2 + $A^2 + $I^2)" | bc -l)
if (( $(echo "$r == 0" | bc -l) )); then
theta=0
else
theta=$(echo "scale=6; a(1) * 180 / 3.141592653589793 * a($I / $r)" | bc -l)
fi
phi=$(echo "scale=6; a(1) * 180 / 3.141592653589793 * a($A / $R)" | bc -l)
# Append to output file
echo "$node $R $A $I $r $theta $phi" >> "$output_file"
done < "$input_dset"
echo "Processing complete. Output saved to $output_file."