Commit 9f413318 authored by jclamber's avatar jclamber

add test programs

git-svn-id: http://svn.oamp.fr/repos/unsio/trunk@166 ce2cc22f-6084-46ce-a062-084b172ee5dc
parent 33afdc71
from py_unsio import * # import py_unsio package
import numpy as np # arrays are treated as numpy arrays
import matplotlib.pyplot as plt
import scipy.interpolate
# Step 1 : create UNSIO object
file="gtr111" # input file (simulation name)
component="disk,stars,gas" # selected components
times="6:10" # selected times
uns=CunsIn(file,component,times) # create UNS object
# Step 2 : load frame
while uns.nextFrame(""): # load snapshot
comp="gas"
# Step 3 : get data
ok,pos=uns.getData(comp,"pos") # positions of stars particles
# Step 3 : get data
ok,rho=uns.getData(comp ,"rho") # gas density
# Step 3 : get data
ok,mass=uns.getData(comp ,"mass") # gas density
# reshape array in x,y,z arrays
pos=np.reshape(pos,(-1,3)) # pos reshaped in a 2D array [nbody,3]
x = pos[:,0] # x coordinates
y = pos[:,1] # y coordinates
z = pos[:,2] # z coordinates
if (rho.size > 0) :
rho = np.log(rho)
else:
rho = z
# center according COM
x -= np.average(x,weights=mass)
y -= np.average(y,weights=mass)
z -= np.average(z,weights=mass)
range=20
if range>0:
xmin = -range
xmax = range
ymin = -range
ymax = range
else:
xmin = x.min()
xmax = x.max()
ymin = y.min()
ymax = y.max()
meshs=2000
# Set up a regular grid of interpolation points
xi, yi = np.linspace(xmin, xmax, meshs), np.linspace(ymin, ymax, meshs)
xi, yi = np.meshgrid(xi, yi)
# Interpolate
zi = scipy.interpolate.griddata((x, y), rho,(xi, yi), method='linear')
plt.imshow(zi, vmin=rho.min(), vmax=rho.max(), origin='lower', interpolation='bilinear',
extent=[xmin, xmax, ymin, ymax])
#plt.scatter(x, y, c=rho)
plt.colorbar()
plt.show()
from py_unsio import * # import py_unsio package
import numpy as np # arrays are treated as numpy arrays
import matplotlib.pyplot as plt
import scipy.interpolate
# Step 1 : create UNSIO object
file="gtr111" # input file (simulation name)
component="disk,stars,gas" # selected components
times="6:10" # selected times
uns=CunsIn(file,component,times) # create UNS object
# Step 2 : load frame
while uns.nextFrame(""): # load snapshot
comp="disk"
# Step 3 : get data
ok,pos=uns.getData(comp,"pos") # positions of stars particles
# Step 3 : get data
ok,rho=uns.getData(comp ,"rho") # gas density
# Step 3 : get data
ok,mass=uns.getData(comp ,"mass") # gas density
# reshape array in x,y,z arrays
pos=np.reshape(pos,(-1,3)) # pos reshaped in a 2D array [nbody,3]
x = pos[:,0] # x coordinates
y = pos[:,1] # y coordinates
z = pos[:,2] # z coordinates
if (rho.size > 0) :
rho = np.log(rho)
else:
rho = z
# center according COM
x -= np.average(x,weights=mass)
y -= np.average(y,weights=mass)
z -= np.average(z,weights=mass)
range=20
if range>0:
xmin = -range
xmax = range
ymin = -range
ymax = range
else:
xmin = x.min()
xmax = x.max()
ymin = y.min()
ymax = y.max()
plt.hexbin(x,y,bins='log',gridsize=500)#, cmap=plt.cm.YlOrRd_r)
plt.axis([xmin, xmax, ymin, ymax])
plt.title("With a log color scale")
cb = plt.colorbar()
cb.set_label('log10(N)')
plt.show()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment