Commit aaaf166d authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Merge branch 'python_scripts' into 'master'

Made all python scripts numpy 1.8.2 compatible, and fixed some bugs while doing it.

Title says it all. This should close #272.

See merge request !319
parents 26ecd35b 1291fec3
...@@ -107,7 +107,7 @@ if n_copy > 1: ...@@ -107,7 +107,7 @@ if n_copy > 1:
for i in range(n_copy): for i in range(n_copy):
for j in range(n_copy): for j in range(n_copy):
for k in range(n_copy): for k in range(n_copy):
coords = np.append(coords, coords_tile + np.array([ i * boxSize, j * boxSize, k * boxSize ]), axis=0) coords = np.append(coords, coords_tile + np.array([ i * boxSize[0], j * boxSize[1], k * boxSize[2] ]), axis=0)
v = np.append(v, v_tile, axis=0) v = np.append(v, v_tile, axis=0)
m = np.append(m, m_tile) m = np.append(m, m_tile)
h = np.append(h, h_tile) h = np.append(h, h_tile)
......
...@@ -227,7 +227,7 @@ ds[()] = u ...@@ -227,7 +227,7 @@ ds[()] = u
u = np.zeros(1) u = np.zeros(1)
# Particle IDs # Particle IDs
ids = 1 + np.linspace(0, N, N, endpoint=False, dtype='L') ids = 1 + np.linspace(0, N, N, endpoint=False)
ds = grp.create_dataset('ParticleIDs', (N, ), 'L') ds = grp.create_dataset('ParticleIDs', (N, ), 'L')
ds[()] = ids ds[()] = ids
......
...@@ -233,7 +233,7 @@ ds[()] = u ...@@ -233,7 +233,7 @@ ds[()] = u
u = np.zeros(1) u = np.zeros(1)
# Particle IDs # Particle IDs
ids = 1 + np.linspace(0, N, N, endpoint=False, dtype='L') ids = 1 + np.linspace(0, N, N, endpoint=False)
ds = grp.create_dataset('ParticleIDs', (N, ), 'L') ds = grp.create_dataset('ParticleIDs', (N, ), 'L')
ds[()] = ids ds[()] = ids
......
...@@ -150,7 +150,7 @@ ds[()] = m ...@@ -150,7 +150,7 @@ ds[()] = m
m = numpy.zeros(1) m = numpy.zeros(1)
ids = 1 + numpy.linspace(0, numPart, numPart, endpoint=False, dtype='L') ids = 1 + numpy.linspace(0, numPart, numPart, endpoint=False)
ds = grp1.create_dataset('ParticleIDs', (numPart, ), 'L') ds = grp1.create_dataset('ParticleIDs', (numPart, ), 'L')
ds[()] = ids ds[()] = ids
......
...@@ -205,7 +205,7 @@ if (entropy_flag == 1): ...@@ -205,7 +205,7 @@ if (entropy_flag == 1):
else: else:
ds[()] = u ds[()] = u
ids = 1 + numpy.linspace(0, numGas, numGas, endpoint=False, dtype='L') ids = 1 + numpy.linspace(0, numGas, numGas, endpoint=False)
ds = grp0.create_dataset('ParticleIDs', (numGas, ), 'L') ds = grp0.create_dataset('ParticleIDs', (numGas, ), 'L')
ds[()] = ids ds[()] = ids
......
...@@ -28,7 +28,7 @@ unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"]) ...@@ -28,7 +28,7 @@ unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
unit_length_cgs = float(params.attrs["InternalUnitSystem:UnitLength_in_cgs"]) unit_length_cgs = float(params.attrs["InternalUnitSystem:UnitLength_in_cgs"])
unit_velocity_cgs = float(params.attrs["InternalUnitSystem:UnitVelocity_in_cgs"]) unit_velocity_cgs = float(params.attrs["InternalUnitSystem:UnitVelocity_in_cgs"])
unit_time_cgs = unit_length_cgs / unit_velocity_cgs unit_time_cgs = unit_length_cgs / unit_velocity_cgs
v_c = float(params.attrs["SoftenedIsothermalPotential:vrot"]) v_c = float(params.attrs["IsothermalPotential:vrot"])
v_c_cgs = v_c * unit_velocity_cgs v_c_cgs = v_c * unit_velocity_cgs
#lambda_cgs = float(params.attrs["LambdaCooling:lambda_cgs"]) #lambda_cgs = float(params.attrs["LambdaCooling:lambda_cgs"])
#X_H = float(params.attrs["LambdaCooling:hydrogen_mass_abundance"]) #X_H = float(params.attrs["LambdaCooling:hydrogen_mass_abundance"])
......
...@@ -46,7 +46,7 @@ unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"]) ...@@ -46,7 +46,7 @@ unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
unit_length_cgs = float(params.attrs["InternalUnitSystem:UnitLength_in_cgs"]) unit_length_cgs = float(params.attrs["InternalUnitSystem:UnitLength_in_cgs"])
unit_velocity_cgs = float(params.attrs["InternalUnitSystem:UnitVelocity_in_cgs"]) unit_velocity_cgs = float(params.attrs["InternalUnitSystem:UnitVelocity_in_cgs"])
unit_time_cgs = unit_length_cgs / unit_velocity_cgs unit_time_cgs = unit_length_cgs / unit_velocity_cgs
v_c = float(params.attrs["SoftenedIsothermalPotential:vrot"]) v_c = float(params.attrs["IsothermalPotential:vrot"])
v_c_cgs = v_c * unit_velocity_cgs v_c_cgs = v_c * unit_velocity_cgs
#lambda_cgs = float(params.attrs["LambdaCooling:lambda_cgs"]) #lambda_cgs = float(params.attrs["LambdaCooling:lambda_cgs"])
#X_H = float(params.attrs["LambdaCooling:hydrogen_mass_abundance"]) #X_H = float(params.attrs["LambdaCooling:hydrogen_mass_abundance"])
......
...@@ -227,7 +227,7 @@ ds[()] = u ...@@ -227,7 +227,7 @@ ds[()] = u
u = np.zeros(1) u = np.zeros(1)
# Particle IDs # Particle IDs
ids = 1 + np.linspace(0, N, N, endpoint=False, dtype='L') ids = 1 + np.linspace(0, N, N, endpoint=False)
ds = grp.create_dataset('ParticleIDs', (N, ), 'L') ds = grp.create_dataset('ParticleIDs', (N, ), 'L')
ds[()] = ids ds[()] = ids
......
...@@ -46,7 +46,7 @@ unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"]) ...@@ -46,7 +46,7 @@ unit_mass_cgs = float(params.attrs["InternalUnitSystem:UnitMass_in_cgs"])
unit_length_cgs = float(params.attrs["InternalUnitSystem:UnitLength_in_cgs"]) unit_length_cgs = float(params.attrs["InternalUnitSystem:UnitLength_in_cgs"])
unit_velocity_cgs = float(params.attrs["InternalUnitSystem:UnitVelocity_in_cgs"]) unit_velocity_cgs = float(params.attrs["InternalUnitSystem:UnitVelocity_in_cgs"])
unit_time_cgs = unit_length_cgs / unit_velocity_cgs unit_time_cgs = unit_length_cgs / unit_velocity_cgs
v_c = float(params.attrs["SoftenedIsothermalPotential:vrot"]) v_c = float(params.attrs["IsothermalPotential:vrot"])
v_c_cgs = v_c * unit_velocity_cgs v_c_cgs = v_c * unit_velocity_cgs
header = f["Header"] header = f["Header"]
N = header.attrs["NumPart_Total"][0] N = header.attrs["NumPart_Total"][0]
......
...@@ -138,7 +138,7 @@ ds = grp1.create_dataset('Masses', (numPart,), 'f') ...@@ -138,7 +138,7 @@ ds = grp1.create_dataset('Masses', (numPart,), 'f')
ds[()] = m ds[()] = m
m = numpy.zeros(1) m = numpy.zeros(1)
ids = 1 + numpy.linspace(0, numPart, numPart, endpoint=False, dtype='L') ids = 1 + numpy.linspace(0, numPart, numPart, endpoint=False)
ds = grp1.create_dataset('ParticleIDs', (numPart, ), 'L') ds = grp1.create_dataset('ParticleIDs', (numPart, ), 'L')
ds[()] = ids ds[()] = ids
......
...@@ -35,8 +35,8 @@ glass = h5py.File("glassCube_64.hdf5", "r") ...@@ -35,8 +35,8 @@ glass = h5py.File("glassCube_64.hdf5", "r")
vol = 8. vol = 8.
pos = glass["/PartType0/Coordinates"][:,:] * cbrt(vol) pos = glass["/PartType0/Coordinates"][:,:] * vol**(1./3.)
h = glass["/PartType0/SmoothingLength"][:] * cbrt(vol) h = glass["/PartType0/SmoothingLength"][:] * vol**(1./3.)
numPart = size(h) numPart = size(h)
# Generate extra arrays # Generate extra arrays
...@@ -65,7 +65,7 @@ file = h5py.File(fileName, 'w') ...@@ -65,7 +65,7 @@ file = h5py.File(fileName, 'w')
# Header # Header
grp = file.create_group("/Header") grp = file.create_group("/Header")
grp.attrs["BoxSize"] = [cbrt(vol), cbrt(vol), cbrt(vol)] grp.attrs["BoxSize"] = [vol**(1./3.), vol**(1./3.), vol**(1./3.)]
grp.attrs["NumPart_Total"] = [numPart, 0, 0, 0, 0, 0] grp.attrs["NumPart_Total"] = [numPart, 0, 0, 0, 0, 0]
grp.attrs["NumPart_Total_HighWord"] = [0, 0, 0, 0, 0, 0] grp.attrs["NumPart_Total_HighWord"] = [0, 0, 0, 0, 0, 0]
grp.attrs["NumPart_ThisFile"] = [numPart, 0, 0, 0, 0, 0] grp.attrs["NumPart_ThisFile"] = [numPart, 0, 0, 0, 0, 0]
......
...@@ -55,7 +55,7 @@ rho_x = 1000.*np.exp(-0.5*A/np.pi/cs2*np.cos(2.*np.pi*x)) ...@@ -55,7 +55,7 @@ rho_x = 1000.*np.exp(-0.5*A/np.pi/cs2*np.cos(2.*np.pi*x))
P = cs2*rho P = cs2*rho
n1D = int(np.cbrt(len(P))) n1D = np.ceil(len(P)**(1./3.))
gradP = np.zeros(P.shape) gradP = np.zeros(P.shape)
for i in range(len(P)): for i in range(len(P)):
iself = int(ids[i]/n1D/n1D) iself = int(ids[i]/n1D/n1D)
......
Supports Markdown
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