[Yt-svn] yt-commit r516 - in trunk: tests yt/lagos yt/raven
mturk at wrangler.dreamhost.com
mturk at wrangler.dreamhost.com
Mon Jun 2 14:36:55 PDT 2008
Author: mturk
Date: Mon Jun 2 14:36:54 2008
New Revision: 516
URL: http://yt.spacepope.org/changeset/516
Log:
Added copyright string to DerivedFields and a get_smallest_appropriate_unit to
the output type.
Fixed some problems with PlotCollection and PlotTypes.
Brought up-to-speed the unit testing for raven. Closes #70.
Fixed tests/runall.py , which is now the appropriate way to run the unit tests.
Boy does it take a long time, though...
Modified:
trunk/tests/runall.py
trunk/tests/test_hdf5_reader.py
trunk/tests/test_raven.py
trunk/yt/lagos/DerivedFields.py
trunk/yt/lagos/OutputTypes.py
trunk/yt/raven/PlotCollection.py
trunk/yt/raven/PlotTypes.py
Modified: trunk/tests/runall.py
==============================================================================
--- trunk/tests/runall.py (original)
+++ trunk/tests/runall.py Mon Jun 2 14:36:54 2008
@@ -4,27 +4,27 @@
You can run this using:
-$ python runall.py
+$ python tests/runall.py
-This can be done from any directory.
+This should be done from the root directory of the installation.
-Currently, YT needs to be installed to run the tests, so that Python
-can find the modules.
+YT can either be installed globally, or the extensions build with:
+
+$ python setup.py build_ext --inplace
"""
import unittest
-from test_lagos import TestLagos
-from test_raven import TestRaven
+import test_lagos
+import test_raven
+import test_hdf5_reader
def get_suite():
- suite_l = unittest.TestLoader().loadTestsFromTestCase(TestLagos)
- suite_r = unittest.TestLoader().loadTestsFromTestCase(TestRaven)
+ suite_l = unittest.defaultTestLoader.loadTestsFromModule(test_lagos)
+ suite_r = unittest.defaultTestLoader.loadTestsFromModule(test_raven)
+ suite_h = unittest.defaultTestLoader.loadTestsFromModule(test_hdf5_reader)
suite = unittest.TestSuite([suite_l, suite_r])
return suite
if __name__ == '__main__':
- suite = get_suite()
- unittest.main()
-
-
+ unittest.main(defaultTest='get_suite')
Modified: trunk/tests/test_hdf5_reader.py
==============================================================================
--- trunk/tests/test_hdf5_reader.py (original)
+++ trunk/tests/test_hdf5_reader.py Mon Jun 2 14:36:54 2008
@@ -18,6 +18,7 @@
recv_array = ReadData("testing_h5lt_io.h5", "/%s" % (self.dtype))
self.assert_(numpy.all(recv_array == self.rand_array))
self.assert_(recv_array.shape == self.rand_array.shape)
+ self.assertTrue(recv_array.flags.owndata)
def tearDown(self):
os.unlink("testing_h5lt_io.h5")
Modified: trunk/tests/test_raven.py
==============================================================================
--- trunk/tests/test_raven.py (original)
+++ trunk/tests/test_raven.py Mon Jun 2 14:36:54 2008
@@ -2,75 +2,174 @@
Test that we can make plots
"""
-import unittest, glob, os.path, os
+import unittest, glob, os.path, os, sys, StringIO
-from yt import ytcfg
-ytcfg["yt","LogLevel"] = '20'
+print "Reporting from %s" % (os.getcwd())
+sys.path = ['.'] + sys.path
+from yt.config import ytcfg
+ytcfg["yt","LogLevel"] = '50'
+ytcfg["yt","logFile"] = "False"
+ytcfg["yt","suppressStreamLogging"] = "True"
+ytcfg["lagos","serialize"] = "False"
+
+import numpy as na
+import yt.lagos
import yt.raven
# The dataset used is located at:
# http://yt.spacepope.org/DD0018.zip
-fn = "DD0018/moving7_0018"
+fn = "DD0010/moving7_0010"
fn = os.path.join(os.path.dirname(__file__),fn)
-class TestRaven(unittest.TestCase):
+class RavenTestingBase:
def setUp(self):
self.OutputFile = yt.lagos.EnzoStaticOutput(fn)
self.hierarchy = self.OutputFile.hierarchy
self.pc = yt.raven.PlotCollection(self.OutputFile)
- v,self.c = self.hierarchy.findMax("Density")
+ self.v, self.c = self.hierarchy.find_max("Density")
+ gp = os.path.join(os.path.dirname(fn),"*.yt")
+ ytFiles = glob.glob(gp)
+ for i in ytFiles:
+ os.unlink(i)
+ self.localSetup()
def tearDown(self):
- self.hierarchy.dataFile.close()
- del self.OutputFile, self.hierarchy, self.pc
-
+ if hasattr(self,'data'): del self.data
+ if hasattr(self,'region'): del self.region
+ if hasattr(self,'ind_to_get'): del self.ind_to_get
+ if hasattr(self,'pc'): del self.pc
+ del self.OutputFile, self.hierarchy
+
def DoSave(self):
fns=self.pc.save("test")
for fn in fns:
- print "Unlinking",fn
+ os.unlink(fn)
- def testSlice(self):
- self.pc.addSlice("Density",0)
+ def _testSlice(self):
+ self.pc.add_slice("Density",0)
self.pc.plots[-1].switch_z("CellMass")
self.pc.set_width(0.5,'1')
self.pc.set_zlim(1,1000)
self.pc.set_cmap("hot")
self.DoSave()
- def testProjection(self):
- self.pc.addProjection("Temperature",1,weightField="Density")
+ def _testProjection(self):
+ self.pc.add_projection("Temperature",1,weight_field="Density")
self.pc.set_width(0.5,'1')
self.pc.set_zlim(1,1000)
self.pc.set_cmap("hot")
self.DoSave()
- def testThreePhaseSphere(self):
+ def _testThreePhaseSphere(self):
print "Testing ThreePhase"
- self.pc.addThreePhaseSphere(1.0,'1',["Density","Temperature","Density"],center=self.c)
- self.DoSave()
-
- def testTwoPhaseSphere(self):
- print "Testing TwoPhase"
- self.pc.addTwoPhaseSphere(1.0,'1',["Temperature","Density"],center=self.c)
+ self.pc.add_phase_sphere(1.0,'1',["Density","Temperature","Density"],center=self.c)
self.DoSave()
- def testCallbacksOnSlices(self):
+ def _testCallbacksOnSlices(self):
# We test a couple things here
# Add callbacks, then remove one, then do the plot-saving
# Both types of callback should be called here
for ax in range(3):
- self.pc.addSlice("Density", 0)
+ self.pc.add_slice("Density", 0)
x,y = yt.raven.axis_labels[ax]
v1 = "%s-velocity" % (x)
v2 = "%s-velocity" % (y)
- qi = self.pc.plots[-1].addCallback(yt.raven.be.quiverCallback(v1,v2,ax,32))
- ti = self.pc.plots[-1].addCallback(yt.raven.be.contourCallback("Temperature",
- ax, ncont=3, factor=10))
- gi = self.pc.plots[-1].addCallback(yt.raven.be.contourCallback("Gas_Energy",
- ax, ncont=3, factor=10))
- self.pc.plots[-1].removeCallback(gi)
+ qi = self.pc.plots[-1].add_callback(yt.raven.QuiverCallback(v1,v2,ax,32))
+ ti = self.pc.plots[-1].add_callback(yt.raven.ContourCallback("Temperature",
+ ncont=3, factor=10))
+ gi = self.pc.plots[-1].add_callback(yt.raven.ContourCallback("Gas_Energy",
+ ncont=3, factor=10))
+ self.pc.plots[-1].remove_callback(gi)
+ self.DoSave()
+
+class PlotTestingBase(RavenTestingBase):
+ def test_set_xlim(self):
+ self.pc.set_xlim(0.25,0.75)
+ self.DoSave()
+
+ def test_set_ylim(self):
+ self.pc.set_ylim(0.25,0.75)
self.DoSave()
+ def test_autoscale(self):
+ # verify autoscale changed
+ self.pc.autoscale()
+ self.DoSave()
+
+ def test_set_zlim(self):
+ self.pc.set_zlim(0.5, 1.0)
+ self.DoSave()
+
+ def test_set_lim(self):
+ self.pc.set_lim((0.25,0.75,0.25,0.75))
+ self.DoSave()
+
+ def test_set_width(self):
+ self.pc.set_width(0.25,'1')
+ self.DoSave()
+
+ def test_set_cmap(self):
+ self.pc.set_cmap("kamae")
+ self.DoSave()
+ self.pc.set_cmap("jet")
+ self.DoSave()
+
+ def test_switch_field(self):
+ for field in ["Temperature","x-velocity"]:
+ self.pc.switch_field(field)
+ # Check if the logging is set correctly
+ self.DoSave()
+
+ def test_clear_plots(self):
+ self.pc.clear_plots()
+ self.assertTrue(len(self.pc.plots) == 0)
+
+ def test_set_label(self):
+ for p in self.pc.plots: p.set_label(r"$\rm{Hi}$")
+ self.DoSave()
+ for p in self.pc.plots: p.set_label("Hi!")
+ self.DoSave()
+
+ def test_set_logfield(self):
+ for p in self.pc.plots: p.set_log_field(False)
+ self.DoSave()
+ for p in self.pc.plots: p.set_log_field(False)
+ self.DoSave()
+
+ def test_save(self):
+ self.DoSave()
+
+class TestSlices(PlotTestingBase, unittest.TestCase):
+ def localSetup(self):
+ self.pc.add_slice("Density",0)
+ self.pc.add_slice("Density",1)
+ self.pc.add_slice("Density",2)
+
+class TestSphere(PlotTestingBase, unittest.TestCase):
+ def localSetup(self):
+ self.pc.add_phase_sphere(1.0,'1',
+ ["Density","TotalEnergy","y-velocity"])
+
+class TestPhaseObject(PlotTestingBase, unittest.TestCase):
+ def localSetup(self):
+ obj = self.hierarchy.region([0.5]*3, [0.0]*3, [1.0]*3)
+ self.pc.add_phase_object(obj, ["Density","TotalEnergy","y-velocity"])
+
+class TestProjection(PlotTestingBase, unittest.TestCase):
+ def localSetup(self):
+ self.pc.add_projection("Density", 0)
+ self.pc.add_projection("Temperature", 1)
+ self.pc.add_projection("x-velocity", 2, weight_field="Density")
+
+class TestMixProjectionSlice(PlotTestingBase, unittest.TestCase):
+ def localSetup(self):
+ self.pc.add_projection("Density",0)
+ self.pc.add_slice("Density",0)
+
+class TestCuttingPlane(PlotTestingBase, unittest.TestCase):
+ def localSetup(self):
+ self.pc.add_cutting_plane("Density", [0.1,0.2,0.3])
+
if __name__ == "__main__":
unittest.main()
Modified: trunk/yt/lagos/DerivedFields.py
==============================================================================
--- trunk/yt/lagos/DerivedFields.py (original)
+++ trunk/yt/lagos/DerivedFields.py Mon Jun 2 14:36:54 2008
@@ -1,3 +1,28 @@
+"""
+Derived fields and support for existing fields included in here.
+
+ at author: U{Matthew Turk<http://www.stanford.edu/~mturk/>}
+ at organization: U{KIPAC<http://www-group.slac.stanford.edu/KIPAC/>}
+ at contact: U{mturk at slac.stanford.edu<mailto:mturk at slac.stanford.edu>}
+ at license:
+ Copyright (C) 2008 Matthew Turk. All Rights Reserved.
+
+ This file is part of yt.
+
+ yt is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+
import types
import numpy as na
import inspect
Modified: trunk/yt/lagos/OutputTypes.py
==============================================================================
--- trunk/yt/lagos/OutputTypes.py (original)
+++ trunk/yt/lagos/OutputTypes.py Mon Jun 2 14:36:54 2008
@@ -69,6 +69,16 @@
+ self.parameters.keys() \
+ self.conversion_factors.keys()
+ def get_smallest_appropriate_unit(self, v):
+ max_nu = 1e30
+ good_u = None
+ for unit in ['mpc','kpc','pc','au','rsun','cm']:
+ vv = v*self[unit]
+ if vv < max_nu and vv > 1.0:
+ good_u = unit
+ max_nu = v*self[unit]
+ return good_u
+
def has_key(self, key):
"""
Returns true or false
Modified: trunk/yt/raven/PlotCollection.py
==============================================================================
--- trunk/yt/raven/PlotCollection.py (original)
+++ trunk/yt/raven/PlotCollection.py Mon Jun 2 14:36:54 2008
@@ -80,8 +80,8 @@
plot.set_zlim(zmin, zmax)
def set_lim(self, lim):
for plot in self.plots:
- plot.set_xlim(lim[:2])
- plot.set_ylim(lim[2:])
+ plot.set_xlim(*lim[:2])
+ plot.set_ylim(*lim[2:])
def set_width(self, width, unit):
for plot in self.plots:
plot.set_width(width, unit)
@@ -231,5 +231,5 @@
def clear_plots(self):
for i in range(len(self.plots)):
- del self.plots[i].data
- del self.plots[i]
+ del self.plots[-1].data
+ del self.plots[-1]
Modified: trunk/yt/raven/PlotTypes.py
==============================================================================
--- trunk/yt/raven/PlotTypes.py (original)
+++ trunk/yt/raven/PlotTypes.py Mon Jun 2 14:36:54 2008
@@ -97,6 +97,9 @@
pass
class RavenPlot:
+
+ datalabel = None
+ colorbar = None
def __init__(self, data, fields, figure = None, axes=None, size=(10,8)):
self.data = data
self.fields = fields
@@ -159,7 +162,10 @@
self._axes.set_ylim(ymin, ymax)
def set_zlim(self, zmin, zmax):
- self._axes.set_zlim(zmin, zmax)
+ self.norm.autoscale(na.array([zmin,zmax]))
+ self.image.changed()
+ if self.colorbar != None:
+ self.colorbar.notify(self.image)
def set_cmap(self, cmap):
if isinstance(cmap, types.StringTypes):
@@ -183,9 +189,11 @@
for cb in self._callbacks:
cb(self)
+ def set_label(self, label):
+ self.datalabel = label
+ if self.colorbar != None: self.colorbar.set_label(str(label))
+
class VMPlot(RavenPlot):
- datalabel = None
- colorbar = None
def __init__(self, data, field, figure = None, axes = None,
use_colorbar = True, size=None):
fields = ['X', 'Y', field, 'X width', 'Y width']
@@ -352,15 +360,6 @@
self.axis_names["Z"] = field
self._redraw_image()
- def set_zlim(self, zmin, zmax):
- self.norm.autoscale(na.array([zmin,zmax]))
- self.image.changed()
- if self.colorbar != None:
- self.colorbar.notify(self.image)
-
- def set_label(self, label):
- if self.colorbar != None: self.colorbar.set_label(str(label))
-
def selfSetup(self):
pass
@@ -379,8 +378,8 @@
if self.colorbar != None: self.colorbar.set_label(str(data_label))
class ProjectionPlot(VMPlot):
- _type_name = "Projection"
+ _type_name = "Projection"
def autoset_label(self):
if self.datalabel != None:
self.colorbar.set_label(str(self.datalabel))
@@ -392,10 +391,13 @@
data_label += r"$"
if self.colorbar != None: self.colorbar.set_label(str(data_label))
+ def switch_z(self, field):
+ mylog.warning("Choosing not to change the field of a projection instance")
+
+
class CuttingPlanePlot(SlicePlot):
_type_name = "CuttingPlane"
-
def _get_buff(self, width=None):
px_min, px_max = self.xlim
py_min, py_max = self.ylim
@@ -453,9 +455,10 @@
class Profile1DPlot(ProfilePlot):
+
+ _type_name = "Profile1D"
def __init__(self, data, fields, id, ticker=None, cmap=None,
figure=None, axes=None, plot_options=None):
- self._type_name = "Profile"
self._semi_unique_id = id
RavenPlot.__init__(self, data, fields, figure, axes)
@@ -515,9 +518,10 @@
switch_y = switch_z # Compatibility...
class PhasePlot(ProfilePlot):
+
+ _type_name = "Profile2D"
def __init__(self, data, fields, id, ticker=None, cmap=None,
figure=None, axes=None):
- self._type_name = "Phase"
self._semi_unique_id = id
RavenPlot.__init__(self, data, fields, figure, axes)
self.ticker = ticker
@@ -619,3 +623,17 @@
self["Field1"] = self.axis_names["X"]
self["Field2"] = self.axis_names["Y"]
self["Field3"] = self.axis_names["Z"]
+
+ def autoset_label(self, field_name, func):
+ if self.datalabel != None:
+ func(str(self.datalabel))
+ return
+ data_label = r"$\rm{%s}" % field_name
+ if field_name in lagos.fieldInfo:
+ data_label += r"\/\/ (%s)" % (lagos.fieldInfo[field_name].get_units())
+ data_label += r"$"
+ func(str(data_label))
+
+ def set_width(self, width, unit):
+ mylog.warning("Choosing not to change the width of a phase plot instance")
+
More information about the yt-svn
mailing list