[yt-users] getting slice array

Nathan Goldbaum nathan12343 at gmail.com
Tue Aug 11 12:07:46 PDT 2015


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

> ​Hi Nathan,
>
> Thanks!  It seems though that the frb cannot be directly passed to
> matplotlib's imshow, though np.array(frb) can.
>

Just to be clear, the FRB is the object that creates the image buffers, so
you would np.array(frb['density']) to create an ndarray representation of
the 2D density image. I think you should be able to pass the YTArray with
units to imshow as well, at least on relatively recent versions of
matplotlib. Most matplotlib plotting functions just strip units from arrays
passed to it, although you're right that sometimes it is necessary to cast
to ndarray.

You can also use the .value or .ndview properties of any YTArray object to
get back a copy of the array cast to ndarray or an ndarray "view" into the
original array, respectively.


>
> I would like it in general if yt could provide simpler means of accessing
> arrays or array-like objects such as are plotted up.  There are many
> reasons for this besides the desire to plot using matplotlib -- e.g. to
> create plots of ratios of quantities, or to plot scaled variables.​
>  Perhaps this is possible now, though it's not obvious from the docs.
>

Did you take a look at the page I linked to earlier?

http://yt-project.org/docs/dev/analyzing/generating_processed_data.html

That page is focused on generating processed data (e.g. images and
histograms) that can be passed to matplotlib. In fact, that's how all of
the one-liner plot recipes yt shows in the docs work behind the scenes.

Is there something we should expand on in that page?


>
> Regards,
> Jon
>
> On Tue, Aug 11, 2015 at 2:42 PM, <yt-users-request at lists.spacepope.org>
> wrote:
>
>> Date: Tue, 11 Aug 2015 13:17:50 -0500
>> From: Nathan Goldbaum <nathan12343 at gmail.com>
>> To: Discussion of the yt analysis package
>>         <yt-users at lists.spacepope.org>
>> Subject: Re: [yt-users] getting slice array
>> Message-ID:
>>         <CAJXewOmiymap0uUBy0hL=
>> zo0Ltf0kG7UErXYFy9dqZseXoapsg at mail.gmail.com>
>> Content-Type: text/plain; charset="utf-8"
>>
>>
>> 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.
>>
>
>
>
>
> --
> ________________________________________________________
> 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/322c7592/attachment.html>


More information about the yt-users mailing list