[Yt-dev] Bug in PlotCollectionInteractive.add_phase_sphere and add_profile_sphere

Andrew Myers atmyers at berkeley.edu
Fri Oct 1 14:49:24 PDT 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-dev-spacepope.org/attachments/20101001/c3f73477/attachment.htm>


More information about the yt-dev mailing list