[yt-svn] commit/yt: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Sat Nov 12 10:14:30 PST 2011
2 new commits in yt:
https://bitbucket.org/yt_analysis/yt/changeset/7c491e206eea/
changeset: 7c491e206eea
branch: yt
user: MatthewTurk
date: 2011-11-12 14:38:58
summary: Adding a simple matplotlib widget that displays data sources using the
matplotlib UI. Closes #299.
affected #: 1 file
diff -r 014872976c354a4bb70f8b41cd4d02d9d9e03048 -r 7c491e206eeacdf2c2fd0fd58e8a6b74e036164b yt/visualization/plot_collection.py
--- a/yt/visualization/plot_collection.py
+++ b/yt/visualization/plot_collection.py
@@ -32,7 +32,8 @@
from yt.data_objects.profiles import \
BinnedProfile1D, \
BinnedProfile2D
-from yt.utilities.definitions import axis_names, inv_axis_names
+from yt.utilities.definitions import \
+ axis_names, inv_axis_names, x_dict, y_dict
from .plot_types import \
FixedResolutionPlot, \
SlicePlot, \
@@ -1790,3 +1791,75 @@
ax.clear()
cbars.append(ax)
return fig, tr, cbars
+
+def _MPLFixImage(data_source, image_obj, field, cbar, cls):
+ nx, ny = image_obj.get_size()
+ def f(axes):
+ x0, x1 = axes.get_xlim()
+ y0, y1 = axes.get_ylim()
+ frb = cls(data_source, (x0, x1, y0, y1), (nx, ny))
+ image_obj.set_data(frb[field])
+ mi, ma = frb[field].min(), frb[field].max()
+ cbar.norm.autoscale((mi, ma))
+ image_obj.set_extent([x0, x1, y0, y1])
+ cbar.update_bruteforce(image_obj)
+ return f
+
+def matplotlib_widget(data_source, field, npix):
+ r"""Create a widget from a data_source that uses the Matplotlib interaction
+ method to pan, zoom, and so on.
+
+ This is a simple way to take a yt data source, for instance a projection or
+ a slice, and to create a matplotlib view into it that you can pan and zoom.
+ It uses the matplotlib interaction engine to manage input and display.
+
+ Parameters
+ ----------
+ data_source : :class:`yt.data_objects.data_containers.AMRProjBase` or :class:`yt.data_objects.data_containers.AMRSliceBase`
+ This is the source to be pixelized, which can be a projection or a
+ slice.
+ field : string
+ The field that you want to display in the window.
+ npix : int
+ The number of pixels on a side you want the image to be.
+
+ Examples
+ --------
+
+ >>> pf = load("DD0030/DD0030")
+ >>> p = pf.h.proj(0, "Density")
+ >>> matplotlib_widget(p, "Density", 1024)
+
+ """
+ import pylab
+ import matplotlib.colors
+ from .fixed_resolution import FixedResolutionBuffer, \
+ ObliqueFixedResolutionBuffer
+ pf = data_source.pf
+ if getattr(data_source, "axis", 4) < 3:
+ cls = FixedResolutionBuffer
+ ax = data_source.axis
+ extent = [pf.domain_left_edge[x_dict[ax]],
+ pf.domain_right_edge[x_dict[ax]],
+ pf.domain_left_edge[y_dict[ax]],
+ pf.domain_right_edge[y_dict[ax]]]
+ else:
+ cls = ObliqueFixedResolutionBuffer
+ extent = [0.0, 1.0, 0.0, 1.0]
+ take_log = pf.field_info[field].take_log
+ if take_log:
+ norm = matplotlib.colors.LogNorm()
+ else:
+ norm = matplotlib.colors.Normalize()
+ ax = pylab.figure().gca()
+ ax.autoscale(False)
+ axi = ax.imshow(na.random.random((npix, npix)),
+ extent = extent, norm = norm,
+ origin = 'lower')
+ cb = pylab.colorbar(axi, norm = norm)
+ showme = _MPLFixImage(data_source, axi, field, cb, cls)
+ ax.callbacks.connect("xlim_changed", showme)
+ ax.callbacks.connect("ylim_changed", showme)
+ ax.set_xlim(extent[0], extent[1])
+ ax.set_ylim(extent[2], extent[3])
+ return ax
https://bitbucket.org/yt_analysis/yt/changeset/1985559446b0/
changeset: 1985559446b0
branch: yt
user: MatthewTurk
date: 2011-11-12 14:59:11
summary: Moving obtain_rvec into Cython. 20-40x speedup for calculating radii, largely
because of all the reshaping, allocating, deallocating and whatnot.
Closes #296.
affected #: 2 files
diff -r 7c491e206eeacdf2c2fd0fd58e8a6b74e036164b -r 1985559446b075d29ffc4ceccdaad52567e1fd19 yt/data_objects/universal_fields.py
--- a/yt/data_objects/universal_fields.py
+++ b/yt/data_objects/universal_fields.py
@@ -34,7 +34,7 @@
from yt.funcs import *
-from yt.utilities.amr_utils import CICDeposit_3
+from yt.utilities.amr_utils import CICDeposit_3, obtain_rvec
from yt.utilities.cosmology import Cosmology
from field_info_container import \
add_field, \
@@ -484,13 +484,6 @@
zv = data["z-velocity"] - bv[2]
return xv, yv, zv
-def obtain_rvec(data):
- center = data.get_field_parameter('center')
- coords = na.array([data['x'],data['y'],data['z']], dtype='float64')
- new_shape = tuple([3] + [1]*(len(coords.shape)-1))
- r_vec = coords - na.reshape(center,new_shape)
- return r_vec # axis 0 is the x,y,z
-
def _SpecificAngularMomentum(field, data):
"""
Calculate the angular velocity. Returns a vector for each cell.
diff -r 7c491e206eeacdf2c2fd0fd58e8a6b74e036164b -r 1985559446b075d29ffc4ceccdaad52567e1fd19 yt/utilities/_amr_utils/misc_utilities.pyx
--- a/yt/utilities/_amr_utils/misc_utilities.pyx
+++ b/yt/utilities/_amr_utils/misc_utilities.pyx
@@ -148,6 +148,49 @@
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
+def obtain_rvec(data):
+ # This is just to let the pointers exist and whatnot. We can't cdef them
+ # inside conditionals.
+ cdef np.ndarray[np.float64_t, ndim=1] xf
+ cdef np.ndarray[np.float64_t, ndim=1] yf
+ cdef np.ndarray[np.float64_t, ndim=1] zf
+ cdef np.ndarray[np.float64_t, ndim=2] rf
+ cdef np.ndarray[np.float64_t, ndim=3] xg
+ cdef np.ndarray[np.float64_t, ndim=3] yg
+ cdef np.ndarray[np.float64_t, ndim=3] zg
+ cdef np.ndarray[np.float64_t, ndim=4] rg
+ cdef np.float64_t c[3]
+ cdef int i, j, k
+ center = data.get_field_parameter("center")
+ c[0] = center[0]; c[1] = center[1]; c[2] = center[2]
+ if len(data['x'].shape) == 1:
+ # One dimensional data
+ xf = data['x']
+ yf = data['y']
+ zf = data['z']
+ rf = np.empty((3, xf.shape[0]), 'float64')
+ for i in range(xf.shape[0]):
+ rf[0, i] = xf[i] - c[0]
+ rf[1, i] = yf[i] - c[1]
+ rf[2, i] = zf[i] - c[2]
+ return rf
+ else:
+ # Three dimensional data
+ xg = data['x']
+ yg = data['y']
+ zg = data['z']
+ rg = np.empty((3, xg.shape[0], xg.shape[1], xg.shape[2]), 'float64')
+ for i in range(xg.shape[0]):
+ for j in range(xg.shape[1]):
+ for k in range(xg.shape[2]):
+ rg[0,i,j,k] = xg[i,j,k] - c[0]
+ rg[1,i,j,k] = yg[i,j,k] - c[1]
+ rg[2,i,j,k] = zg[i,j,k] - c[2]
+ return rg
+
+ at cython.boundscheck(False)
+ at cython.wraparound(False)
+ at cython.cdivision(True)
def kdtree_get_choices(np.ndarray[np.float64_t, ndim=3] data,
np.ndarray[np.float64_t, ndim=1] l_corner,
np.ndarray[np.float64_t, ndim=1] r_corner):
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