[yt-svn] commit/yt: jzuhone: Merged in ngoldbaum/yt (pull request #2279)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Jul 20 07:04:37 PDT 2016
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/40d042d8579a/
Changeset: 40d042d8579a
Branch: yt
User: jzuhone
Date: 2016-07-20 14:04:01+00:00
Summary: Merged in ngoldbaum/yt (pull request #2279)
Print a more informative error message when PlotWindow is passed a particle field. Closes #878
Affected #: 3 files
diff -r d5370abb4e58e08220904367f8383b7e22d8e9bc -r 40d042d8579aee72aa4580a343448649bcecbb28 yt/utilities/exceptions.py
--- a/yt/utilities/exceptions.py
+++ b/yt/utilities/exceptions.py
@@ -545,6 +545,20 @@
def __str__(self):
return "Can't identify shader_type for file '%s.'" % (self.source)
+class YTInvalidFieldType(YTException):
+ def __init__(self, fields):
+ self.fields = fields
+
+ def __str__(self):
+ msg = ("\nSlicePlot, ProjectionPlot, and OffAxisProjectionPlot can only "
+ "plot fields that\n"
+ "are defined on a mesh, but received the following particle "
+ "fields:\n\n"
+ " %s\n\n"
+ "Did you mean to use ParticlePlot or plot a deposited particle "
+ "field instead?" % self.fields)
+ return msg
+
class YTUnknownUniformKind(YTException):
def __init__(self, kind):
self.kind = kind
diff -r d5370abb4e58e08220904367f8383b7e22d8e9bc -r 40d042d8579aee72aa4580a343448649bcecbb28 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -65,7 +65,8 @@
YTCannotParseUnitDisplayName, \
YTUnitConversionError, \
YTPlotCallbackError, \
- YTDataTypeUnsupported
+ YTDataTypeUnsupported, \
+ YTInvalidFieldType
# Some magic for dealing with pyparsing being included or not
# included in matplotlib (not in gentoo, yes in everything else)
@@ -130,6 +131,17 @@
axes_unit = None
return axes_unit
+def validate_mesh_fields(data_source, fields):
+ canonical_fields = data_source._determine_fields(fields)
+ invalid_fields = []
+ for field in canonical_fields:
+ if data_source.ds.field_info[field].particle_type is True:
+ invalid_fields.append(field)
+
+ if len(invalid_fields) > 0:
+ raise YTInvalidFieldType(invalid_fields)
+
+
class PlotWindow(ImagePlotContainer):
r"""
A ploting mechanism based around the concept of a window into a
@@ -1241,6 +1253,7 @@
slc = ds.slice(axis, center[axis], field_parameters=field_parameters,
center=center, data_source=data_source)
slc.get_data(fields)
+ validate_mesh_fields(slc, fields)
PWViewerMPL.__init__(self, slc, bounds, origin=origin,
fontsize=fontsize, fields=fields,
window_size=window_size, aspect=aspect)
@@ -1401,6 +1414,11 @@
get_window_parameters(axis, center, width, ds)
if field_parameters is None: field_parameters = {}
+ # We don't use the plot's data source for validation like in the other
+ # plotting classes to avoid an exception
+ test_data_source = ds.all_data()
+ validate_mesh_fields(test_data_source, fields)
+
if isinstance(ds, YTSpatialPlotDataset):
proj = ds.all_data()
proj.axis = axis
@@ -1507,6 +1525,7 @@
field_parameters=field_parameters,
data_source=data_source)
cutting.get_data(fields)
+ validate_mesh_fields(cutting, fields)
# Hard-coding the origin keyword since the other two options
# aren't well-defined for off-axis data objects
PWViewerMPL.__init__(self, cutting, bounds, fields=fields,
@@ -1647,11 +1666,17 @@
center_rot, ds, normal, oap_width, fields, interpolated,
weight=weight_field, volume=volume, no_ghost=no_ghost,
le=le, re=re, north_vector=north_vector, method=method)
+
+ validate_mesh_fields(OffAxisProj, fields)
+
if max_level is not None:
OffAxisProj.dd.max_level = max_level
- # If a non-weighted, integral projection, assure field-label reflects that
+
+ # If a non-weighted, integral projection, assure field label
+ # reflects that
if weight_field is None and OffAxisProj.method == "integrate":
self.projected = True
+
# Hard-coding the origin keyword since the other two options
# aren't well-defined for off-axis data objects
PWViewerMPL.__init__(
diff -r d5370abb4e58e08220904367f8383b7e22d8e9bc -r 40d042d8579aee72aa4580a343448649bcecbb28 yt/visualization/tests/test_plotwindow.py
--- a/yt/visualization/tests/test_plotwindow.py
+++ b/yt/visualization/tests/test_plotwindow.py
@@ -22,9 +22,11 @@
from yt.extern.parameterized import parameterized, param
from yt.testing import \
fake_random_ds, assert_equal, assert_rel_equal, assert_array_equal, \
- assert_array_almost_equal
+ assert_array_almost_equal, assert_raises
from yt.utilities.answer_testing.framework import \
requires_ds, data_dir_load, PlotWindowAttributeTest
+from yt.utilities.exceptions import \
+ YTInvalidFieldType
from yt.visualization.api import \
SlicePlot, ProjectionPlot, OffAxisSlicePlot, OffAxisProjectionPlot
from yt.units.yt_array import YTArray, YTQuantity
@@ -419,3 +421,24 @@
sl_off = OffAxisSlicePlot(ds, L, 'density', center=[0,0,0], north_vector=north_vector)
assert_array_almost_equal(sl_on.frb['density'], sl_off.frb['density'])
+
+def test_plot_particle_field_error():
+ ds = fake_random_ds(32, particles=100)
+
+ field_names = [
+ 'particle_mass',
+ ['particle_mass', 'density'],
+ ['density', 'particle_mass'],
+ ]
+
+ objects_normals = [
+ (SlicePlot, 2),
+ (SlicePlot, [1, 1, 1]),
+ (ProjectionPlot, 2),
+ (OffAxisProjectionPlot, [1, 1, 1]),
+ ]
+
+ for object, normal in objects_normals:
+ for field_name_list in field_names:
+ assert_raises(
+ YTInvalidFieldType, object, ds, normal, field_name_list)
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list