def op(proj_name): import p p.init() p.proj_name = proj_name set_params.op(1) p.create_dir() if COMM.rank == 0: print "Computing Optical Flow" data1 = myio.fin1(p.tess_file) CG = data1['CG'] numberofJobs = len(CG) input_data = divide(numberofJobs) if COMM.rank == 0: jobs = split(input_data, COMM.size) else: jobs = None jobs = COMM.scatter(jobs, root=0) res = [] for job in jobs: ComputeOptFlowPrDPsiAll1(job) res.append([]) if COMM.rank == 0: set_params.op(0) MPI.COMM_WORLD.gather(res, root=0) return
def op(proj_name): import p p.init() p.proj_name = proj_name set_params.op(1) p.create_dir() if COMM.rank == 0: print "Computing Edge Measurements" data1 = myio.fin1(p.CC_graph_file) G = data1['G'] edgeNumRange = data1['edgeNumRange'] flowVecPctThresh = p.opt_movie['flowVecPctThresh'] input_data = divide1(edgeNumRange,G) params1 = dict(G=G, flowVecPctThresh=flowVecPctThresh) else: params1 = None params1 = COMM.bcast(params1, root=0) if COMM.rank == 0: jobs = split(input_data, COMM.size) else: jobs = None jobs = COMM.scatter(jobs, root=0) res = [] for job in jobs: G = params1['G'] flowVecPctThresh = params1['flowVecPctThresh'] ComputeEdgeMeasurePairWisePsiAll(job,G,flowVecPctThresh) res.append([]) if COMM.rank == 0: set_params.op(0) MPI.COMM_WORLD.gather(res, root=0) return
def readBadNodesPsisTau(badNodesPsisTaufile): try: dataR = myio.fin1(badNodesPsisTaufile) badNodesPsisTau = dataR['badNodesPsisTau'] except: badNodesPsisTau = np.empty((0, 0)) return badNodesPsisTau
def divide(N): ll = [] for prD in range(N): CC_OF_file = '{}{}'.format(p.CC_OF_file, prD) if os.path.exists(CC_OF_file): data = myio.fin1(CC_OF_file) if data is not None: continue ll.append([CC_OF_file, prD]) return ll
def divide1(R, G): ll = [] for e in R: currPrD = G['Edges'][e, 0] nbrPrD = G['Edges'][e, 1] CC_meas_file = '{}{}_{}_{}'.format(p.CC_meas_file, e, currPrD, nbrPrD) if os.path.exists(CC_meas_file): data = myio.fin1(CC_meas_file) if data is not None: continue ll.append([currPrD,nbrPrD,CC_meas_file,e]) return ll
def count1(R, G): c = 0 for e in R: currPrD = G['Edges'][e, 0] nbrPrD = G['Edges'][e, 1] CC_meas_file = '{}{}_{}_{}'.format(p.CC_meas_file, e, currPrD, nbrPrD) if os.path.exists(CC_meas_file): data = myio.fin1(CC_meas_file) if data is not None: continue c += 1 return c
def op(CC_graph_file_pruned): import p trash_list=np.array(p.trash_list) good_nodes = np.nonzero(trash_list==0)[0] bad_nodes = np.nonzero(trash_list==1)[0] numNodes = len(good_nodes) num_pruned_nodes = len(bad_nodes) print "Number of nodes removed from the original graph (isolated nodes):",num_pruned_nodes maxState = 2 * p.num_psis # Up and Down if numNodes> 1: # Modifying the graph structure data = myio.fin1(p.CC_graph_file) G=data['G'] G.update(nPsiModes=p.num_psis) # prune edges corresponding to the bad nodes with actually removing those bad nodes newAdjMat=lil_matrix(G['AdjMat']) newAdjMat[bad_nodes,:]=0 newAdjMat[:,bad_nodes]=0 newAdjMat = csr_matrix(newAdjMat) G.update(AdjMat=newAdjMat) # Updated graph info G = CreateGraphStruct(G['maxState'],[],[], newAdjMat) #print 'newEdges',newEdges #print 'num_newEdges',num_newEdges #print 'bad_nodes',bad_nodes #print 'Number of Nodes in the pruned graph',np.unique(G['Edges']) else: print 'Single PrD. Empty graph structure created with one node.' G = CreateGraphStruct(maxState, [0], 0) # Determine if there are multiple connected components / subgraph # proceed to the pairwise measurements only after we are fine with the connected components Gsub, G = getSubGraph(G) # if pruned # replace #CC_graph_file_pruned = '{}_pruned'. format(p.CC_graph_file) myio.fout1(CC_graph_file_pruned,['G', 'Gsub'],[G, Gsub]) return G,Gsub
def getMask2D(prD, maskType, radius): #print 'Reading PD from dist_file and tesselation info from tess_file.' if maskType == 'annular': #annular mask N = p.nPix diam_angst = p.obj_diam diam_pix = diam_angst / p.pix_size if radius == None: # if no input is provided N2 = N / 2. - .25 * (N - diam_pix) * 0.30 else: N2 = radius # also includes radius = 0 if prD == 0: print('Annular mask radius: {} pixels'.format(N2)) mask = annularMask.op(0, N2, N, N) elif maskType == 'volumetric': #3d volume mask from user-input dist_file = '{}prD_{}'.format(p.dist_file, prD) data = myio.fin1(dist_file) PD = data['PD'] maskFile = p.mask_vol_file with mrcfile.open(maskFile) as mrc: mask3D = mrc.data mask = projectMask.op(mask3D, PD) else: mask = 1 ''' elif maskType=='average2Dmovie': mask=2 # do it after reading the movie else: mask=1 ''' return mask
def op(prD): #print '\nprD',prD findBadPsiTau = 1 ''' useMask = 1 # default p.mask_vol_file = '' #use mask or not, for movies if not p.mask_vol_file: # use default annular/circular mask maskType = 'annular' else: useMask = 1 maskType ='mask3Dprojection' ''' useMask = 1 # default if p.opt_mask_type == 0: useMask = 0 maskType = 'None' radius = p.opt_mask_param elif p.opt_mask_type == 1: useMask = 1 maskType = 'annular' radius = p.opt_mask_param elif p.opt_mask_type == 2: useMask = 1 maskType = 'volumetric' radius = None # for volumetric we don't need any radius psi2_file = p.psi2_file NumPsis = p.num_psis #print 'NumPsis',NumPsis #useMask = p.useMask #maskType = p.maskType moviePrDPsis = [None] * NumPsis tauPrDPsis = [None] * NumPsis badPsis = [] k = 0 if useMask: # create one mask for a prD mask2D = getMask2D(prD, maskType, radius) for psinum in range(NumPsis): imgPsiFileName = '{}prD_{}_psi_{}'.format(psi2_file, prD, psinum) data_IMG = myio.fin1(imgPsiFileName) #IMG1 = data_IMG["IMG1"].T IMG1 = data_IMG["IMG1"].T tau = data_IMG["tau"] #print 'PrD:',prD,', Psi',psinum Mpsi = -IMG1 # checkflip if useMask: # masked being applied to each frame of the movie M if maskType == 'average2Dmovie': Mpsi_masked = maskAvgMovie(Mpsi) else: Mpsi_masked = Mpsi * (mask2D.flatten('F') ) # broadcast to all frames else: Mpsi_masked = Mpsi #Mpsi_masked = rotate_psi(prD,Mpsi_masked) moviePrDPsis[psinum] = Mpsi_masked tauPrDPsis[psinum] = tau if findBadPsiTau: #b = findBadNodePsiTau(Mpsi,tau), if using psi-movie to determine b = findBadNodePsiTau(tau) if b: #print 'bad psinum',psinum badPsis.append(psinum) k = k + 1 else: badPsis = [] #print 'badPsis',badPsis return moviePrDPsis, badPsis
def ComputeEdgeMeasurePairWisePsiAll(input_data, G, flowVecPctThresh): currPrD = input_data[0] nbrPrD = input_data[1] CC_meas_file = input_data[2] edgeNum = input_data[3] currentPrDPsiFile = '{}{}'.format(p.CC_OF_file, currPrD) nbrPrDPsiFile = '{}{}'.format(p.CC_OF_file, nbrPrD) NumPsis = p.num_psis #print 'NumPsis',NumPsis #load the data for the current and neighbor prds #print '\nLoading data for current and neighbor PrD, Edge:{} ...'.format(edgeNum) data = myio.fin1(currentPrDPsiFile) FlowVecCurrPrD = data['FlowVecPrD'] data = myio.fin1(nbrPrDPsiFile) FlowVecNbrPrD = data['FlowVecPrD'] nEdges = G['nEdges'] if len(FlowVecCurrPrD[0]['FWD']['Vx'].shape) > 2: numtblocks = FlowVecCurrPrD[0]['FWD']['Vx'].shape[2] else: numtblocks = 1 measureOFCurrNbrFWD = np.empty((nEdges, NumPsis, NumPsis)) measureOFCurrNbrREV = np.empty((nEdges, NumPsis, NumPsis)) if numtblocks > 1: #numtblocks = 3 # temp , have to fix this from beginning measureOFCurrNbrFWD_tblock = np.empty( (nEdges, NumPsis, NumPsis * numtblocks)) measureOFCurrNbrREV_tblock = np.empty( (nEdges, NumPsis, NumPsis * numtblocks)) psiSelcurrPrD = range(NumPsis) psiCandidatesNnbrPrD = range( NumPsis) # in case psis for currPrD is different from nbrPrD badNodesPsisBlock = np.zeros((G['nNodes'], NumPsis)) #loop over for psi selections for current prD for psinum_currPrD in psiSelcurrPrD: if FlowVecCurrPrD[psinum_currPrD][ 'FWD']: # check if this condition holds for all kind of entries of the dict FlowVecCurrPrDFWD = SelectFlowVec( FlowVecCurrPrD[psinum_currPrD]['FWD'], flowVecPctThresh) # psi selection candidates for the neighboring prD for psinum_nbrPrD in psiCandidatesNnbrPrD: #print '\nCurrent-PrD:{}, Current-PrD-Psi:{}\nNeighbor-PrD:{}, Neighbor-PrD-Psi:{}'.format(currPrD, psinum_currPrD, nbrPrD, psinum_nbrPrD) if FlowVecNbrPrD[psinum_nbrPrD]['REV']: FlowVecNbrPrDFWD = SelectFlowVec( FlowVecNbrPrD[psinum_nbrPrD]['FWD'], flowVecPctThresh) FlowVecNbrPrDREV = SelectFlowVec( FlowVecNbrPrD[psinum_nbrPrD]['REV'], flowVecPctThresh) prds_psinums = [currPrD, psinum_currPrD, nbrPrD, psinum_nbrPrD] FlowVecSelAFWD = FlowVecCurrPrDFWD FlowVecSelBFWD = FlowVecNbrPrDFWD FlowVecSelBREV = FlowVecNbrPrDREV psiMovieOFmeasures, isBadPsiAB_block = ComputeMeasuresPsiMoviesOpticalFlow( FlowVecSelAFWD, FlowVecSelBFWD, FlowVecSelBREV, prds_psinums) #print 'psiMovieOFmeasures:',psiMovieOFmeasures,'\n' measureOFCurrNbrFWD[edgeNum][ psinum_currPrD, psinum_nbrPrD] = psiMovieOFmeasures['MeasABFWD'] measureOFCurrNbrREV[edgeNum][ psinum_currPrD, psinum_nbrPrD] = psiMovieOFmeasures['MeasABREV'] if numtblocks > 1: badNodesPsisBlock[currPrD, psinum_currPrD] = -100 * np.sum( isBadPsiAB_block[0]) badNodesPsisBlock[nbrPrD, psinum_nbrPrD] = -100 * np.sum( isBadPsiAB_block[1]) if numtblocks > 1: t = psinum_nbrPrD * numtblocks #time block #print 't',t,'numtblocks',numtblocks measureOFCurrNbrFWD_tblock[edgeNum][ psinum_currPrD, t:t + numtblocks] = np.transpose( psiMovieOFmeasures['MeasABFWD_tblock']) measureOFCurrNbrREV_tblock[edgeNum][ psinum_currPrD, t:t + numtblocks] = np.transpose( psiMovieOFmeasures['MeasABREV_tblock']) measureOFCurrNbrEdge = np.hstack( (measureOFCurrNbrFWD[edgeNum], measureOFCurrNbrREV[edgeNum])) if numtblocks > 1: measureOFCurrNbrEdge_tblock = np.hstack( (measureOFCurrNbrFWD_tblock[edgeNum], measureOFCurrNbrREV_tblock[edgeNum])) else: measureOFCurrNbrEdge_tblock = [] #print '\nCurrent-PrD:{}, Neighbor-PrD:{}'.format(currPrD, nbrPrD) #print 'measureOFCurrNbrEdge',measureOFCurrNbrEdge #print 'measureOFCurrNbrEdge_tblock',measureOFCurrNbrEdge_tblock #return #print 'Writing edge-{} data to file'.format(edgeNum) myio.fout1(CC_meas_file, [ 'measureOFCurrNbrEdge', 'measureOFCurrNbrEdge_tblock', 'badNodesPsisBlock' ], [measureOFCurrNbrEdge, measureOFCurrNbrEdge_tblock, badNodesPsisBlock]) ####################################################### # create empty PD files after each Pickle dump to... # ...be used to resume (avoiding corrupt Pickle files): progress_fname = os.path.join(p.CC_meas_prog, '%s' % (edgeNum)) open(progress_fname, 'a').close() #create empty file to signify non-corrupted Pickle dump
def op(G, nodeRange, edgeNumRange, *argv): nodeEdgeNumRange = [nodeRange, edgeNumRange] # Step 1. Compute Optical Flow Vectors # Save the optical flow vectors for each psi-movie of individual projection direction if p.getOpticalFlow: print( '\n1.Now computing optical flow vectors for all (selected) PrDs...\n' ) #Optical flow vectors for each psi-movies of each node are saved to disk if argv: ComputeOpticalFlowPrDAll.op(nodeEdgeNumRange, argv[0]) else: ComputeOpticalFlowPrDAll.op(nodeEdgeNumRange) # Step 2. Compute the pairwise edge measurements # Save individual edge measurements if p.getAllEdgeMeasures: print('\n2.Now computing pairwise edge-measurements...\n') # measures for creating potentials later on # edgeMeasures files for each edge (pair of nodes) are saved to disk if argv: ComputeMeasureEdgeAll.op(G, nodeEdgeNumRange, argv[0]) else: ComputeMeasureEdgeAll.op(G, nodeEdgeNumRange) # Step 3. Extract the pairwise edge measurements # to be used for node-potential and edge-potential calculations print('\n3.Reading all the edge measurements from disk...') # load the measurements file for each edge separately #edgeMeasures = np.empty((len(edgeNumRange)),dtype=object) #in case there are some nodes/edges for which we do not want to calculate the measures,the number of edges and # max edge indices may not match, so use the full G.nEdges as the size of the edgeMeasures. The edges which are not # calculated will remain as empty edgeMeasures = np.empty((G['nEdges']), dtype=object) edgeMeasures_tblock = np.empty((G['nEdges']), dtype=object) badNodesPsisBlock = np.zeros((G['nNodes'], p.num_psis)) for e in edgeNumRange: currPrD = G['Edges'][e, 0] nbrPrD = G['Edges'][e, 1] #print 'Reading Edge:',e,'currPrD:',currPrD,'nbrPrD:',nbrPrD CC_meas_file = '{}{}_{}_{}'.format(p.CC_meas_file, e, currPrD, nbrPrD) data = myio.fin1(CC_meas_file) measureOFCurrNbrEdge = data['measureOFCurrNbrEdge'] measureOFCurrNbrEdge_tblock = data['measureOFCurrNbrEdge_tblock'] bpsi = data['badNodesPsisBlock'] badNodesPsisBlock = badNodesPsisBlock + bpsi edgeMeasures[e] = measureOFCurrNbrEdge edgeMeasures_tblock[e] = measureOFCurrNbrEdge_tblock ###Test 30aug2019 #print 'before:',edgeMeasures[0][:,:] #print 'before:',edgeMeasures[2][:,:] scaleRange = [5.0, 30.0] edgeMeasures = reScaleLinear(edgeMeasures, edgeNumRange, scaleRange) #print 'badNodesPsisBlock',badNodesPsisBlock[0:10,:] #print 'after rescale:',edgeMeasures[0][:,:] #print 'after rescale:',edgeMeasures[2][:,:] #print 'badNodesPsis',badNodesPsis #print 'edgeMeasures_tblock',type(edgeMeasures_tblock) return edgeMeasures, edgeMeasures_tblock, badNodesPsisBlock
def op(*argv): import p time.sleep(5) set_params.op(1) # file i/o CC_file = '{}/CC_file'.format(p.CC_dir) if os.path.exists(CC_file): os.remove(CC_file) nodeOutputFile = '{}/comp_psi_sense_nodes.txt'.format(p.CC_dir) if os.path.exists(nodeOutputFile): os.remove(nodeOutputFile) nodeBelFile1 = '{}/nodeAllStateBel_rc1.txt'.format(p.CC_dir) if os.path.exists(nodeBelFile1): os.remove(nodeBelFile1) nodeBelFile2 = '{}/nodeAllStateBel_rc2.txt'.format(p.CC_dir) if os.path.exists(nodeBelFile2): os.remove(nodeBelFile2) CC_graph_file_pruned = '{}_pruned'.format(p.CC_graph_file) if os.path.exists(CC_graph_file_pruned): os.remove(CC_graph_file_pruned) #if OF_CC, OF_CC_fig directory doesn't exist then if not os.path.exists(p.CC_OF_dir): call(["mkdir", "-p", p.CC_OF_dir]) trash_list = np.array(p.trash_list) #print 'p.trash_list',trash_list trash_list_PDs = np.nonzero(trash_list == 1)[0] t = 0 for i in p.trash_list: if int(i) == int(1): t = t + 1 if t > 0: print 'Number of trash PDs', trash_list_PDs.shape[0] CC_graph_file = CC_graph_file_pruned G, Gsub = FindCCGraphPruned.op(CC_graph_file) else: CC_graph_file = p.CC_graph_file data = myio.fin1(CC_graph_file) G = data['G'] Gsub = data['Gsub'] numConnComp = len(G['NodesConnComp']) #print "Number of connected component:",numConnComp anchorlist = [a[0] for a in p.anch_list] anchorlist = [ a - 1 for a in anchorlist ] # we need labels with 0 index to compare with the node labels in G, Gsub print '\nAnchor list:', anchorlist, ', Number of anchor nodes:', len( anchorlist), '\n' if any(a in anchorlist for a in G['Nodes']): if len(anchorlist) + t == G['nNodes']: print '\nAll nodes have been manually selected (as anchor nodes). ' \ 'Reaction-coordinate propagation is not required. Exiting this program.\n' psinums = np.zeros((2, G['nNodes']), dtype='int') senses = np.zeros((2, G['nNodes']), dtype='int') #CC1 #psinums[0,:]=[a[1]-1 for a in p.anch_list] #senses[0,:]=[a[2] for a in p.anch_list] for a in p.anch_list: #for row in anch_list; e.g. [1, 1, -1, 0] psinums[0, a[0] - 1] = a[1] - 1 senses[0, a[0] - 1] = a[2] idx = 0 for t in p.trash_list: #for row in trash_list; e.g. [36, True] means PD 36 is Trash if t == 1: psinums[0, idx] = -1 senses[0, idx] = 0 idx += 1 #print 'psinums',psinums #print 'senses',senses #CC2 #psinums[1,:]=[a[4] for a in p.anch_list] # a[col], whatever column number is in the p.anch_list for CC2 #senses[2,:]=[a[5] for a in p.anch_list] print '\nFind CC: Writing the output to disk...\n' p.CC_file = '{}/CC_file'.format(p.CC_dir) myio.fout1(p.CC_file, ['psinums', 'senses'], [psinums, senses]) p.allAnchorPassed = 1 if argv: progress5 = argv[0] # We introduce some time delay for proper communication between the execution of this code and the GUI for i in xrange(101): time.sleep(0.01) progress5.emit(int(i)) return else: print 'Some(or all) of the anchor nodes are NOT in the Graph node list.' return nodelCsel = [] edgelCsel = [] # this list keeps track of the connected component (single nodes included) for which no anchor was provided connCompNoAnchor = [] for i in xrange(numConnComp): nodesGsubi = Gsub[i]['originalNodes'] edgelistGsubi = Gsub[i]['originalEdgeList'] edgesGsubi = Gsub[i]['originalEdges'] #print 'Checking connected component ','i=',i,', Gsub[i]',', Original node list:',nodesGsubi,\ # 'Original edge list:',edgelistGsubi[0],'Original edges:', edgesGsubi, 'No. edges:',len(edgesGsubi) #print 'Checking connected component ','i=',i,', Gsub[i]',', Original node list:',nodesGsubi,\ # 'Original edge list:',edgelistGsubi[0],'Size Edges:',len(edgesGsubi) if any(x in anchorlist for x in nodesGsubi): #print 'Atleast one anchor node in connected component',i,'is selected.\n' nodelCsel.append(nodesGsubi.tolist()) edgelCsel.append(edgelistGsubi[0]) else: connCompNoAnchor.append(i) #print 'Anchor node(s) in connected component',i,' NOT selected.' #print '\nIf you proceed without atleast one anchor node for the connected component',i,\ # ', all the corresponding nodes will not be assigned with reaction coordinate labels.\n' G.update(ConnCompNoAnchor=connCompNoAnchor) #print connCompNoAnchor,G['ConnCompNoAnchor'] #nodeRange = nodelCsel #edgeNumRange = edgelCsel nodeRange = [y for x in nodelCsel for y in x] #flatten list another way? edgeNumRange = [y for x in edgelCsel for y in x] #flatten list another way? #nodeRange = range(G['nNodes']) #edgeNumRange = range(G['nEdges']) #nodeRange = [171,172,173,174,175,176] #edgeNumRange = [1247,1248,1262,1267] #nodeRange = [0,1,2] #edgeNumRange = [0,1] nodeRange = np.sort(nodeRange) edgeNumRange = np.sort(edgeNumRange) # adding these two params to the CC graph file *Hstau Aug 19 data = myio.fin1(CC_graph_file) extra = dict(nodeRange=nodeRange, edgeNumRange=edgeNumRange) data.update(extra) myio.fout2(CC_graph_file, data) #print 'Selected graph G nodes and edges in the connected components for which atleast one anchor node were selected:' #print 'nodeRange',nodeRange #print 'edgeNumRange',edgeNumRange # compute all pairwise edge measurements # Step 1: compute the optical flow vectors for all prds # Step 2: compute the pairwise edge measurements for all psi - psi movies # Step 3: Extract the pairwise edge measurements to be used for node-potential and edge-potential calculations if argv: edgeMeasures, edgeMeasures_tblock, badNodesPsisBlock = ComputePsiMovieEdgeMeasurements.op( G, nodeRange, edgeNumRange, argv[0]) else: edgeMeasures, edgeMeasures_tblock, badNodesPsisBlock = ComputePsiMovieEdgeMeasurements.op( G, nodeRange, edgeNumRange) #print '\nedgeMeasures:\n',edgeMeasures # Setup and run the Optimization: Belief propagation print '\n4.Running Global optimization to estimate state probability of all nodes ...' BPoptions = dict(maxProduct=1, verbose=0, tol=1e-4, maxIter=300, eqnStates=1.0, alphaDamp=1.0) #reaction coordinate number rc = 1,2 psinums = np.zeros((2, G['nNodes']), dtype='int') senses = np.zeros((2, G['nNodes']), dtype='int') cc = 1 print('\nFinding CC for Dim:1') nodeStateBP_cc1, psinums_cc1, senses_cc1, OptNodeBel_cc1, nodeBelief_cc1 = runGlobalOptimization.op( G, BPoptions, edgeMeasures, edgeMeasures_tblock, badNodesPsisBlock, cc) psinums[0, :] = psinums_cc1 senses[0, :] = senses_cc1 if p.dim == 2: cc = 2 print('\nFinding CC for Dim:2') nodeStateBP_cc2, psinums_cc2, senses_cc2, OptNodeBel_cc2, nodeBelief_cc2 = runGlobalOptimization.op( G, BPoptions, edgeMeasures, edgeMeasures_tblock, cc, nodeStateBP_cc1) psinums[1, :] = psinums_cc2 senses[1, :] = senses_cc2 # save print '\nFind CC: Writing the output to disk...\n' p.CC_file = '{}/CC_file'.format(p.CC_dir) myio.fout1(p.CC_file, ['psinums', 'senses'], [psinums, senses]) if p.dim == 1: # 1 dimension node_list = np.empty((G['nNodes'], 4)) node_list[:, 0] = range(1, G['nNodes'] + 1) # 1 indexing node_list[:, 1] = psinums[0, :] + 1 # indexing 1 node_list[:, 2] = senses[0, :] node_list[:, 3] = OptNodeBel_cc1 # save the found psinum , senses also as text file #node_list is variable name with columns: if dim =1 : (PrD, CC1, S1) + (CC2, S2) if dim =2 np.savetxt(nodeOutputFile, node_list, fmt='%i\t%i\t%i\t%f', delimiter='\t') nodeBels1 = np.empty( (nodeBelief_cc1.T.shape[0], nodeBelief_cc1.T.shape[1] + 1)) nodeBels1[:, 0] = range(1, G['nNodes'] + 1) nodeBels1[:, 1:] = nodeBelief_cc1.T np.savetxt(nodeBelFile1, nodeBels1, fmt='%f', delimiter='\t') elif p.dim == 2: # 2 dimension node_list = np.empty((G['nNodes'], 7)) node_list[:, 0] = range(1, G['nNodes'] + 1) # 1 indexing node_list[:, 1:3] = (psinums + 1).T # indexing 1 and indices 1:3 means 1 & 2 node_list[:, 3:5] = senses.T #indices 3:5 means 3 & 4 node_list[:, 5] = OptNodeBel_cc1 node_list[:, 6] = OptNodeBel_cc2 # save the found psinum , senses also as text file #node_list is variable name with columns: if dim =1 : (PrD, CC1, S1) + (CC2, S2) if dim =2 np.savetxt(nodeOutputFile, node_list, fmt='%i\t%i\t%i\t%i\t%i\t%f\t%f', delimiter='\t') nodeBels2 = np.empty( (nodeBelief_cc2.T.shape[0], nodeBelief_cc2.T.shape[1] + 1)) nodeBels2[:, 0] = range(1, G['nNodes'] + 1) nodeBels2[:, 1:] = nodeBelief_cc2.T np.savetxt(nodeBelFile2, nodeBels2, fmt='%f', delimiter='\t') if argv: progress5 = argv[0] progress5.emit(int(100)) time.sleep(0.05)