Bug in PlotCollectionInteractive.add_phase_sphere and add_profile_sphere
Hi Folks, I wanted to bring them problem to your attention as well as show you an extremely hacky attempt at solving it. The add_profile_sphere and add_phase_sphere methods of PlotCollectionInteractive appear to have a bug in them. When I do: In [3]: p = pc.add_phase_sphere(0.015, 'pc', ["Density", "Temperature", "CellMassMsun"], weight = None) I get the following traceback: TypeError Traceback (most recent call last) /indirect/o/atmyers/yt/src/yt-trunk-svn/scripts/iyt in <module>() ----> 1 2 3 4 5 /indirect/o/atmyers/yt/src/yt-trunk-svn/yt/raven/plot_collection.py in pylabify(self, *args, **kwargs) 1440 kwargs['axes'] = self.pylab.gca() 1441 kwargs['figure'] = self.pylab.gcf() -> 1442 retval = func(self, *args, **kwargs) 1443 retval._redraw_image() 1444 retval._fig_num = new_fig.number /indirect/o/atmyers/yt/src/yt-trunk-svn/yt/raven/plot_collection.py in add_phase_sphere(self, radius, unit, fields, center, cmap, weight, accumulation, x_bins, x_log, x_bounds, y_bins, y_log, y_bounds, lazy_reader, id, axes, figure, fractional) 1128 x_bins, x_log, x_bounds, 1129 y_bins, y_log, y_bounds, -> 1130 lazy_reader, id, axes, figure, fractional) 1131 p["Width"] = radius 1132 p["Unit"] = unit /indirect/o/atmyers/yt/src/yt-trunk-svn/yt/raven/plot_collection.py in pylabify(self, *args, **kwargs) 1440 kwargs['axes'] = self.pylab.gca() 1441 kwargs['figure'] = self.pylab.gcf() -> 1442 retval = func(self, *args, **kwargs) 1443 retval._redraw_image() 1444 retval._fig_num = new_fig.number TypeError: add_phase_object() got multiple values for keyword argument 'axes' The same thing happens when I use pc.add_profile_sphere, but only with PlotCollectionInteractive. Using the same methods with PlotCollection works fine. The problem seems to be that the wrapper that "Interactifies" the PlotCollection methods assumes that you will not call them with "axes" or "figure" in the positional arguments. However, as currently coded, the add_phase_sphere and add_profile_sphere methods both call add_phase_object or add_profile_object, and when they do so they pass an axes and figure in the positional arguments. Probably the best way to fix this is to re-write the wrapper function to not assume that you don't have an axes or figure in *args, but in the meantime I've got mine to work just by changing add_profile_sphere and add_phase_sphere like so (docstring snipped) def add_phase_sphere(self, radius, unit, fields, center = None, cmap=None, weight="CellMassMsun", accumulation=False, x_bins=64, x_log=True, x_bounds=None, y_bins=64, y_log=True, y_bounds=None, lazy_reader=True, id=None, axes = None, figure = None, fractional=False): if center is None: center = self.c r = radius/self.pf[unit] data_source = self.pf.hierarchy.sphere(center, r) p = self.add_phase_object(data_source, fields, cmap, weight, accumulation, x_bins, x_log, x_bounds, y_bins, y_log, y_bounds, lazy_reader, id, axes = axes, figure = figure, fractional = fractional) p["Width"] = radius p["Unit"] = unit p["Axis"] = None return p So now the call to add_phase_object takes keyword arguments instead of positional ones for axes and figure. I made the same change to add_profile_sphere, and they work for me in interactive mode now. Thanks, Andrew M
Hi Andrew, (Sorry for the delay in replying! I've been out of commission for a few days.)
I wanted to bring them problem to your attention as well as show you an extremely hacky attempt at solving it. The add_profile_sphere and add_phase_sphere methods of PlotCollectionInteractive appear to have a bug in them. When I do: [snip] The same thing happens when I use pc.add_profile_sphere, but only with PlotCollectionInteractive. Using the same methods with PlotCollection works fine. The problem seems to be that the wrapper that "Interactifies" the PlotCollection methods assumes that you will not call them with "axes" or "figure" in the positional arguments. However, as currently coded, the add_phase_sphere and add_profile_sphere methods both call add_phase_object or add_profile_object, and when they do so they pass an axes and figure in the positional arguments.
Ah, yes, I see the issue, and I agree with your assessment -- changing them to keywords instead of positional should fix the problem. The Interactive plot collection has always been something of a shoehorn; it tries to be a multiple-figure-manager for matplotlib, but that's a tricky business and somewhat ill-defined anyway. Jeff Oishi is writing a replacement for the Plot Collection methodology that will be more single-window focused, which should provide a much better way of managing interactive figures.
Probably the best way to fix this is to re-write the wrapper function to not assume that you don't have an axes or figure in *args, but in the meantime I've got mine to work just by changing add_profile_sphere and add_phase_sphere like so (docstring snipped)
def add_phase_sphere(self, radius, unit, fields, center = None, cmap=None, weight="CellMassMsun", accumulation=False, x_bins=64, x_log=True, x_bounds=None, y_bins=64, y_log=True, y_bounds=None, lazy_reader=True, id=None, axes = None, figure = None, fractional=False):
if center is None: center = self.c r = radius/self.pf[unit] data_source = self.pf.hierarchy.sphere(center, r) p = self.add_phase_object(data_source, fields, cmap, weight, accumulation, x_bins, x_log, x_bounds, y_bins, y_log, y_bounds, lazy_reader, id, axes = axes, figure = figure, fractional = fractional) p["Width"] = radius p["Unit"] = unit p["Axis"] = None return p
So now the call to add_phase_object takes keyword arguments instead of positional ones for axes and figure. I made the same change to add_profile_sphere, and they work for me in interactive mode now.
I've applied this change (and one that checks the kwargs) and pushed to both the 'yt' branch and the 'stable' branch in hg. Thanks very much for this report -- and the fix! -Matt
Thanks, Andrew M
_______________________________________________ Yt-dev mailing list Yt-dev@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org
participants (2)
-
Andrew Myers
-
Matthew Turk