コード例 #1
0
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)
コード例 #2
0
ファイル: shocksine.py プロジェクト: MGYBY/CLAWPACK_practice
def setplot(plotdata):
#--------------------------
    """ 
    Specify what is to be plotted at each frame.
    Input:  plotdata, an instance of visclaw.data.ClawPlotData.
    Output: a modified version of plotdata.
    """ 
    from matplotlib import animation
    from IPython.display import HTML
    from clawpack.visclaw.data import ClawPlotData
    from clawpack.visclaw import plotpages
    plotdata.clearfigures()  # clear any old figures,axes,items data
    # Figure for pressure and velocity:

    # Figure for density
    plotfigure = plotdata.new_plotfigure(name='', figno=0)

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(211)'
    plotaxes.title = 'Density'
    plotaxes.xlimits = (-5.,5.)

    plotitem = plotaxes.new_plotitem(plot_type='1d')
    plotitem.plot_var = density
    plotitem.kwargs = {'linewidth':3}
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Energy'
    plotaxes.axescmd = 'subplot(212)'

    plotitem = plotaxes.new_plotitem(plot_type='1d')
    plotitem.plot_var = energy
    plotitem.kwargs = {'linewidth':3}
    plotaxes.xlimits = (-5.,5.)
    
    plotdata.printfigs = True                # print figures False to supress png output
    plotdata.plotdir = './_plots'
    plotdata.print_format = 'png'            # file format
    plotdata.print_framenos = 'all'          # list of frames to print
    plotdata.print_fignos = 'all'            # list of figures to print
    plotdata.html = True                     # create html files of plots?
    plotdata.html_homelink = '../README.html'
    plotdata.latex = True                    # create latex file of plots?
    plotdata.latex_figsperline = 2           # layout of plots
    plotdata.latex_framesperline = 1         # layout of plots
    plotdata.latex_makepdf = False           # also run pdflatex?
    plotpages.plotclaw_driver(plotdata)

    
    return plotdata
コード例 #3
0
ファイル: plotclaw.py プロジェクト: imclab/visclaw
def plotclaw(outdir='.', plotdir='_plots', setplot = 'setplot.py',format='ascii'):
    """
    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

    plotpages.plotclaw_driver(plotdata, verbose=False, format=format)
コード例 #4
0
def setplot(plotdata):
    #--------------------------
    """ 
    Specify what is to be plotted at each frame.
    Input:  plotdata, an instance of visclaw.data.ClawPlotData.
    Output: a modified version of plotdata.
    """
    from matplotlib import animation, pylab
    from IPython.display import HTML
    from clawpack.visclaw.data import ClawPlotData
    from clawpack.visclaw import plotpages

    def change_fonts(current_data):
        pylab.xticks(fontsize=15)
        pylab.yticks(fontsize=15)

    # Figure for depth and momentum:

    plotdata.clearfigures()  # clear any old figures,axes,items data

    # Figure for depth
    plotfigure = plotdata.new_plotfigure(name='Water height', figno=0)
    plotfigure.kwargs = {'figsize': [9, 12], 'facecolor': 'white'}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    # plotaxes.xlimits = [-5.0,5.0]
    plotaxes.title = 'Water height'
    plotaxes.axescmd = 'subplot(211)'
    plotaxes.afteraxes = change_fonts

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='1d')
    plotitem.plot_var = depth
    plotitem.plotstyle = '-'
    plotitem.color = 'b'
    plotitem.kwargs = {'linewidth': 3}

    # Figure for momentum[1]
    #plotfigure = plotdata.new_plotfigure(name='Momentum', figno=1)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(212)'
    # plotaxes.xlimits = [-5.0,5.0]
    plotaxes.title = 'Momentum'
    plotaxes.afteraxes = change_fonts

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='1d')
    plotitem.plot_var = momentum
    plotitem.plotstyle = '-'
    plotitem.color = 'b'
    plotitem.kwargs = {'linewidth': 3}

    plotdata.printfigs = True  # print figures False to supress png output
    plotdata.plotdir = './_plots'
    plotdata.print_format = 'png'  # file format
    plotdata.print_framenos = 'all'  # list of frames to print
    plotdata.print_fignos = 'all'  # list of figures to print
    plotdata.html = False  # create html files of plots?
    plotdata.html_homelink = '../README.html'
    plotdata.latex = False  # create latex file of plots?
    plotdata.latex_figsperline = 2  # layout of plots
    plotdata.latex_framesperline = 1  # layout of plots
    plotdata.latex_makepdf = False  # also run pdflatex?
    plotpages.plotclaw_driver(plotdata)

    return plotdata
コード例 #5
0
ファイル: plotclaw.py プロジェクト: donnaaboise/visclaw
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)
コード例 #6
0
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)