[yt-users] Why the two figures have different resolutions?

Nathan Goldbaum nathan12343 at gmail.com
Thu May 18 12:27:58 PDT 2017


I've gone ahead and opened an issue on github:

https://github.com/yt-project/yt/issues/1405

Let's move discussion about this over there.

On Thu, May 18, 2017 at 1:38 PM, Nathan Goldbaum <nathan12343 at gmail.com>
wrote:

>
>
> On Thu, May 18, 2017 at 1:24 PM, Matthew Turk <matthewturk at gmail.com>
> wrote:
>
>> Hi,
>>
>> I looked into this, and one thing I thought would fix it (adding a
>> _block_reorder attribute to ParticleOctreeSubset) didn't fix it, which
>> surprised me.  But, transposing the return value rv in
>> OctreeSubsetBlockSlicePosition did.  I thought that doing the copy in a
>> different order would be sufficient, since we don't use memoryviews
>> internal to the VR.
>>
>> I'm not ready yet to submit a PR for this yet, until I understand where
>> it's coming from.  Nathan, wasn't there a recent change to the i,j,k loop
>> order in the smoothing?
>>
>
> Not that I remember, but I could be forgetting something.
>
>
>> Are we sure this behavior has been around for a long time?
>>
>
> I have no idea, I haven't tried testing on an old version of yt.
>
>
>>
>> -Matt
>>
>> On Thu, May 18, 2017 at 9:41 AM, Nathan Goldbaum <nathan12343 at gmail.com>
>> wrote:
>>
>>> Hi Dan,
>>>
>>> Thanks for the info. I was able to reproduce the behavior you're seeing.
>>> Your script wasn't quite runnable (it still used set_size_inches, and you
>>> also forgot to save the first image). I also noticed that the difference is
>>> visible at yt's default resolution and with the ('gas', 'density') field,
>>> so in the interest of making the script simpler I used those:
>>>
>>> http://paste.yt-project.org/show/7150/
>>>
>>> For anyone following along, here are the two images this script produces:
>>>
>>> axis-aligned projection: http://i.imgur.com/ddKkxaC.png
>>>
>>> off-axis projection: http://i.imgur.com/mhWR2NL.png
>>>
>>> The problem gets worse when I increase over_refine_factor to 2 and set
>>> index_ptype='PartType0':
>>>
>>> axis-aligned projection: http://i.imgur.com/fctKRSO.png
>>>
>>> off-axis projection: http://i.imgur.com/eAz9BNt.png
>>>
>>> I'm not sure offhand why the results are different, in principle they
>>> should be the same, although as I mentioned earlier the images are produced
>>> using very different algorithms. It's possible there's a bug in how the
>>> volume renderer is dealing with SPH particle data. The fact that the
>>> problem gets worse when the resolution of the octree increases indicates to
>>> me that this is likely a bug. I know we've had other issues in the past
>>> using the volume rendering infrastructure with SPH data.
>>>
>>> Sorry to not have a more satisfactory answer. I think at this point we
>>> should probably open an issue on github to track this, I think we have good
>>> evidence that there are artifacts in SPH off-axis projections.
>>>
>>> I'm currently actively working on improving yt's support for particle
>>> data of all kinds and SPH data in particular. See this page for more
>>> details: https://bitbucket.org/ngoldbaum/ytep/src/2a754cae8a
>>> 5825109bad00aa9a5607abbcc4f095/source/YTEPs/YTEP-0031.rst?at
>>> =default&fileviewer=file-view-default
>>>
>>> Part of this will include writing a new particle-centric volume renderer
>>> which will hopefully fix this. That's definitely a more long term goal
>>> which will hopefully be done in the next few months. In the meantime
>>> someone will need to try to figure out what's introducing these artifacts
>>> we're seeing and optimally fix them somehow :)
>>>
>>> -Nathan
>>>
>>> On Thu, May 18, 2017 at 12:54 AM, bazhaoyu_sjtu <
>>> hudan_bazhaoyu at sjtu.edu.cn> wrote:
>>>
>>>> Hi Nathan,
>>>>
>>>> I'm so sorry that I haven't expressed clearly.
>>>>
>>>> I learned your code, and replotted two images. The complete script:
>>>> http://paste.yt-project.org/show/7146/
>>>> where the 'surface brightness' is a derived field by myself.
>>>>
>>>> And my data 'snap_206.hdf5':  http://use.yt/upload/c7c0d617
>>>>
>>>> Here's the two images:
>>>> regular projection:   https://1drv.ms/i/s!Aq__4QGcEmxvh06ErW9t_0BK-LQR
>>>> off-axis projection:   https://1drv.ms/i/s!Aq__4QGcEmxvh09ajn0UdatFjIil
>>>>
>>>> The off-axis one is still blockier. So How can I fix it? I want to have
>>>> same resolution of two figures.
>>>> Thanks for you help!
>>>>
>>>>
>>>> Regards,
>>>> Dan
>>>>
>>>>
>>>>
>>>> On 05/16/2017 08:39 PM, Nathan Goldbaum wrote:
>>>>
>>>>
>>>> On Tue, May 16, 2017 at 6:38 AM bazhaoyu_sjtu <
>>>> <hudan_bazhaoyu at sjtu.edu.cn>hudan_bazhaoyu at sjtu.edu.cn> wrote:
>>>>
>>>>> Hi Nathan,
>>>>>
>>>>> Thank you for your prompt reply!
>>>>>
>>>>> I also have two questions:
>>>>>
>>>>> 1.  When I tried your new script, the bug are presented below:
>>>>> ------------------------------------------------------------
>>>>> -------------------------------------
>>>>> pz.set_size_inches(10)
>>>>> AttributeError: 'ProjectionPlot' object has no attribute
>>>>> 'set_size_inches'
>>>>>
>>>>
>>>> Oops, that should have been pz.set_figure_size(10). I thought I fixed
>>>> that it I guess I forgot to update the email. Sorry for the confusion.
>>>>
>>>>
>>>>> ------------------------------------------------------------
>>>>> -------------------------------------
>>>>>
>>>>> 2.  For your two images, I also found that figure's resolution of the
>>>>> 'off-axis projection' is worse than the 'regular projection', for example,
>>>>> the 'off-axis projection' figure has more obvious grid point.
>>>>> Is there any difference between two projection ways? Because I
>>>>> supposed it should be same.
>>>>>
>>>>
>>>> They are generated using very different algorithms. The axis-aligned
>>>> projection is calculated based on an adaptive quadtree while the off-axis
>>>> projection is calculated using a ray-casting volume renderer.
>>>>
>>>> I agree with you that in principle they should come out with
>>>> identical-looking results for the script you provided. It's possible that
>>>> you're data is exposing a corner case that somehow makes the off-axis
>>>> projection appear blockier. It's hard to say without more info. Please see
>>>> the last paragraph of my last message about this, if you share an example
>>>> dataset that triggers this behavior or share the images you are seeing it
>>>> will make it easier to speak intelligently about what you are seeing.
>>>>
>>>>
>>>>>
>>>>> Thank you again!
>>>>>
>>>>> Regards,
>>>>> Dan
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On 05/15/2017 09:56 PM, Nathan Goldbaum wrote:
>>>>>
>>>>> Hi Dan,
>>>>>
>>>>> I adapted your script to use a public dataset from yt-project.org/data.
>>>>> I also don't have a definition for a surface_brightness field in my copy of
>>>>> yt, so I guess you defined that elsewhere? I used 'density'. Here's the
>>>>> script I ended up coming up with:
>>>>>
>>>>> http://paste.yt-project.org/show/7142/
>>>>>
>>>>> (note that you can upload scripts with the "yt pastebin" command line
>>>>> tool, e.g. "yt pastebin my_script.py")
>>>>>
>>>>> And indeed, in that case I get two images that aren't the desired high
>>>>> resolution you're looking for (although both images have the same
>>>>> resolution). The issue is that yt is saving the figure to disk through
>>>>> matplotlib. To control the image size in pixels through matplotlib you need
>>>>> to know the figure size in inches and the dpi (e.g. the number of pixels
>>>>> per inch of figure). Here's a revised version of the script above which
>>>>> saves to disk two images with the desired 3200x3200 resolution:
>>>>>
>>>>> http://paste.yt-project.org/show/7145/
>>>>>
>>>>> It also hides the axes and colorbar, since that makes it easier to
>>>>> guess ahead of time what the final image resolution will be. Here are the
>>>>> two images:
>>>>>
>>>>> regular projection: http://i.imgur.com/ialfYC4.png
>>>>> off-axis projection: http://i.imgur.com/PcvPZ9f.png
>>>>>
>>>>> You can share images you make using yt using the "yt upload_image"
>>>>> command, which will upload an image stored locally to imgur. We usually
>>>>> suggest using that to share images or alternatively something like a
>>>>> Jupyter notebook on gist.github.com to avoid clogging people's e-mail
>>>>> with high resolution images.
>>>>>
>>>>> Finally, if you don't want to mess with matplotlib and just want the
>>>>> underlying images, you can get those via the frb attribute of the plot
>>>>> object. Something like:
>>>>>
>>>>>     plot = yt.ProjectionPlot(ds, 'z', ('gas', 'density'))
>>>>>     plot.set_buff_size((3200, 3200))
>>>>>
>>>>>     # image will be a 3200x3200 numpy array
>>>>>     image = plot.frb['gas', 'density']
>>>>>
>>>>> I hope that helps clear things up. If you are still having issues it
>>>>> would help if you could share the exact yt version you are using as well as
>>>>> a runnable test script that demonstrates the issue. If you can't trigger
>>>>> the issue using one of the public SPH datasets on yt-project.org/data,
>>>>> you can share one of your datasets using the yt curldrop:
>>>>> https://docs.hub.yt/services.html#curldrop
>>>>>
>>>>> -Nathan
>>>>>
>>>>> On Mon, May 15, 2017 at 4:40 AM, bazhaoyu_sjtu <
>>>>> <hudan_bazhaoyu at sjtu.edu.cn>hudan_bazhaoyu at sjtu.edu.cn> wrote:
>>>>>
>>>>>> Hi yt-users:
>>>>>>
>>>>>> I want to ask you a question about the figures' resolution, I handled
>>>>>> Gadget file -- hdf5.
>>>>>>
>>>>>> I used the 'ProjectionPlot' to plot the surface brightness map which
>>>>>> is integrated along the 'z' axis, please see the figure 1; And I plot
>>>>>> another surface brightness map by 'OffAxisProjectionPlot' with the
>>>>>> normal_vector is [0, 0, 1], please see the figure 2.
>>>>>>
>>>>>> # I can't upload attachments ??? #
>>>>>>
>>>>>> Comparing two figures, we can find the structures of them is same,
>>>>>> but the resolution is different! The 'OffAxisProjectionPlot' is obviously
>>>>>> worse than 'ProjectionPlot', I don't know why!
>>>>>>
>>>>>> Below are the process I created two figures:
>>>>>>
>>>>>> ============================================================
>>>>>> ==========
>>>>>> import yt
>>>>>> import numpy as np
>>>>>> import yt.units as units
>>>>>> import pylab
>>>>>>
>>>>>> fname = "snap_206.hdf5"
>>>>>> unit_base = {'UnitLength_in_cm' : 3.08568e+21,
>>>>>> 'UnitMass_in_g' : 1.989e+43,
>>>>>> 'UnitVelocity_in_cm_per_s' : 100000}
>>>>>> bbox_lim = 1e5 # kpc
>>>>>> bbox = [[-bbox_lim,bbox_lim],
>>>>>> [-bbox_lim,bbox_lim],
>>>>>> [-bbox_lim,bbox_lim]]
>>>>>> ds = yt.load(fname,unit_base=unit_base,bounding_box=bbox)
>>>>>> ds.index
>>>>>> ad= ds.all_data()
>>>>>>
>>>>>>
>>>>>> ## For 'ProjectionPlot' ##
>>>>>> pz = yt.ProjectionPlot(ds, 'z', ('gas', 'surface_brightness'), 'max',
>>>>>> width=(0.4,'Mpc'))
>>>>>>
>>>>>>
>>>>>> ## For 'OffAxisProjectionPlot' ##
>>>>>> L = [0,0,1]
>>>>>> north_vector = [0,1,0]
>>>>>> pz = yt.OffAxisProjectionPlot(ds, L, ('gas', 'surface_brightness'),
>>>>>> 'max', north_vector = north_vector, width=(0.4,'Mpc'))
>>>>>>
>>>>>>
>>>>>> pz.set_buff_size((3200,3200))
>>>>>> pz.save()
>>>>>> ============================================================
>>>>>> =============
>>>>>>
>>>>>> What can i do to fix this difference of resolution between two plot
>>>>>> ways?
>>>>>> Thanks a lot!
>>>>>>
>>>>>> Regards,
>>>>>> Dan
>>>>>>
>>>>>>
>>>>>> ==================================
>>>>>> Department of Physics, Shanghai Jiao Tong University
>>>>>> 800 Dongchuan Road, Minhang, Shanghai 200240, PRC
>>>>>> E-mail : hudan_bazhaoyu at 163.com
>>>>>> hudan_bazhaoyu at sjtu.edu.cn
>>>>>> ==================================
>>>>>> _______________________________________________
>>>>>> yt-users mailing list
>>>>>> yt-users at lists.spacepope.org
>>>>>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> yt-users mailing listyt-users at lists.spacepope.orghttp://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
>>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> yt-users mailing listyt-users at lists.spacepope.orghttp://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
>>>>
>>>>
>>>
>>> _______________________________________________
>>> 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
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20170518/c33fa12d/attachment.html>


More information about the yt-users mailing list