def plotclaw(outdir='.', plotdir='_plots', setplot='setplot.py', format='ascii', msgfile=''): """ Create html and/or latex versions of plots. INPUT: setplot is a module containing a function setplot that will be called to set various plotting parameters. format specifies the format of the files output from Clawpack """ from clawpack.visclaw.data import ClawPlotData from clawpack.visclaw import plotpages plotdata = ClawPlotData() plotdata.outdir = outdir plotdata.plotdir = plotdir plotdata.setplot = setplot plotdata.format = format plotdata.msgfile = msgfile plotpages.plotclaw_driver(plotdata, verbose=False, format=format)
def plotclaw(outdir='.', plotdir='_plots', setplot = 'setplot.py', format='ascii', msgfile=''): """ Create html and/or latex versions of plots. INPUT: setplot is a module containing a function setplot that will be called to set various plotting parameters. format specifies the format of the files output from Clawpack """ from clawpack.visclaw.data import ClawPlotData from clawpack.visclaw import plotpages plotdata = ClawPlotData() plotdata.outdir = outdir plotdata.plotdir = plotdir plotdata.setplot = setplot plotdata.format = format plotdata.msgfile = msgfile plotpages.plotclaw_driver(plotdata, verbose=False, format=format)
def plotclaw(outdir='.', plotdir='_plots', setplot = 'setplot.py', format='ascii', msgfile='', frames=None, verbose=False): """ Create html and/or latex versions of plots. INPUT: setplot is a module containing a function setplot that will be called to set various plotting parameters. format specifies the format of the files output from Clawpack """ from clawpack.visclaw.data import ClawPlotData from clawpack.visclaw import plotpages plotdata = ClawPlotData() plotdata.outdir = outdir plotdata.plotdir = plotdir plotdata.setplot = setplot plotdata.format = format plotdata.msgfile = msgfile frametools.call_setplot(plotdata.setplot, plotdata) if plotdata.num_procs is None: plotdata.num_procs = int(os.environ.get("OMP_NUM_THREADS", 1)) # Make sure plotdata.parallel is False in some cases: if plotdata.parallel: assert type(setplot) in [str, bool, type(None)], \ "*** Parallel plotting is not supported when ClawPlotData " \ + "attribute setplot is a function." if plotdata.parallel and (plotdata.num_procs > 1): # If this is the original call then we need to split up the work and # call this function again # First set up plotdir: plotdata._parallel_todo = 'initialize' plotpages.plotclaw_driver(plotdata, verbose=False, format=format) if frames is None: if plotdata.num_procs is None: plotdata.num_procs = int(os.environ.get("OMP_NUM_THREADS", 1)) frames = [[] for n in xrange(plotdata.num_procs)] framenos = frametools.only_most_recent(plotdata.print_framenos, outdir) # don't use more procs than frames or infinite loop!! num_procs = min(plotdata.num_procs, len(framenos)) for (n, frame) in enumerate(framenos): frames[n%num_procs].append(frame) # Create subprocesses to work on each plotclaw_cmd = "python %s" % __file__ process_queue = [] for n in xrange(num_procs): plot_cmd = "%s %s %s %s" % (plotclaw_cmd, outdir, plotdir, setplot) plot_cmd = plot_cmd + " " + " ".join([str(i) for i in frames[n]]) process_queue.append(subprocess.Popen(plot_cmd, shell=True)) poll_interval = 5 try: while len(process_queue) > 0: time.sleep(poll_interval) for process in process_queue: if process.poll() is not None: process_queue.remove(process) if verbose: print "Number of processes currently:",len(process_queue) # Stop child processes if interrupt was caught or something went # wrong except KeyboardInterrupt: print "ABORTING: A keyboard interrupt was caught. All " + \ "child processes will be terminated as well." for process in process_queue: process.terminate() raise except: print "ERROR: An error occurred while waiting for " + \ "plotting processes to complete. Aborting all " + \ "child processes." for process in process_queue: process.terminate() raise # After all frames have been plotted via recursive calls, # make index and gauge plots only: plotdata._parallel_todo = 'finalize' plotpages.plotclaw_driver(plotdata, verbose=False, format=format) else: # make frame plots only: plotdata._parallel_todo = 'frames' plotdata.print_framenos = frames plotpages.plotclaw_driver(plotdata, verbose=False, format=format) else: # not in parallel: plotdata._parallel_todo = None plotpages.plotclaw_driver(plotdata, verbose=False, format=format)
def plot_all(values_to_plot,nb_test,nb_frames,format='ascii',msgfile='',**kargs): # ============================ # = Create Initial Condition = # ============================ # Construct output and plot directory paths name = 'multilayer/dry_state_rarefaction_test' prefix = 'ml_e%s_m%s_fix_m%s_vel' % (2, 500, values_to_plot[0]) prefix = "".join((prefix, "F")) outdir,plotdir,log_path = runclaw.create_output_paths(name, prefix, **kargs) script_dir = os.path.dirname(__file__) plots_dir = os.path.join(script_dir, 'All_plots/') if not os.path.isdir(plots_dir): os.makedirs(plots_dir) # Set physics data global g g=Solution(0, path=outdir,read_aux=True).state.problem_data['g'] global manning manning=Solution(0, path=outdir,read_aux=True).state.problem_data['manning'] global rho_air rho_air=Solution(0, path=outdir,read_aux=True).state.problem_data['rho_air'] global rho rho=Solution(0, path=outdir,read_aux=True).state.problem_data['rho'] global r r=Solution(0, path=outdir,read_aux=True).state.problem_data['r'] global one_minus_r one_minus_r=Solution(0, path=outdir,read_aux=True).state.problem_data['one_minus_r'] global num_layers num_layers=Solution(0, path=outdir,read_aux=True).state.problem_data['num_layers'] global b b = Solution(0, path=outdir,read_aux=True).state.aux[bathy_index,:] # Set method parameters, this ensures it gets to the Fortran routines eigen_method=Solution(0, path=outdir,read_aux=True).state.problem_data['eigen_method'] dry_tolerance=Solution(0, path=outdir,read_aux=True).state.problem_data['dry_tolerance'] inundation_method=Solution(0, path=outdir,read_aux=True).state.problem_data['inundation_method'] entropy_fix=Solution(0, path=outdir,read_aux=True).state.problem_data['entropy_fix'] #num_cells=Solution(0,path=outdir,read_aux=True).state.problem_data['num_cells'] #does not work num_cells=500 plt.clf() # Load bathymetery #b = Solution(0, path=outdir,read_aux=True).state.aux[bathy_index,:] # Load gravitation #g = Solution(0, path=outdir,read_aux=True).state.problem_data['g'] # Load one minus r #one_minus_r=Solution(0, path=outdir,read_aux=True).state.problem_data['one_minus_r'] xlimits=[] for t in range(nb_frames): #Depths plotdata=ClawPlotData() plotfigure_depths = plotdata.new_plotfigure(name='Depths') plotfigure_depths.show=True plotaxes_depths = plotfigure_depths.new_plotaxes() plotaxes_depths.title = "Depths" plotaxes_depths.xlimits = xlimits plotaxes_depths.ylimits = 'auto' # fig2 = plt.figure(num=2) # plt.xlabel('x(m)') # plt.ylabel('Depths') # plt.title('Solution at t = %3.5f' % t) # plt.ylim(-1.1, 0.1) #Entropy fig7 = plt.figure(num=2) plt.xlabel('x(m)') plt.ylabel('Entropy') plt.title('Entropy as t = %3.5f' % t) #Composite Froude number fig12 = plt.figure(num=12) plt.xlabel('x(m)') plt.ylabel('Composite Froude number') plt.title('Composite Froude number at t = %3.5f' % t) plotdata.outdir = outdir plotdata.plotdir = plots_dir print(plotdir) Solutions_=[] x = [k/1000 for k in range(0,1000,2)] print('Plot the figures at frame %s' % t) for i in range(nb_test): # Construct output and plot directory paths name = 'multilayer/dry_state_rarefaction_test' prefix = 'ml_e%s_m%s_fix_m%s_vel' % (eigen_method, num_cells, values_to_plot[i]) if entropy_fix: prefix = "".join((prefix, "T")) else: prefix = "".join((prefix, "F")) outdir,plotdir,log_path = runclaw.create_output_paths(name, prefix, **kargs) #exec("cd_"+str(i)+"='"Solution(t,path=outdir,read_aux=True)+"'") cd = Solution(t,path=outdir,read_aux=True) Solutions_ += [Solution(t,path=outdir,read_aux=True)] #=====Plotting===== plot_color='g' plot_style='-' if values_to_plot[i] >= 3.9 : if values_to_plot[i] >= 8.0 : plot_color = 'r' plot_style = ':' else : plot_color = 'b' plot_style = '-.' #depth #plotdata.setplot = setplot plotdata.format = format plotdata.msgfile = msgfile plotitem_depths = plotaxes_depths.new_plotitem(plot_type='1d') plotitem_depths.plot_var = eta_1 plotitem_depths.plotstyle='k' plotitem_depths.color=plot_color plotitem_depths.show=True # plt.figure(num=2) # plt.plot(bathy(cd),'k') # plt.plot(eta_1(cd),'k',color=plot_color,linestyle=plot_style) # plt.plot(eta_2(cd),'k',color=plot_color,linestyle=plot_style) # depthname = 'frame00%sfig1002.png' % t # plt.savefig(plots_dir + depthname) #plt.close() #Entropy # plt.figure(num=7) # plt.plot(entropy(cd),'k',color=plot_color,linestyle=plot_style) # entropyname = 'frame00%sfig1007.png' % t # plt.savefig(plots_dir + entropyname) # # #Composite Froude number # plt.figure(num=12) # plt.plot(composite_Froude_nb(cd),'k',color=plot_color,linestyle=plot_style) # froudename = 'frame00%sfig1012.png' % ( t ) # plt.savefig(plots_dir + froudename) #plt.close() plt.close('all')
def plotclaw(outdir='.', plotdir='_plots', setplot='setplot.py', format='ascii', msgfile='', frames=None, verbose=False): """ Create html and/or latex versions of plots. INPUT: setplot is a module containing a function setplot that will be called to set various plotting parameters. format specifies the format of the files output from Clawpack """ from clawpack.visclaw.data import ClawPlotData from clawpack.visclaw import plotpages plotdata = ClawPlotData() plotdata.outdir = outdir plotdata.plotdir = plotdir plotdata.setplot = setplot plotdata.format = format plotdata.msgfile = msgfile frametools.call_setplot(plotdata.setplot, plotdata) if plotdata.num_procs is None: plotdata.num_procs = int(os.environ.get("OMP_NUM_THREADS", 1)) # Make sure plotdata.parallel is False in some cases: if plotdata.parallel: assert type(setplot) in [str, bool, type(None)], \ "*** Parallel plotting is not supported when ClawPlotData " \ + "attribute setplot is a function." if plotdata.parallel and (plotdata.num_procs > 1): # If this is the original call then we need to split up the work and # call this function again # First set up plotdir: plotdata._parallel_todo = 'initialize' plotpages.plotclaw_driver(plotdata, verbose=False, format=format) if frames is None: if plotdata.num_procs is None: plotdata.num_procs = int(os.environ.get("OMP_NUM_THREADS", 1)) frames = [[] for n in range(plotdata.num_procs)] framenos = frametools.only_most_recent(plotdata.print_framenos, outdir) # don't use more procs than frames or infinite loop!! num_procs = min(plotdata.num_procs, len(framenos)) for (n, frame) in enumerate(framenos): frames[n % num_procs].append(frame) # Create subprocesses to work on each plotclaw_cmd = "python %s" % __file__ process_queue = [] for n in range(num_procs): plot_cmd = "%s %s %s %s" % (plotclaw_cmd, outdir, plotdir, setplot) plot_cmd = plot_cmd + " " + " ".join( [str(i) for i in frames[n]]) process_queue.append(subprocess.Popen(plot_cmd, shell=True)) poll_interval = 5 try: while len(process_queue) > 0: time.sleep(poll_interval) for process in process_queue: if process.poll() is not None: process_queue.remove(process) if verbose: print("Number of processes currently:", len(process_queue)) # Stop child processes if interrupt was caught or something went # wrong except KeyboardInterrupt: print("ABORTING: A keyboard interrupt was caught. All " + \ "child processes will be terminated as well.") for process in process_queue: process.terminate() raise except: print("ERROR: An error occurred while waiting for " + \ "plotting processes to complete. Aborting all " + \ "child processes.") for process in process_queue: process.terminate() raise # After all frames have been plotted via recursive calls, # make index and gauge plots only: plotdata._parallel_todo = 'finalize' plotpages.plotclaw_driver(plotdata, verbose=False, format=format) else: # make frame plots only: plotdata._parallel_todo = 'frames' plotdata.print_framenos = frames plotpages.plotclaw_driver(plotdata, verbose=False, format=format) else: # not in parallel: plotdata._parallel_todo = None plotpages.plotclaw_driver(plotdata, verbose=False, format=format)