Beispiel #1
0
def test_paramfile():

	#Create an empty gadget snapshot
	snap = Gadget2Snapshot()

	#Generate random positions and velocities
	NumPart = 32**3
	x = np.random.normal(loc=7.0,scale=5.0,size=(NumPart,3)) * Mpc
	v = np.zeros((NumPart,3)) * m / s

	#Put the particles in the snapshot
	snap.setPositions(x)
	snap.setVelocities(v)

	#Generate minimal header
	snap.setHeaderInfo()

	#Split the particles between two files
	snap.write("gadget_sphere",files=2)

	#Generate the parameter file that will determine the evolution
	snap.writeParameterFile("gadget_sphere.param")

	#Generate a file with the scale factor of the output snapshots
	z = np.arange(90.0,0.0,-10.0)
	a = 1.0 / (1 + z)
	np.savetxt("outputs.txt",a)
Beispiel #2
0
def test_write():

	#Create an empty gadget snapshot
	snap = Gadget2Snapshot()

	#Generate random positions and velocities
	NumPart = 32**3
	x = np.random.normal(loc=7.0,scale=5.0,size=(NumPart,3)) * Mpc
	v = np.random.uniform(-1,1,size=(NumPart,3)) * m / s

	#Put the particles in the snapshot
	snap.setPositions(x)
	snap.setVelocities(v)

	#Generate minimal header
	snap.setHeaderInfo()

	#Visualize
	snap.visualize(s=1)
	snap.savefig("gadget_initial_condition.png")

	#Write the snapshot
	snap.write("gadget_ic")
Beispiel #3
0
from lenstools.simulations import Gadget2Snapshot

import numpy as np
import matplotlib.pyplot as plt

from astropy.units import Mpc, m, s

########################Write#################################

#Create an empty gadget snapshot
snap = Gadget2Snapshot()

#Generate random positions and velocities
NumPart = 32**3
x = np.random.normal(loc=7.0, scale=5.0, size=(NumPart, 3)) * Mpc
v = np.random.uniform(-1, 1, size=(NumPart, 3)) * m / s

#Put the particles in the snapshot
snap.setPositions(x)
snap.setVelocities(v)

#Generate minimal header
snap.setHeaderInfo()

#Write the snapshot
snap.write("gadget_ic")

######################Read and visualize#########################

#Open the snapshot
snap = Gadget2Snapshot.open("gadget_ic")