[yt-svn] commit/yt: 7 new changesets
Bitbucket
commits-noreply at bitbucket.org
Mon Sep 3 05:06:17 PDT 2012
7 new commits in yt:
https://bitbucket.org/yt_analysis/yt/changeset/f1f5b5c886d6/
changeset: f1f5b5c886d6
branch: yt
user: ngoldbaum
date: 2012-09-02 23:51:35
summary: Merging.
affected #: 1 file
diff -r 4561e3ff9d02043ae20e66fc2623c82b69f5ef42 -r f1f5b5c886d6d60d4ae96b60a73f809822d2651d yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -348,9 +348,13 @@
plot._axes.hold(True)
plot._axes.add_collection(grid_collection)
if self.draw_ids:
- ids = [g.id for g in plot.data._grids]
- for n in visible.nonzero()[0]:
- plot._axes.text(left_edge_x[n]+(2*(xx1-xx0)/xpix),left_edge_y[n]+(2*(yy1-yy0)/ypix),ids[n],clip_on=True)
+ for i, g in enumerate(plot.data._grids[visible]):
+ if na.any(g.child_mask):
+ gid = na.where(visible)[0][i]
+ plot._axes.text(
+ left_edge_x[gid] + (2 * (xx1 - xx0) / xpix),
+ left_edge_y[gid] + (2 * (yy1 - yy0) / ypix),
+ g.id, clip_on=True)
plot._axes.hold(False)
class StreamlineCallback(PlotCallback):
https://bitbucket.org/yt_analysis/yt/changeset/6f63804e2143/
changeset: 6f63804e2143
branch: yt
user: ngoldbaum
date: 2012-09-02 23:59:26
summary: Merging.
affected #: 1 file
diff -r 80ff2fb3b5eb96f600df3da184d908b6ed4d81eb -r 6f63804e21438fe998a507a9f1361100c701e9bc yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -708,10 +708,12 @@
# This sets the size of the figure, and defaults to making one of the dimensions smaller.
# This should protect against giant images in the case of a very large aspect ratio.
+ norm_size = 10.0
+ cbar_frac = 0.0
if aspect > 1.0:
- size = (10.0, 10.0/aspect)
+ size = (norm_size*(1.+cbar_frac), norm_size/aspect)
else:
- size = (10.0*aspect, 10.0)
+ size = (aspect*norm_size*(1.+cbar_frac), norm_size)
self.plots[f] = WindowPlotMPL(self._frb[f], extent, self._field_transform[f],
self._colormaps[f], size, zlim)
@@ -1207,10 +1209,13 @@
figure = None
def __init__(self, field, size):
self._plot_valid = True
- self.figure = matplotlib.figure.Figure(figsize = size, frameon = True)
+ fsize, axrect, caxrect = self._get_best_layout(size)
# Hardcoding the axis dimensions for now
- self.axes = self.figure.add_axes((.07,.10,.8,.8))
- self.cax = self.figure.add_axes((.87,.10,.04,.8))
+
+ self.figure = matplotlib.figure.Figure(figsize = fsize,
+ frameon = True)
+ self.axes = self.figure.add_axes(axrect)
+ self.cax = self.figure.add_axes(caxrect)
def save(self, name, canvas = None):
if name[-4:] == '.png':
@@ -1229,9 +1234,47 @@
else:
mylog.warning("Unknown suffix %s, defaulting to Agg", suffix)
canvas = FigureCanvasAgg(self.figure)
- canvas.print_figure(fn, bbox_inches='tight')
+ canvas.print_figure(fn)
return fn
+ def _get_best_layout(self, size):
+ aspect = 1.0*size[0]/size[1]
+
+ # add room for a colorbar
+ cbar_inches = 0.7
+ newsize = [size[0] + cbar_inches, size[1]]
+
+ # add buffers for text, and a bit of whitespace on top
+ text_buffx = 1.0/(newsize[0])
+ text_bottomy = 0.7/size[1]
+ text_topy = 0.3/size[1]
+
+ # calculate how much room the colorbar takes
+ cbar_frac = cbar_inches/newsize[0]
+
+ # Calculate y fraction, then use to make x fraction.
+ yfrac = 1.0-text_bottomy-text_topy
+ ysize = yfrac*size[1]
+ xsize = aspect*ysize
+ xfrac = xsize/newsize[0]
+
+ # Now make sure it all fits!
+ xbig = xfrac + text_buffx + 2.0*cbar_frac
+ ybig = yfrac + text_bottomy + text_topy
+
+ if xbig > 1:
+ xsize /= xbig
+ ysize /= xbig
+ if ybig > 1:
+ xsize /= ybig
+ ysize /= ybig
+ xfrac = xsize/newsize[0]
+ yfrac = ysize/newsize[1]
+
+ axrect = (text_buffx, text_bottomy, xfrac, yfrac )
+ caxrect = (text_buffx+xfrac, text_bottomy, cbar_frac/4., yfrac )
+ return newsize, axrect, caxrect
+
def _repr_png_(self):
canvas = FigureCanvasAgg(self.figure)
f = cStringIO.StringIO()
https://bitbucket.org/yt_analysis/yt/changeset/010761fec279/
changeset: 010761fec279
branch: yt
user: ngoldbaum
date: 2012-09-02 23:59:35
summary: Merging.
affected #: 0 files
https://bitbucket.org/yt_analysis/yt/changeset/a7adfaeec819/
changeset: a7adfaeec819
branch: yt
user: ngoldbaum
date: 2012-09-03 01:10:48
summary: Only plot ids for grids that are (roughly) bigger than the annotation. I use 20 pixels, I guess we could do something fancier, but this choice seems to work.
affected #: 1 file
diff -r 010761fec27923eee26a306495ab4e5164b5d651 -r a7adfaeec8198eaf8307d42d33395655faa0979e yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -295,7 +295,7 @@
class GridBoundaryCallback(PlotCallback):
_type_name = "grids"
- def __init__(self, alpha=1.0, min_pix=1, draw_ids=False, periodic=True):
+ def __init__(self, alpha=1.0, min_pix=1, min_pix_ids=20, draw_ids=False, periodic=True):
"""
annotate_grids(alpha=1.0, min_pix=1, draw_ids=False, periodic=True)
@@ -306,6 +306,7 @@
PlotCallback.__init__(self)
self.alpha = alpha
self.min_pix = min_pix
+ self.min_pix_ids = min_pix_ids
self.draw_ids = draw_ids # put grid numbers in the corner.
self.periodic = periodic
@@ -348,9 +349,11 @@
plot._axes.hold(True)
plot._axes.add_collection(grid_collection)
if self.draw_ids:
- for i, g in enumerate(plot.data._grids[visible]):
+ visible_ids = ( xpix * (right_edge_x - left_edge_x) / (xx1 - xx0) > self.min_pix_ids ) & \
+ ( ypix * (right_edge_y - left_edge_y) / (yy1 - yy0) > self.min_pix_ids )
+ for i, g in enumerate(plot.data._grids[visible_ids]):
if na.any(g.child_mask):
- gid = na.where(visible)[0][i]
+ gid = na.where(visible_ids)[0][i]
plot._axes.text(
left_edge_x[gid] + (2 * (xx1 - xx0) / xpix),
left_edge_y[gid] + (2 * (yy1 - yy0) / ypix),
https://bitbucket.org/yt_analysis/yt/changeset/8e367bcb5612/
changeset: 8e367bcb5612
branch: yt
user: ngoldbaum
date: 2012-09-03 01:12:01
summary: Documenting min_pix_ids
affected #: 1 file
diff -r a7adfaeec8198eaf8307d42d33395655faa0979e -r 8e367bcb5612ce3af7aaa1dc1252ff8c5d2c3ba0 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -302,6 +302,7 @@
Adds grid boundaries to a plot, optionally with *alpha*-blending.
Cuttoff for display is at *min_pix* wide.
*draw_ids* puts the grid id in the corner of the grid. (Not so great in projections...)
+ Grids must be wider than *min_pix_ids* otherwise the ID will not be drawn.
"""
PlotCallback.__init__(self)
self.alpha = alpha
https://bitbucket.org/yt_analysis/yt/changeset/487adfd5ee1d/
changeset: 487adfd5ee1d
branch: yt
user: ngoldbaum
date: 2012-09-03 01:27:48
summary: Allowing the axes unit to be set in the plot window constructors.
affected #: 1 file
diff -r 8e367bcb5612ce3af7aaa1dc1252ff8c5d2c3ba0 -r 487adfd5ee1d935938f33afb872dd829e4c49a45 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -189,8 +189,8 @@
_contour_info = None
_vector_info = None
_frb = None
- def __init__(self, data_source, bounds, buff_size=(800,800), antialias = True,
- periodic = True, origin='center-window', oblique=False):
+ def __init__(self, data_source, bounds, buff_size=(800,800), antialias=True,
+ periodic=True, origin='center-window', oblique=False):
r"""
PlotWindow(data_source, bounds, buff_size=(800,800), antialias = True)
@@ -451,16 +451,17 @@
pass
class PWViewer(PlotWindow):
+ _unit = None
+ _colormaps = defaultdict(lambda: 'algae')
+ _callbacks = []
+ _field_transform = {}
"""A viewer for PlotWindows.
"""
def __init__(self, *args,**kwargs):
setup = kwargs.pop("setup", True)
PlotWindow.__init__(self, *args,**kwargs)
- self._colormaps = defaultdict(lambda: 'algae')
self.setup_callbacks()
- self._callbacks = []
- self._field_transform = {}
for field in self._frb.data.keys():
if self.pf.field_info[field].take_log:
self._field_transform[field] = log_transform
@@ -577,7 +578,6 @@
callback.__doc__ = CallbackMaker.__init__.__doc__
self.__dict__['annotate_'+cbname] = types.MethodType(callback,self)
- _unit = None
@invalidate_plot
def set_axes_unit(self, unit_name):
r"""Set the unit for display on the x and y axes of the image.
@@ -587,7 +587,7 @@
unit_name : string
A unit, available for conversion in the parameter file, that the
image extents will be displayed in. If set to None, any previous
- units will be reset.
+ units will be reset. If the unit is None, the default is chosen.
Raises
------
@@ -850,7 +850,8 @@
raise YTNotInsideNotebook
class SlicePlot(PWViewerMPL):
- def __init__(self, pf, axis, fields, center='c', width=None, origin='center-window'):
+ def __init__(self, pf, axis, fields, center='c', width=None, axes_unit=None,
+ origin='center-window'):
r"""Creates a slice plot from a parameter file
Given a pf object, an axis to slice along, and a field name
@@ -895,6 +896,9 @@
the y axis. In the other two examples, code units are assumed, for example
(0.2, 0.3) requests a plot that has and x width of 0.2 and a y width of 0.3
in code units.
+ axes_unit : A string
+ The name of the unit for the tick labels on the x and y axes.
+ Defaults to None, which automatically picks an appropriate unit.
origin : string
The location of the origin of the plot coordinate system.
Currently, can be set to three options: 'left-domain', corresponding
@@ -916,9 +920,10 @@
(bounds,center) = GetBoundsAndCenter(axis, center, width, pf)
slc = pf.h.slice(axis, center[axis], fields=fields)
PWViewerMPL.__init__(self, slc, bounds, origin=origin)
+ self.set_axes_unit(axes_unit)
class ProjectionPlot(PWViewerMPL):
- def __init__(self, pf, axis, fields, center='c', width=None,
+ def __init__(self, pf, axis, fields, center='c', width=None, axes_unit=None,
weight_field=None, max_level=None, origin='center-window'):
r"""Creates a projection plot from a parameter file
@@ -964,6 +969,9 @@
the y axis. In the other two examples, code units are assumed, for example
(0.2, 0.3) requests a plot that has and x width of 0.2 and a y width of 0.3
in code units.
+ axes_unit : A string
+ The name of the unit for the tick labels on the x and y axes.
+ Defaults to None, which automatically picks an appropriate unit.
origin : A string
The location of the origin of the plot coordinate system.
Currently, can be set to three options: 'left-domain', corresponding
@@ -989,9 +997,11 @@
(bounds,center) = GetBoundsAndCenter(axis,center,width,pf)
proj = pf.h.proj(axis,fields,weight_field=weight_field,max_level=max_level,center=center)
PWViewerMPL.__init__(self,proj,bounds,origin=origin)
+ self.set_axes_unit(axes_unit)
class OffAxisSlicePlot(PWViewerMPL):
- def __init__(self, pf, normal, fields, center='c', width=(1,'unitary'), north_vector=None):
+ def __init__(self, pf, normal, fields, center='c', width=(1,'unitary'),
+ axes_unit=None, north_vector=None):
r"""Creates an off axis slice plot from a parameter file
Given a pf object, a normal vector defining a slicing plane, and
@@ -1019,6 +1029,9 @@
A tuple containing the width of image and the string key of
the unit: (width, 'unit'). If set to a float, code units
are assumed
+ axes_unit : A string
+ The name of the unit for the tick labels on the x and y axes.
+ Defaults to None, which automatically picks an appropriate unit.
north-vector : a sequence of floats
A vector defining the 'up' direction in the plot. This
option sets the orientation of the slicing plane. If not
@@ -1030,6 +1043,7 @@
# Hard-coding the origin keyword since the other two options
# aren't well-defined for off-axis data objects
PWViewerMPL.__init__(self,cutting,bounds,origin='center-window',periodic=False,oblique=True)
+ self.set_axes_unit(axes_unit)
_metadata_template = """
%(pf)s<br>
https://bitbucket.org/yt_analysis/yt/changeset/15008795b735/
changeset: 15008795b735
branch: yt
user: MatthewTurk
date: 2012-09-03 14:06:15
summary: Merged in ngoldbaum/yt-cleancopy (pull request #261)
affected #: 2 files
diff -r 3840366c03796c355a7043f43f6a135f35211be3 -r 15008795b7351ee3024db8fa4506abde8d502b89 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -295,17 +295,19 @@
class GridBoundaryCallback(PlotCallback):
_type_name = "grids"
- def __init__(self, alpha=1.0, min_pix=1, draw_ids=False, periodic=True):
+ def __init__(self, alpha=1.0, min_pix=1, min_pix_ids=20, draw_ids=False, periodic=True):
"""
annotate_grids(alpha=1.0, min_pix=1, draw_ids=False, periodic=True)
Adds grid boundaries to a plot, optionally with *alpha*-blending.
Cuttoff for display is at *min_pix* wide.
*draw_ids* puts the grid id in the corner of the grid. (Not so great in projections...)
+ Grids must be wider than *min_pix_ids* otherwise the ID will not be drawn.
"""
PlotCallback.__init__(self)
self.alpha = alpha
self.min_pix = min_pix
+ self.min_pix_ids = min_pix_ids
self.draw_ids = draw_ids # put grid numbers in the corner.
self.periodic = periodic
@@ -348,9 +350,11 @@
plot._axes.hold(True)
plot._axes.add_collection(grid_collection)
if self.draw_ids:
- for i, g in enumerate(plot.data._grids[visible]):
+ visible_ids = ( xpix * (right_edge_x - left_edge_x) / (xx1 - xx0) > self.min_pix_ids ) & \
+ ( ypix * (right_edge_y - left_edge_y) / (yy1 - yy0) > self.min_pix_ids )
+ for i, g in enumerate(plot.data._grids[visible_ids]):
if na.any(g.child_mask):
- gid = na.where(visible)[0][i]
+ gid = na.where(visible_ids)[0][i]
plot._axes.text(
left_edge_x[gid] + (2 * (xx1 - xx0) / xpix),
left_edge_y[gid] + (2 * (yy1 - yy0) / ypix),
diff -r 3840366c03796c355a7043f43f6a135f35211be3 -r 15008795b7351ee3024db8fa4506abde8d502b89 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -189,8 +189,8 @@
_contour_info = None
_vector_info = None
_frb = None
- def __init__(self, data_source, bounds, buff_size=(800,800), antialias = True,
- periodic = True, origin='center-window', oblique=False):
+ def __init__(self, data_source, bounds, buff_size=(800,800), antialias=True,
+ periodic=True, origin='center-window', oblique=False):
r"""
PlotWindow(data_source, bounds, buff_size=(800,800), antialias = True)
@@ -451,16 +451,17 @@
pass
class PWViewer(PlotWindow):
+ _unit = None
+ _colormaps = defaultdict(lambda: 'algae')
+ _callbacks = []
+ _field_transform = {}
"""A viewer for PlotWindows.
"""
def __init__(self, *args,**kwargs):
setup = kwargs.pop("setup", True)
PlotWindow.__init__(self, *args,**kwargs)
- self._colormaps = defaultdict(lambda: 'algae')
self.setup_callbacks()
- self._callbacks = []
- self._field_transform = {}
for field in self._frb.data.keys():
if self.pf.field_info[field].take_log:
self._field_transform[field] = log_transform
@@ -577,7 +578,6 @@
callback.__doc__ = CallbackMaker.__init__.__doc__
self.__dict__['annotate_'+cbname] = types.MethodType(callback,self)
- _unit = None
@invalidate_plot
def set_axes_unit(self, unit_name):
r"""Set the unit for display on the x and y axes of the image.
@@ -587,7 +587,7 @@
unit_name : string
A unit, available for conversion in the parameter file, that the
image extents will be displayed in. If set to None, any previous
- units will be reset.
+ units will be reset. If the unit is None, the default is chosen.
Raises
------
@@ -850,7 +850,8 @@
raise YTNotInsideNotebook
class SlicePlot(PWViewerMPL):
- def __init__(self, pf, axis, fields, center='c', width=None, origin='center-window'):
+ def __init__(self, pf, axis, fields, center='c', width=None, axes_unit=None,
+ origin='center-window'):
r"""Creates a slice plot from a parameter file
Given a pf object, an axis to slice along, and a field name
@@ -895,6 +896,9 @@
the y axis. In the other two examples, code units are assumed, for example
(0.2, 0.3) requests a plot that has and x width of 0.2 and a y width of 0.3
in code units.
+ axes_unit : A string
+ The name of the unit for the tick labels on the x and y axes.
+ Defaults to None, which automatically picks an appropriate unit.
origin : string
The location of the origin of the plot coordinate system.
Currently, can be set to three options: 'left-domain', corresponding
@@ -916,9 +920,10 @@
(bounds,center) = GetBoundsAndCenter(axis, center, width, pf)
slc = pf.h.slice(axis, center[axis], fields=fields)
PWViewerMPL.__init__(self, slc, bounds, origin=origin)
+ self.set_axes_unit(axes_unit)
class ProjectionPlot(PWViewerMPL):
- def __init__(self, pf, axis, fields, center='c', width=None,
+ def __init__(self, pf, axis, fields, center='c', width=None, axes_unit=None,
weight_field=None, max_level=None, origin='center-window'):
r"""Creates a projection plot from a parameter file
@@ -964,6 +969,9 @@
the y axis. In the other two examples, code units are assumed, for example
(0.2, 0.3) requests a plot that has and x width of 0.2 and a y width of 0.3
in code units.
+ axes_unit : A string
+ The name of the unit for the tick labels on the x and y axes.
+ Defaults to None, which automatically picks an appropriate unit.
origin : A string
The location of the origin of the plot coordinate system.
Currently, can be set to three options: 'left-domain', corresponding
@@ -989,9 +997,11 @@
(bounds,center) = GetBoundsAndCenter(axis,center,width,pf)
proj = pf.h.proj(axis,fields,weight_field=weight_field,max_level=max_level,center=center)
PWViewerMPL.__init__(self,proj,bounds,origin=origin)
+ self.set_axes_unit(axes_unit)
class OffAxisSlicePlot(PWViewerMPL):
- def __init__(self, pf, normal, fields, center='c', width=(1,'unitary'), north_vector=None):
+ def __init__(self, pf, normal, fields, center='c', width=(1,'unitary'),
+ axes_unit=None, north_vector=None):
r"""Creates an off axis slice plot from a parameter file
Given a pf object, a normal vector defining a slicing plane, and
@@ -1019,6 +1029,9 @@
A tuple containing the width of image and the string key of
the unit: (width, 'unit'). If set to a float, code units
are assumed
+ axes_unit : A string
+ The name of the unit for the tick labels on the x and y axes.
+ Defaults to None, which automatically picks an appropriate unit.
north-vector : a sequence of floats
A vector defining the 'up' direction in the plot. This
option sets the orientation of the slicing plane. If not
@@ -1030,6 +1043,7 @@
# Hard-coding the origin keyword since the other two options
# aren't well-defined for off-axis data objects
PWViewerMPL.__init__(self,cutting,bounds,origin='center-window',periodic=False,oblique=True)
+ self.set_axes_unit(axes_unit)
_metadata_template = """
%(pf)s<br>
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