def test_surfshots(): fotos = fs.SurfaceSnapshots() # Test underlying command yield assert_equal, fotos.cmd, "tksurfer" # Test mandatory args exception yield assert_raises, ValueError, fotos.run # Create testing files files, cwd, oldwd = create_files_in_directory() # Test input settins fotos.inputs.subject_id = "fsaverage" fotos.inputs.hemi = "lh" fotos.inputs.surface = "pial" # Test a basic command line yield assert_equal, fotos.cmdline, "tksurfer fsaverage lh pial -tcl snapshots.tcl" # Test identity schmotos = fs.SurfaceSnapshots(subject_id="mysubject", hemi="rh", surface="white") yield assert_not_equal, fotos, schmotos # Test that the tcl script gets written fotos._write_tcl_script() yield assert_equal, True, os.path.exists("snapshots.tcl") # Test that we can use a different tcl script foo = open("other.tcl", "w").close() fotos.inputs.tcl_script = "other.tcl" yield assert_equal, fotos.cmdline, "tksurfer fsaverage lh pial -tcl other.tcl" # Test that the interface crashes politely if graphics aren't enabled try: hold_display = os.environ["DISPLAY"] del os.environ["DISPLAY"] yield assert_raises, RuntimeError, fotos.run os.environ["DISPLAY"] = hold_display except KeyError: pass # Clean up our mess clean_directory(cwd, oldwd)
def test_surfshots(create_files_in_directory_plus_dummy_file): fotos = fs.SurfaceSnapshots() # Test underlying command assert fotos.cmd == "tksurfer" # Test mandatory args exception with pytest.raises(ValueError): fotos.run() # Create testing files files, cwd = create_files_in_directory_plus_dummy_file # Test input settins fotos.inputs.subject_id = "fsaverage" fotos.inputs.hemi = "lh" fotos.inputs.surface = "pial" # Test a basic command line assert fotos.cmdline == "tksurfer fsaverage lh pial -tcl snapshots.tcl" # Test identity schmotos = fs.SurfaceSnapshots(subject_id="mysubject", hemi="rh", surface="white") assert fotos != schmotos # Test that the tcl script gets written fotos._write_tcl_script() assert os.path.exists("snapshots.tcl") # Test that we can use a different tcl script foo = open("other.tcl", "w").close() fotos.inputs.tcl_script = "other.tcl" assert fotos.cmdline == "tksurfer fsaverage lh pial -tcl other.tcl" # Test that the interface crashes politely if graphics aren't enabled try: hold_display = os.environ["DISPLAY"] del os.environ["DISPLAY"] with pytest.raises(RuntimeError): fotos.run() os.environ["DISPLAY"] = hold_display except KeyError: pass
def makeBrainPic(freesurfer_dir): for side in ['lh', 'rh']: tcl_script = os.path.join(freesurfer_dir, 'tmp', side + '_tksurfer.tcl') #annotFile = os.path.join(freesurfer_dir, #'mri/aparc+aseg.mgz') #print os.path.dirname(freesurfer_dir) shots = fs.SurfaceSnapshots( subject_id=os.path.basename(freesurfer_dir), subjects_dir=os.path.dirname(freesurfer_dir), hemi=side, tcl_script=tcl_script, #annot_file = annotFile, #overlay_range = (-4,4), #screenshot_stem = freesurfer_dir+'_'+side, six_images=True, surface="inflated") os.environ["SUBJECTS_DIR"] = os.path.dirname(freesurfer_dir) #print shots.cmdline #print "export SUBJECTS_DIR={0}".format(os.path.dirname(freesurfer_dir)) os.popen(shots.cmdline).read() #print '*'*80 #try: ##res = shots.run() #pass #except: #pass createdList = [ side + '_' + x + '.tif' for x in ["inferior", "lateral", "medial"] ] for img in createdList: #print img if 'baseline' in freesurfer_dir: folderName = os.path.dirname(freesurfer_dir).split( '/baseline')[0] else: folderName = os.path.dirname(freesurfer_dir) shutil.move( img.split('_')[1], os.path.join( '/ccnc/mri_team/', os.path.basename(folderName) + '_' + os.path.basename(img)))