[Yt-svn] yt-commit r519 - in trunk: examples yt/fido yt/raven

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Mon Jun 2 22:47:25 PDT 2008


Author: mturk
Date: Mon Jun  2 22:47:24 2008
New Revision: 519
URL: http://yt.spacepope.org/changeset/519

Log:
Whole bunch of PEP-8 fixes.  There's little to no code coverage for the fido
module, so some breakage is expected -- but no one uses fido right now.  (This,
I think, will change.)

Also updated PlotConfig to bring it largely up to date.  I am still unsatisfied
with it, though, so it might undergo some more revisions in the future.

Updated sample_raven_config.xml to get rid of some stuff, fix some other stuff.



Modified:
   trunk/examples/sample_raven_config.xml
   trunk/yt/fido/FileHandling.py
   trunk/yt/fido/OutputWatcher.py
   trunk/yt/fido/RunStandalones.py
   trunk/yt/raven/PlotConfig.py

Modified: trunk/examples/sample_raven_config.xml
==============================================================================
--- trunk/examples/sample_raven_config.xml	(original)
+++ trunk/examples/sample_raven_config.xml	Mon Jun  2 22:47:24 2008
@@ -2,60 +2,30 @@
 <raven>
     <proj mindx="1">
         <field weight="Temperature">Density</field>
-        <width unit="au">10000</width>
-        <width unit="au">1000</width>
-        <width unit="au">100</width>
-        <width unit="au">10</width>
-        <width unit="au">1</width>
-        <width unit="rsun">10000</width>
-        <width unit="rsun">1000</width>
-        <width unit="rsun">100</width>
-        <width unit="rsun">10</width>
-        <width unit="rsun">1</width>
+        <width unit="kpc">10000</width>
+        <width unit="kpc">1000</width>
+        <width unit="kpc">100</width>
+        <width unit="kpc">10</width>
+        <width unit="kpc">1</width>
     </proj>
     <slice mindx="1">
-        <field>H2I_Fraction</field>
         <field>Temperature</field>
         <field>NumberDensity</field>
         <field>RadialVelocity</field>
-        <width unit="au">10000</width>
-        <width unit="au">1000</width>
-        <width unit="au">100</width>
-        <width unit="au">10</width>
-        <width unit="au">1</width>
-        <width unit="rsun">10000</width>
-        <width unit="rsun">1000</width>
-        <width unit="rsun">100</width>
-        <width unit="rsun">10</width>
-        <width unit="rsun">1</width>
+        <width unit="kpc">10000</width>
+        <width unit="kpc">1000</width>
+        <width unit="kpc">100</width>
+        <width unit="kpc">10</width>
+        <width unit="kpc">1</width>
     </slice>
-    <threephase mindx="1">
+    <phase mindx="1">
         <field>NumberDensity</field>
         <field>Temperature</field>
-        <field>H2I_Fraction</field>
-        <width unit="au">10000</width>
-        <width unit="au">1000</width>
-        <width unit="au">100</width>
-        <width unit="au">10</width>
-        <width unit="au">1</width>
-        <width unit="rsun">10000</width>
-        <width unit="rsun">1000</width>
-        <width unit="rsun">100</width>
-        <width unit="rsun">10</width>
-        <width unit="rsun">1</width>
-    </threephase>
-    <twophase mindx="1">
-        <field>NumberDensity</field>
-        <field>Temperature</field>
-        <width unit="au">10000</width>
-        <width unit="au">1000</width>
-        <width unit="au">100</width>
-        <width unit="au">10</width>
-        <width unit="au">1</width>
-        <width unit="rsun">10000</width>
-        <width unit="rsun">1000</width>
-        <width unit="rsun">100</width>
-        <width unit="rsun">10</width>
-        <width unit="rsun">1</width>
-    </twophase>
+        <field>CellMassMsun</field>
+        <width unit="kpc">10000</width>
+        <width unit="kpc">1000</width>
+        <width unit="kpc">100</width>
+        <width unit="kpc">10</width>
+        <width unit="kpc">1</width>
+    </phase>
 </raven>

Modified: trunk/yt/fido/FileHandling.py
==============================================================================
--- trunk/yt/fido/FileHandling.py	(original)
+++ trunk/yt/fido/FileHandling.py	Mon Jun  2 22:47:24 2008
@@ -26,66 +26,66 @@
 
 from yt.fido import *
 
-def copyOutput(basename, newLocation, extraFiles=None):
-    if extraFiles == None: extraFiles = []
-    copyGlob("%s*" % (basename), newLocation)
-    for file in extraFiles:
-        copyGlob(file, location)
-    return os.path.join(newLocation, os.path.basename(basename))
-
-def moveOutput(basename, newLocation, extraFiles=None):
-    if extraFiles == None: extraFiles = []
-    moveGlob("%s*" % (basename), newLocation)
-    for file in extraFiles:
-        moveGlob(file, location)
-
-def deleteOutput(basename, extraFiles=None):
-    if extraFiles == None: extraFiles = []
-    deleteGlob("%s*" % os.path.normpath(filename), location)
-    for file in extraFiles:
-        deleteGlob(file)
-
-def buryOutput(filename, newPrefix = None, newLocation=None, extraFiles=None):
-    if extraFiles == None: extraFiles = []
-    if not newLocation:
+def copy_output(basename, new_location, extra_files=None):
+    if extra_files == None: extra_files = []
+    copy_glob("%s*" % (basename), new_location)
+    for file in extra_files:
+        copy_glob(file, location)
+    return os.path.join(new_location, os.path.basename(basename))
+
+def move_output(basename, new_location, extra_files=None):
+    if extra_files == None: extra_files = []
+    move_glob("%s*" % (basename), new_location)
+    for file in extra_files:
+        move_glob(file, location)
+
+def delete_output(basename, extra_files=None):
+    if extra_files == None: extra_files = []
+    delete_glob("%s*" % os.path.normpath(filename), location)
+    for file in extra_files:
+        delete_glob(file)
+
+def bury_output(filename, new_prefix = None, new_location=None, extra_files=None):
+    if extra_files == None: extra_files = []
+    if not new_location:
         dirname = NewDirectoryPattern % filename
-        if not newPrefix: newPrefix = os.getcwd()
-        newLocation = os.path.abspath(os.path.join(newPrefix, dirname))
-    moveGlob("%s*" % filename, newLocation)
-    for file in extraFiles:
-        moveGlob(file, newLocation)
-    return os.path.join(newLocation, filename)
-
-def digupOutput(filename, newLocation=None, extraFiles=None):
-    if extraFiles == None: extraFiles = []
-    if not newLocation:
-        newLocation = get_parent_dir(filename)
+        if not new_prefix: new_prefix = os.getcwd()
+        new_location = os.path.abspath(os.path.join(new_prefix, dirname))
+    move_glob("%s*" % filename, new_location)
+    for file in extra_files:
+        move_glob(file, new_location)
+    return os.path.join(new_location, filename)
+
+def digup_output(filename, new_location=None, extra_files=None):
+    if extra_files == None: extra_files = []
+    if not new_location:
+        new_location = get_parent_dir(filename)
     else:
         # Make sure we have no relative references
-        newLocation = os.path.normpath(newLocation)
-    print "%s*" % (filename), newLocation
-    moveGlob("%s*" % filename, newLocation)
-
-def copyGlob(globPattern, newLocation):
-    if not os.path.isdir(newLocation):
-        os.makedirs(newLocation)
-    for file in glob.glob(globPattern):
-        mylog.debug("Copying %s to %s", file, newLocation)
-        shutil.copy(file, newLocation)
+        new_location = os.path.normpath(new_location)
+    print "%s*" % (filename), new_location
+    move_glob("%s*" % filename, new_location)
+
+def copy_glob(glob_pattern, new_location):
+    if not os.path.isdir(new_location):
+        os.makedirs(new_location)
+    for file in glob.glob(glob_pattern):
+        mylog.debug("Copying %s to %s", file, new_location)
+        shutil.copy(file, new_location)
     
-def moveGlob(globPattern, newLocation):
-    if not os.path.isdir(newLocation):
-        os.makedirs(newLocation)
+def move_glob(glob_pattern, new_location):
+    if not os.path.isdir(new_location):
+        os.makedirs(new_location)
     # This is slower than dumping to shell.
     # But, I trust it.  And it should work on boh
     # BSD and GNU util systems.
-    for file in glob.glob(globPattern):
-        if os.path.abspath(file) == os.path.abspath(newLocation): continue
-        nl = os.path.join(newLocation, os.path.basename(file))
+    for file in glob.glob(glob_pattern):
+        if os.path.abspath(file) == os.path.abspath(new_location): continue
+        nl = os.path.join(new_location, os.path.basename(file))
         mylog.debug("Moving %s to %s", file, nl)
         shutil.move(file, nl)
 
-def deleteGlob(globPattern):
-    for file in glob.glob(globPattern):
+def delete_glob(glob_pattern):
+    for file in glob.glob(glob_pattern):
         print "Removing %s" % (file)
         shutil.unlink(file)

Modified: trunk/yt/fido/OutputWatcher.py
==============================================================================
--- trunk/yt/fido/OutputWatcher.py	(original)
+++ trunk/yt/fido/OutputWatcher.py	Mon Jun  2 22:47:24 2008
@@ -26,41 +26,40 @@
 from yt.fido import *
 
 class Watcher:
-    def __init__(self, title=None, path=".", newPrefix="", oc=None,
-                 process=None, functionHandler = None):
-        self.originalPath = os.getcwd()
+    def __init__(self, title=None, path=".", new_prefix="", oc=None,
+                 process=None, function_handler = None):
+        self.original_path = os.getcwd()
         os.chdir(path)
         if title == None: title = os.path.basename(os.getcwd())
         if oc == None: oc = OutputCollection(title)
         self.title = title
         self.oc = oc
         self.process = process
-        self.newPrefix = newPrefix
-        self.skipFiles = [] # Forward compatible
-        self.functionHandler = None
-        if functionHandler != None:
-            self.functionHandler = functionHandler()
+        self.new_prefix = new_prefix
+        self.skip_files = [] # Forward compatible
+        self.function_handler = None
+        if function_handler != None:
+            self.function_handler = function_handler()
 
-    def run(self, runOnce=False):
+    def run(self, run_once=False):
         mylog.info("Entering main Fido loop (CTRL-C or touch 'stopFido' to end)")
         wb = ytcfg.getfloat("fido","WaitBetween")
-        while not self.checkForStop():
-            nn = self.checkForOutput()
+        while not self.check_for_stop():
+            nn = self.check_for_output()
             for bn in nn:
-                newName = buryOutput(bn, newPrefix=self.newPrefix)
-                self.dealWithOutput(newName)
-            if runOnce: break
+                new_name = bury_output(bn, new_prefix=self.new_prefix)
+                self.handle_output(new_name)
+            if run_once: break
             try:
                 time.sleep(wb)
             except KeyboardInterrupt:
                 sys.exit()
 
-    def dealWithOutput(self, filename):
+    def handle_output(self, filename):
         # First, add it to the OutputCollection
-        self.oc.addOutput(filename)
-        self.oc.writeOut()
-        if self.functionHandler == None:
-            return
+        self.oc.add_output(filename)
+        self.oc.write_out()
+        if self.function_handler == None: return
         # Now, we pass it to our function handler
         pid = os.fork()
         if pid:
@@ -69,24 +68,24 @@
             mylog.debug("Exit status %s from PID %s", exit, newpid)
         else:
             mylog.info("Forked process reporting for duty!")
-            self.functionHandler(filename)
+            self.function_handler(filename)
             sys.exit()
 
-    def checkForOutput(self):
-        newFiles = []
+    def check_for_output(self):
+        new_files = []
         if os.path.isfile(NEW_OUTPUT_CREATED):
             os.unlink(NEW_OUTPUT_CREATED)
             # So something is created!  Now let's snag it
             # We insert our additional glob patterns here
-            filesFound = glob.glob("*.hierarchy") #\
+            files_found = glob.glob("*.hierarchy") #\
                          #[glob.glob(pat) for pat in GlobPatterns]
-            for file in filter(lambda a: a not in self.skipFiles, filesFound):
+            for file in [fn for fn in files_found if fn not in self.skip_files]:
                 #if self.oc.has_key(os.path.basename(file[:-10])): continue
-                newFiles.append(file.rsplit(".",1)[0])
-                mylog.info("Found output %s", newFiles[-1])
-        return newFiles
+                new_files.append(file.rsplit(".",1)[0])
+                mylog.info("Found output %s", new_files[-1])
+        return new_files
 
-    def checkForStop(self):
+    def check_for_stop(self):
         if os.path.exists("stopFido"):
             # We should log this rather than print it
             mylog.info("Stopping fido")

Modified: trunk/yt/fido/RunStandalones.py
==============================================================================
--- trunk/yt/fido/RunStandalones.py	(original)
+++ trunk/yt/fido/RunStandalones.py	Mon Jun  2 22:47:24 2008
@@ -26,15 +26,15 @@
 from yt.fido import *
 import exceptions
 
-def selectOutput(collection = None):
-    if not collection: collection = selectCollection()
+def select_output(collection = None):
+    if not collection: collection = select_collection()
     for i, o in enumerate(collection):
         print "%s\t %s" % (i+1,o)
     print
     loki = int(raw_input("Which output do you want?"))-1
     return collection[loki-1]
 
-def selectCollection():
+def select_collection():
     cs = GrabCollections()
     for i, o in enumerate(cs):
         print "%s\t %s" % (i+1,o)
@@ -56,7 +56,7 @@
     def SetupParser(self):
         pass
 
-    def GuessOC(self, createNew = False):
+    def _guess_collection(self, createNew = False):
         tryTitle=os.path.basename(os.getcwd())
         gc = GrabCollections()
         for c in gc:
@@ -66,9 +66,9 @@
         self.oc = None
         if createNew:
             Import().PerformAction()
-            self.GuessOC(createNew=False)
+            self._guess_collection(createNew=False)
 
-    def ParseArgs(self):
+    def _parse_args(self):
         self.SetupParser()
         self.opts, self.args = self.parser.parse_args()
 
@@ -82,24 +82,24 @@
     description = "Bury an output in a subdirectory"
     def __init__(self):
         FidoAction.__init__(self)
-        self.ParseArgs()
-        self.GuessOC()
+        self._parse_args()
+        self._guess_collection()
         if not self.oc:
             # Should we import here?
             raise KeyError, "Needs to be imported before you can bury."
 
     def PerformAction(self):
         for bn in self.args:
-            newName = buryOutput(bn)
-            self.oc.addOutput(newName)
-        self.oc.writeOut()
+            newName = bury_output(bn)
+            self.oc.add_output(newName)
+        self.oc.write_out()
 
 class DigUp(FidoAction):
     description = "Un-bury an output"
     def __init__(self):
         FidoAction.__init__(self)
-        self.ParseArgs()
-        self.GuessOC()
+        self._parse_args()
+        self._guess_collection()
         if not self.oc:
             # Should we import here?
             raise KeyError, "Needs to be imported before you can bury."
@@ -107,7 +107,7 @@
     def SetupParser(self):
         self.parser.add_option("-d", "--dest",
                                action='store', type='string',
-                               dest='newLocation', default=os.getcwd())
+                               dest='new_location', default=os.getcwd())
 
     def PerformAction(self):
         for bn in self.args:
@@ -119,21 +119,21 @@
             b = os.path.basename(b)
             print b
             toGlob = self.oc[b][0]
-            digupOutput(toGlob, newLocation=self.opts.newLocation)
+            digup_output(toGlob, new_location=self.opts.new_location)
             del self.oc[b]
-        self.oc.writeOut()
+        self.oc.write_out()
 
 class Branch(FidoAction):
     description = "Un-bury an output"
     def __init__(self):
         FidoAction.__init__(self)
-        self.ParseArgs()
-        if self.opts.newLocation == None:
+        self._parse_args()
+        if self.opts.new_location == None:
             print "You must supply a location for the branching."
             print "See --help ."
             print
             raise KeyError
-        self.GuessOC()
+        self._guess_collection()
         if not self.oc:
             # Should we import here?
             raise KeyError, "Needs to be imported before you can branch."
@@ -141,7 +141,7 @@
     def SetupParser(self):
         self.parser.add_option("-d", "--newdir",
                                action='store', type='string',
-                               dest='newLocation', default=None)
+                               dest='new_location', default=None)
         self.parser.add_option("-m", "--metadatastring",
                                action='store', type='string',
                                dest='md', default=None)
@@ -155,8 +155,8 @@
             b = os.path.basename(b)
         if b.endswith('.dir'):
             b = os.path.join(b, b[:-4])
-        #print "Copying %s to %s" % (b, self.opts.newLocation)
-        newName=copyOutput(b, self.opts.newLocation)
+        #print "Copying %s to %s" % (b, self.opts.new_location)
+        newName=copy_outputs(b, self.opts.new_location)
         print newName
         #Okay, now that we've copied it...
         #First we update the CurrentTimeIdentifier string
@@ -175,8 +175,8 @@
     description = "Import an existing set of buried outputs"
     def __init__(self):
         FidoAction.__init__(self)
-        self.ParseArgs()
-        self.GuessOC()
+        self._parse_args()
+        self._guess_collection()
         self.title = os.path.basename(os.getcwd())
         if self.oc != None: self.title = self.oc.title
         else: self.oc=OutputCollection(self.title)
@@ -185,17 +185,17 @@
     def PerformAction(self):
         for i in glob.glob("*.dir/*.hierarchy"):
             fn = i[:-10]
-            self.oc.addOutput(os.path.abspath(fn))
+            self.oc.add_output(os.path.abspath(fn))
         Giles = Watcher(title=self.title, oc=self.oc)
         Giles.run(True)
-        self.oc.writeOut()
+        self.oc.write_out()
 
 class FidoStandalone(FidoAction):
     description = "Run Fido, all by itself."
     def __init__(self):
         FidoAction.__init__(self)
-        self.ParseArgs()
-        self.GuessOC()
+        self._parse_args()
+        self._guess_collection()
         self.title = os.path.basename(os.getcwd())
         if self.oc != None: self.title = self.oc.title
 
@@ -208,15 +208,15 @@
                                dest='cfgFile', default=None)
         self.parser.add_option("-p", "--newpath",
                                action='store', type='string',
-                               dest='newPrefix', default=None)
+                               dest='new_prefix', default=None)
 
     def PerformAction(self):
         if self.opts.cfgFile != None: func=self.MakePlots
         else: func = None
-        Giles = Watcher(title=self.title, oc=self.oc, functionHandler=func,
-                        newPrefix=self.opts.newPrefix)
+        Giles = Watcher(title=self.title, oc=self.oc, function_handler=func,
+                        new_prefix=self.opts.new_prefix)
         Giles.run()
-        self.oc.writeOut()
+        self.oc.write_out()
 
     def MakePlots(self):
         import yt.lagos as lagos
@@ -248,7 +248,4 @@
     acts = {'fbury':Bury, 'fdigup':DigUp,
             'fbranch':Branch, 'fimport':Import,
             'fido':FidoStandalone}
-    #try:
     acts[pg]().PerformAction()
-    #except:
-        #print "Error: terminating."

Modified: trunk/yt/raven/PlotConfig.py
==============================================================================
--- trunk/yt/raven/PlotConfig.py	(original)
+++ trunk/yt/raven/PlotConfig.py	Mon Jun  2 22:47:24 2008
@@ -41,7 +41,7 @@
     pi = et(file=fn)
     r = pi.getroot()
     bn = pf.basename
-    dx = pf.h.getSmallestDx()
+    dx = pf.h.get_smallest_dx()
     for plot in r.getchildren():
         # Now we have a plot type, so let's get going, peoples!
         if plot.attrib.has_key("mindx"):
@@ -85,7 +85,7 @@
                     prefixDict['width'] = width
                     prefixDict['unit'] = unit
                     pc.save(prefix % prefixDict, "png")
-        elif plotType == "threephase":
+        elif plotType == "phase":
             for width, unit in widths:
                 pc = PlotCollection(pf, deliverator)
                 if (width/pf[unit] < mindx*dx):
@@ -93,16 +93,7 @@
                 prefixDict['width'] = width
                 prefixDict['unit'] = unit
                 #print fields, width, unit
-                pc.add_threephase_sphere(width, unit, fields)
-                pc.save(prefix % prefixDict, "png")
-        elif plotType == "twophase":
-            for width, unit in widths:
-                pc = PlotCollection(pf, deliverator)
-                if (width/pf[unit] < mindx*dx):
-                    continue
-                prefixDict['width'] = width
-                prefixDict['unit'] = unit
-                pc.add_twophase_sphere(width, unit, fields)
+                pc.add_phase_sphere(width, unit, fields)
                 pc.save(prefix % prefixDict, "png")
         elif plotType == "proj":
             pc = PlotCollection(pf, deliverator)



More information about the yt-svn mailing list