def set_afni_version(self): # version number and package type cmd = '''afni -vnum -package''' com = BASE.shell_com(cmd, capture=1, save_hist=0) com.run() check_for_shell_com_failure(com, cmd, disp_so=False, disp_se=False) self.afni_ver = ", ".join(com.so)
def __init__(self): self.full_cmd = '' # existential... self.prog_ver = ddefs['DEF_ver'] self.afni_ver = '' self.is_verbose = False self.dset = '' self.dset_info = '' self.rep_vox_iso = False self.rep_mat_even = False self.rep_vox_1mm_max = False self.rep_vox_05mm_min = False self.vox_dim = [] self.mat_dim = [] self.vox_dim_str = '' self.mat_dim_str = '' self.eps_iso = ddefs['DEF_eps_iso'] self.eps_size = ddefs['DEF_eps_size'] self.check_all = -1 # def: do all self.stat_mat_even = -1 # status self.stat_vox_iso = -1 # status self.stat_vox_1mm_max = -1 # status self.stat_vox_05mm_min = -1 # status self.stat_fs_safe = -1 # status # This is here basically to just initialize the 'comm' obj cmd = 'pwd' self.comm = BASE.shell_com( cmd, capture=1 ) self.comm.run() check_for_shell_com_failure( self.comm, cmd, disp_so=False, disp_se=False )
def get_all_3dinfo_dset_basic(fname): '''Input: a volume 'pon which to run 3dinfo. Output: dictionary whose keys are 3dinfo opt names relevant for a single volume (not helpy ones or comparison ones like -same*); the '-' part is part of the key here, at the moment. There is no filtering of empty fields here-- the bog standard outputs are all returned; each value in the dictionary is a list of string(s), which may be null. See "get_all_3dinfo_dset_neatly()" for some filtering/proc'ing of opts. ''' # ------- Quick check on dset being valid cmd = '''3dinfo -prefix {fff}'''.format(fff=fname) com = BASE.shell_com(cmd, capture=1, save_hist=0) com.run() if com.so[0] == 'NO-DSET': print('+* WARNING: No valid dset of that name: {fff}\n.' ' Bye.'.format(fff=fname)) return {} # ------- Get list of all opts in 3dinfo cmd = '''apsearch -list_popts 3dinfo''' com = BASE.shell_com(cmd, capture=1, save_hist=0) com.run() # filter out some ones we don't want list_3dinfo_opts = [] for x in com.so: y = x.strip() if not (list_3dinfo_ignore.__contains__(y)): list_3dinfo_opts.append(y) dict_info = {} for opt in list_3dinfo_opts: cmd = '''3dinfo {ooo} {fff}'''.format(ooo=opt, fff=fname) com = BASE.shell_com(cmd, capture=1, save_hist=0) com.run() dict_info[opt] = com.so return dict_info
def finish_defs(self): # get some basic versions that matter cmd = '''afni -ver''' com = BASE.shell_com(cmd, capture=1, save_hist=0) com.run() check_for_shell_com_failure(com, cmd, disp_so=False, disp_se=False) self.set_afni_ver(com.so[0])
def __init__(self): self.full_cmd = '' # existential... self.code_ver = ddefs['DEF_ver'] self.afni_ver = '' self.overwrite = '' # pass along overwrite flag (or not) # This is here basically to just initialize the 'comm' obj cmd = 'pwd' self.comm = BASE.shell_com(cmd, capture=1) self.comm.run() check_for_shell_com_failure(self.comm, cmd, disp_so=False, disp_se=False)
def run_fix_all(self): # all tests for resampling voxel size if self.stat_vox_iso == False or \ self.stat_vox_1mm_max == False or \ self.stat_vox_05mm_min == False : self.fix_vox = True # all tests for changing matrix dims-- note that if we # resample the vox sizes, then we will also do the # pad_to_evens, just to be sure the grid hasn't changed (and # to have consistent output naming); so, leave this check # after the 'fix_vox' one. if self.stat_mat_even == False or \ self.fix_vox == True : self.fix_mat = True # have this be a bool, for verbose output if self.fix_mat or self.fix_vox: self.fix_make_changes = True else: self.fix_make_changes = False # determine output voxel size; user might have entered a value # (and that will have already been checked for validity at input) if self.fix_vox: if self.fix_out_vox_dim == None: # then it hasn't been set by user if self.vox_dim_min < 0.5: self.fix_out_vox_dim = 0.5 elif 1.0 < self.vox_dim_min: self.fix_out_vox_dim = 1.0 else: self.fix_out_vox_dim = self.vox_dim_min # do resampling and/or matrix padding, in that order: if self.fix_vox: # generate name with random string for fix_vox # use this function here, because this file won't exist yet! pp = os.path.dirname(self.fix_out_prefix) if not (pp): pp = '.' # the above returns '' for local dir-- not cool cmd = '''3dnewid -fun11''' com = BASE.shell_com(cmd, capture=1, save_hist=0) com.run() check_for_shell_com_failure(com, cmd, disp_so=False, disp_se=False) self.fix_tmp_fname = pp + '/' + ddefs['DEF_dset_tmp_base'] self.fix_tmp_fname += com.so[0] + '.nii' # resampling to iso vox cmd = '''3dAllineate {ow} \ -1Dmatrix_apply IDENTITY \ -mast_dxyz {dxyz} \ -final wsinc5 \ -source {src} \ -prefix {pref} '''.format(ow=self.fix_overwrite, dxyz=self.fix_out_vox_dim, src=self.dset, pref=self.fix_tmp_fname) com = BASE.shell_com(cmd, capture=1, save_hist=0) com.run() check_for_shell_com_failure(com, cmd, disp_so=False, disp_se=False) # any fixing will lead to having this performed if self.fix_mat: # decide if we already did one correction step or not if self.fix_tmp_fname: input_dset = self.fix_tmp_fname else: input_dset = self.dset # resampling to iso vox cmd = '''3dZeropad {ow} \ -pad2evens \ -prefix {pref} \ {src} '''.format(ow=self.fix_overwrite, src=input_dset, pref=self.fix_out_prefix) com = BASE.shell_com(cmd, capture=1, save_hist=0) com.run() check_for_shell_com_failure(com, cmd, disp_so=False, disp_se=False) # clean up, if intermed dset exists if self.fix_vox: cmd = '''\\rm {pref} '''.format(pref=self.fix_tmp_fname) com = BASE.shell_com(cmd, capture=1, save_hist=0) com.run() check_for_shell_com_failure(com, cmd, disp_so=False, disp_se=False) if not (self.fix_make_changes): # no changes, but output a dset with the correct file name cmd = '''3dcalc {ow} \ -a {src} \ -expr 'a' \ -prefix {pref} '''.format(ow=self.fix_overwrite, src=self.dset, pref=self.fix_out_prefix) com = BASE.shell_com(cmd, capture=1, save_hist=0) com.run() check_for_shell_com_failure(com, cmd, disp_so=False, disp_se=False) # get info about output set self.set_fix_out_info()
# -------------------------------------------------------------------- # QC block: "warns" # item : censor fraction, per stimulus # use if: there are stim files present, and censoring ldep = ['stats_dset', 'censor_dset', 'ss_review_dset', 'xmat_stim'] if lat.check_dep(ap_ssdict, ldep): # get the ss_review_basic info as a dict rev_dict = lat.read_in_txt_to_dict(ap_ssdict['ss_review_dset'], tmp_name='__tmp_ss_rev.json') cmd = '''1d_tool.py -verb 0 -infile {xmat_stim} -show_labels '''.format(**ap_ssdict) com = BASE.shell_com(cmd, capture=1, save_hist=0) com.run() all_labels = com.so[0].split() # list of all labels ban = lat.bannerize('Censor fraction (per stim)') obase = 'qc_{:02d}'.format(idx) cmd = lat.apqc_warns_cen_stim(obase, "warns", "cen_stim", rev_dict=rev_dict, label_list=all_labels) str_FULL += ban str_FULL += cmd idx += 1