[yt-svn] commit/yt: atmyers: Merged in MatthewTurk/yt (pull request #2245)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri Sep 30 10:54:29 PDT 2016
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/1d70bf412499/
Changeset: 1d70bf412499
Branch: yt
User: atmyers
Date: 2016-09-30 17:54:01+00:00
Summary: Merged in MatthewTurk/yt (pull request #2245)
Change pixelizers to composite
Affected #: 15 files
diff -r 743f56472b10f18505a7e1c1061b496050e8aaf1 -r 1d70bf4124996d584483c173e37f29670a73db99 doc/source/analyzing/generating_processed_data.rst
--- a/doc/source/analyzing/generating_processed_data.rst
+++ b/doc/source/analyzing/generating_processed_data.rst
@@ -26,13 +26,16 @@
sizes into a fixed-size array that appears like an image. This process is that
of pixelization, which yt handles transparently internally. You can access
this functionality by constructing a
-:class:`~yt.visualization.fixed_resolution.FixedResolutionBuffer` (or
-:class:`~yt.visualization.fixed_resolution.ObliqueFixedResolutionBuffer`) and
-supplying to it your :class:`~yt.data_objects.data_containers.YTSelectionContainer2D`
+:class:`~yt.visualization.fixed_resolution.FixedResolutionBuffer` and supplying
+to it your :class:`~yt.data_objects.data_containers.YTSelectionContainer2D`
object, as well as some information about how you want the final image to look.
You can specify both the bounds of the image (in the appropriate x-y plane) and
-the resolution of the output image. You can then have yt pixelize any
-field you like.
+the resolution of the output image. You can then have yt pixelize any field
+you like.
+
+.. note:: In previous versions of yt, there was a special class of
+ FixedResolutionBuffer for off-axis slices. This is no longer
+ necessary.
To create :class:`~yt.data_objects.data_containers.YTSelectionContainer2D` objects, you can
access them as described in :ref:`data-objects`, specifically the section
diff -r 743f56472b10f18505a7e1c1061b496050e8aaf1 -r 1d70bf4124996d584483c173e37f29670a73db99 doc/source/reference/api/api.rst
--- a/doc/source/reference/api/api.rst
+++ b/doc/source/reference/api/api.rst
@@ -49,7 +49,6 @@
~yt.visualization.fixed_resolution.FixedResolutionBuffer
~yt.visualization.fixed_resolution.ParticleImageBuffer
~yt.visualization.fixed_resolution.CylindricalFixedResolutionBuffer
- ~yt.visualization.fixed_resolution.ObliqueFixedResolutionBuffer
~yt.visualization.fixed_resolution.OffAxisProjectionFixedResolutionBuffer
Data Sources
diff -r 743f56472b10f18505a7e1c1061b496050e8aaf1 -r 1d70bf4124996d584483c173e37f29670a73db99 tests/tests.yaml
--- a/tests/tests.yaml
+++ b/tests/tests.yaml
@@ -39,7 +39,7 @@
local_owls_000:
- yt/frontends/owls/tests/test_outputs.py
- local_pw_006:
+ local_pw_008:
- yt/visualization/tests/test_plotwindow.py:test_attributes
- yt/visualization/tests/test_plotwindow.py:test_attributes_wt
- yt/visualization/tests/test_profile_plots.py:test_phase_plot_attributes
@@ -50,7 +50,7 @@
local_tipsy_001:
- yt/frontends/tipsy/tests/test_outputs.py
- local_varia_004:
+ local_varia_005:
- yt/analysis_modules/radmc3d_export
- yt/frontends/moab/tests/test_c5.py
- yt/analysis_modules/photon_simulator/tests/test_spectra.py
diff -r 743f56472b10f18505a7e1c1061b496050e8aaf1 -r 1d70bf4124996d584483c173e37f29670a73db99 yt/data_objects/selection_data_containers.py
--- a/yt/data_objects/selection_data_containers.py
+++ b/yt/data_objects/selection_data_containers.py
@@ -463,12 +463,12 @@
self.fields = ensure_list(fields) + [k for k in self.field_data.keys()
if k not in self._key_fields]
from yt.visualization.plot_window import get_oblique_window_parameters, PWViewerMPL
- from yt.visualization.fixed_resolution import ObliqueFixedResolutionBuffer
+ from yt.visualization.fixed_resolution import FixedResolutionBuffer
(bounds, center_rot) = get_oblique_window_parameters(normal, center, width, self.ds)
pw = PWViewerMPL(
self, bounds, fields=self.fields, origin='center-window',
periodic=False, oblique=True,
- frb_generator=ObliqueFixedResolutionBuffer,
+ frb_generator=FixedResolutionBuffer,
plot_type='OffAxisSlice')
if axes_unit is not None:
pw.set_axes_unit(axes_unit)
@@ -476,8 +476,8 @@
return pw
def to_frb(self, width, resolution, height=None, periodic=False):
- r"""This function returns an ObliqueFixedResolutionBuffer generated
- from this object.
+ r"""This function returns a FixedResolutionBuffer generated from this
+ object.
An ObliqueFixedResolutionBuffer is an object that accepts a
variable-resolution 2D object and transforms it into an NxM bitmap that
@@ -526,9 +526,9 @@
height = self.ds.quan(height[0], height[1])
if not iterable(resolution):
resolution = (resolution, resolution)
- from yt.visualization.fixed_resolution import ObliqueFixedResolutionBuffer
+ from yt.visualization.fixed_resolution import FixedResolutionBuffer
bounds = (-width/2.0, width/2.0, -height/2.0, height/2.0)
- frb = ObliqueFixedResolutionBuffer(self, bounds, resolution,
+ frb = FixedResolutionBuffer(self, bounds, resolution,
periodic=periodic)
return frb
diff -r 743f56472b10f18505a7e1c1061b496050e8aaf1 -r 1d70bf4124996d584483c173e37f29670a73db99 yt/geometry/coordinates/cartesian_coordinates.py
--- a/yt/geometry/coordinates/cartesian_coordinates.py
+++ b/yt/geometry/coordinates/cartesian_coordinates.py
@@ -128,22 +128,24 @@
period[1] = self.period[self.y_axis[dim]]
if hasattr(period, 'in_units'):
period = period.in_units("code_length").d
- buff = pixelize_cartesian(data_source['px'], data_source['py'],
+ buff = np.zeros((size[1], size[0]), dtype="f8")
+ pixelize_cartesian(buff, data_source['px'], data_source['py'],
data_source['pdx'], data_source['pdy'],
- data_source[field], size[0], size[1],
+ data_source[field],
bounds, int(antialias),
- period, int(periodic)).transpose()
+ period, int(periodic))
return buff
def _oblique_pixelize(self, data_source, field, bounds, size, antialias):
- indices = np.argsort(data_source['dx'])[::-1]
- buff = pixelize_off_axis_cartesian(
+ indices = np.argsort(data_source['pdx'])[::-1]
+ buff = np.zeros((size[1], size[0]), dtype="f8")
+ pixelize_off_axis_cartesian(buff,
data_source['x'], data_source['y'],
data_source['z'], data_source['px'],
data_source['py'], data_source['pdx'],
data_source['pdy'], data_source['pdz'],
data_source.center, data_source._inv_mat, indices,
- data_source[field], size[0], size[1], bounds).transpose()
+ data_source[field], bounds)
return buff
def convert_from_cartesian(self, coord):
diff -r 743f56472b10f18505a7e1c1061b496050e8aaf1 -r 1d70bf4124996d584483c173e37f29670a73db99 yt/geometry/coordinates/cylindrical_coordinates.py
--- a/yt/geometry/coordinates/cylindrical_coordinates.py
+++ b/yt/geometry/coordinates/cylindrical_coordinates.py
@@ -113,19 +113,22 @@
period[1] = self.period[self.y_axis[dim]]
if hasattr(period, 'in_units'):
period = period.in_units("code_length").d
- buff = pixelize_cartesian(data_source['px'], data_source['py'],
+ buff = np.zeros(size, dtype="f8")
+ pixelize_cartesian(buff, data_source['px'], data_source['py'],
data_source['pdx'], data_source['pdy'],
- data_source[field], size[0], size[1],
+ data_source[field],
bounds, int(antialias),
- period, int(periodic)).transpose()
+ period, int(periodic))
return buff
def _cyl_pixelize(self, data_source, field, bounds, size, antialias):
- buff = pixelize_cylinder(data_source['px'],
- data_source['pdx'],
- data_source['py'],
- data_source['pdy'],
- size, data_source[field], bounds)
+ buff = np.zeros((size[1], size[0]), dtype="f8")
+ pixelize_cylinder(buff,
+ data_source['px'],
+ data_source['pdx'],
+ data_source['py'],
+ data_source['pdy'],
+ data_source[field], bounds)
return buff
_x_pairs = (('r', 'theta'), ('z', 'r'), ('theta', 'r'))
diff -r 743f56472b10f18505a7e1c1061b496050e8aaf1 -r 1d70bf4124996d584483c173e37f29670a73db99 yt/geometry/coordinates/geographic_coordinates.py
--- a/yt/geometry/coordinates/geographic_coordinates.py
+++ b/yt/geometry/coordinates/geographic_coordinates.py
@@ -203,9 +203,9 @@
else:
# We should never get here!
raise NotImplementedError
- buff = pixelize_cylinder(r, data_source['pdy'],
- px, pdx,
- size, data_source[field], bounds)
+ buff = np.zeros((size[1], size[0]), dtype="f8")
+ pixelize_cylinder(buff, r, data_source['pdy'],
+ px, pdx, data_source[field], bounds)
if do_transpose:
buff = buff.transpose()
return buff
diff -r 743f56472b10f18505a7e1c1061b496050e8aaf1 -r 1d70bf4124996d584483c173e37f29670a73db99 yt/geometry/coordinates/spherical_coordinates.py
--- a/yt/geometry/coordinates/spherical_coordinates.py
+++ b/yt/geometry/coordinates/spherical_coordinates.py
@@ -123,19 +123,22 @@
def _cyl_pixelize(self, data_source, field, bounds, size, antialias,
dimension):
name = self.axis_name[dimension]
+ buff = np.zeros((size[1], size[0]), dtype="f8")
if name == 'theta':
- buff = pixelize_cylinder(data_source['px'],
- data_source['pdx'],
- data_source['py'],
- data_source['pdy'],
- size, data_source[field], bounds)
+ pixelize_cylinder(buff,
+ data_source['px'],
+ data_source['pdx'],
+ data_source['py'],
+ data_source['pdy'],
+ data_source[field], bounds)
elif name == 'phi':
- buff = pixelize_cylinder(data_source['px'],
- data_source['pdx'],
- data_source['py'],
- data_source['pdy'],
- size, data_source[field], bounds)
- buff = buff.transpose()
+ # Note that we feed in buff.T here
+ pixelize_cylinder(buff.T,
+ data_source['px'],
+ data_source['pdx'],
+ data_source['py'],
+ data_source['pdy'],
+ data_source[field], bounds)
else:
raise RuntimeError
return buff
diff -r 743f56472b10f18505a7e1c1061b496050e8aaf1 -r 1d70bf4124996d584483c173e37f29670a73db99 yt/utilities/lib/pixelization_routines.pyx
--- a/yt/utilities/lib/pixelization_routines.pyx
+++ b/yt/utilities/lib/pixelization_routines.pyx
@@ -54,12 +54,13 @@
@cython.cdivision(True)
@cython.boundscheck(False)
@cython.wraparound(False)
-def pixelize_cartesian(np.ndarray[np.float64_t, ndim=1] px,
- np.ndarray[np.float64_t, ndim=1] py,
- np.ndarray[np.float64_t, ndim=1] pdx,
- np.ndarray[np.float64_t, ndim=1] pdy,
- np.ndarray[np.float64_t, ndim=1] data,
- int cols, int rows, bounds,
+def pixelize_cartesian(np.float64_t[:,:] buff,
+ np.float64_t[:] px,
+ np.float64_t[:] py,
+ np.float64_t[:] pdx,
+ np.float64_t[:] pdy,
+ np.float64_t[:] data,
+ bounds,
int antialias = 1,
period = None,
int check_period = 1,
@@ -78,7 +79,6 @@
cdef int yiter[2]
cdef np.float64_t xiterv[2]
cdef np.float64_t yiterv[2]
- cdef np.ndarray[np.float64_t, ndim=2] my_array
if period is not None:
period_x = period[0]
period_y = period[1]
@@ -88,18 +88,15 @@
y_max = bounds[3]
width = x_max - x_min
height = y_max - y_min
- px_dx = width / (<np.float64_t> rows)
- px_dy = height / (<np.float64_t> cols)
+ px_dx = width / (<np.float64_t> buff.shape[1])
+ px_dy = height / (<np.float64_t> buff.shape[0])
ipx_dx = 1.0 / px_dx
ipx_dy = 1.0 / px_dy
- if rows == 0 or cols == 0:
- raise YTPixelizeError("Cannot scale to zero size")
if px.shape[0] != py.shape[0] or \
px.shape[0] != pdx.shape[0] or \
px.shape[0] != pdy.shape[0] or \
px.shape[0] != data.shape[0]:
raise YTPixelizeError("Arrays are not of correct shape.")
- my_array = np.zeros((rows, cols), "float64")
xiter[0] = yiter[0] = 0
xiterv[0] = yiterv[0] = 0.0
# Here's a basic outline of what we're going to do here. The xiter and
@@ -120,6 +117,31 @@
# (lr) and then iterate up to "right column" (rc) and "uppeR row" (rr),
# depositing into them the data value. Overlap computes the relative
# overlap of a data value with a pixel.
+ #
+ # NOTE ON ROWS AND COLUMNS:
+ #
+ # The way that images are plotting in matplotlib is somewhat different
+ # from what most might expect. The first axis of the array plotted is
+ # what varies along the x axis. So for instance, if you supply
+ # origin='lower' and plot the results of an mgrid operation, at a fixed
+ # 'y' value you will see the results of that array held constant in the
+ # first dimension. Here is some example code:
+ #
+ # import matplotlib.pyplot as plt
+ # import numpy as np
+ # x, y = np.mgrid[0:1:100j,0:1:100j]
+ # plt.imshow(x, interpolation='nearest', origin='lower')
+ # plt.imshow(y, interpolation='nearest', origin='lower')
+ #
+ # The values in the image:
+ # lower left: arr[0,0]
+ # lower right: arr[0,-1]
+ # upper left: arr[-1,0]
+ # upper right: arr[-1,-1]
+ #
+ # So what we want here is to fill an array such that we fill:
+ # first axis : y_min .. y_max
+ # second axis: x_min .. x_max
with nogil:
for p in range(px.shape[0]):
xiter[1] = yiter[1] = 999
@@ -161,8 +183,10 @@
# truncated, but no similar truncation was done in the
# comparison of j to rc (double). So give ourselves a
# bonus row and bonus column here.
- rc = <int> fmin(((xsp+dxsp-x_min)*ipx_dx + 1), rows)
- rr = <int> fmin(((ysp+dysp-y_min)*ipx_dy + 1), cols)
+ rc = <int> fmin(((xsp+dxsp-x_min)*ipx_dx + 1), buff.shape[1])
+ rr = <int> fmin(((ysp+dysp-y_min)*ipx_dy + 1), buff.shape[0])
+ # Note that we're iterating here over *y* in the i
+ # direction. See the note above about this.
for i in range(lr, rr):
lypx = px_dy * i + y_min
rypx = px_dy * (i+1) + y_min
@@ -187,7 +211,7 @@
fabs(cy - (ysp-dysp)))
ld_y *= ipx_dy
if ld_x <= line_width or ld_y <= line_width:
- my_array[j,i] = 1.0
+ buff[i,j] = 1.0
elif antialias == 1:
overlap1 = ((fmin(rxpx, xsp+dxsp)
- fmax(lxpx, (xsp-dxsp)))*ipx_dx)
@@ -200,16 +224,15 @@
# This will reduce artifacts if we ever move to
# compositing instead of replacing bitmaps.
if overlap1 * overlap2 == 0.0: continue
- my_array[j,i] += (dsp * overlap1) * overlap2
+ buff[i,j] += (dsp * overlap1) * overlap2
else:
- my_array[j,i] = dsp
-
- return my_array
+ buff[i,j] = dsp
@cython.cdivision(True)
@cython.boundscheck(False)
@cython.wraparound(False)
def pixelize_off_axis_cartesian(
+ np.float64_t[:,:] buff,
np.float64_t[:] x,
np.float64_t[:] y,
np.float64_t[:] z,
@@ -222,7 +245,7 @@
np.float64_t[:,:] inv_mat,
np.int64_t[:] indices,
np.float64_t[:] data,
- int cols, int rows, bounds):
+ bounds):
cdef np.float64_t x_min, x_max, y_min, y_max
cdef np.float64_t width, height, px_dx, px_dy, ipx_dx, ipx_dy, md
cdef int i, j, p, ip
@@ -231,7 +254,6 @@
cdef np.float64_t xsp, ysp, zsp, dxsp, dysp, dzsp, dsp
cdef np.float64_t pxsp, pysp, cxpx, cypx, cx, cy, cz
# Some periodicity helpers
- cdef np.ndarray[np.float64_t, ndim=2] my_array
cdef np.ndarray[np.int64_t, ndim=2] mask
x_min = bounds[0]
x_max = bounds[1]
@@ -239,12 +261,10 @@
y_max = bounds[3]
width = x_max - x_min
height = y_max - y_min
- px_dx = width / (<np.float64_t> rows)
- px_dy = height / (<np.float64_t> cols)
+ px_dx = width / (<np.float64_t> buff.shape[1])
+ px_dy = height / (<np.float64_t> buff.shape[0])
ipx_dx = 1.0 / px_dx
ipx_dy = 1.0 / px_dy
- if rows == 0 or cols == 0:
- raise YTPixelizeError("Cannot scale to zero size")
if px.shape[0] != py.shape[0] or \
px.shape[0] != pdx.shape[0] or \
px.shape[0] != pdy.shape[0] or \
@@ -252,8 +272,7 @@
px.shape[0] != indices.shape[0] or \
px.shape[0] != data.shape[0]:
raise YTPixelizeError("Arrays are not of correct shape.")
- my_array = np.zeros((rows, cols), "float64")
- mask = np.zeros((rows, cols), "int64")
+ mask = np.zeros((buff.shape[0], buff.shape[1]), "int64")
with nogil:
for ip in range(indices.shape[0]):
p = indices[ip]
@@ -275,8 +294,8 @@
continue
lc = <int> fmax(((pxsp - md - x_min)*ipx_dx),0)
lr = <int> fmax(((pysp - md - y_min)*ipx_dy),0)
- rc = <int> fmin(((pxsp + md - x_min)*ipx_dx + 1), rows)
- rr = <int> fmin(((pysp + md - y_min)*ipx_dy + 1), cols)
+ rc = <int> fmin(((pxsp + md - x_min)*ipx_dx + 1), buff.shape[1])
+ rr = <int> fmin(((pysp + md - y_min)*ipx_dy + 1), buff.shape[0])
for i in range(lr, rr):
cypx = px_dy * (i + 0.5) + y_min
for j in range(lc, rc):
@@ -289,40 +308,35 @@
fabs(zsp - cz) * 0.99 > dzsp:
continue
mask[i, j] += 1
- my_array[i, j] += dsp
- my_array /= mask
- return my_array.T
-
+ buff[i, j] += dsp
+ for i in range(buff.shape[0]):
+ for j in range(buff.shape[1]):
+ if mask[i,j] == 0: continue
+ buff[i,j] /= mask[i,j]
@cython.cdivision(True)
@cython.boundscheck(False)
@cython.wraparound(False)
-def pixelize_cylinder(np.ndarray[np.float64_t, ndim=1] radius,
- np.ndarray[np.float64_t, ndim=1] dradius,
- np.ndarray[np.float64_t, ndim=1] theta,
- np.ndarray[np.float64_t, ndim=1] dtheta,
- buff_size,
- np.ndarray[np.float64_t, ndim=1] field,
- extents, input_img = None):
+def pixelize_cylinder(np.float64_t[:,:] buff,
+ np.float64_t[:] radius,
+ np.float64_t[:] dradius,
+ np.float64_t[:] theta,
+ np.float64_t[:] dtheta,
+ np.float64_t[:] field,
+ extents):
- cdef np.ndarray[np.float64_t, ndim=2] img
cdef np.float64_t x, y, dx, dy, r0, theta0
cdef np.float64_t rmax, x0, y0, x1, y1
cdef np.float64_t r_i, theta_i, dr_i, dtheta_i, dthetamin
cdef np.float64_t costheta, sintheta
cdef int i, pi, pj
-
- imax = radius.argmax()
+
+ cdef int imax = np.asarray(radius).argmax()
rmax = radius[imax] + dradius[imax]
- if input_img is None:
- img = np.zeros((buff_size[0], buff_size[1]))
- img[:] = np.nan
- else:
- img = input_img
x0, x1, y0, y1 = extents
- dx = (x1 - x0) / img.shape[0]
- dy = (y1 - y0) / img.shape[1]
+ dx = (x1 - x0) / buff.shape[1]
+ dy = (y1 - y0) / buff.shape[0]
cdef np.float64_t rbounds[2]
cdef np.float64_t corners[8]
# Find our min and max r
@@ -371,16 +385,12 @@
x = r_i * sintheta
pi = <int>((x - x0)/dx)
pj = <int>((y - y0)/dy)
- if pi >= 0 and pi < img.shape[0] and \
- pj >= 0 and pj < img.shape[1]:
- if img[pi, pj] != img[pi, pj]:
- img[pi, pj] = 0.0
- img[pi, pj] = field[i]
+ if pi >= 0 and pi < buff.shape[0] and \
+ pj >= 0 and pj < buff.shape[1]:
+ buff[pi, pj] = field[i]
r_i += 0.5*dx
theta_i += dthetamin
- return img
-
cdef void aitoff_thetaphi_to_xy(np.float64_t theta, np.float64_t phi,
np.float64_t *x, np.float64_t *y):
cdef np.float64_t z = math.sqrt(1 + math.cos(phi) * math.cos(theta / 2.0))
@@ -390,12 +400,12 @@
@cython.cdivision(True)
@cython.boundscheck(False)
@cython.wraparound(False)
-def pixelize_aitoff(np.ndarray[np.float64_t, ndim=1] theta,
- np.ndarray[np.float64_t, ndim=1] dtheta,
- np.ndarray[np.float64_t, ndim=1] phi,
- np.ndarray[np.float64_t, ndim=1] dphi,
+def pixelize_aitoff(np.float64_t[:] theta,
+ np.float64_t[:] dtheta,
+ np.float64_t[:] phi,
+ np.float64_t[:] dphi,
buff_size,
- np.ndarray[np.float64_t, ndim=1] field,
+ np.float64_t[:] field,
extents, input_img = None,
np.float64_t theta_offset = 0.0,
np.float64_t phi_offset = 0.0):
diff -r 743f56472b10f18505a7e1c1061b496050e8aaf1 -r 1d70bf4124996d584483c173e37f29670a73db99 yt/visualization/fixed_resolution.py
--- a/yt/visualization/fixed_resolution.py
+++ b/yt/visualization/fixed_resolution.py
@@ -18,12 +18,13 @@
from yt.funcs import \
get_output_filename, \
mylog, \
- ensure_list
+ ensure_list, \
+ deprecate
from .volume_rendering.api import off_axis_projection
from .fixed_resolution_filters import apply_filter, filter_registry
from yt.data_objects.image_array import ImageArray
from yt.utilities.lib.pixelization_routines import \
- pixelize_cylinder, pixelize_off_axis_cartesian
+ pixelize_cylinder
from yt.utilities.lib.api import add_points_to_greyscale_image
from yt.frontends.stream.api import load_uniform_grid
@@ -51,9 +52,8 @@
Parameters
----------
data_source : :class:`yt.data_objects.construction_data_containers.YTQuadTreeProj` or :class:`yt.data_objects.selection_data_containers.YTSlice`
- This is the source to be pixelized, which can be a projection or a
- slice. (For cutting planes, see
- `yt.visualization.fixed_resolution.ObliqueFixedResolutionBuffer`.)
+ This is the source to be pixelized, which can be a projection, slice or
+ cutting plane.
bounds : sequence of floats
Bounds are the min and max in the image plane that we want our
image to cover. It's in the order of (xmin, xmax, ymin, ymax),
@@ -67,12 +67,6 @@
This can be true or false, and governs whether the pixelization
will span the domain boundaries.
- See Also
- --------
- :class:`yt.visualization.fixed_resolution.ObliqueFixedResolutionBuffer` : A similar object,
- used for cutting
- planes.
-
Examples
--------
To make a projection and then several images, you can generate a
@@ -494,6 +488,11 @@
self.__dict__['apply_' + filtername] = \
types.MethodType(filt, self)
+class ObliqueFixedResolutionBuffer(FixedResolutionBuffer):
+ @deprecate("FixedResolutionBuffer")
+ def __init__(self, *args, **kwargs):
+ super(ObliqueFixedResolutionBuffer, self).__init__(*args, **kwargs)
+
class CylindricalFixedResolutionBuffer(FixedResolutionBuffer):
"""
This object is a subclass of
@@ -515,41 +514,13 @@
def __getitem__(self, item) :
if item in self.data: return self.data[item]
- buff = pixelize_cylinder(self.data_source["r"], self.data_source["dr"],
- self.data_source["theta"], self.data_source["dtheta"],
- self.buff_size, self.data_source[item].astype("float64"),
- self.radius)
+ buff = np.zeros(self.buff_size, dtype="f8")
+ pixelize_cylinder(buff, self.data_source["r"], self.data_source["dr"],
+ self.data_source["theta"], self.data_source["dtheta"],
+ self.data_source[item].astype("float64"), self.radius)
self[item] = buff
return buff
-class ObliqueFixedResolutionBuffer(FixedResolutionBuffer):
- """
- This object is a subclass of
- :class:`yt.visualization.fixed_resolution.FixedResolutionBuffer`
- that supports non-aligned input data objects, primarily cutting planes.
- """
- def __getitem__(self, item):
- if item in self.data: return self.data[item]
- indices = np.argsort(self.data_source['dx'])[::-1]
- bounds = []
- for b in self.bounds:
- if hasattr(b, "in_units"):
- b = float(b.in_units("code_length"))
- bounds.append(b)
- buff = pixelize_off_axis_cartesian(
- self.data_source['x'], self.data_source['y'], self.data_source['z'],
- self.data_source['px'], self.data_source['py'],
- self.data_source['pdx'], self.data_source['pdy'], self.data_source['pdz'],
- self.data_source.center, self.data_source._inv_mat, indices,
- self.data_source[item],
- self.buff_size[0], self.buff_size[1],
- bounds).transpose()
- ia = ImageArray(buff, input_units=self.data_source[item].units,
- info=self._get_info(item))
- self[item] = ia
- return ia
-
-
class OffAxisProjectionFixedResolutionBuffer(FixedResolutionBuffer):
"""
This object is a subclass of
diff -r 743f56472b10f18505a7e1c1061b496050e8aaf1 -r 1d70bf4124996d584483c173e37f29670a73db99 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -392,8 +392,10 @@
xx0, xx1 = plot._axes.get_xlim()
yy0, yy1 = plot._axes.get_ylim()
plot._axes.hold(True)
- nx = plot.image._A.shape[0] / self.factor
- ny = plot.image._A.shape[1] / self.factor
+ # See the note about rows/columns in the pixelizer for more information
+ # on why we choose the bounds we do
+ nx = plot.image._A.shape[1] / self.factor
+ ny = plot.image._A.shape[0] / self.factor
# periodicity
ax = plot.data.axis
ds = plot.data.ds
@@ -410,18 +412,18 @@
if self.bv_y != 0.0:
# Workaround for 0.0 without units
fv_y -= self.bv_y
- pixX = pixelize_cartesian(plot.data['px'], plot.data['py'],
+ pixX = np.zeros((ny, nx), dtype="f8")
+ pixY = np.zeros((ny, nx), dtype="f8")
+ pixelize_cartesian(pixX, plot.data['px'], plot.data['py'],
plot.data['pdx'], plot.data['pdy'],
- fv_x, int(nx), int(ny),
+ fv_x,
(x0, x1, y0, y1), 0, # bounds, antialias
- (period_x, period_y), periodic,
- ).transpose()
- pixY = pixelize_cartesian(plot.data['px'], plot.data['py'],
+ (period_x, period_y), periodic)
+ pixelize_cartesian(pixY, plot.data['px'], plot.data['py'],
plot.data['pdx'], plot.data['pdy'],
- fv_y, int(nx), int(ny),
+ fv_y,
(x0, x1, y0, y1), 0, # bounds, antialias
- (period_x, period_y), periodic,
- ).transpose()
+ (period_x, period_y), periodic)
X,Y = np.meshgrid(np.linspace(xx0,xx1,nx,endpoint=True),
np.linspace(yy0,yy1,ny,endpoint=True))
if self.normalize:
@@ -481,8 +483,10 @@
plot._axes.hold(True)
- numPoints_x = plot.image._A.shape[0]
- numPoints_y = plot.image._A.shape[1]
+ # See the note about rows/columns in the pixelizer for more information
+ # on why we choose the bounds we do
+ numPoints_x = plot.image._A.shape[1]
+ numPoints_y = plot.image._A.shape[0]
# Multiply by dx and dy to go from data->plot
dx = (xx1 - xx0) / (x1-x0)
@@ -606,7 +610,7 @@
xx0, xx1 = plot._axes.get_xlim()
yy0, yy1 = plot._axes.get_ylim()
(dx, dy) = self.pixel_scale(plot)
- (xpix, ypix) = plot.image._A.shape
+ (ypix, xpix) = plot.image._A.shape
ax = plot.data.axis
px_index = plot.data.ds.coordinates.x_axis[ax]
py_index = plot.data.ds.coordinates.y_axis[ax]
@@ -716,29 +720,33 @@
xx0, xx1 = plot._axes.get_xlim()
yy0, yy1 = plot._axes.get_ylim()
plot._axes.hold(True)
- nx = plot.image._A.shape[0] / self.factor
- ny = plot.image._A.shape[1] / self.factor
- pixX = pixelize_cartesian(plot.data['px'], plot.data['py'],
+ # See the note about rows/columns in the pixelizer for more information
+ # on why we choose the bounds we do
+ nx = plot.image._A.shape[1] / self.factor
+ ny = plot.image._A.shape[0] / self.factor
+ pixX = np.zeros((ny, nx), dtype="f8")
+ pixY = np.zeros((ny, nx), dtype="f8")
+ pixelize_cartesian(pixX, plot.data['px'], plot.data['py'],
plot.data['pdx'], plot.data['pdy'],
plot.data[self.field_x],
- int(nx), int(ny),
- (x0, x1, y0, y1),).transpose()
- pixY = pixelize_cartesian(plot.data['px'], plot.data['py'],
+ (x0, x1, y0, y1))
+ pixelize_cartesian(pixY, plot.data['px'], plot.data['py'],
plot.data['pdx'], plot.data['pdy'],
plot.data[self.field_y],
- int(nx), int(ny),
- (x0, x1, y0, y1),).transpose()
+ (x0, x1, y0, y1))
if self.field_color:
- self.field_color = pixelize_cartesian(
+ field_colors = np.zeros((ny, nx), dtype="f8")
+ pixelize_cartesian(field_colors,
plot.data['px'], plot.data['py'],
plot.data['pdx'], plot.data['pdy'],
- plot.data[self.field_color], int(nx), int(ny),
- (x0, x1, y0, y1),).transpose()
-
+ plot.data[self.field_color],
+ (x0, x1, y0, y1))
+ else:
+ field_colors = None
X,Y = (np.linspace(xx0,xx1,nx,endpoint=True),
np.linspace(yy0,yy1,ny,endpoint=True))
streamplot_args = {'x': X, 'y': Y, 'u':pixX, 'v': pixY,
- 'density': self.dens, 'color':self.field_color}
+ 'density': self.dens, 'color':field_colors}
streamplot_args.update(self.plot_args)
plot._axes.streamplot(**streamplot_args)
plot._axes.set_xlim(xx0,xx1)
@@ -877,26 +885,26 @@
xx0, xx1 = plot._axes.get_xlim()
yy0, yy1 = plot._axes.get_ylim()
plot._axes.hold(True)
- nx = plot.image._A.shape[0] / self.factor
- ny = plot.image._A.shape[1] / self.factor
+ nx = plot.image._A.shape[1] / self.factor
+ ny = plot.image._A.shape[0] / self.factor
indices = np.argsort(plot.data['dx'])[::-1]
- pixX = pixelize_off_axis_cartesian(
+ pixX = np.zeros((ny, nx), dtype="f8")
+ pixY = np.zeros((ny, nx), dtype="f8")
+ pixelize_off_axis_cartesian(pixX,
plot.data['x'], plot.data['y'], plot.data['z'],
plot.data['px'], plot.data['py'],
plot.data['pdx'], plot.data['pdy'], plot.data['pdz'],
plot.data.center, plot.data._inv_mat, indices,
plot.data[self.field_x],
- int(nx), int(ny),
- (x0, x1, y0, y1)).transpose()
- pixY = pixelize_off_axis_cartesian(
+ (x0, x1, y0, y1))
+ pixelize_off_axis_cartesian(pixY,
plot.data['x'], plot.data['y'], plot.data['z'],
plot.data['px'], plot.data['py'],
plot.data['pdx'], plot.data['pdy'], plot.data['pdz'],
plot.data.center, plot.data._inv_mat, indices,
plot.data[self.field_y],
- int(nx), int(ny),
- (x0, x1, y0, y1)).transpose()
+ (x0, x1, y0, y1))
X,Y = np.meshgrid(np.linspace(xx0,xx1,nx,endpoint=True),
np.linspace(yy0,yy1,ny,endpoint=True))
@@ -942,7 +950,7 @@
dxf = "d%s" % xf
dyf = "d%s" % yf
- nx, ny = plot.image._A.shape
+ ny, nx = plot.image._A.shape
buff = np.zeros((nx,ny),dtype='float64')
for i,clump in enumerate(reversed(self.clumps)):
mylog.info("Pixelizing contour %s", i)
@@ -950,12 +958,12 @@
xf_copy = clump[xf].copy().in_units("code_length")
yf_copy = clump[yf].copy().in_units("code_length")
- temp = pixelize_cartesian(xf_copy, yf_copy,
+ temp = np.zeros((ny, nx), dtype="f8")
+ pixelize_cartesian(temp, xf_copy, yf_copy,
clump[dxf].in_units("code_length")/2.0,
clump[dyf].in_units("code_length")/2.0,
clump[dxf].d*0.0+i+1, # inits inside Pixelize
- int(nx), int(ny),
- (x0, x1, y0, y1), 0).transpose()
+ (x0, x1, y0, y1), 0)
buff = np.maximum(temp, buff)
self.rv = plot._axes.contour(buff, np.unique(buff),
extent=extent, **self.plot_args)
@@ -2410,8 +2418,10 @@
extent = [xx0,xx1,yy0,yy1]
plot._axes.hold(True)
- nx = plot.image._A.shape[0]
- ny = plot.image._A.shape[1]
+ # We are feeding this size into the pixelizer, where it will properly
+ # set it in reverse order
+ nx = plot.image._A.shape[1]
+ ny = plot.image._A.shape[0]
pixX = plot.data.ds.coordinates.pixelize(plot.data.axis,
plot.data,
self.field_x,
@@ -2436,19 +2446,20 @@
kernel = kernel.astype(np.double)
lic_data = line_integral_convolution_2d(vectors,self.texture,kernel)
- lic_data = np.flipud(lic_data / lic_data.max())
+ lic_data = lic_data / lic_data.max()
lic_data_clip = np.clip(lic_data,self.lim[0],self.lim[1])
if self.const_alpha:
plot._axes.imshow(lic_data_clip, extent=extent, cmap=self.cmap,
- alpha=self.alpha)
+ alpha=self.alpha, origin='lower')
else:
lic_data_rgba = cm.ScalarMappable(norm=None, cmap=self.cmap).\
to_rgba(lic_data_clip)
lic_data_clip_rescale = (lic_data_clip - self.lim[0]) \
/ (self.lim[1] - self.lim[0])
lic_data_rgba[...,3] = lic_data_clip_rescale * self.alpha
- plot._axes.imshow(lic_data_rgba, extent=extent, cmap=self.cmap)
+ plot._axes.imshow(lic_data_rgba, extent=extent, cmap=self.cmap,
+ origin='lower')
plot._axes.hold(False)
return plot
@@ -2499,8 +2510,8 @@
xx0, xx1 = plot._axes.get_xlim()
yy0, yy1 = plot._axes.get_ylim()
plot._axes.hold(True)
- nx = plot.image._A.shape[0]
- ny = plot.image._A.shape[1]
+ nx = plot.image._A.shape[1]
+ ny = plot.image._A.shape[0]
aspect = float((y1 - y0) / (x1 - x0))
pixel_aspect = float(ny)/nx
relative_aspect = pixel_aspect / aspect
@@ -2519,16 +2530,17 @@
ny = 1600
long_axis = nx
line_width = max(self.line_width*long_axis, 1.0)
- im = pixelize_cartesian(plot.data['px'],
+ im = np.zeros((ny, nx), dtype="f8")
+ pixelize_cartesian(im,
+ plot.data['px'],
plot.data['py'],
plot.data['pdx'],
plot.data['pdy'],
plot.data['px'], # dummy field
- int(nx), int(ny),
(x0, x1, y0, y1),
- line_width=line_width).transpose()
+ line_width=line_width)
# New image:
- im_buffer = np.zeros((nx, ny, 4), dtype="uint8")
+ im_buffer = np.zeros((ny, nx, 4), dtype="uint8")
im_buffer[im > 0, 3] = 255
im_buffer[im > 0, :3] = self.color
plot._axes.imshow(im_buffer, origin='lower',
diff -r 743f56472b10f18505a7e1c1061b496050e8aaf1 -r 1d70bf4124996d584483c173e37f29670a73db99 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -26,7 +26,6 @@
ImagePlotMPL
from .fixed_resolution import \
FixedResolutionBuffer, \
- ObliqueFixedResolutionBuffer, \
OffAxisProjectionFixedResolutionBuffer
from .plot_modifications import callback_registry
from .plot_container import \
@@ -156,11 +155,9 @@
Parameters
----------
- data_source : :class:`yt.data_objects.construction_data_containers.YTQuadTreeProj`
or :class:`yt.data_objects.selection_data_containers.YTSlice`
This is the source to be pixelized, which can be a projection or a
- slice. (For cutting planes, see
- `yt.visualization.fixed_resolution.ObliqueFixedResolutionBuffer`.)
+ slice or a cutting plane.
bounds : sequence of floats
Bounds are the min and max in the image plane that we want our
image to cover. It's in the order of (xmin, xmax, ymin, ymax),
@@ -272,8 +269,6 @@
bounds = self.xlim+self.ylim+self.zlim
else:
bounds = self.xlim+self.ylim
- if self._frb_generator is ObliqueFixedResolutionBuffer:
- bounds = np.array([b.in_units('code_length') for b in bounds])
# Generate the FRB
self.frb = self._frb_generator(self.data_source, bounds,
@@ -1577,7 +1572,7 @@
"""
_plot_type = 'OffAxisSlice'
- _frb_generator = ObliqueFixedResolutionBuffer
+ _frb_generator = FixedResolutionBuffer
def __init__(self, ds, normal, fields, center='c', width=None,
axes_unit=None, north_vector=None, right_handed=True, fontsize=18,
diff -r 743f56472b10f18505a7e1c1061b496050e8aaf1 -r 1d70bf4124996d584483c173e37f29670a73db99 yt/visualization/tests/test_plotwindow.py
--- a/yt/visualization/tests/test_plotwindow.py
+++ b/yt/visualization/tests/test_plotwindow.py
@@ -423,6 +423,13 @@
assert_array_almost_equal(sl_on.frb['density'], sl_off.frb['density'])
+ sl_on.set_buff_size((800, 400))
+ sl_on._recreate_frb()
+ sl_off.set_buff_size((800, 400))
+ sl_off._recreate_frb()
+
+ 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)
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