%pylab inline
#plt.style.use('dark_background')
from IPython.display import Image
by Alejandro Benitez-Llambay
Image("imgs/frame.png",width=200, height=200)
import h5py
from sphviewer.tools import QuickView, cmaps
with h5py.File('data/darkmatter_box.h5py','r') as f:
pdrk = f['PartType1/Coordinates'].value.astype(np.float64)
qv = QuickView(pdrk, r='infinity', plot=False)
fig = plt.figure(1, figsize=(15,7))
ax1 = fig.add_subplot(121)
ax2 = fig.add_subplot(122)
ax1.plot(pdrk[:,0], pdrk[:,1], 'k.', ms=0.1)
ax2.imshow(qv.get_image(), extent=qv.get_extent(),
origin='lower', cmap=cmaps.twilight(),
vmin=-0.5)
Under the SPH approximation, the projected density field at any pixel is the contribution of all particles within the “projected” kernel.
We only need to decide which kernel we are going to use. For simplicity we a kernel with analytic integral.
where $\alpha$ is the normalization of the kernel
Py-SPHViewer is structured in four main classes:
The interface between python and C is done through the Python API for C.
Image("imgs/strong_scaling.png", width=400, height=400)
Image("imgs/scaling_npixels.png", width=400, height=400)
# We first load the particle data
pos = np.load('data/pdrk_L0012N0376.npy') #positions
h = np.load('data/hsml_L0012N0376.npy') #smoothing lengths
sigma= np.load('data/sigma_L0012N0376.npy') #local velocity dispersion
mass = np.ones(len(pos)) #masses
hlittle = 0.6777
lbox = 12.5 * hlittle
import sphviewer as sph
%time Particles = sph.Particles(pos, mass, h)
%time Camera = sph.Camera(r='infinity', t=0, p=0, roll=0, xsize=500, ysize=500, x=lbox/2., y=lbox/2., z=lbox/2., extent=[-lbox/2.,lbox/2.,-lbox/2.,lbox/2.])
%time Scene = sph.Scene(Particles, Camera)
%time Render = sph.Render(Scene)
extent = Render.get_extent()
lpixel = (extent[1]-extent[0])/500.
fig = plt.figure(1,figsize=(10,10))
imshow(np.log10(Render.get_image())-np.log10(lpixel**2),
extent=[extent[0]+Scene.Camera.get_params()['x'],
extent[1]+Scene.Camera.get_params()['x'],
extent[2]+Scene.Camera.get_params()['y'],
extent[3]+Scene.Camera.get_params()['y']],
vmin=4, vmax=9, cmap=cmaps.twilight(), origin='lower')
Scene.update_camera(x=2.319, y=4.481, z=5.141, extent=[-1,1,-1,1])
Render = sph.Render(Scene)
extent = Render.get_extent()
lpixel = (extent[1]-extent[0])/500.
fig = plt.figure(1,figsize=(10,10))
imshow(np.log10(Render.get_image())-np.log10(lpixel**2), extent=Render.get_extent(),
vmin=4, vmax=9, cmap=cmaps.twilight(), origin='lower')
Scene.update_camera(x=2.319, y=4.481, z=5.141, extent=[-0.1,0.1,-0.1,0.1])
Render = sph.Render(Scene)
extent = Render.get_extent()
lpixel = (extent[1]-extent[0])/500.
fig = plt.figure(1,figsize=(10,10))
imshow(np.log10(Render.get_image())-np.log10(lpixel**2), extent=Render.get_extent(),
vmin=5, vmax=9, cmap=cmaps.twilight(), origin='lower')
from IPython.lib.display import YouTubeVideo
YouTubeVideo('9ju8Ukfz_ug', width=1280/2, height=720/2)
qv1 = QuickView(pos, mass, h, r='infinity', plot=False, logscale=False)
qv2 = QuickView(pos, mass*sigma, h, r='infinity', plot=False, logscale=False)
img1 = qv1.get_image()
img2 = qv2.get_image()
extent = qv2.get_extent()
qv1 = 0
qv2 = 0
fig = plt.figure(1,figsize=(15,7))
ax1 = fig.add_subplot(121)
ax2 = fig.add_subplot(122)
ax1.imshow(np.log10(img1), extent=extent,
vmin=0, vmax=5, cmap=cmaps.twilight())
ax2.imshow(np.log10(img2/img1), extent=extent,
vmin=0, vmax=3, cmap=cmaps.twilight())
from IPython.lib.display import YouTubeVideo
YouTubeVideo('s0cLeRTfYHU', width=1280/2, height=720/2)
from sphviewer.tools import hsv_tools
from sphviewer_cbar import colorbar
fig = plt.figure(1,figsize=(10,10))
hmin = 180./360.
hmax = 1.0
rgb = hsv_tools.image_from_hsv(h=np.log10(img2/img1), v=np.log10(img1), hmin=hmin,
hmax=hmax, img_hmin=0.5, img_hmax=2, img_vmin=1, img_vmax=4)
imshow(rgb)
mycbar = colorbar()
mycbar.make_colorbar( pos=[0.95,0.15], size=0.2, extent=[1,4,0.5,2], hmin=hmin, hmax=hmax)
from IPython.lib.display import YouTubeVideo
YouTubeVideo('4ZIgVbNlDU4', width=1280/2, height=720/2)
from IPython.display import Image
Image("imgs/auriga.png", width=600, height=600)
from mpi4py import MPI
import glob
import h5py
import matplotlib.pyplot as plt
from sphviewer.tools import QuickView
import numpy as np
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
path = '/cosma5/data/Eagle/ScienceRuns/Planck1/L0050N0752/PE/Z0p10_W1p00_E_3p0_0p3_ALPHA1p0e6_rhogas1_reposlim3p0soft_100mgas/data/snapshot_028_z000p000/'
files = glob.glob(path+'*.hdf5')
local_imgs = []
for i in files[rank::size]:
print rank, i
# Reding files
#-----------------------
with h5py.File(i,'r') as f:
pgas = f['PartType0/Coordinates'].value
mgas = f['PartType0/Mass'].value*1e10
rhogas = f['PartType0/Density'].value*1e10
tgas = f['PartType0/Temperature'].value
hsml = f['PartType0/SmoothingLength'].value
lbox = f['Header'].attrs['BoxSize']
#-----------------------
#-----------------------
#Constructing local images
xc = yc = zc = lbox/2.0
extent = [-lbox/2.0,lbox/2.,-lbox/2.,lbox/2.]
r = 'infinity'
xsize = ysize = 500
qv = QuickView(pgas, mgas, hsml, r=r, extent=extent,
x=xc, y=yc, z=zc, plot=False,
xsize=xsize, ysize=ysize, logscale=False)
local_imgs.append(qv.get_image())
#-----------------------
#---------------------
#Collecting local images for final result and saving
all_images = comm.gather(local_imgs, root=0)
final_image = np.zeros([ysize, xsize], dtype=np.float32)
if(rank == 0):
for imgs in all_images:
for img in imgs:
print np.shape(img)
final_image += img
np.save('EAGLE_0050N0752.npy', final_image)
#---------------------