Example #1
0
def plot(setplot=None,
         outdir="./_output",
         plotdir=None,
         htmlplot=False,
         iplot=True,
         file_format='ascii',
         **plot_kargs):
    r"""
    setplot can be a function or a path to a file.
    """

    # Construct a plot directory if not provided
    if plotdir is None:
        try:
            plotdir = os.path.join(os.path.split(outdir)[:-2], "_plots")
        except AttributeError:
            plotdir = os.path.join(os.getcwd(), "_plots")

    if htmlplot or iplot:
        # Grab and import the setplot function
        if not isinstance(setplot, types.FunctionType):
            # Use local setplot if available
            if setplot is None:
                local_setplot_path = os.path.join(os.getcwd(), 'setplot.py')
                if os.path.exists(local_setplot_path):
                    setplot = local_setplot_path

            # If setplot is still None then we import the default setplot
            if setplot is None:
                import clawpack.visclaw.setplot_default as setplot_module
            else:
                path = os.path.abspath(
                    os.path.expandvars(os.path.expanduser(setplot)))
                setplot_module_dir = os.path.dirname(path)
                setplot_module_name = os.path.splitext(
                    os.path.basename(setplot))[0]
                sys.path.insert(0, setplot_module_dir)
                setplot_module = __import__(setplot_module_name)
            reload(setplot_module)
            setplot = lambda plotdata: setplot_module.setplot(
                plotdata, **plot_kargs)

        if not isinstance(setplot, types.FunctionType):
            raise ImportError("Failed to import %s.setplot" %
                              setplot_module_name)

        if iplot:
            from clawpack.visclaw import Iplotclaw

            ip = Iplotclaw.Iplotclaw(setplot=setplot, outdir=outdir)
            ip.plotdata.format = file_format

            ip.plotloop()

        if htmlplot:
            from clawpack.visclaw import plotclaw
            plotclaw.plotclaw(outdir,
                              plotdir,
                              format=file_format,
                              setplot=setplot)
Example #2
0
def plot(setplot=None, outdir="./_output", plotdir=None, htmlplot=False, 
         iplot=True, file_format='ascii', **plot_kargs):
    r"""setplot can be a function or a path to a file."""
    
    # Construct a plot directory if not provided
    if plotdir is None:
        try: 
            plotdir = os.path.join(os.path.split(outdir)[:-2],"_plots")
        except AttributeError:
            plotdir = os.path.join(os.getcwd(),"_plots")
    
    if htmlplot or iplot:
        setplot_func = None
        # No setplot specified, try to use a local file
        if setplot is None:
            # Grab and import the setplot function
            local_setplot_path = os.path.join(os.getcwd(),'setplot.py')
            if os.path.exists(local_setplot_path):
                setplot = local_setplot_path

        # Fetch setplot function depending on type of setplot
        if isinstance(setplot, types.FunctionType):
            # setplot points to a function
            setplot_func = lambda plotdata:setplot(plotdata, **plot_kargs)

        elif isinstance(setplot, types.ModuleType):
            # setplot points to a module
            setplot_func = lambda plotdata:setplot.setplot(plotdata, **plot_kargs)
            
        elif isinstance(setplot, six.string_types):
            # setplot contains a path to a module
            path = os.path.abspath(os.path.expandvars(os.path.expanduser(setplot)))
            setplot_module_dir = os.path.dirname(path)
            setplot_module_name = os.path.splitext(os.path.basename(setplot))[0]
            sys.path.insert(0,setplot_module_dir)
            setplot_module = __import__(setplot_module_name)
            setplot_func = lambda plotdata:setplot_module.setplot(plotdata, **plot_kargs)
        
        if not isinstance(setplot_func, types.FunctionType):
            # Everything else has failed, use default setplot
            import clawpack.visclaw.setplot_default as setplot_module
            setplot_func = setplot_module.setplot

        # Interactive plotting
        if iplot:
            from clawpack.visclaw import Iplotclaw
        
            ip = Iplotclaw.Iplotclaw(setplot=setplot_func, outdir=outdir)
            ip.plotdata.format = file_format
        
            ip.plotloop()
            
        # Static HTML plotting
        if htmlplot:
            from clawpack.visclaw import plotclaw
            plotclaw.plotclaw(outdir, plotdir, format=file_format,
                                               setplot=setplot_func)
Example #3
0
def plot(setplot=None, outdir="./_output", plotdir=None, htmlplot=False, 
         iplot=True, file_format='ascii', **plot_kargs):
    r"""setplot can be a function or a path to a file."""
    
    # Construct a plot directory if not provided
    if plotdir is None:
        try: 
            plotdir = os.path.join(outdir,"../_plots")
        except AttributeError:
            plotdir = os.path.join(os.getcwd(),"_plots")
    
    if htmlplot or iplot:
        setplot_func = None
        # No setplot specified, try to use a local file
        if setplot is None:
            # Grab and import the setplot function
            local_setplot_path = os.path.join(os.getcwd(),'setplot.py')
            if os.path.exists(local_setplot_path):
                setplot = local_setplot_path

        # Fetch setplot function depending on type of setplot
        if isinstance(setplot, types.FunctionType):
            # setplot points to a function
            setplot_func = lambda plotdata:setplot(plotdata, **plot_kargs)

        elif isinstance(setplot, types.ModuleType):
            # setplot points to a module
            setplot_func = lambda plotdata:setplot.setplot(plotdata, **plot_kargs)
            
        elif isinstance(setplot, six.string_types):
            # setplot contains a path to a module
            path = os.path.abspath(os.path.expandvars(os.path.expanduser(setplot)))
            setplot_module_dir = os.path.dirname(path)
            setplot_module_name = os.path.splitext(os.path.basename(setplot))[0]
            sys.path.insert(0,setplot_module_dir)
            setplot_module = __import__(setplot_module_name)
            setplot_func = lambda plotdata:setplot_module.setplot(plotdata, **plot_kargs)
        
        if not isinstance(setplot_func, types.FunctionType):
            # Everything else has failed, use default setplot
            import clawpack.visclaw.setplot_default as setplot_module
            setplot_func = setplot_module.setplot

        # Interactive plotting
        if iplot:
            from clawpack.visclaw import Iplotclaw
        
            ip = Iplotclaw.Iplotclaw(setplot=setplot_func, outdir=outdir)
            ip.plotdata.format = file_format
        
            ip.plotloop()
            
        # Static HTML plotting
        if htmlplot:
            from clawpack.visclaw import plotclaw
            plotclaw.plotclaw(outdir, plotdir, format=file_format,
                                               setplot=setplot_func)
Example #4
0
def plot(setplot=None,outdir="./_output",plotdir=None,htmlplot=False,iplot=True,
         file_format='ascii',**plot_kargs):
    r"""
    setplot can be a function or a path to a file.
    """
    
    # Construct a plot directory if not provided
    if plotdir is None:
        try: 
            plotdir = os.path.join(os.path.split(outdir)[:-2],"_plots")
        except AttributeError:
            plotdir = os.path.join(os.getcwd(),"_plots")
    
    if htmlplot or iplot:
        # Grab and import the setplot function
        if not isinstance(setplot,types.FunctionType):
            # Use local setplot if available
            if setplot is None:
                local_setplot_path = os.path.join(os.getcwd(),'setplot.py')
                if os.path.exists(local_setplot_path):
                    setplot = local_setplot_path

            # If setplot is still None then we import the default setplot
            if setplot is None:
                import clawpack.visclaw.setplot_default as setplot_module
            else:
                path = os.path.abspath(os.path.expandvars(os.path.expanduser(setplot)))
                setplot_module_dir = os.path.dirname(path)
                setplot_module_name = os.path.splitext(os.path.basename(setplot))[0]
                sys.path.insert(0,setplot_module_dir)
                setplot_module = __import__(setplot_module_name)
            reload(setplot_module)
            setplot = lambda plotdata:setplot_module.setplot(plotdata,**plot_kargs)
        
        if not isinstance(setplot,types.FunctionType):
            raise ImportError("Failed to import %s.setplot" % setplot_module_name)
        
        if iplot:
            from clawpack.visclaw import Iplotclaw
        
            ip = Iplotclaw.Iplotclaw(setplot=setplot,outdir=outdir)
            ip.plotdata.format = file_format
        
            ip.plotloop()
            
        if htmlplot:
            from clawpack.visclaw import plotclaw
            plotclaw.plotclaw(outdir,plotdir,format=file_format,setplot=setplot)
Example #5
0
    plotdata.parallel = False
    plotdata.print_format = 'png'  # file format
    plotdata.print_framenos = 'all'  # list of frames to print
    plotdata.print_gaugenos = 'all'  # list of gauges to print
    plotdata.print_fignos = [1, 300]  # list of figures to print

    plotdata.printfigs = True  # print figures
    plotdata.overwrite = True

    plotdata.html = False  # create html files of plots?
    plotdata.html_movie = False  # create html files of plots?
    plotdata.html_homelink = '../README.html'  # pointer for top of index

    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?

    plotdata.kml = True

    return plotdata


if __name__ == "__main__":
    from clawpack.visclaw.plotclaw import plotclaw
    plotclaw(outdir='.',
             setplot=setplot,
             plotdir='_plots',
             format='forestclaw')
Example #6
0
def run_regression_tests(regression_dir="_regression_tests", \
            regression_output_files="all", \
            regression_plot_files="all", \
            make_new=True, run_tests=True, compare_results=True, \
            relocatable=False):

    if make_new:
        # Compile code from scratch to make sure up to date:
        os.system('make new')

    if run_tests:

        if os.path.exists(regression_dir):
            ans = raw_input("Directory %s exists, ok to overwrite? " %
                            regression_dir)
            if ans == 'y':
                os.system('rm -rf %s' % regression_dir)
            else:
                print "*** Aborting regression tests"
                sys.exit()

        os.system('mkdir %s' % regression_dir)

        # -----------------------------------------------------------
        # Define the regression test runs:
        # -----------------------------------------------------------

        # initialize rundata using setrun but then change some things for each run:
        rundata = setrun()
        clawdata = rundata.clawdata
        amrdata = rundata.amrdata

        #--------------
        # Test 1:
        #--------------

        suffix = "_test1"
        outdir = regression_dir + "/_output" + suffix
        plotdir = regression_dir + "/_plots" + suffix

        amrdata.amr_levels_max = 1
        rundata.write()

        runclaw(xclawcmd="xamr", outdir=outdir, print_git_status=True)
        plotclaw(outdir=outdir, plotdir=plotdir)

        #--------------
        # Test 2:
        #--------------
        amrdata.amr_levels_max = 2
        rundata.write()

        suffix = "_test2"
        outdir = regression_dir + "/_output" + suffix
        plotdir = regression_dir + "/_plots" + suffix

        runclaw(xclawcmd="xamr", outdir=outdir, print_git_status=True)
        plotclaw(outdir=outdir, plotdir=plotdir)

        #--------------
        # Test 3:
        #--------------

        amrdata.amr_levels_max = 3
        rundata.write()

        suffix = "_test3"
        outdir = regression_dir + "/_output" + suffix
        plotdir = regression_dir + "/_plots" + suffix

        runclaw(xclawcmd="xamr", outdir=outdir, print_git_status=True)
        plotclaw(outdir=outdir, plotdir=plotdir)

        # ----------------------------------------------------
        # End of test case definitions
        # ----------------------------------------------------

        print "Output and plots are in ", regression_dir

    regression_ok = None

    if compare_results:
        regression_ok = compare_regression_tests(regression_dir,\
                        regression_output_files, regression_plot_files, \
                        relocatable=relocatable)
        if regression_ok:
            print "The specified regression files are identical in all"
            print "    directories checked"
        else:
            print "*** Some regression tests did not pass"

    return regression_ok
Example #7
0
def run_regression_tests(regression_dir="_regression_tests", \
            regression_output_files="all", \
            regression_plot_files="all", \
            make_new=True, run_tests=True, compare_results=True):

    if make_new:
        # Compile code from scratch to make sure up to date:
        os.system('make new')

    if run_tests:

        if os.path.exists(regression_dir):
            ans = raw_input("Directory %s exists, ok to overwrite? " % regression_dir)
            if ans=='y':
                os.system('rm -rf %s' % regression_dir)
            else:
                print "*** Aborting regression tests"
                sys.exit()

        os.system('mkdir %s' % regression_dir)

        # -----------------------------------------------------------
        # Define the regression test runs:
        # -----------------------------------------------------------

        # initialize rundata using setrun but then change some things for each run:
        rundata = setrun()
        clawdata = rundata.clawdata
        amrdata = rundata.amrdata


        #--------------
        # Test 1:
        #--------------

        suffix = "_test1"
        outdir = regression_dir + "/_output" + suffix
        plotdir = regression_dir + "/_plots" + suffix

        amrdata.amr_levels_max = 1
        rundata.write()

        runclaw(xclawcmd = "xamr", outdir=outdir, print_git_status=True)
        plotclaw(outdir=outdir, plotdir=plotdir)

        #--------------
        # Test 2:
        #--------------
        amrdata.amr_levels_max = 2
        rundata.write()

        suffix = "_test2"
        outdir = regression_dir + "/_output" + suffix
        plotdir = regression_dir + "/_plots" + suffix

        runclaw(xclawcmd = "xamr", outdir=outdir, print_git_status=True)
        plotclaw(outdir=outdir, plotdir=plotdir)

        #--------------
        # Test 3:
        #--------------

        amrdata.amr_levels_max = 3
        rundata.write()

        suffix = "_test3"
        outdir = regression_dir + "/_output" + suffix
        plotdir = regression_dir + "/_plots" + suffix

        runclaw(xclawcmd = "xamr", outdir=outdir, print_git_status=True)
        plotclaw(outdir=outdir, plotdir=plotdir)

        # ----------------------------------------------------
        # End of test case definitions
        # ----------------------------------------------------

        print "Output and plots are in ", regression_dir


    if compare_results:
        regression_ok = compare_regression_tests(regression_dir,\
                        regression_output_files, regression_plot_files)
        if regression_ok:
            print "The specified regression files are identical in all"
            print "    directories checked"
        else:
            print "*** Some regression tests did not pass"

    return regression_ok
Example #8
0
#!/usr/bin/env python
# encoding: utf-8
r"""
Simple convenience script for setting up and running an interactive plotting
sesssion.
"""

import sys
import clawpack.visclaw.Iplotclaw as Iplotclaw
import clawpack.visclaw.plotclaw as plot

def run_iplotclaw(setplot='setplot.py',outdir='./_output'):
    ip = Iplotclaw.Iplotclaw(setplot=setplot,outdir=outdir)
    ip.plotloop()

if __name__ == '__main__':
    if len(sys.argv) > 1:
        if sys.argv[1].lower() == 'html':
            plot.plotclaw()
        else:
            run_iplotclaw(**sys.argv[1])
    else:
        run_iplotclaw()
Example #9
0
def html_plot(outdir='./_output',format='petsc'):
    """
    Convenience function for creating html page with plots.
    """
    import clawpack.visclaw.plotclaw as plotclaw
    plotclaw.plotclaw(outdir,format=format)