[yt-users] saving files with a different resolution

Matthew Turk matthewturk at gmail.com
Wed Mar 31 09:57:43 PDT 2010


Hi Luigi,

For very small plots, or if you need to hand-carve the setup, I
recommend skipping the PlotCollection and using a
FixedResolutionBuffer -- it's a bit advanced, but if you want strict
control you can use it.  This object will take the flat, (5, N) array
of points that comprise a slice or a projection and turn them into a
2D image buffer.  You can access it like this:

from yt.mods import *
pf = load(...)
proj = pf.h.slice(axis, coordinate)
frb = raven.FixedResolutionBuffer(proj, (px_min, px_max, py_min,
py_max), (px_res, py_res))

This then provides access to:

frb[some_field]

What happens then is that the FRB will pixelize the data returned from
the slice into an x_res by y_res image, with extents from px_min to
px_max and the same for py.  ("p"x and "p"y because it's in the
image/pixel plane.)  You can then plot this by hand -- either in
python with Matplotlib/pylab or outside of Python.

Additionally, the add_projection command can accept both figure and
axes arguments, so you can fine tune how it's plotted using those, as
well -- this is how I make multi-panel image plots for papers and
talks, by using the PlotCollection but giving it a figure and axes
object that I create myself.

Hope that helps!  I'll commit the fix now, as well.  :)

Best,

Matt

On Wed, Mar 31, 2010 at 9:52 AM, Luigi Iapichino
<luigi at ita.uni-heidelberg.de> wrote:
> Hi Matt,
>
> your fix works, provided the plot is not smaller than 750x600 and the aspect
> ratio is 1.25:1 (thus allowing space for the colorbar). For smaller plots the
> label of the colorbar (whose font size does not scale) will go out of the
> figure. This is not a crucial issue to be fixed: I will simply stay above
> this threshold.
> Thanks for your help,
>
>  Luigi
>
> On Wednesday 31 March 2010, Matthew Turk wrote:
>> Hi Luigi,
>>
>> I think I have tracked it down.  The issue only shows up when the
>> aspect ratio of the axes object -- the image itself -- is not 1.0.
>> What seems to have happened is that there is confusion in the contour
>> callback object (as well as the grid boundary callback, so I would be
>> unsurprised if you saw these same issues there) as to which axis is x
>> and which is y.  I believe this is my fault, dating back quite some
>> time -- fortunately, as you point out, it's very obvious (and should
>> result in broken contours at the edges.)
>>
>> What tipped me off to this was your statement about the figure sizes
>> -- this shouldn't be directly used, but instead only used indirectly
>> via seeing how big (canvas-space) the axes object is inside the
>> contouring code.  Running with a fig_size like (20,16) that ensures
>> aspect ratio of 1.0 in the axes object (allowing 20% for colorbar on
>> the figure itself) worked, so that theory started to pan out.  I have
>> tested with fig_size = (12,9) as well, and this fix works.
>>
>> If you could try changing lines 153 and 154 of yt/raven/Callbacks.py
>> to be "dy =" and "dx =" instead of "dx =" and "dy =" that would be a
>> great help.  If that works for you, I'll commit it to the repository.
>>
>> Thanks very much for this report, and I hope this works out.
>>
>> -Matt
>>
>> On Wed, Mar 31, 2010 at 1:53 AM, Luigi Iapichino
>>
>> <luigi at ita.uni-heidelberg.de> wrote:
>> > Hi Matt,
>> >
>> > both methods work, but I have a further problem: if I try to add density
>> > contours, they appear in the plot, but they are not superimposed at the
>> > correct location. They look like shifted, and I suppose that
>> >
>> > p.modify["contour"]("Density", ncont=5,take_log=True)
>> >
>> > does not "see" that I changed the size of the figure.
>> > Am I missing something?
>> > Thanks,
>> >
>> >  Luigi
>> >
>> > On Tuesday 30 March 2010, Matthew Turk wrote:
>> >> Hi Luigi,
>> >>
>> >> Yup, you'll just need to provide it with a new "figure".  In
>> >> matplotlib, figures are the background - the entire image, if you will
>> >> - and "axes" are individual plot elements on that.  Here we're going
>> >> to create a figure with 100 dpi that's 12 inches by 9 inches -- this
>> >> should be 1200 by 900 pixels:
>> >>
>> >> fig = raven.matplotlib.figure.Figure(dpi = 100, figsize = (12, 9))
>> >> p = pc.add_projection("Temperature", 0, weight_field="Density")
>> >>
>> >> That's the slightly harder way -- you'll have to generate a new Figure
>> >> object for every plot.  There's a shortcut in yt already, though, that
>> >> accepts a figsize=(width, height) argument, where width and height are
>> >> in inches:
>> >>
>> >> p = pc.add_projection("Temperature", 0, weight_field="Density",
>> >> fig_size=(20, 16))
>> >>
>> >> if you wanted 2000 by 1600 pixels.
>> >>
>> >> Does that help out?
>> >>
>> >> Best,
>> >>
>> >> Matt
>> >>
>> >> On Tue, Mar 30, 2010 at 7:47 AM, Luigi Iapichino
>> >>
>> >> <luigi at ita.uni-heidelberg.de> wrote:
>> >> > Dear all,
>> >> >
>> >> > in one of my scripts I have something like this:
>> >> >
>> >> >    pc = PlotCollection(pf, center=[0.5,0.5,0.5])
>> >> >
>> >> >    p = pc.add_projection("Temperature", 0, weight_field="Density")
>> >> >    p.modify["contour"]("Density", ncont=5, take_log=True)
>> >> >    ...
>> >> >    ...
>> >> >    ...
>> >> >    pc.save("%s_temp-proj" % pf,override=True)
>> >> >
>> >> > The saved file has a resolution of 800x800. Is there a way to change
>> >> > this number in YT? I had a look in the PlotCollection class, but I
>> >> > haven't found what I'm searching.
>> >> >
>> >> > Looking forward to your suggestions,
>> >> > Cheers
>> >> >
>> >> >  Luigi
>> >> >
>> >> > --
>> >> >
>> >> > ---------------------------------------------------------------
>> >> >
>> >> > Luigi Iapichino
>> >> > Zentrum fuer Astronomie der Universitaet Heidelberg
>> >> > Institut fuer Theoretische Astrophysik
>> >> > Albert-Ueberle-Str. 2, D-69120 Heidelberg, Germany
>> >> > Tel: +49 6221 548983, Fax: +49 6221 544221
>> >> > e-mail: luigi at ita.uni-heidelberg.de
>> >> > URL: http://www.ita.uni-heidelberg.de/~luigi/
>> >> > _______________________________________________
>> >> > yt-users mailing list
>> >> > yt-users at lists.spacepope.org
>> >> > http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>> >>
>> >> _______________________________________________
>> >> yt-users mailing list
>> >> yt-users at lists.spacepope.org
>> >> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>> >
>> > --
>> >
>> > ---------------------------------------------------------------
>> >
>> > Luigi Iapichino
>> > Zentrum fuer Astronomie der Universitaet Heidelberg
>> > Institut fuer Theoretische Astrophysik
>> > Albert-Ueberle-Str. 2, D-69120 Heidelberg, Germany
>> > Tel: +49 6221 548983, Fax: +49 6221 544221
>> > e-mail: luigi at ita.uni-heidelberg.de
>> > URL: http://www.ita.uni-heidelberg.de/~luigi/
>> > _______________________________________________
>> > yt-users mailing list
>> > yt-users at lists.spacepope.org
>> > http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>
>> _______________________________________________
>> yt-users mailing list
>> yt-users at lists.spacepope.org
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
>
>
> --
>
> ---------------------------------------------------------------
>
> Luigi Iapichino
> Zentrum fuer Astronomie der Universitaet Heidelberg
> Institut fuer Theoretische Astrophysik
> Albert-Ueberle-Str. 2, D-69120 Heidelberg, Germany
> Tel: +49 6221 548983, Fax: +49 6221 544221
> e-mail: luigi at ita.uni-heidelberg.de
> URL: http://www.ita.uni-heidelberg.de/~luigi/
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>



More information about the yt-users mailing list