def create_W_pics(self, it=None, comm=MPI.COMM_WORLD, out_path=None, comp_rate=1, filenames=[]): """ Creates sequence of images from W. Requires None or list. If *it*=None creates pictures of all GF saved at folder *.../h5file* (-.h5). If *it*=list checks for lenght. Lenght == 1 : saves this iteration number. If length == 2, first < second, saves pictures in this interval. *comp_rate*, integer that allows to plot ONLY each comp_rate*i (i integer) field. """ if 'W' in self.variables: W = self.h5file.root.W[:] num_W, H, D = W.shape D2 = np.int(np.sqrt(D)) if D2**2 != D: #We correct for channel splitting D2 = np.int(np.sqrt(D // 2)) D = D2**2 temp_W = W.reshape(num_W, H, 2 * D2, D2) W = (temp_W[:, :, 0:D2, :] - temp_W[:, :, D2:2 * D2, :]).reshape(num_W, H, D) del temp_W if it == None: iter_list = xrange(num_W) #Print_all case #In all the rest of the cases it should be a list elif it.__class__ != [].__class__: raise TypeError("Input should be a list") else: #Print a specific number if len(it) == 1: iter_list = it elif len(it) == 2: if it[0] >= it[1]: print '\n\n OK, nothing will be printed \n\n' iter_list = xrange(it[0], it[1]) else: raise ValueError("list should contain 1 or 2 elements!") if out_path == None: out_dir = self.h5file.filename[0:-3] else: out_dir = out_path if comm.rank == 0: mkdir(out_dir) #The path is only generated at processor 0 fields = range(0, H, comp_rate) if len(iter_list) != len(filenames): for indW in iter_list: save_path = out_dir + '/W_' + iter_to_str(indW + 1, num_W) + '.png' self.create_W_pic(W[indW, :, :], save_path, fields) else: num_order = 0 for indW in iter_list: save_path = out_dir + filenames[num_order] self.create_W_pic(W[indW, :, :], save_path, fields) num_order += 1
def create_W_pics(self, it=None, comm=MPI.COMM_WORLD, out_path=None, comp_rate=1, filenames=[]): """ Creates sequence of images from W. Requires None or list. If *it*=None creates pictures of all GF saved at folder *.../h5file* (-.h5). If *it*=list checks for lenght. Lenght == 1 : saves this iteration number. If length == 2, first < second, saves pictures in this interval. *comp_rate*, integer that allows to plot ONLY each comp_rate*i (i integer) field. """ if 'W' in self.variables: W = self.h5file.root.W[:] num_W, H, D = W.shape D2 = np.int(np.sqrt(D)) if D2**2 != D: #We correct for channel splitting D2 = np.int(np.sqrt(D//2)) D = D2**2 temp_W = W.reshape(num_W, H, 2*D2, D2) W = (temp_W[:, :, 0:D2, :] - temp_W[:, :, D2:2*D2, :]).reshape(num_W, H, D) del temp_W if it == None: iter_list = xrange(num_W) #Print_all case #In all the rest of the cases it should be a list elif it.__class__ != [].__class__: raise TypeError("Input should be a list") else: #Print a specific number if len(it) == 1: iter_list = it elif len(it) == 2: if it[0] >= it[1]: print '\n\n OK, nothing will be printed \n\n' iter_list = xrange(it[0], it[1]) else: raise ValueError("list should contain 1 or 2 elements!") if out_path == None: out_dir = self.h5file.filename[0:-3] else: out_dir = out_path if comm.rank == 0: mkdir(out_dir) #The path is only generated at processor 0 fields = range(0, H, comp_rate) if len(iter_list) != len(filenames): for indW in iter_list: save_path = out_dir + '/W_' + iter_to_str(indW+1, num_W) + '.png' self.create_W_pic(W[indW, :,:], save_path, fields) else: num_order = 0 for indW in iter_list: save_path = out_dir + filenames[num_order] self.create_W_pic(W[indW, :,:], save_path, fields) num_order +=1
def create_W_pics(self, iteration=None, destination=''): """ Creates the pictures of the W matrices. If an iteration is given, only that very iteration is saved into the same folder as the h5-file. If no iteration is given, a subfolder names as the h5-file is created and all the W pics are saved in there. (Notice the difference to DataPlotter here.) """ if 'W' in self.variables: W = self.h5file.root.W[:] num_of_W, H, D = W.shape if iteration >= num_of_W: raise ValueError("Given iteration is too large.") out_dir = self.h5file.filename[0:-3].split('/')[-1] if iteration == None: D2 = np.sqrt(D) rows = int(np.ceil(sqrt(H))) cols = int(np.round(sqrt(H))) pyplot.figure(1113) mkdir(out_dir) for indW in xrange(num_of_W): W_tmp = W[indW, :, :] for ind_plot in xrange(H): spl = pl.subplot(rows, cols, ind_plot + 1) spl.cla() spl.imshow(W_tmp[ind_plot].reshape(D2, D2), interpolation='nearest', cmap=pyplot.cm.jet) pyplot.axis('off') pl.savefig(destination + out_dir + '/W_' + iter_to_str(indW + 1, num_of_W) + '.png') else: W = W[iteration, :, :] D2 = np.sqrt(D) rows = int(np.ceil(sqrt(H))) cols = rows pyplot.figure(1113) for ind_plot in xrange(H): spl = pl.subplot(rows, cols, ind_plot + 1) spl.cla() spl.imshow(W[ind_plot].reshape(D2, D2), interpolation='nearest', cmap=pyplot.cm.jet) pyplot.axis('off') pl.savefig(destination + 'W_' + out_dir + '_iter_' + np.str(iteration + 1) + '.png')