In order to create visualizations we used python and the terminal on a Linux computer. With python we could easily import the libraries necessary to create visualizations such as matplotlib and numpy.
Credit: https://www.python.org/
Here is a walkthrough of how to use matplotlib and numpy to create a simple visualization. In this case, we will be creating a circle and putting it onto a graph.
First you will want to open the terminal on your Linux or Mac. If you are using Windows, then install Putty and open it up.
Next you will need to type in python and then hit Enter.
This will allow you to now Enter python code into the terminal. You know this works if you see >>> in your terminal.
Next type in this code:
import numpy as np
import matplotlib.pyplot as plt
theta = np.linspace(0,360,500) #degrees
theta = theta * np.pi/180 # now converted to radians
radius = 5 # radius of circle
x = radius * np.cos(theta)
y = radius * np.sin(theta)
plt.plot(x,y)
plt.axis("equal")
plt.savefig("circle.png")
plt.show()
An image should pop up which displays a circle in it. Here is an image of what it should look like:
In this Walkthrough, you'll learn how to create a gif, like the one to the left, of a halo.
Again you want to open the terminal on your computer and install the python package sphviewer on your laptop in order to make pretty visualizations. You will want to create a new python file which you can do on Mac by using:
touch fileName.py; open fileName.py
Then in the file you created copy and paste this script:
from sphviewer.tools import QuickView
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
from sphviewer.tools import camera_tools
import sphviewer as sph
// Load your own set of data (particles)
pos = np.load("halo_0_pos_99.npy")*2/1000.#/1000.
n_parts = pos.shape[0]
mass = np.ones(n_parts)
print(pos.shape)
print(mass.shape)
P = sph.Particles(pos, mass)
S = sph.Scene(P)
cm_0 = [0,0,0]
cm_1 = [-1.4,-2.55,1.1]
targets = [cm_0,cm_1]
anchors = {}
anchors['sim_times'] = [0.0, 1.0, 2.0, 3.0, 4.0,5.0,6.0,7.0,8.0]
anchors['id_frames'] = np.array([0,2,5,7,10,12,15,17,20])*10
anchors['r'] = [7,'same',7.,'same',7,'same',6.2,'same','same']
anchors['id_targets']= [0,'pass',0,'same',1,'same','same','same','same']
anchors['t'] = [0,'same','same','same','same','same','same','same',0]
anchors['p'] = [0,'pass','pass','pass','pass','pass','pass','pass',200]
anchors['zoom'] = [.4,'pass',1.,'same',1,'same',1.5,'same','same']
anchors['extent'] = [.1, 'same','same','same','same','same','same','same','same']
data = camera_tools.get_camera_trajectory(targets,anchors)
h = 0
for i in data[:200]:
i['xsize'] = 1000
i['ysize'] = 1000
i['roll'] = 1
S = sph.Scene(P)
S.update_camera(**i)
R = sph.Render(S)
img = R.get_image()
R.set_logscale()
plt.imsave('try1/image_'+str('%04d.png'%h), img, vmin=0, vmax=6,cmap=plt.cm.magma)
h += 1
Now save the file and open the terminal again.
Type python filename.py to run the file. You should end up with a gif similar to the one above.