[yt-svn] commit/yt: 5 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Jul 20 07:04:33 PDT 2016
5 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/ad2acb0f1b93/
Changeset: ad2acb0f1b93
Branch: yt
User: ngoldbaum
Date: 2016-07-16 15:36:56+00:00
Summary: Print a more informative error message when PlotWindow is passed a particle field
Closes #878
Affected #: 3 files
diff -r 1c339ea7619997cba6842e973cf5f0e13b2f30ee -r ad2acb0f1b933018babdae3a8a50cf228550255d 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 1c339ea7619997cba6842e973cf5f0e13b2f30ee -r ad2acb0f1b933018babdae3a8a50cf228550255d 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)
@@ -185,6 +186,7 @@
self.override_fields = list(set(fields).intersection(set(skip)))
self.fields = [f for f in fields if f not in skip]
super(PlotWindow, self).__init__(data_source, window_size, fontsize)
+ self._validate_mesh_fields()
self._set_window(bounds) # this automatically updates the data and plot
self.origin = origin
if self.data_source.center is not None and oblique is False:
@@ -273,6 +275,16 @@
for key in self.override_fields:
self._frb[key]
+ def _validate_mesh_fields(self):
+ canonical_fields = self.data_source._determine_fields(self.fields)
+ invalid_fields = []
+ for field in canonical_fields:
+ if self.data_source.ds.field_info[field].particle_type is True:
+ invalid_fields.append(field)
+
+ if len(invalid_fields) > 0:
+ raise YTInvalidFieldType(invalid_fields)
+
@property
def width(self):
Wx = self.xlim[1] - self.xlim[0]
diff -r 1c339ea7619997cba6842e973cf5f0e13b2f30ee -r ad2acb0f1b933018babdae3a8a50cf228550255d 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,11 @@
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)
+ assert_raises(YTInvalidFieldType, SlicePlot, ds, 2, 'particle_mass')
+ assert_raises(
+ YTInvalidFieldType, SlicePlot, ds, 2, ['particle_mass', 'density'])
+ assert_raises(
+ YTInvalidFieldType, SlicePlot, ds, 2, ['density', 'particle_mass'])
https://bitbucket.org/yt_analysis/yt/commits/871daae6ed48/
Changeset: 871daae6ed48
Branch: yt
User: ngoldbaum
Date: 2016-07-16 18:48:10+00:00
Summary: Move the _validate_mesh_fields() call into subclasses to avoid breaking ParticlePlot
Affected #: 1 file
diff -r ad2acb0f1b933018babdae3a8a50cf228550255d -r 871daae6ed488de55c60ea6d5c5c90b67f2c190d yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -186,7 +186,6 @@
self.override_fields = list(set(fields).intersection(set(skip)))
self.fields = [f for f in fields if f not in skip]
super(PlotWindow, self).__init__(data_source, window_size, fontsize)
- self._validate_mesh_fields()
self._set_window(bounds) # this automatically updates the data and plot
self.origin = origin
if self.data_source.center is not None and oblique is False:
@@ -1256,6 +1255,7 @@
PWViewerMPL.__init__(self, slc, bounds, origin=origin,
fontsize=fontsize, fields=fields,
window_size=window_size, aspect=aspect)
+ self._validate_mesh_fields()
if axes_unit is None:
axes_unit = get_axes_unit(width, ds)
self.set_axes_unit(axes_unit)
@@ -1428,6 +1428,7 @@
PWViewerMPL.__init__(self, proj, bounds, fields=fields, origin=origin,
fontsize=fontsize, window_size=window_size,
aspect=aspect)
+ self._validate_mesh_fields()
if axes_unit is None:
axes_unit = get_axes_unit(width, ds)
self.set_axes_unit(axes_unit)
@@ -1524,6 +1525,7 @@
PWViewerMPL.__init__(self, cutting, bounds, fields=fields,
origin='center-window',periodic=False,
oblique=True, fontsize=fontsize)
+ self._validate_mesh_fields()
if axes_unit is None:
axes_unit = get_axes_unit(width, ds)
self.set_axes_unit(axes_unit)
@@ -1667,6 +1669,7 @@
PWViewerMPL.__init__(
self, OffAxisProj, bounds, fields=fields, origin='center-window',
periodic=False, oblique=True, fontsize=fontsize)
+ self._validate_mesh_fields()
if axes_unit is None:
axes_unit = get_axes_unit(width, ds)
self.set_axes_unit(axes_unit)
https://bitbucket.org/yt_analysis/yt/commits/b720c6b79532/
Changeset: b720c6b79532
Branch: yt
User: ngoldbaum
Date: 2016-07-18 02:20:06+00:00
Summary: Refactor so mesh field validation happens before the plot is initialized
Affected #: 1 file
diff -r 871daae6ed488de55c60ea6d5c5c90b67f2c190d -r b720c6b79532ed30c6321b941b201f4aabf10d21 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -131,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
@@ -274,16 +285,6 @@
for key in self.override_fields:
self._frb[key]
- def _validate_mesh_fields(self):
- canonical_fields = self.data_source._determine_fields(self.fields)
- invalid_fields = []
- for field in canonical_fields:
- if self.data_source.ds.field_info[field].particle_type is True:
- invalid_fields.append(field)
-
- if len(invalid_fields) > 0:
- raise YTInvalidFieldType(invalid_fields)
-
@property
def width(self):
Wx = self.xlim[1] - self.xlim[0]
@@ -1252,10 +1253,10 @@
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)
- self._validate_mesh_fields()
if axes_unit is None:
axes_unit = get_axes_unit(width, ds)
self.set_axes_unit(axes_unit)
@@ -1413,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
@@ -1428,7 +1434,6 @@
PWViewerMPL.__init__(self, proj, bounds, fields=fields, origin=origin,
fontsize=fontsize, window_size=window_size,
aspect=aspect)
- self._validate_mesh_fields()
if axes_unit is None:
axes_unit = get_axes_unit(width, ds)
self.set_axes_unit(axes_unit)
@@ -1520,12 +1525,12 @@
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,
origin='center-window',periodic=False,
oblique=True, fontsize=fontsize)
- self._validate_mesh_fields()
if axes_unit is None:
axes_unit = get_axes_unit(width, ds)
self.set_axes_unit(axes_unit)
@@ -1659,17 +1664,22 @@
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__(
self, OffAxisProj, bounds, fields=fields, origin='center-window',
periodic=False, oblique=True, fontsize=fontsize)
- self._validate_mesh_fields()
if axes_unit is None:
axes_unit = get_axes_unit(width, ds)
self.set_axes_unit(axes_unit)
https://bitbucket.org/yt_analysis/yt/commits/e7e4cd4d9d7e/
Changeset: e7e4cd4d9d7e
Branch: yt
User: ngoldbaum
Date: 2016-07-18 02:20:19+00:00
Summary: Expand tests for mesh field validation to cover all mesh plotting clases
Affected #: 1 file
diff -r b720c6b79532ed30c6321b941b201f4aabf10d21 -r e7e4cd4d9d7e6d84186f1d4ffe2cf1990e82e17e yt/visualization/tests/test_plotwindow.py
--- a/yt/visualization/tests/test_plotwindow.py
+++ b/yt/visualization/tests/test_plotwindow.py
@@ -424,8 +424,21 @@
def test_plot_particle_field_error():
ds = fake_random_ds(32, particles=100)
- assert_raises(YTInvalidFieldType, SlicePlot, ds, 2, 'particle_mass')
- assert_raises(
- YTInvalidFieldType, SlicePlot, ds, 2, ['particle_mass', 'density'])
- assert_raises(
- YTInvalidFieldType, SlicePlot, ds, 2, ['density', 'particle_mass'])
+
+ 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)
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