yt-project / yt

Main yt repository
http://yt-project.org
Other
468 stars 279 forks source link

Slice Plots using gather and scatter output has discrepancy #3684

Closed juju1993 closed 2 years ago

juju1993 commented 2 years ago

Bug report

Bug summary When I used slice plots for SPH dataset (Miluphcuda solver). The output is drastically different for gather method and scatter method.

Code for reproduction

''curl link''' http://use.yt/upload/472925e3

import yt
print(yt.__version__)
import h5py
import numpy as np
import matplotlib.pyplot as plt

# In[7]:

#reading the h5py file and converting into dictionary so that it can be read in yt
def load_file_yt(name):
    f = h5py.File('c:\\users\\shrikanth.nps\\crater\\'+name+'.h5','r')
    dset = f['x'] #position
    dset_m = f['m']#mass
    dset_sml =0.5*np.array( f['sml'])#rendering with final sml
    dset_density = f['rho']#density
    dset_vel = f['v']#velocity
    time = f['time']#time 
    ppx, ppy, ppz = dset[:,0], dset[:,1], dset[:,2]
    data = {'particle_position_x': ppx,
        'particle_position_y': ppy,
        'particle_position_z' : ppz,
        'particle_mass' : dset_m,
       'smoothing_length':dset_sml,
       'density':dset_density,
       'particle_velocity':dset_vel}
    load_particles(ppx,ppy,ppz,data,time)
load_file_yt("impact.0200")

# In[3]:

def load_particles(xpos,ypos,zpos,data,time):
    bbox = 1*np.array([[min(xpos), max(xpos)], [min(ypos), max(ypos)], [min(zpos), max(zpos)]])
    ds = yt.load_particles(data, length_unit = 100.0, unit_system = "mks", bbox=bbox)
    slice_plot(ds,time)

def slice_plot(ip,time):
    #we need to define a center because in the impact.0200. the particles are more than a meter apart!
    #so to get the desired plot we need to define the center and restrict it to 20 cm or mm !
    c = [-0.00,0.00,0.0]
    ip.sph_smoothing_style="gather"
    plot = yt.SlicePlot(ip,"y",("io","density"), width = (20,"cm"),center = c)
    plot.annotate_title(f"Slice Plot for time = {time[:]}s ")    
    plot.show()
    plot.save("slice_plot_gather.PNG")

Actual outcome

slice_plot_scatter PNG_Slice_y_density

slice_plot_gather PNG_Slice_y_density

Expected outcome I cannot interpret the output I got using the "gather" method. I want to analyze the impact of the crater at the center

Version Information

I installed yt using pip

welcome[bot] commented 2 years ago

Hi, and welcome to yt! Thanks for opening your first issue. We have an issue template that helps us to gather relevant information to help diagnosing and fixing the issue.

neutrinoceros commented 2 years ago

hi @juju1993, thank your for reporting. Seems like at least half off the code you copy-pasted here is commented, it would help if you could remove the unused parts. I've taken the liberty of editing your message already because the code blocks were not properly delimited and the images didn't show. It would also be helpful to know what data format you're using; there are different mechanisms to change units depending on the data format.

juju1993 commented 2 years ago

hi @neutrinoceros thanks for the quick reply and sorry for the mess, I have cleaned the code now. I uploaded the h5py file in curl. We use SI units for our simulation.

neutrinoceros commented 2 years ago

from reading yt.load_particles's docstring it looks like what you need to fix the length units something like

ds = yt.load_particles(data, length_unit=0.01,  unit_system = "mks", bbox=bbox)

Though I'm not 100% sure that's the correct value to pass (it's supposed to be the conversion factor from code units to cm) Please tell be if this works for you.

As for the interpretation issue with the gather method, I have exactly 0 experience there so I'll defer to the particle experts.

juju1993 commented 2 years ago

Hi,

Thanks that solves the scaling problem. But its written other way around ds = yt.load_particles(data, length_unit=100.0, unit_system = "mks", bbox=bbox)

Is there a documentation where I can read more about gather and scatter methods?

juju1993 commented 2 years ago

hi @neutrinoceros ,

I think I found the problem in "gather" approach! Actually you helped me put the piece together by posting a link slack #help group! ... For "gather" approach. I added ds.use_sph_normalization = False and then I got the output which we expected! I will close the issue! image

neutrinoceros commented 2 years ago

Glad you found a solution, I wasn't aware of this attribute.