alejandrobll / py-sphviewer

Py-SPHViewer is a framework for rendering cosmological simulations in Python using the Smoothed Particle Hydrodynamics scheme.
https://alejandrobll.github.com/py-sphviewer
GNU General Public License v3.0
70 stars 29 forks source link

empty plots with large number of particles #35

Open jegarfa opened 3 months ago

jegarfa commented 3 months ago

Hi! I'm trying to plot a DM-only simulation using py-sphviewer. The simulation consists of 2048^3 particles. However, the result I'm getting is either a completely white or black plot. Below is the code, which I've taken from the examples.

Particles = sph.Particles(pos, mass, nb=4)
hsml      = Particles.get_hsml()
Scene     = sph.Scene(Particles)

fig = plt.figure(1, figsize=(15,7))
ax1 = fig.add_subplot(111)
ax1.imshow(qv_perspective.get_image(), extent=qv_perspective.get_extent(),
           origin='lower', cmap=cmaps.twilight(), 
           vmin=-0.5)
plt.show()

When I plot smaller simulations, everything works fine, and I get pretty plots. I suspect this issue might not be related to py-sphviewer but rather to matplotlib. I've noticed that when I create a simple 2D scatter plot with matplotlib for the 2048^3 particles (x, y), it results in an empty figure. So, I do not get errors, only empty plots.

Have you ever faced a similar issue when plotting large amounts of data? do you have any hint on what could be causing the problem?
thanks,

alejandrobll commented 3 months ago

Hi Jorge, this is likely an issue related to kdtree for a large number of particles. Try estimating the smoothing length before using sphviewer. This should fix the problem.

Cheers, Alejandro

On Fri, 17 May 2024 at 21:47, Jorge García Farieta @.***> wrote:

Hi! I'm trying to plot a DM-only simulation using py-sphviewer. The simulation consists of 2048^3 particles. However, the result I'm getting is either a completely white or black plot. Below is the code, which I've taken from the examples.

Particles = sph.Particles(pos, mass, nb=4) hsml = Particles.get_hsml() Scene = sph.Scene(Particles)

fig = plt.figure(1, figsize=(15,7)) ax1 = fig.add_subplot(111) ax1.imshow(qv_perspective.get_image(), extent=qv_perspective.get_extent(), origin='lower', cmap=cmaps.twilight(), vmin=-0.5) plt.show()

When I plot smaller simulations, everything works fine, and I get pretty plots. I suspect this issue might not be related to py-sphviewer but rather to matplotlib. I've noticed that when I create a simple 2D scatter plot with matplotlib for the 2048^3 particles (x, y), it results in an empty figure. So, I do not get errors, only empty plots.

Have you ever faced a similar issue when plotting large amounts of data? do you have any hint on what could be causing the problem? thanks,

— Reply to this email directly, view it on GitHub https://github.com/alejandrobll/py-sphviewer/issues/35, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABYAMDOL5WH2LF46HPE5BY3ZCZNFHAVCNFSM6AAAAABH4WDKUKVHI2DSMVQWIX3LMV43ASLTON2WKOZSGMYDGNBXGEYDONA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jegarfa commented 3 months ago

Hi Alejandro, right, in fact after loading the particles I am computing the hsml hsml = Particles.get_hsml() I tried varying the vmin and vmax. I noticed something odd after render.

Render = sph.Render(Scene)
img = Render.get_image()

the image only contains zeros, however, it loaded all the particles and hsml. And since I don't get an error I was not able to track the issue.

I also did a test with random data but I got the same result, an empty plot. N = int(2048**3) pos = np.random.rand(N, 3)

alejandrobll commented 3 months ago

To make sure it is not related to py-kdtree, could you try computing the smoothing lengths yourself? I still think it is related to the smoothing length of particles having odd or NaN values. If you can check this first, that would help to track the issue.

Cheers, Alejandro.

On Wed, 22 May 2024 at 12:05, Jorge García Farieta @.***> wrote:

Hi Alejandro, right, in fact after loading the particles I am computing the hsml hsml = Particles.get_hsml() I tried varying the vmin and vmax. I noticed something odd after render.

Render = sph.Render(Scene) img = Render.get_image()

the image only contains zeros, however, it loaded all the particles and hsml. And since I don't get an error I was not able to track the issue.

I also did a test with random data but I got the same result, an empty plot. N = int(2048**3) pos = np.random.rand(N, 3)

— Reply to this email directly, view it on GitHub https://github.com/alejandrobll/py-sphviewer/issues/35#issuecomment-2124396326, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABYAMDJEVIEAV3HUHQW5B3LZDRUWHAVCNFSM6AAAAABH4WDKUKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRUGM4TMMZSGY . You are receiving this because you commented.Message ID: @.***>

-- Alejandro Benítez Llambay