[yt-svn] commit/yt: 12 new changesets
Bitbucket
commits-noreply at bitbucket.org
Fri Jul 27 12:33:28 PDT 2012
12 new commits in yt:
https://bitbucket.org/yt_analysis/yt/changeset/e7e05b21c020/
changeset: e7e05b21c020
branch: yt
user: ngoldbaum
date: 2012-07-23 22:59:31
summary: This explicitly closes old figures. We need to do this so out of date
interactive plot windows don't stick around.
affected #: 1 file
diff -r cb00e376315b5cf349b16c41b8cab9e1e940a602 -r e7e05b21c020866c43052092fe12dabd1e84e2b6 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -586,6 +586,7 @@
if f in self.plots.keys():
zlim = (self.plots[f].zmin,self.plots[f].zmax)
+ matplotlib.pyplot.close(self.plots[f].axes.figure)
else:
zlim = (None,None)
https://bitbucket.org/yt_analysis/yt/changeset/835140ea8f5d/
changeset: 835140ea8f5d
branch: yt
user: ngoldbaum
date: 2012-07-23 23:27:45
summary: Merging
affected #: 5 files
diff -r e7e05b21c020866c43052092fe12dabd1e84e2b6 -r 835140ea8f5dc17ba9f8110eb033eb6b79b14132 doc/install_script.sh
--- a/doc/install_script.sh
+++ b/doc/install_script.sh
@@ -56,6 +56,22 @@
# arguments. For instance, "-j4"
MAKE_PROCS=""
+# Make sure we are NOT being run as root
+if [[ $EUID -eq 0 ]]; then
+ echo "******************************************************"
+ echo "* *"
+ echo "* *"
+ echo "* IT IS A BAD IDEA TO RUN THIS SCRIPT AS ROOT!!!! *"
+ echo "* *"
+ echo "* *"
+ echo "******************************************************"
+ echo
+ echo "If you really want to do this, you must manually edit"
+ echo "the script to re-enable root-level installation. Sorry!"
+ exit 1
+fi
+# ...
+
#------------------------------------------------------------------------------#
# #
# Okay, the script starts here. Feel free to play with it, but hopefully #
diff -r e7e05b21c020866c43052092fe12dabd1e84e2b6 -r 835140ea8f5dc17ba9f8110eb033eb6b79b14132 yt/data_objects/time_series.py
--- a/yt/data_objects/time_series.py
+++ b/yt/data_objects/time_series.py
@@ -109,7 +109,8 @@
def __len__(self):
return len(self._pre_outputs)
- def piter(self, storage = None, dynamic = False):
+ def piter(self, storage = None):
+ dynamic = False
if self.parallel == False:
njobs = 1
else:
diff -r e7e05b21c020866c43052092fe12dabd1e84e2b6 -r 835140ea8f5dc17ba9f8110eb033eb6b79b14132 yt/data_objects/universal_fields.py
--- a/yt/data_objects/universal_fields.py
+++ b/yt/data_objects/universal_fields.py
@@ -541,16 +541,16 @@
r_vec = coords - na.reshape(center,new_shape)
v_vec = na.array([xv,yv,zv], dtype='float64')
return na.cross(r_vec, v_vec, axis=0)
-add_field("ParticleSpecificAngularMomentum",
- function=_ParticleSpecificAngularMomentum, particle_type=True,
- convert_function=_convertSpecificAngularMomentum, vector_field=True,
- units=r"\rm{cm}^2/\rm{s}", validators=[ValidateParameter('center')])
+#add_field("ParticleSpecificAngularMomentum",
+# function=_ParticleSpecificAngularMomentum, particle_type=True,
+# convert_function=_convertSpecificAngularMomentum, vector_field=True,
+# units=r"\rm{cm}^2/\rm{s}", validators=[ValidateParameter('center')])
def _convertSpecificAngularMomentumKMSMPC(data):
return data.convert("mpc")/1e5
-add_field("ParticleSpecificAngularMomentumKMSMPC",
- function=_ParticleSpecificAngularMomentum, particle_type=True,
- convert_function=_convertSpecificAngularMomentumKMSMPC, vector_field=True,
- units=r"\rm{km}\rm{Mpc}/\rm{s}", validators=[ValidateParameter('center')])
+#add_field("ParticleSpecificAngularMomentumKMSMPC",
+# function=_ParticleSpecificAngularMomentum, particle_type=True,
+# convert_function=_convertSpecificAngularMomentumKMSMPC, vector_field=True,
+# units=r"\rm{km}\rm{Mpc}/\rm{s}", validators=[ValidateParameter('center')])
def _ParticleSpecificAngularMomentumX(field, data):
if data.has_field_parameter("bulk_velocity"):
@@ -593,15 +593,15 @@
def _ParticleAngularMomentum(field, data):
return data["ParticleMass"] * data["ParticleSpecificAngularMomentum"]
-add_field("ParticleAngularMomentum",
- function=_ParticleAngularMomentum, units=r"\rm{g}\/\rm{cm}^2/\rm{s}",
- particle_type=True, validators=[ValidateParameter('center')])
+#add_field("ParticleAngularMomentum",
+# function=_ParticleAngularMomentum, units=r"\rm{g}\/\rm{cm}^2/\rm{s}",
+# particle_type=True, validators=[ValidateParameter('center')])
def _ParticleAngularMomentumMSUNKMSMPC(field, data):
return data["ParticleMass"] * data["ParticleSpecificAngularMomentumKMSMPC"]
-add_field("ParticleAngularMomentumMSUNKMSMPC",
- function=_ParticleAngularMomentumMSUNKMSMPC,
- units=r"M_{\odot}\rm{km}\rm{Mpc}/\rm{s}",
- particle_type=True, validators=[ValidateParameter('center')])
+#add_field("ParticleAngularMomentumMSUNKMSMPC",
+# function=_ParticleAngularMomentumMSUNKMSMPC,
+# units=r"M_{\odot}\rm{km}\rm{Mpc}/\rm{s}",
+# particle_type=True, validators=[ValidateParameter('center')])
def _ParticleAngularMomentumX(field, data):
return data["CellMass"] * data["ParticleSpecificAngularMomentumX"]
diff -r e7e05b21c020866c43052092fe12dabd1e84e2b6 -r 835140ea8f5dc17ba9f8110eb033eb6b79b14132 yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -1140,11 +1140,11 @@
unit = args.unit
if unit is None:
- unit = '1'
- width = args.width
- if width is None:
- width = 0.5*(pf.domain_right_edge - pf.domain_left_edge)
- width /= pf[unit]
+ unit = 'unitary'
+ if args.width is None:
+ width = (1.0, 'unitary')
+ else:
+ width = (args.width, args.unit)
for ax in axes:
mylog.info("Adding plot for axis %i", ax)
diff -r e7e05b21c020866c43052092fe12dabd1e84e2b6 -r 835140ea8f5dc17ba9f8110eb033eb6b79b14132 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -25,7 +25,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import base64
-import matplotlib.pyplot
+import matplotlib.figure
import cStringIO
import types
from functools import wraps
@@ -41,6 +41,7 @@
callback_registry
from .tick_locators import LogLocator, LinearLocator
from yt.utilities.delaunay.triangulate import Triangulation as triang
+from ._mpl_imports import *
from yt.funcs import *
from yt.utilities.lib import write_png_to_string
@@ -586,7 +587,6 @@
if f in self.plots.keys():
zlim = (self.plots[f].zmin,self.plots[f].zmax)
- matplotlib.pyplot.close(self.plots[f].axes.figure)
else:
zlim = (None,None)
@@ -596,8 +596,8 @@
self.plots[f] = WindowPlotMPL(self._frb[f], extent, self._field_transform[f],
self._colormaps[f], size, zlim)
- self.plots[f].cb = \
- matplotlib.pyplot.colorbar(self.plots[f].image,cax = self.plots[f].cax)
+ self.plots[f].cb = self.plots[f].figure.colorbar(
+ self.plots[f].image, cax = self.plots[f].cax)
if self.oblique == False:
labels = [r'$\rm{'+axis_labels[axis_index][i].encode('string-escape')+
@@ -885,8 +885,6 @@
if self._contour_info is None and self._vector_info is None:
return write_png_to_string(img)
from matplotlib.figure import Figure
- from yt.visualization._mpl_imports import \
- FigureCanvasAgg, FigureCanvasPdf, FigureCanvasPS
vi, vj, vn = img.shape
@@ -1007,18 +1005,29 @@
figure = None
def __init__(self, field, size):
self._plot_valid = True
- self.figure = matplotlib.pyplot.figure(figsize=size,frameon=True)
+ self.figure = matplotlib.figure.Figure(figsize = size, frameon = True)
# Hardcoding the axis dimensions for now
self.axes = self.figure.add_axes((.07,.10,.8,.8))
self.cax = self.figure.add_axes((.86,.10,.04,.8))
- def save(self,name):
+ def save(self, name, canvas = None):
if name[-4:] == '.png':
suffix = ''
else:
suffix = '.png'
- print "saving plot %s"%name+suffix
- self.figure.savefig('%s'%name+suffix)
+ fn = "%s%s" % (name, suffix)
+ mylog.info("Saving plot %s", fn)
+ if canvas is None:
+ if suffix == ".png":
+ canvas = FigureCanvasAgg(self.figure)
+ elif suffix == ".pdf":
+ canvas = FigureCanvasPdf(self.figure)
+ elif suffix in (".eps", ".ps"):
+ canvas = FigureCanvasPS
+ else:
+ mylog.warning("Unknown suffix %s, defaulting to Agg", suffix)
+ canvas = FigureCanvasAgg(self.figure)
+ canvas.print_figure(fn)
class WindowPlotMPL(PlotMPL):
def __init__(self, data, extent, field_transform, cmap, size, zlim):
https://bitbucket.org/yt_analysis/yt/changeset/5812bf1c60b1/
changeset: 5812bf1c60b1
branch: yt
user: ngoldbaum
date: 2012-07-23 23:39:02
summary: Merging.
affected #: 2 files
diff -r 835140ea8f5dc17ba9f8110eb033eb6b79b14132 -r 5812bf1c60b1244daf4fe0129da6150d53201005 yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -134,7 +134,7 @@
help="Field to weight projections with"),
cmap = dict(long="--colormap",
action="store", type=str,
- dest="cmap", default="jet",
+ dest="cmap", default="algae",
help="Colormap name"),
zlim = dict(short="-z", long="--zlim",
action="store", type=float,
@@ -1161,7 +1161,7 @@
time = pf.current_time*pf['Time']*pf['years']
plt.annotate_text((0.2,0.8), 't = %5.2e yr'%time)
- plt.set_cmap(args.field,args.cmap)
+ plt.set_cmap(args.field, args.cmap)
if args.zlim:
plt.set_zlim(args.field,*args.zlim)
if not os.path.isdir(args.output): os.makedirs(args.output)
diff -r 835140ea8f5dc17ba9f8110eb033eb6b79b14132 -r 5812bf1c60b1244daf4fe0129da6150d53201005 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -31,6 +31,7 @@
from functools import wraps
import numpy as na
+from ._mpl_imports import *
from .color_maps import yt_colormaps, is_colormap
from .image_writer import \
write_image, apply_colormap
@@ -41,7 +42,6 @@
callback_registry
from .tick_locators import LogLocator, LinearLocator
from yt.utilities.delaunay.triangulate import Triangulation as triang
-from ._mpl_imports import *
from yt.funcs import *
from yt.utilities.lib import write_png_to_string
@@ -595,7 +595,6 @@
self.plots[f] = WindowPlotMPL(self._frb[f], extent, self._field_transform[f],
self._colormaps[f], size, zlim)
-
self.plots[f].cb = self.plots[f].figure.colorbar(
self.plots[f].image, cax = self.plots[f].cax)
https://bitbucket.org/yt_analysis/yt/changeset/36cdddbc5562/
changeset: 36cdddbc5562
branch: yt
user: ngoldbaum
date: 2012-07-27 03:51:07
summary: Merging
affected #: 54 files
Diff too large to display.
https://bitbucket.org/yt_analysis/yt/changeset/bf6c131d6d2b/
changeset: bf6c131d6d2b
branch: yt
user: ngoldbaum
date: 2012-07-27 04:28:53
summary: Merging.
affected #: 2 files
diff -r 36cdddbc55620e4024c9d8b106dddeb14d7dd3aa -r bf6c131d6d2bb1dac6bf64ae76f4d039da2e5069 yt/utilities/exceptions.py
--- a/yt/utilities/exceptions.py
+++ b/yt/utilities/exceptions.py
@@ -101,3 +101,12 @@
return "Simulation %s has no stopping condition. StopTime or StopCycle should be set." % \
self.pf
+class YTNotInsideNotebook(YTException):
+ def __str__(self):
+ return "This function only works from within an IPython Notebook."
+
+class YTNotDeclaredInsideNotebook(YTException):
+ def __str__(self):
+ return "You have not declared yourself to be inside the IPython" + \
+ "Notebook. Do so with this command:\n\n" + \
+ "ytcfg['yt','ipython_notebook'] = 'True'"
diff -r 36cdddbc55620e4024c9d8b106dddeb14d7dd3aa -r bf6c131d6d2bb1dac6bf64ae76f4d039da2e5069 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -28,6 +28,7 @@
import matplotlib.figure
import cStringIO
import types
+import __builtin__
from functools import wraps
import numpy as na
@@ -54,12 +55,6 @@
from yt.utilities.math_utils import \
ortho_find
-try:
- from IPython.zmq.pylab.backend_inline import \
- send_figure
-except ImportError:
- pass
-
def invalidate_data(f):
@wraps(f)
def newfunc(*args, **kwargs):
@@ -692,6 +687,8 @@
return names
def _send_zmq(self):
+ from IPython.zmq.pylab.backend_inline import \
+ send_figure
for k, v in sorted(self.plots.iteritems()):
canvas = FigureCanvasAgg(v.figure)
send_figure(v.figure)
@@ -700,19 +697,12 @@
r"""This will send any existing plots to the IPython notebook.
function name.
- If yt is being run from within an IPython notebook, and it is able to
+ If yt is being run from within an IPython session, and it is able to
determine this, this function will send any existing plots to the
notebook for display.
- A common way of signalling this is to create an IPython profile that
- has in its 00 startup script this code:
-
- .. code-block:: python
-
- from yt.config import ytcfg
- ytcfg["yt","ipython_notebook"] = "True"
-
- If not running in the notebook, this will raise NotImplementedError.
+ If yt can't determine if it's inside an IPython session, it will raise
+ YTNotInsideNotebook.
Examples
--------
@@ -721,10 +711,10 @@
>>> slc.show()
"""
- if ytcfg.getboolean("yt", "ipython_notebook"):
+ if "__IPYTHON__" in dir(__builtin__):
self._send_zmq()
else:
- raise NotImplementedError
+ raise YTNotInsideNotebook
class SlicePlot(PWViewerMPL):
def __init__(self, pf, axis, fields, center='c', width=(1,'unitary'), origin='center-window'):
https://bitbucket.org/yt_analysis/yt/changeset/1af402deb4f5/
changeset: 1af402deb4f5
branch: yt
user: ngoldbaum
date: 2012-07-27 07:12:42
summary: Fixing the contour callback.
affected #: 1 file
diff -r bf6c131d6d2bb1dac6bf64ae76f4d039da2e5069 -r 1af402deb4f59fd0b2a5ad0e79e7382b70bbd7a5 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -208,8 +208,8 @@
plot._axes.hold(True)
numPoints_x = plot.image._A.shape[0]
numPoints_y = plot.image._A.shape[1]
- dy = plot.image._A.shape[0] / (x1-x0)
- dx = plot.image._A.shape[1] / (y1-y0)
+ dy = (xx1 - xx0) / (x1-x0)
+ dx = (yy1 - yy0) / (y1-y0)
#dcollins Jan 11 2009. Improved to allow for periodic shifts in the plot.
#Now makes a copy of the position fields "px" and "py" and adds the
#appropriate shift to the coppied field.
@@ -232,6 +232,8 @@
wI = (AllX & AllY)
xi, yi = na.mgrid[0:numPoints_x:numPoints_x/(self.factor*1j),\
0:numPoints_y:numPoints_y/(self.factor*1j)]
+ xi = xi/xi.max()*(x1 - x0)
+ yi = yi/yi.max()*(y1 - y0)
x = (XShifted[wI]-x0)*dx
y = (YShifted[wI]-y0)*dy
z = plot.data[self.field][wI]
@@ -239,6 +241,9 @@
zi = self.triang(x,y).nn_interpolator(z)(xi,yi)
print z.min(), z.max(), na.nanmin(z), na.nanmax(z)
print zi.min(), zi.max(), na.nanmin(zi), na.nanmax(zi)
+ xi = xi/(x1 - x0)*dx + xx0
+ yi = yi/(y1 - y0)*dx + yy0
+ pdb.set_trace()
plot._axes.contour(xi,yi,zi,self.ncont, **self.plot_args)
plot._axes.set_xlim(xx0,xx1)
plot._axes.set_ylim(yy0,yy1)
https://bitbucket.org/yt_analysis/yt/changeset/d93c4275618e/
changeset: d93c4275618e
branch: yt
user: ngoldbaum
date: 2012-07-27 07:14:47
summary: Removing a pdb call.
affected #: 1 file
diff -r 1af402deb4f59fd0b2a5ad0e79e7382b70bbd7a5 -r d93c4275618ed485498720daef1c6403bd9a277a yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -243,7 +243,6 @@
print zi.min(), zi.max(), na.nanmin(zi), na.nanmax(zi)
xi = xi/(x1 - x0)*dx + xx0
yi = yi/(y1 - y0)*dx + yy0
- pdb.set_trace()
plot._axes.contour(xi,yi,zi,self.ncont, **self.plot_args)
plot._axes.set_xlim(xx0,xx1)
plot._axes.set_ylim(yy0,yy1)
https://bitbucket.org/yt_analysis/yt/changeset/52f4e921c74f/
changeset: 52f4e921c74f
branch: yt
user: ngoldbaum
date: 2012-07-27 07:16:23
summary: Cleaning up.
affected #: 1 file
diff -r d93c4275618ed485498720daef1c6403bd9a277a -r 52f4e921c74fa1eac7700627f38636c0305c535c yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -202,12 +202,15 @@
def __call__(self, plot):
x0, x1 = plot.xlim
y0, y1 = plot.ylim
- print x0, x1, y0, y1
+
xx0, xx1 = plot._axes.get_xlim()
yy0, yy1 = plot._axes.get_ylim()
+
plot._axes.hold(True)
+
numPoints_x = plot.image._A.shape[0]
numPoints_y = plot.image._A.shape[1]
+
dy = (xx1 - xx0) / (x1-x0)
dx = (yy1 - yy0) / (y1-y0)
#dcollins Jan 11 2009. Improved to allow for periodic shifts in the plot.
@@ -230,19 +233,22 @@
AllX |= xlim
AllY |= ylim
wI = (AllX & AllY)
+
xi, yi = na.mgrid[0:numPoints_x:numPoints_x/(self.factor*1j),\
0:numPoints_y:numPoints_y/(self.factor*1j)]
xi = xi/xi.max()*(x1 - x0)
yi = yi/yi.max()*(y1 - y0)
+
x = (XShifted[wI]-x0)*dx
y = (YShifted[wI]-y0)*dy
z = plot.data[self.field][wI]
if self.take_log: z=na.log10(z)
+
zi = self.triang(x,y).nn_interpolator(z)(xi,yi)
- print z.min(), z.max(), na.nanmin(z), na.nanmax(z)
- print zi.min(), zi.max(), na.nanmin(zi), na.nanmax(zi)
+
xi = xi/(x1 - x0)*dx + xx0
yi = yi/(y1 - y0)*dx + yy0
+
plot._axes.contour(xi,yi,zi,self.ncont, **self.plot_args)
plot._axes.set_xlim(xx0,xx1)
plot._axes.set_ylim(yy0,yy1)
https://bitbucket.org/yt_analysis/yt/changeset/931a841c5a20/
changeset: 931a841c5a20
branch: yt
user: ngoldbaum
date: 2012-07-27 08:00:09
summary: Fixing the hop_circles callback
affected #: 1 file
diff -r 52f4e921c74fa1eac7700627f38636c0305c535c -r 931a841c5a2021c69fecfca57a114128e5bc7bac yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -52,11 +52,25 @@
def convert_to_plot(self, plot, coord, offset = True):
x0, x1 = plot.xlim
xx0, xx1 = plot._axes.get_xlim()
+
y0, y1 = plot.ylim
yy0, yy1 = plot._axes.get_ylim()
+
return ((coord[0]-x0)/(x1-x0)*(xx1-xx0) + xx0,
(coord[1]-y0)/(y1-y0)*(yy1-yy0) + yy0)
+ def pixel_scale(self,plot):
+ x0, x1 = plot.xlim
+ xx0, xx1 = plot._axes.get_xlim()
+ dx = (xx0 - xx1)/(x1 - x0)
+
+ y0, y1 = plot.ylim
+ yy0, yy1 = plot._axes.get_ylim()
+ dy = (yy0 - yy1)/(y1 - y0)
+
+ return (dx,dy)
+
+
class VelocityCallback(PlotCallback):
_type_name = "velocity"
def __init__(self, factor=16, scale=None, scale_units=None, normalize=False):
@@ -777,13 +791,6 @@
def __call__(self, plot):
from matplotlib.patches import Circle
- x0, x1 = plot.xlim
- y0, y1 = plot.ylim
- l, b, width, height = mpl_get_bounds(plot._axes.bbox)
- xi = x_dict[plot.data.axis]
- yi = y_dict[plot.data.axis]
- dx = plot.image._A.shape[0] / (x1-x0)
- dy = plot.image._A.shape[1] / (y1-y0)
for halo in self.hop_output[:self.max_number]:
size = halo.get_size()
if size < self.min_size or size > self.max_size: continue
@@ -793,10 +800,13 @@
plot.data.center)[plot.data.axis] > \
self.width:
continue
- radius = halo.maximum_radius() * dx
+
+ radius = halo.maximum_radius() * self.pixel_scale(plot)[0]
center = halo.center_of_mass()
- center_x = (center[xi] - x0)*dx
- center_y = (center[yi] - y0)*dy
+
+ (xi, yi) = (x_dict[plot.data.axis], y_dict[plot.data.axis])
+
+ (center_x,center_y) = self.convert_to_plot(plot,(center[xi], center[yi]))
cir = Circle((center_x, center_y), radius, fill=False)
plot._axes.add_patch(cir)
if self.annotate:
https://bitbucket.org/yt_analysis/yt/changeset/65e1a4bf725e/
changeset: 65e1a4bf725e
branch: yt
user: ngoldbaum
date: 2012-07-27 08:10:57
summary: Fixing the sphere callback
affected #: 1 file
diff -r 931a841c5a2021c69fecfca57a114128e5bc7bac -r 65e1a4bf725ed053ac950c7b21cd8035784570c5 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -747,17 +747,13 @@
def __call__(self, plot):
from matplotlib.patches import Circle
- x0, x1 = plot.xlim
- y0, y1 = plot.ylim
- l, b, width, height = mpl_get_bounds(plot._axes.bbox)
- xi = x_dict[plot.data.axis]
- yi = y_dict[plot.data.axis]
- dx = plot.image._A.shape[0] / (x1-x0)
- dy = plot.image._A.shape[1] / (y1-y0)
- radius = self.radius * dx
- center_x = (self.center[xi] - x0)*dx
- center_y = (self.center[yi] - y0)*dy
- # origin = lower? not sure why center_y and center_x are reversed
+
+ radius = self.radius * self.pixel_scale(plot)[0]
+
+ (xi, yi) = (x_dict[plot.data.axis], y_dict[plot.data.axis])
+
+ (center_x,center_y) = self.convert_to_plot(plot,(self.center[xi], self.center[yi]))
+
cir = Circle((center_x, center_y), radius, **self.circle_args)
plot._axes.add_patch(cir)
if self.text is not None:
https://bitbucket.org/yt_analysis/yt/changeset/34a060779605/
changeset: 34a060779605
branch: yt
user: ngoldbaum
date: 2012-07-27 08:49:45
summary: Fixing the hop_particles callback and removing the vestigal
voboz_circle callback (I don't see any other reference to voboz in yt)
affected #: 1 file
diff -r 65e1a4bf725ed053ac950c7b21cd8035784570c5 -r 34a060779605bcfbecb499dab45f7b2bfb288fcd yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -50,14 +50,24 @@
pass
def convert_to_plot(self, plot, coord, offset = True):
- x0, x1 = plot.xlim
- xx0, xx1 = plot._axes.get_xlim()
+ ncoord = na.array(coord).shape[1]
+
+ x0 = na.tile(plot.xlim[0],ncoord)
+ x1 = na.tile(plot.xlim[1],ncoord)
+ xx0 = na.tile(plot._axes.get_xlim()[0],ncoord)
+ xx1 = na.tile(plot._axes.get_xlim()[1],ncoord)
- y0, y1 = plot.ylim
- yy0, yy1 = plot._axes.get_ylim()
+ y0 = na.tile(plot.ylim[0],ncoord)
+ y1 = na.tile(plot.ylim[1],ncoord)
+ yy0 = na.tile(plot._axes.get_ylim()[0],ncoord)
+ yy1 = na.tile(plot._axes.get_ylim()[1],ncoord)
- return ((coord[0]-x0)/(x1-x0)*(xx1-xx0) + xx0,
- (coord[1]-y0)/(y1-y0)*(yy1-yy0) + yy0)
+ if na.array(coord).shape == (2,):
+ return ((coord[0]-x0)/(x1-x0)*(xx1-xx0) + xx0,
+ (coord[1]-y0)/(y1-y0)*(yy1-yy0) + yy0)
+ else:
+ return ((coord[:][0]-x0)/(x1-x0)*(xx1-xx0) + xx0,
+ (coord[:][1]-y0)/(y1-y0)*(yy1-yy0) + yy0)
def pixel_scale(self,plot):
x0, x1 = plot.xlim
@@ -818,7 +828,7 @@
class HopParticleCallback(PlotCallback):
_type_name = "hop_particles"
- def __init__(self, hop_output, max_number, p_size=1.0,
+ def __init__(self, hop_output, max_number=None, p_size=1.0,
min_size=20, alpha=0.2):
"""
annotate_hop_particles(hop_output, max_number, p_size=1.0,
@@ -836,67 +846,22 @@
self.alpha = alpha
def __call__(self,plot):
- if self.max_number < 1: return
- x0, x1 = plot.xlim
- y0, y1 = plot.ylim
- xx0, xx1 = plot._axes.get_xlim()
- yy0, yy1 = plot._axes.get_ylim()
- xf = axis_names[x_dict[plot.data.axis]]
- yf = axis_names[y_dict[plot.data.axis]]
- dx = plot.image._A.shape[0] / (x1-x0)
- dy = plot.image._A.shape[1] / (y1-y0)
+ (dx,dy) = self.pixel_scale(plot)
+
+ (xi, yi) = (x_names[plot.data.axis], y_names[plot.data.axis])
+
# now we loop over the haloes
for halo in self.hop_output[:self.max_number]:
size = halo.get_size()
+
if size < self.min_size: continue
- colors = na.ones(size)
- plot._axes.hold(True)
- px = (halo["particle_position_%s" % xf] - x0)*dx
- py = (halo["particle_position_%s" % yf] - y0)*dy
+
+ (px,py) = self.convert_to_plot(plot,(halo["particle_position_%s" % xi],
+ halo["particle_position_%s" % yi]))
+
plot._axes.scatter(px, py, edgecolors="None",
s=self.p_size, c='black', alpha=self.alpha)
- plot._axes.set_xlim(xx0,xx1)
- plot._axes.set_ylim(yy0,yy1)
- plot._axes.hold(False)
-class VobozCircleCallback(PlotCallback):
- _type_name = "voboz_circle"
- def __init__(self, voboz_output, max_number=None,
- annotate=False, min_size=20, font_size=8, print_halo_size=False):
- self.axis = axis
- self.voboz_output = voboz_output
- self.max_number = max_number
- self.annotate = annotate
- self.min_size = min_size
- self.font_size = font_size
- self.print_halo_size = print_halo_size
-
- def __call__(self, plot):
- from matplotlib.patches import Circle
- x0, x1 = plot.xlim
- y0, y1 = plot.ylim
- l, b, width, height = mpl_get_bounds(plot._axes.bbox)
- xi = x_dict[plot.data.axis]
- yi = y_dict[plot.data.axis]
- dx = plot.image._A.shape[0] / (x1-x0)
- dy = plot.image._A.shape[1] / (y1-y0)
- for i,halo in enumerate(self.voboz_output[:self.max_number]):
- if (len(halo.particles) >= self.min_size):
- radius = halo.maximum_radius * dx
- center = halo.center_of_mass
- center_x = (center[xi] - x0)*dx
- center_y = (center[yi] - y0)*dy
- #print "voboz center = (%f,%f)" % (center[xi],center[yi])
- #print "voboz radius = %f" % halo.maximum_radius
- cir = Circle((center_x, center_y), radius, fill=False)
- plot._axes.add_patch(cir)
- if self.annotate:
- if self.print_halo_size:
- plot._axes.text(center_x, center_y, "%s" % len(halo.particles),
- fontsize=self.font_size)
- else:
- plot._axes.text(center_x, center_y, "%s" % i,
- fontsize=self.font_size)
class CoordAxesCallback(PlotCallback):
_type_name = "coord_axes"
https://bitbucket.org/yt_analysis/yt/changeset/1df752548a7a/
changeset: 1df752548a7a
branch: yt
user: ngoldbaum
date: 2012-07-27 21:21:48
summary: Fixing the hop_particles callback and adding some comments.
affected #: 1 file
diff -r 34a060779605bcfbecb499dab45f7b2bfb288fcd -r 1df752548a7a43afb617532f04537ceb698cc3aa yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -50,8 +50,12 @@
pass
def convert_to_plot(self, plot, coord, offset = True):
+ # coord should be a 2 x ncoord array-like datatype.
ncoord = na.array(coord).shape[1]
+ # Convert the data and plot limits to tiled numpy arrays so that
+ # convert_to_plot is automatically vectorized.
+
x0 = na.tile(plot.xlim[0],ncoord)
x1 = na.tile(plot.xlim[1],ncoord)
xx0 = na.tile(plot._axes.get_xlim()[0],ncoord)
@@ -62,12 +66,13 @@
yy0 = na.tile(plot._axes.get_ylim()[0],ncoord)
yy1 = na.tile(plot._axes.get_ylim()[1],ncoord)
+ # We need a special case for when we are only given one coordinate.
if na.array(coord).shape == (2,):
return ((coord[0]-x0)/(x1-x0)*(xx1-xx0) + xx0,
(coord[1]-y0)/(y1-y0)*(yy1-yy0) + yy0)
else:
- return ((coord[:][0]-x0)/(x1-x0)*(xx1-xx0) + xx0,
- (coord[:][1]-y0)/(y1-y0)*(yy1-yy0) + yy0)
+ return ((coord[0][:]-x0)/(x1-x0)*(xx1-xx0) + xx0,
+ (coord[1][:]-y0)/(y1-y0)*(yy1-yy0) + yy0)
def pixel_scale(self,plot):
x0, x1 = plot.xlim
@@ -858,9 +863,22 @@
(px,py) = self.convert_to_plot(plot,(halo["particle_position_%s" % xi],
halo["particle_position_%s" % yi]))
+
+ # Need to get the plot limits and set the hold state before scatter
+ # and then restore the limits and turn off the hold state afterwards
+ # because scatter will automatically adjust the plot window which we
+ # do not want
+
+ xlim = plot._axes.get_xlim()
+ ylim = plot._axes.get_ylim()
+ plot._axes.hold(True)
plot._axes.scatter(px, py, edgecolors="None",
s=self.p_size, c='black', alpha=self.alpha)
+
+ plot._axes.set_xlim(xlim)
+ plot._axes.set_ylim(ylim)
+ plot._axes.hold(False)
class CoordAxesCallback(PlotCallback):
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