def make_col_type_string(self): """return a string showing which columns are main, baseline or motion (return error code (0=success) and cormat string)""" mat = self.matX if not mat.ready: return 1, '** no X-matrix to get col types from' mstr = 'Columns by regressor type:\n\n' mstr += ' main regressor columns : %s\n' % \ UTIL.encode_1D_ints(list(range(self.matX.ncols))) mstr += ' chosen regressor columns : %s\n' % \ UTIL.encode_1D_ints(self.col_list) mstr += ' baseline regressor columns : %s\n' % \ UTIL.encode_1D_ints(self.matX.cols_by_group_list([-1])) mstr += ' motion regressor columns : %s\n' % \ UTIL.encode_1D_ints(self.matX.cols_by_group_list([0])) return 0, mstr
all_lost_labs = '' all_lost_vals = '' all_lost_vals_list = [] for ii in range( len(lost_ref_labs) ): if not(ii % 5) : all_lost_labs+= '\n# ' all_lost_vals+= '\n# ' all_lost_labs+= '{:<10s} '.format(lost_ref_labs[ii]) all_lost_vals+= '{:<10d} '.format(lost_ref_vals[ii]) all_lost_vals_list.append(lost_ref_vals[ii]) # for later reporting; makes a string of AFNI-encoded items # separated with .. and , (which is NOT used right now), and a # simple, comma-separated list in a string all_lost_vals_enc_1D = au.encode_1D_ints(all_lost_vals_list) all_lost_vals_comma = ','.join([str(x) for x in all_lost_vals_list]) # calc physical volumes size of ROIs and masks new_inp_vols = nvox2phys_vol( new_inp_nvox, inp_voxvol ) ref_vols = nvox2phys_vol( ref_nvox, ref_voxvol ) inp_mask_vol = nvox2phys_vol( inp_mask_size, inp_voxvol ) ref_mask_vol = nvox2phys_vol( ref_mask_size, ref_voxvol ) # calc fractional volumes of ROIs in mask: vals / N_mask new_inp_fracs = nvox2frac_size( new_inp_nvox, inp_mask_size ) ref_fracs = nvox2frac_size( ref_nvox, ref_mask_size ) # -------------------- make HEADER of file ------------------------
# ================================================================= if __name__=="__main__": # --------------------- get input ------------------------ print("++ Command line:\n ", ' '.join(sys.argv)) (ifile, inumb, ofile) = get_arg(sys.argv[1:]) # --------------------- proc it ------------------------ bad_list_init = au.read_text_file( ifile ) bad_list_proc = Convert_StrList_to_NumArr( bad_list_init ) good_list = Invert_BadInd_List( bad_list_proc, inumb ) good_encoded = au.encode_1D_ints( good_list ) # ------------------- write out ------------------------- print("++ OK, the list of good indices in AFNI selector format is:") print("\n %s\n" % good_encoded) f = open(ofile, 'w') f.write(good_encoded) f.close() print(" ... which has been written to file: %s" % ofile) print("++ Done.") sys.exit(0)
# [PT: May 22, 2018] want INTERSECTION, not union... Nlstr = len(lstr) if Nlstr < 1: sys.exit("Couldn't find any number strings??") # put all selectors together sss = set(au.decode_1D_ints(lstr[0], imax=maxind)) for i in range(1,Nlstr): ll = lstr[i] sss = set.intersection(sss, set(au.decode_1D_ints(ll, imax=maxind))) # listify and sort list_final = list(sss) list_final.sort() good_encoded = au.encode_1D_ints( list_final ) # ------------------- write out ------------------------- print("++ OK, the list of good indices in AFNI selector format is:") print("\n %s\n" % good_encoded) f = open(ofile, 'w') f.write(good_encoded) f.close() print(" ... which has been written to file: %s" % ofile) print("++ Done.") sys.exit(0)
def plot_mat_by_cols(self, amat, cols=[]): """plot the given columns from a single AfniMatrix""" if not isinstance(amat, AM.AfniXmat): print('** plot_MBC: instance is not AfniXmat') return if not cols: if amat.verb > 1: print('-- plotting default of %d cols' % amat.ncols) cols = [i for i in range(amat.ncols)] ncols = len(cols) if ncols < 1: return # create reduced matrix and column labels mat = amat.mat[:,cols] yformat = FormatStrFormatter('%5.1f') if amat.labels: labels = N.array(amat.labels) labels = labels[cols] labels = labels.tolist() # create axis formatter string striplabs = 1 for label in labels: # strip trailing '#' if indices are all 0 ind = regress_index(label) if ind > 0: striplabs = 0 maxlen = 0 for l in range(len(labels)): label = labels[l] if striplabs: labels[l] = labels[l][0:labels[l].rfind('#')] if len(labels[l]) > maxlen: maxlen = len(labels[l]) for i in range(ncols): if i == 0: title = '%s [%s]' % (os.path.basename(amat.fname), UTIL.encode_1D_ints(cols)) else : title = '' if self.as_one: # then only create one axis if i == 0: ax = self.figure.add_subplot(1,1,1,title=title) else: ax = self.figure.add_subplot(ncols,1,i+1,title=title) data = mat[:,i] ax.plot(data) # apply y tickmarks ymin, ymax = ax.get_ylim() width = ymax - ymin if ymin*ymax < 0.0: ymean = 0.0 else: ymean = round((ymin+ymax)/2.0,2) ax.grid(True) ax.yaxis.set_major_formatter(yformat) amax = round(data.max(),1) if self.as_one: pass # use default yticks elif amax == 1.0 and ymin == 0.0: ax.set_yticks(N.array([ymin,amax])) elif ncols > 10: ax.set_yticks(N.array([ymin,ymax])) else: ax.set_yticks(N.array([ymin,ymean,ymax])) # now that yticks are set, prevent tight limits if not self.as_one: if ymin == data.min(): ymin -= 0.15 * width ax.set_ylim((ymin, ymax)) if ymax == data.max(): ymax += 0.15 * width ax.set_ylim((ymin, ymax)) if amat.run_len > 10 and amat.nruns > 1: ax.set_xticks(N.array([r*amat.run_len for r in range(amat.nruns+1)])) if i < ncols - 1: ax.set_xticklabels([]) else: ax.set_xlabel('TRs') if self.as_one: ax.set_ylabel('') elif amat.labels: ax.set_ylabel('%-*s ' % (maxlen,labels[i]), rotation='horizontal') rv, plist = self.axis_posn(ax) # rcr - fix #if rv == 0: ax.set_position((0.2, plist[1], plist[2], plist[3])) if rv == 0: ax.set_position((0.15, plist[1], 0.7, 0.7/ncols)) self.Fit() self.canvas.draw()