Пример #1
0
 def do_resetplot(self, rest):
     if rest:
         self.setplot = rest
         print '*** Resetting setplot to: ',rest
         self.plotdata.setplot = self.setplot
     print 'Executing setplot from ',self.setplot
     try:
         frametools.call_setplot(self.setplot,self.plotdata)
     except:
         print '*** Problem re-executing setplot'
         raise
Пример #2
0
 def do_resetplot(self, rest):
     if rest:
         self.setplot = rest
         print('*** Resetting setplot to: ', rest)
         self.plotdata.setplot = self.setplot
     print('Executing setplot from ', self.setplot)
     try:
         frametools.call_setplot(self.setplot, self.plotdata)
     except:
         print('*** Problem re-executing setplot')
         raise
Пример #3
0
 def set_plotdata(self):
     from clawpack.visclaw import data
     from clawpack.visclaw import frametools
     plotdata = data.ClawPlotData()
     plotdata.setplot = self.setplot
     self.plotdata = frametools.call_setplot(self.setplot, plotdata)
     plotdata._mode = 'iplotclaw'
Пример #4
0
 def set_plotdata(self):
     from clawpack.visclaw import data
     from clawpack.visclaw import frametools
     plotdata = data.ClawPlotData()
     plotdata.setplot = self.setplot
     self.plotdata = frametools.call_setplot(self.setplot,plotdata)
     plotdata._mode = 'iplotclaw'
Пример #5
0
    def __init__(self, setplot='setplot.py', outdir=None, \
                 completekey='tab', stdin=None, stdout=None):
        """Instantiate a line-oriented interpreter framework.


        The optional argument 'completekey' is the readline name of a
        completion key; it defaults to the Tab key. If completekey is
        not None and the readline module is available, command completion
        is done automatically. The optional arguments stdin and stdout
        specify alternate input and output file objects; if not specified,
        sys.stdin and sys.stdout are used.

        """
        import sys
        if stdin is not None:
            self.stdin = stdin
        else:
            self.stdin = sys.stdin
        if stdout is not None:
            self.stdout = stdout
        else:
            self.stdout = sys.stdout
        self.cmdqueue = []
        self.completekey = completekey
 
        self.setplot = setplot
        plotdata = data.ClawPlotData()
        plotdata.setplot = self.setplot
        plotdata._mode = 'iplotclaw'

        if outdir is None:
            try:
                # possibly set by 'make .output' and stored in .output:
                dot_output = open('.output','r')    
                outdir = dot_output.readline().strip()
                dot_output.close()
            except:
                outdir = '.'
        plotdata.outdir = outdir
        # Note also that outdir might be reset by setplot!

        try:
            plotdata = frametools.call_setplot(self.setplot,plotdata)
        except:
            print '*** Problem executing setplot in Iplotclaw'
            #print '    plotdata = ', plotdata
            print '    setplot = ', self.setplot
            print '*** Either this file does not exist or '
            print '    there is a problem executing the function setplot in this file.'
            print '*** PLOT PARAMETERS MAY NOT BE SET! ***'
            raise
            #return
        self.plotdata = plotdata
        self.prevplotdata = plotdata
        self.restart = False
        self.prevframeno = 0
Пример #6
0
    def __init__(self, setplot='setplot.py', outdir=None, \
                 completekey='tab', stdin=None, stdout=None):
        """Instantiate a line-oriented interpreter framework.


        The optional argument 'completekey' is the readline name of a
        completion key; it defaults to the Tab key. If completekey is
        not None and the readline module is available, command completion
        is done automatically. The optional arguments stdin and stdout
        specify alternate input and output file objects; if not specified,
        sys.stdin and sys.stdout are used.

        """
        import sys
        if stdin is not None:
            self.stdin = stdin
        else:
            self.stdin = sys.stdin
        if stdout is not None:
            self.stdout = stdout
        else:
            self.stdout = sys.stdout
        self.cmdqueue = []
        self.completekey = completekey

        self.setplot = setplot
        plotdata = data.ClawPlotData()
        plotdata.setplot = self.setplot
        plotdata._mode = 'iplotclaw'

        if outdir is None:
            try:
                # possibly set by 'make .output' and stored in .output:
                dot_output = open('.output', 'r')
                outdir = dot_output.readline().strip()
                dot_output.close()
            except:
                outdir = '.'
        plotdata.outdir = outdir
        # Note also that outdir might be reset by setplot!

        try:
            plotdata = frametools.call_setplot(self.setplot, plotdata)
        except:
            print '*** Problem executing setplot in Iplotclaw'
            #print '    plotdata = ', plotdata
            print '    setplot = ', self.setplot
            print '*** Either this file does not exist or '
            print '    there is a problem executing the function setplot in this file.'
            print '*** PLOT PARAMETERS MAY NOT BE SET! ***'
            raise
            #return
        self.plotdata = plotdata
        self.prevplotdata = plotdata
        self.restart = False
        self.prevframeno = 0
Пример #7
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 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)
Пример #8
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)