[Yt-svn] yt-commit r771 - trunk/yt

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Thu Sep 11 08:53:08 PDT 2008


Author: mturk
Date: Thu Sep 11 08:53:07 2008
New Revision: 771
URL: http://yt.spacepope.org/changeset/771

Log:
New feature, which will be expanding: idioms and recipes designed for ease of
use.

I've added a new simple feature to do frame inspection looking for the variable
'pf'.  So you can now do something like this:

from yt.mods import *
pf = EnzoStaticOutput("RD0035")
hop_plot()

and it will pick up the pf and go to town making up projections with Hop halo
positions as circles.  It will output both the Hop stuff and additionally the
projections with Hop circles overlaid.

This is a bit of magic, and I'm not sure it's going to stick around.  But it is
promising for a bit more ease-of-use.  I was told today that I need better
'test cases' of people who have a hard time using YT, and that I should target
these people.  I think that making the syntax more *verb* like is a good step
toward that.  People don't always want to generate lots of EnzoStaticOutputs,
or PlotCollections; often they just want stuff dumped out.  I'm going to try to
make that easier.



Modified:
   trunk/yt/mods.py

Modified: trunk/yt/mods.py
==============================================================================
--- trunk/yt/mods.py	(original)
+++ trunk/yt/mods.py	Thu Sep 11 08:53:07 2008
@@ -31,6 +31,7 @@
 import yt.fido as fido
 import numpy as na
 import sys, types
+from logger import ytLogger as mylog
 
 from yt.lagos import EnzoStaticOutput, \
     BinnedProfile1D, BinnedProfile2D, BinnedProfile3D, \
@@ -51,8 +52,17 @@
 
 from yt.fido import GrabCollections, OutputCollection
 
+# Some convenience functions to ease our time running scripts
+# from the command line
+
 def get_pf():
-    return lagos.EnzoStaticOutput(sys.argv[-1])
+    return EnzoStaticOutput(sys.argv[-1])
+
+def get_pc():
+    return PlotCollection(EnzoStaticOutput(sys.argv[-1]))
+
+# Now the | operator overloading
+# (which is totally a stunt)
 
 class _StaticOutputIfier(object):
     def __init__(self):
@@ -124,3 +134,28 @@
     def _add_plot(self, pc):
         for ax in range(3): pc.add_projection(self.field, ax, **self.kwargs)
 projector = _MultiPlotProj()
+
+# Now some recipes
+#
+# NOTE HIGH LEVEL OF MAGIC.
+# This is not for advanced users.
+
+def _get_current_pf():
+    # We continue until we have 'pf' in the locals space
+    import inspect
+    for s in inspect.stack()[1:]:
+        if 'pf' in s[0].f_locals:
+            __pf = s[0].f_locals['pf']
+            mylog.info("Obtained parameter file %s", __pf)
+            return __pf
+    
+def hop_plot():
+    pf = _get_current_pf()
+    pc = PlotCollection(pf, center=[0.5,0.5,0.5])
+    center = (pf["DomainRightEdge"]-pf["DomainLeftEdge"])/2.0
+    hop_output = hop.HopList(pf.h.sphere(center, 1.0/pf["1"]))
+    hop_output.write_out("%s.hop" % pf)
+    for ax in range(3):
+        pc.add_projection("Density", ax).add_callback(
+                            HopCircleCallback(hop_output, ax))
+    pc.save("%s_hop" % pf)



More information about the yt-svn mailing list