[yt-users] getting slice array

Nathan Goldbaum nathan12343 at gmail.com
Tue Aug 11 11:17:50 PDT 2015


On Tue, Aug 11, 2015 at 1:10 PM, Slavin, Jonathan <jslavin at cfa.harvard.edu>
wrote:

> Hi all,
>
> I'm new to using yt, though I'm an experienced python and matplotlib
> user.  I've been doing runs with FLASH and would like to be able to plot
> the results with matplotlib.  I've used yt "interactively" in an ipython
> notebook and found it a bit cumbersome - e.g. you can't pan and zoom like
> you can with matplotlib.  On the other hand yt has some nice facilities for
> accessing the data.  So my question is, how do I get a slice, such as is
> plotted using the yt.SlicePlot function, in an array that I can then
> manipulate, plot, etc.?  If I do:
> ds = yt.load(file)
> slc = ds.slice(2,0.)
> d = slc['density']
> I have a YTArray that's apparently 1-D:
> d.shape
> (138496,)
> I should mention that this is a 2-D, cylindrically symmetric (r-z) run.
> Thanks in advance for any help you can offer.
>

If you have a yt plot object (e.g. a SlicePlot or a ProjectionPlot), you
can do:

slc = yt.SlicePlot(...)
densit_image = slc.frb['density']

"frb" here is a FixedResolutionBuffer object which translates the
multiresolution 1-D array you ran into above into a 2D pixelized
representation of your data.

You can also create a FixedResolutionBuffer object directly:
http://yt-project.org/docs/dev/analyzing/generating_processed_data.html#d-image-arrays

The image arrays you get back from a FixedResolutionBuffer object can be
passed directly to e.g. matplotlib's imshow command.

By the way, Matt Turk has an open pull request to add the interactive
panning and zooming you were looking for:

http://yt-project.org/docs/dev/analyzing/generating_processed_data.html#d-image-arrays

I'm hoping to finish up that pull request soon, since having interactive
plots both in the notebook and using matplotlib's interactive backends is a
common feature request.


> Regards,
> Jon Slavin
>
> --
> ________________________________________________________
> Jonathan D. Slavin                 Harvard-Smithsonian CfA
> jslavin at cfa.harvard.edu       60 Garden Street, MS 83
> phone: (617) 496-7981       Cambridge, MA 02138-1516
> cell: (781) 363-0035             USA
> ________________________________________________________
>
>
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20150811/2f78d68d/attachment.htm>


More information about the yt-users mailing list