Hello,
I have a question about creating scripts for TkSurfer. I really know next to nothing about scripts in general so these are rather basic questions. There seems to be a lot of scripting commands for TkMedit but not for TkSurfer. Is there a general list of the basic commands?
The commands I need to know how to do are:
Open a subject Load a surface (inflated and pial) Display the color bar in a for loop Overlay a .w file Redraw the image Save as a .rgb image end loop
Is this all done in a csh script? And then how do I run the script?
Thank you for any help.
Sarah
I have a question about creating scripts for TkSurfer. I really know next to nothing about scripts in general so these are rather basic questions. There seems to be a lot of scripting commands for TkMedit but not for TkSurfer. Is there a general list of the basic commands?
First of all, the scripting langugage for tkmedit and tksurfer is Tcl, so you should get an introduction to Tcl on the web or from a book. The syntax is pretty simple.
You will start up tksurfer from the command line normally, so you can load your subject and surface from there. Then, you pass the script you want to run with the -tcl option. For example:
tksurfer bert lh inflated -tcl my_script.tcl
my_script.tcl would be a text file with your script commands.
Display the color bar in a for loop Overlay a .w file Redraw the image Save as a .rgb image end loop
To turn on the color bar:
set colscalebarflag 1
To read a .w file, use the commands:
set val <filename> sclv_read_binary_values <field>
Where <filename> is the .w file name and <field> is 0-9, signifying which overlay layer you want to load this into. If you load an overlay into a layer that is already filled, it will replace what's there.
You will need to force a redraw of the screen after loading an overlay, so use this command:
redraw
To save an rgb image:
set rgb <filename> save_rgb
Where <filename> is the name of the RGB file you want to create.
There are different kinds of loops available, but if you want to loop over a series of elements in a list, such as file names to load, you can use:
foreach <varname> <list> {
}
This will iterate over all the elements in <list>, setting <varname> to each. For example:
set colscalebarflag 1 foreach file_name { overlay1.w overlay2.w overlay3.w } {
set val $file_name sclv_read_binary_values 0 redraw
set rgb ${file_name}-capture.rgb save_rgb }
This will load overlay1.w and create overlay1.w-capture.rgb, then overlay2.w and create overlay2.w-capture.rgb, and so on.
You may need to use full file names if you don't want to load everything from the current directory and save all the RGBs there. Tcl has a nice set of functions in the file command to do stuff like join paths, extract file names, and chop off extensions, e.g.:
set path [file join path to my data] - path becomes /path/to/my/data
set file_name [file tail /path/to/my/data/overlay1.w] - file_name becomes overlay1.w
set simple_file_name [file name overlay1.w] - simple_file_name becomes overlay1
So:
set base_directory [file join path to my data] set file_name overlay1.w set val [file join $base_directory $file_name] ... set rgb_directory [file join path to my rgbs] set rgb [file join $rgb_directory [file tail [file name $val]]].rgb
This will set val to /path/to/my/data/overlay1.w, and rgb to /path/to/my/rgbs/overlay1.rgb
There's a lot here, so I would suggest starting out with an introduction to Tcl, then creating a simple script to load and display an overlay file, then gradually add to it.
I forgot, every tksurfer script must start with the command:
open_window
Just stick it at the top of the file before you do anything else.
hi Sarah-
i'll try my hand at what you want to do below:
I have a question about creating scripts for TkSurfer. I really know next to nothing about scripts in general so these are rather basic questions. There seems to be a lot of scripting commands for TkMedit but not for TkSurfer. Is there a general list of the basic commands?
there is, just type: tksurfer on the command line
Open a subject Load a surface (inflated and pial)
tksurfer subject rh inflated tksurfer subject rh pial #see below for how to define tcl script to tksurfer, but you can also type #the following in the tksurfer tcl prompt:
Display the color bar
set colscalebarflag 1
in a for loop
set filelist "file1.w file2.w" set layr 0 foreach i $filelist {
Overlay a .w file Redraw the image
set val $i sclv_read_binary_values $layr
#maybe you want to also set thresholds for the overlay #and change the lighting model set fthresh 1.3 set fslope 1 set fmid 2 do_lighting_model 0.4 0.0 0.6 0.2 0.4;
Save as a .rgb image
set filestem "$sbjdir/rgb/${hemi}.$i" puts "Taking Snapshots to $filestem"; make_lateral_view; redraw; setfile rgb "${filestem}_lat.rgb"; puts $rgb; save_rgb; rotate_brain_x 90; redraw; setfile rgb "${filestem}_inf.rgb"; puts $rgb; save_rgb; make_lateral_view; rotate_brain_y 180; redraw; setfile rgb "${filestem}_med.rgb"; puts $rgb; save_rgb; incr layr #you can load up to 8 or 9 layers(overlays) in tksurfer #if you have more, tksurfer won't like you and will quit. #alternatively, you can just not increment the layr (above) #and keep loading in layer 0
end loop
}
Is this all done in a csh script? And then how do I run the script?
it's all in tcl. a quick way to learn is TclTutor: http://www.msen.com/~clif/TclTutor.html
you define the .tcl script for tksurfer on the command line
foreach s ($SUBJECTS) foreach h (rh lh) tksurfer $s $h inflated -tcl load_ovrly_and_snaps.tcl tksurfer $s $h pial -tcl load_ovrly_and_snaps.tcl end end
i hope this helps.
good luck,
freesurfer@nmr.mgh.harvard.edu