[yt-svn] commit/yt: 4 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri Nov 8 08:33:07 PST 2013
4 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/49a5b85d82ef/
Changeset: 49a5b85d82ef
Branch: yt
User: jwise77
Date: 2013-11-05 21:37:39
Summary: Updating eps_writer to be compatible with PlotWindow.
Affected #: 2 files
diff -r 34a804fd78c6514644998b0559e04f162b468d4b -r 49a5b85d82ef2e04d7ff4e31021ca7f69a58c5e9 yt/visualization/eps_writer.py
--- a/yt/visualization/eps_writer.py
+++ b/yt/visualization/eps_writer.py
@@ -25,6 +25,7 @@
from .plot_types import \
VMPlot, \
ProfilePlot
+from .plot_window import PlotWindow
class DualEPS(object):
def __init__(self, figsize=(12,12)):
@@ -40,6 +41,7 @@
self.figsize = figsize
self.canvas = None
self.colormaps = None
+ self.field = None
self.axes_drawn = False
def hello_world(self):
@@ -271,18 +273,28 @@
>>> d.axis_box_yt(p)
>>> d.save_fig()
"""
- plot._redraw_image()
- if isinstance(plot, VMPlot):
+ if isinstance(plot, PlotWindow):
+ plot.refresh()
+ width = plot.width[0]
+ else:
+ plot._redraw_image()
+ if isinstance(plot, VMPlot):
+ width = plot.width
+ if isinstance(plot, VMPlot) or isinstance(plot, PlotWindow):
+ if isinstance(plot, PlotWindow):
+ data = plot._frb
+ else:
+ data = plot.data
if units == None:
# Determine the best units
astro_units = ['cm', 'rsun', 'au', 'pc', 'kpc', 'mpc']
best_fit = 0
- while plot.width*plot.pf[astro_units[best_fit]] > 1e3 and \
+ while width*plot.pf[astro_units[best_fit]] > 1e3 and \
best_fit < len(astro_units):
best_fit += 1
units = astro_units[best_fit]
- _xrange = (0, plot.width * plot.pf[units])
- _yrange = (0, plot.width * plot.pf[units])
+ _xrange = (0, width * plot.pf[units])
+ _yrange = (0, width * plot.pf[units])
_xlog = False
_ylog = False
if bare_axes:
@@ -293,11 +305,17 @@
if xlabel != None:
_xlabel = xlabel
else:
- _xlabel = '%s (%s)' % (x_names[plot.data.axis], units)
+ if data.axis != 4:
+ _xlabel = '%s (%s)' % (x_names[data.axis], units)
+ else:
+ _xlabel = 'Image x (%s)' % (units)
if ylabel != None:
_ylabel = ylabel
else:
- _ylabel = '%s (%s)' % (y_names[plot.data.axis], units)
+ if data.axis != 4:
+ _ylabel = '%s (%s)' % (y_names[data.axis], units)
+ else:
+ _ylabel = 'Image y (%s)' % (units)
if tickcolor == None:
_tickcolor = pyx.color.cmyk.white
else:
@@ -362,7 +380,7 @@
#=============================================================================
- def insert_image_yt(self, plot, pos=(0,0), scale=1.0):
+ def insert_image_yt(self, plot, field=None, pos=(0,0), scale=1.0):
r"""Inserts a bitmap taken from a yt plot.
Parameters
@@ -385,23 +403,38 @@
For best results, set use_colorbar=False when creating the yt
image.
"""
+
# We need to remove the colorbar (if necessary), remove the
# axes, and resize the figure to span the entire figure
- if plot.colorbar != None and \
- isinstance(plot, VMPlot):
- print "WARNING: Image (slices, projections, etc.) plots must not"\
- "have a colorbar."
- print "Removing it."
- plot.colorbar = None
+ shift = 0.0
if self.canvas is None:
self.canvas = pyx.canvas.canvas()
- plot._redraw_image()
- _p1 = plot._figure
- if isinstance(plot, ProfilePlot):
+ if isinstance(plot, VMPlot):
+ if plot.colorbar != None:
+ print "WARNING: Image (slices, projections, etc.) plots must not"\
+ "have a colorbar. Removing it."
+ plot.colorbar = None
+ plot._redraw_image()
+ _p1 = plot._figure
+ elif isinstance(plot, PlotWindow):
+ self.field = field
+ if self.field == None:
+ self.field = plot.plots.keys()[0]
+ print "No field specified. Choosing first field (%s)" % field
+ if self.field not in plot.plots.keys():
+ raise RuntimeError("Field '%s' does not exist!" % str(self.field))
+ plot.plots[self.field].hide_colorbar()
+ plot.refresh()
+ _p1 = plot.plots[self.field].figure
+ # hack to account for non-square display ratios (not sure why)
+ shift = 12.0 / 340
+ elif isinstance(plot, ProfilePlot):
+ plot._redraw_image()
# Remove colorbar
+ _p1 = plot._figure
_p1.delaxes(_p1.axes[1])
_p1.axes[0].set_axis_off() # remove axes
- _p1.axes[0].set_position([0,0,1,1]) # rescale figure
+ _p1.axes[0].set_position([-shift,0,1,1]) # rescale figure
_p1.set_facecolor('w') # set background color
figure_canvas = FigureCanvasAgg(_p1)
figure_canvas.draw()
@@ -410,7 +443,7 @@
figure_canvas.tostring_rgb())
#figure_canvas.print_png('test.png')
self.canvas.insert(pyx.bitmap.bitmap(pos[0], pos[1], image,
- width=scale*self.figsize[0],
+ width=(1.0+2*shift)*scale*self.figsize[0],
height=scale*self.figsize[1]))
#=============================================================================
@@ -556,21 +589,40 @@
>>> d.colorbar_yt(p)
>>> d.save_fig()
"""
- if plot.cmap != None:
- _cmap = plot.cmap.name
+ _cmap = None
+ if isinstance(plot, PlotWindow):
+ _cmap = plot._colormaps[self.field]
else:
+ if plot.cmap != None:
+ _cmap = plot.cmap.name
+ if _cmap == None:
_cmap = 'algae'
if isinstance(plot, VMPlot):
- # Taken from yt
proj = "Proj" in plot._type_name and \
- plot.data._weight is None
+ plot.data._weight is None
_zlabel = plot.pf.field_info[plot.axis_names["Z"]].get_label(proj)
_zlabel = _zlabel.replace("_","\;")
_zlog = plot.log_field
+ _zrange = (plot.norm.vmin, plot.norm.vmax)
+ elif isinstance(plot, PlotWindow):
+ proj = plot._plot_type.endswith("Projection") and \
+ plot.data_source.weight_field == None
+ _zlabel = plot.pf.field_info[self.field].get_label(proj)
+ _zlabel = _zlabel.replace("_","\;")
+ _zlog = plot.get_log(self.field)[self.field]
+ if plot.plots[self.field].zmin == None:
+ zmin = plot.plots[self.field].image._A.min()
+ else:
+ zmin = plot.plots[self.field].zmin
+ if plot.plots[self.field].zmax == None:
+ zmax = plot.plots[self.field].image._A.max()
+ else:
+ zmax = plot.plots[self.field].zmax
+ _zrange = (zmin, zmax)
else:
_zlabel = plot._z_label.replace("_","\;")
_zlog = plot._log_z
- _zrange = (plot.norm.vmin, plot.norm.vmax)
+ _zrange = (plot.norm.vmin, plot.norm.vmax)
self.colorbar(_cmap, zrange=_zrange, label=_zlabel, log=_zlog, **kwargs)
#=============================================================================
diff -r 34a804fd78c6514644998b0559e04f162b468d4b -r 49a5b85d82ef2e04d7ff4e31021ca7f69a58c5e9 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -649,6 +649,27 @@
self._field_transform[field] = linear_transform
return self
+ def get_log(self, field):
+ """get the transform type of a field.
+
+ Parameters
+ ----------
+ field : string
+ the field to get a transform
+
+ """
+ log = {}
+ if field == 'all':
+ fields = self.plots.keys()
+ else:
+ fields = [field]
+ for field in fields:
+ if self._field_transform[field] == log_transform:
+ log[field] = True
+ else:
+ log[field] = False
+ return log
+
@invalidate_plot
def set_transform(self, field, name):
if name not in field_transforms:
https://bitbucket.org/yt_analysis/yt/commits/73be28fbfc42/
Changeset: 73be28fbfc42
Branch: yt
User: jwise77
Date: 2013-11-06 15:31:45
Summary: Fixed an info message.
Affected #: 1 file
diff -r 49a5b85d82ef2e04d7ff4e31021ca7f69a58c5e9 -r 73be28fbfc42f7d12d5711977f8eb7f892d6f652 yt/visualization/eps_writer.py
--- a/yt/visualization/eps_writer.py
+++ b/yt/visualization/eps_writer.py
@@ -420,7 +420,7 @@
self.field = field
if self.field == None:
self.field = plot.plots.keys()[0]
- print "No field specified. Choosing first field (%s)" % field
+ print "No field specified. Choosing first field (%s)" % self.field
if self.field not in plot.plots.keys():
raise RuntimeError("Field '%s' does not exist!" % str(self.field))
plot.plots[self.field].hide_colorbar()
https://bitbucket.org/yt_analysis/yt/commits/c1c42c1fc4fc/
Changeset: c1c42c1fc4fc
Branch: yt
User: jwise77
Date: 2013-11-06 15:48:03
Summary: Getting rid of all of the print statements in eps_writer, and using
the logger.warning or RuntimeErrors. Also used
get_smallest_appropriate_unit() to determine units instead of my old
and similar version.
Affected #: 1 file
diff -r 73be28fbfc42f7d12d5711977f8eb7f892d6f652 -r c1c42c1fc4fc56d20e544a31270de6088d39c47f yt/visualization/eps_writer.py
--- a/yt/visualization/eps_writer.py
+++ b/yt/visualization/eps_writer.py
@@ -17,6 +17,7 @@
from matplotlib import cm
from _mpl_imports import FigureCanvasAgg
+from yt.utilities.logger import ytLogger as mylog
from yt.utilities.definitions import \
x_dict, x_names, \
y_dict, y_names, \
@@ -26,6 +27,7 @@
VMPlot, \
ProfilePlot
from .plot_window import PlotWindow
+from .plot_modifications import get_smallest_appropriate_unit
class DualEPS(object):
def __init__(self, figsize=(12,12)):
@@ -286,13 +288,7 @@
else:
data = plot.data
if units == None:
- # Determine the best units
- astro_units = ['cm', 'rsun', 'au', 'pc', 'kpc', 'mpc']
- best_fit = 0
- while width*plot.pf[astro_units[best_fit]] > 1e3 and \
- best_fit < len(astro_units):
- best_fit += 1
- units = astro_units[best_fit]
+ units = get_smallest_appropriate_unit(width, plot.pf)
_xrange = (0, width * plot.pf[units])
_yrange = (0, width * plot.pf[units])
_xlog = False
@@ -411,8 +407,8 @@
self.canvas = pyx.canvas.canvas()
if isinstance(plot, VMPlot):
if plot.colorbar != None:
- print "WARNING: Image (slices, projections, etc.) plots must not"\
- "have a colorbar. Removing it."
+ mylog.warning("Image (slices, projections, etc.) plots must not"\
+ "have a colorbar. Removing it.")
plot.colorbar = None
plot._redraw_image()
_p1 = plot._figure
@@ -420,7 +416,8 @@
self.field = field
if self.field == None:
self.field = plot.plots.keys()[0]
- print "No field specified. Choosing first field (%s)" % self.field
+ mylog.warning("No field specified. Choosing first field (%s)" % \
+ self.field)
if self.field not in plot.plots.keys():
raise RuntimeError("Field '%s' does not exist!" % str(self.field))
plot.plots[self.field].hide_colorbar()
@@ -501,7 +498,7 @@
size = (self.figsize[0], 0.1*self.figsize[1])
imsize = (256,1)
else:
- print "orientation %s unknown" % orientation
+ raise RuntimeError("orientation %s unknown" % orientation)
return
# If shrink is a scalar, then convert into tuple
@@ -780,7 +777,7 @@
elif format == "pdf":
self.canvas.writePDFfile(filename)
else:
- print "format %s unknown." % (format)
+ raise RuntimeError("format %s unknown." % (format))
#=============================================================================
#=============================================================================
@@ -863,14 +860,14 @@
# Error check
if images != None:
if len(images) != ncol*nrow:
- print "Number of images (%d) doesn't match nrow(%d) x ncol(%d)." %\
- (len(images), nrow, ncol)
+ raise RuntimeError("Number of images (%d) doesn't match nrow(%d)"\
+ " x ncol(%d)." % (len(images), nrow, ncol))
return
if yt_plots is None and images is None:
- print "Must supply either yt_plots or image filenames."
+ raise RuntimeError("Must supply either yt_plots or image filenames.")
return
if yt_plots != None and images != None:
- print "Given both images and yt plots. Ignoring images."
+ mylog.warning("Given both images and yt plots. Ignoring images.")
if yt_plots != None:
_yt = True
else:
@@ -1044,8 +1041,9 @@
>>> yt_nocbar=False, margins=(0.5,0.5))
"""
if len(plot_col.plots) < nrow*ncol:
- print "Number of plots in PlotCollection is less than nrow(%d) "\
- "x ncol(%d)." % (len(plot_col.plots), nrow, ncol)
+ raise RuntimeError("Number of plots in PlotCollection is less "\
+ "than nrow(%d) x ncol(%d)." % \
+ (len(plot_col.plots), nrow, ncol))
return
figure = multiplot(ncol, nrow, yt_plots=plot_col.plots, **kwargs)
return figure
https://bitbucket.org/yt_analysis/yt/commits/6cf2b25b9cf2/
Changeset: 6cf2b25b9cf2
Branch: yt
User: MatthewTurk
Date: 2013-11-08 17:33:00
Summary: Merged in jwise77/yt-clean (pull request #633)
Updating eps_writer to be compatible with PlotWindow.
Affected #: 2 files
diff -r 6f28a14770559418a3c74922c21eb5de1e2bff60 -r 6cf2b25b9cf21f6759a3161dff30f7cdcdcf0c91 yt/visualization/eps_writer.py
--- a/yt/visualization/eps_writer.py
+++ b/yt/visualization/eps_writer.py
@@ -17,6 +17,7 @@
from matplotlib import cm
from _mpl_imports import FigureCanvasAgg
+from yt.utilities.logger import ytLogger as mylog
from yt.utilities.definitions import \
x_dict, x_names, \
y_dict, y_names, \
@@ -25,6 +26,8 @@
from .plot_types import \
VMPlot, \
ProfilePlot
+from .plot_window import PlotWindow
+from .plot_modifications import get_smallest_appropriate_unit
class DualEPS(object):
def __init__(self, figsize=(12,12)):
@@ -40,6 +43,7 @@
self.figsize = figsize
self.canvas = None
self.colormaps = None
+ self.field = None
self.axes_drawn = False
def hello_world(self):
@@ -271,18 +275,22 @@
>>> d.axis_box_yt(p)
>>> d.save_fig()
"""
- plot._redraw_image()
- if isinstance(plot, VMPlot):
+ if isinstance(plot, PlotWindow):
+ plot.refresh()
+ width = plot.width[0]
+ else:
+ plot._redraw_image()
+ if isinstance(plot, VMPlot):
+ width = plot.width
+ if isinstance(plot, VMPlot) or isinstance(plot, PlotWindow):
+ if isinstance(plot, PlotWindow):
+ data = plot._frb
+ else:
+ data = plot.data
if units == None:
- # Determine the best units
- astro_units = ['cm', 'rsun', 'au', 'pc', 'kpc', 'mpc']
- best_fit = 0
- while plot.width*plot.pf[astro_units[best_fit]] > 1e3 and \
- best_fit < len(astro_units):
- best_fit += 1
- units = astro_units[best_fit]
- _xrange = (0, plot.width * plot.pf[units])
- _yrange = (0, plot.width * plot.pf[units])
+ units = get_smallest_appropriate_unit(width, plot.pf)
+ _xrange = (0, width * plot.pf[units])
+ _yrange = (0, width * plot.pf[units])
_xlog = False
_ylog = False
if bare_axes:
@@ -293,11 +301,17 @@
if xlabel != None:
_xlabel = xlabel
else:
- _xlabel = '%s (%s)' % (x_names[plot.data.axis], units)
+ if data.axis != 4:
+ _xlabel = '%s (%s)' % (x_names[data.axis], units)
+ else:
+ _xlabel = 'Image x (%s)' % (units)
if ylabel != None:
_ylabel = ylabel
else:
- _ylabel = '%s (%s)' % (y_names[plot.data.axis], units)
+ if data.axis != 4:
+ _ylabel = '%s (%s)' % (y_names[data.axis], units)
+ else:
+ _ylabel = 'Image y (%s)' % (units)
if tickcolor == None:
_tickcolor = pyx.color.cmyk.white
else:
@@ -362,7 +376,7 @@
#=============================================================================
- def insert_image_yt(self, plot, pos=(0,0), scale=1.0):
+ def insert_image_yt(self, plot, field=None, pos=(0,0), scale=1.0):
r"""Inserts a bitmap taken from a yt plot.
Parameters
@@ -385,23 +399,39 @@
For best results, set use_colorbar=False when creating the yt
image.
"""
+
# We need to remove the colorbar (if necessary), remove the
# axes, and resize the figure to span the entire figure
- if plot.colorbar != None and \
- isinstance(plot, VMPlot):
- print "WARNING: Image (slices, projections, etc.) plots must not"\
- "have a colorbar."
- print "Removing it."
- plot.colorbar = None
+ shift = 0.0
if self.canvas is None:
self.canvas = pyx.canvas.canvas()
- plot._redraw_image()
- _p1 = plot._figure
- if isinstance(plot, ProfilePlot):
+ if isinstance(plot, VMPlot):
+ if plot.colorbar != None:
+ mylog.warning("Image (slices, projections, etc.) plots must not"\
+ "have a colorbar. Removing it.")
+ plot.colorbar = None
+ plot._redraw_image()
+ _p1 = plot._figure
+ elif isinstance(plot, PlotWindow):
+ self.field = field
+ if self.field == None:
+ self.field = plot.plots.keys()[0]
+ mylog.warning("No field specified. Choosing first field (%s)" % \
+ self.field)
+ if self.field not in plot.plots.keys():
+ raise RuntimeError("Field '%s' does not exist!" % str(self.field))
+ plot.plots[self.field].hide_colorbar()
+ plot.refresh()
+ _p1 = plot.plots[self.field].figure
+ # hack to account for non-square display ratios (not sure why)
+ shift = 12.0 / 340
+ elif isinstance(plot, ProfilePlot):
+ plot._redraw_image()
# Remove colorbar
+ _p1 = plot._figure
_p1.delaxes(_p1.axes[1])
_p1.axes[0].set_axis_off() # remove axes
- _p1.axes[0].set_position([0,0,1,1]) # rescale figure
+ _p1.axes[0].set_position([-shift,0,1,1]) # rescale figure
_p1.set_facecolor('w') # set background color
figure_canvas = FigureCanvasAgg(_p1)
figure_canvas.draw()
@@ -410,7 +440,7 @@
figure_canvas.tostring_rgb())
#figure_canvas.print_png('test.png')
self.canvas.insert(pyx.bitmap.bitmap(pos[0], pos[1], image,
- width=scale*self.figsize[0],
+ width=(1.0+2*shift)*scale*self.figsize[0],
height=scale*self.figsize[1]))
#=============================================================================
@@ -468,7 +498,7 @@
size = (self.figsize[0], 0.1*self.figsize[1])
imsize = (256,1)
else:
- print "orientation %s unknown" % orientation
+ raise RuntimeError("orientation %s unknown" % orientation)
return
# If shrink is a scalar, then convert into tuple
@@ -556,21 +586,40 @@
>>> d.colorbar_yt(p)
>>> d.save_fig()
"""
- if plot.cmap != None:
- _cmap = plot.cmap.name
+ _cmap = None
+ if isinstance(plot, PlotWindow):
+ _cmap = plot._colormaps[self.field]
else:
+ if plot.cmap != None:
+ _cmap = plot.cmap.name
+ if _cmap == None:
_cmap = 'algae'
if isinstance(plot, VMPlot):
- # Taken from yt
proj = "Proj" in plot._type_name and \
- plot.data._weight is None
+ plot.data._weight is None
_zlabel = plot.pf.field_info[plot.axis_names["Z"]].get_label(proj)
_zlabel = _zlabel.replace("_","\;")
_zlog = plot.log_field
+ _zrange = (plot.norm.vmin, plot.norm.vmax)
+ elif isinstance(plot, PlotWindow):
+ proj = plot._plot_type.endswith("Projection") and \
+ plot.data_source.weight_field == None
+ _zlabel = plot.pf.field_info[self.field].get_label(proj)
+ _zlabel = _zlabel.replace("_","\;")
+ _zlog = plot.get_log(self.field)[self.field]
+ if plot.plots[self.field].zmin == None:
+ zmin = plot.plots[self.field].image._A.min()
+ else:
+ zmin = plot.plots[self.field].zmin
+ if plot.plots[self.field].zmax == None:
+ zmax = plot.plots[self.field].image._A.max()
+ else:
+ zmax = plot.plots[self.field].zmax
+ _zrange = (zmin, zmax)
else:
_zlabel = plot._z_label.replace("_","\;")
_zlog = plot._log_z
- _zrange = (plot.norm.vmin, plot.norm.vmax)
+ _zrange = (plot.norm.vmin, plot.norm.vmax)
self.colorbar(_cmap, zrange=_zrange, label=_zlabel, log=_zlog, **kwargs)
#=============================================================================
@@ -728,7 +777,7 @@
elif format == "pdf":
self.canvas.writePDFfile(filename)
else:
- print "format %s unknown." % (format)
+ raise RuntimeError("format %s unknown." % (format))
#=============================================================================
#=============================================================================
@@ -811,14 +860,14 @@
# Error check
if images != None:
if len(images) != ncol*nrow:
- print "Number of images (%d) doesn't match nrow(%d) x ncol(%d)." %\
- (len(images), nrow, ncol)
+ raise RuntimeError("Number of images (%d) doesn't match nrow(%d)"\
+ " x ncol(%d)." % (len(images), nrow, ncol))
return
if yt_plots is None and images is None:
- print "Must supply either yt_plots or image filenames."
+ raise RuntimeError("Must supply either yt_plots or image filenames.")
return
if yt_plots != None and images != None:
- print "Given both images and yt plots. Ignoring images."
+ mylog.warning("Given both images and yt plots. Ignoring images.")
if yt_plots != None:
_yt = True
else:
@@ -992,8 +1041,9 @@
>>> yt_nocbar=False, margins=(0.5,0.5))
"""
if len(plot_col.plots) < nrow*ncol:
- print "Number of plots in PlotCollection is less than nrow(%d) "\
- "x ncol(%d)." % (len(plot_col.plots), nrow, ncol)
+ raise RuntimeError("Number of plots in PlotCollection is less "\
+ "than nrow(%d) x ncol(%d)." % \
+ (len(plot_col.plots), nrow, ncol))
return
figure = multiplot(ncol, nrow, yt_plots=plot_col.plots, **kwargs)
return figure
diff -r 6f28a14770559418a3c74922c21eb5de1e2bff60 -r 6cf2b25b9cf21f6759a3161dff30f7cdcdcf0c91 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -649,6 +649,27 @@
self._field_transform[field] = linear_transform
return self
+ def get_log(self, field):
+ """get the transform type of a field.
+
+ Parameters
+ ----------
+ field : string
+ the field to get a transform
+
+ """
+ log = {}
+ if field == 'all':
+ fields = self.plots.keys()
+ else:
+ fields = [field]
+ for field in fields:
+ if self._field_transform[field] == log_transform:
+ log[field] = True
+ else:
+ log[field] = False
+ return log
+
@invalidate_plot
def set_transform(self, field, name):
if name not in field_transforms:
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