1
0
Fork 0
mirror of https://github.com/glatterf42/sims_python_files.git synced 2024-09-19 16:13:45 +02:00

re-apply fixes to vis*

This commit is contained in:
Lukas Winkler 2022-05-23 15:54:28 +02:00
parent 70cdf5a29a
commit 4d5e8bb575
Signed by: lukas
GPG key ID: 54DE4D798D244853

View file

@ -60,19 +60,17 @@ def find_move_candidates(original_data, minimum, maximum, lower_limit_top, upper
# print(point)
return move_candidates
# file = h5py.File(directory / "auriga6_halo7_8_9.hdf5", "r")
def read_file(filename):
file = h5py.File(str(filename), "r")
Header = file['Header']
Header = dict(file['Header'].attrs)
highres_coordinates = file["PartType1"]["Coordinates"][:] # for cdm particles
highres_names = file["PartType1"]["ParticleIDs"][:]
highres_velocities = file["PartType1"]["Velocities"][:]
highres_masses = file['PartType1']['Masses'][:]
highres_group_ids = file['PartType1']['FOFGroupIDs'][:]
highres_absolute_velo = np.sqrt(np.sum(highres_velocities ** 2, axis=1))
if "PartType2" in file:
lowres_coordinates = file["PartType2"]["Coordinates"][:] # for cdm particles
lowres_names = file["PartType2"]["ParticleIDs"][:]
lowres_velocities = file["PartType2"]["Velocities"][:]
@ -81,6 +79,19 @@ def read_file(filename):
lowres_absolute_velo = np.sqrt(np.sum(lowres_velocities ** 2, axis=1))
original_coordinates = np.concatenate((highres_coordinates, lowres_coordinates))
names = np.concatenate((highres_names, lowres_names))
velocities = np.concatenate((highres_velocities, lowres_velocities))
masses = np.concatenate((highres_masses, lowres_masses))
group_ids = np.concatenate((highres_group_ids, lowres_group_ids))
absolute_velo = np.concatenate((highres_absolute_velo, lowres_absolute_velo))
else:
original_coordinates = highres_coordinates
names = highres_names
velocities = highres_velocities
masses = highres_masses
group_ids = highres_group_ids
absolute_velo = highres_absolute_velo
file.close()
# if "auriga" in str(filename):
# original_coordinates /= 1000
# print(original_coordinates.mean())
@ -89,13 +100,9 @@ def read_file(filename):
# print(file['Header'])
# print(list(file['Units'].attrs.items()))
# exit()
names = np.concatenate((highres_names, lowres_names))
velocities = np.concatenate((highres_velocities, lowres_velocities))
masses = np.concatenate((highres_masses, lowres_masses))
group_ids = np.concatenate((highres_group_ids, lowres_group_ids))
absolute_velo = np.concatenate((highres_absolute_velo, lowres_absolute_velo))
# for bla in [original_coordinates, names, velocities, masses, absolute_velo]:
# print(bla.shape)
print(original_coordinates.shape)
original_data = np.vstack([
original_coordinates[::, 0],
original_coordinates[::, 1],
@ -110,8 +117,16 @@ def read_file(filename):
]).T
print(original_data.shape)
assert (original_coordinates == original_data[::, 0:3]).all()
return Header, highres_names, original_data
boundaries = Header.attrs['BoxSize'] # BoxLength for e5 boxes depends on Nres, 2.36438 for 256, 4.72876 for 512.
# file = h5py.File(directory / "auriga6_halo7_8_9.hdf5", "r")
def main():
for filename in sys.argv[1:]:
filename = Path(filename)
print(filename)
Header, highres_names, original_data = read_file(filename)
boundaries = Header['BoxSize'] # BoxLength for e5 boxes depends on Nres, 2.36438 for 256, 4.72876 for 512.
print(boundaries, len(highres_names))
if not boundaries.shape:
boundaries = np.array([boundaries] * 3)
@ -122,7 +137,6 @@ def read_file(filename):
# assumes cube form and 0.1 as desired ratio to move
minimum = 0.0
maximum = max(boundaries)
ratio = 0.1
box_length = maximum - minimum
range_to_move = 0.1 * box_length
upper_limit_bottom = minimum + range_to_move
@ -130,27 +144,7 @@ def read_file(filename):
print("Find candidates to move...")
@numba.njit()
def find_move_candidates():
move_candidates = []
print("finding move candidates")
for particle in original_data:
point = particle[0:3]
if (
minimum <= point[0] <= upper_limit_bottom or
lower_limit_top <= point[0] <= maximum or
minimum <= point[1] <= upper_limit_bottom or
lower_limit_top <= point[1] <= maximum or
minimum <= point[2] <= upper_limit_bottom or
lower_limit_top <= point[2] <= maximum
):
move_candidates.append(particle)
# print(point)
return move_candidates
move_candidates = find_move_candidates()
move_candidates = find_move_candidates(original_data, minimum, maximum, lower_limit_top, upper_limit_bottom)
move_candidates = np.array(move_candidates)
print("...done.")
@ -159,7 +153,10 @@ def read_file(filename):
for z in offsets:
if (x, y, z) == (0, 0, 0):
continue
moved_coordinates = find_coordinates_to_move(minimum, maximum, ratio, x, y, z, move_candidates)
moved_coordinates = find_coordinates_to_move(
minimum, maximum, lower_limit_top, upper_limit_bottom,
x, y, z, move_candidates
)
# print(moved_coordinates)
moved_coordinates = np.array(moved_coordinates)
# if not moved_coordinates:
@ -225,9 +222,12 @@ def read_file(filename):
# all_data = all_data[sorted_index, :]
# np.savetxt("out_"+filename.with_suffix(".csv").name, all_data[indices], delimiter=",", fmt="%.3f", header="x,y,z,vx,vy,vz,v,name") #if indices are needed
np.savetxt(directory / f"out_{filename.with_suffix('.csv').name}",
np.savetxt(f"out_{filename.with_suffix('.csv').name}",
export_data,
delimiter=",",
fmt="%.3f",
header="num,x,y,z,name,vx,vy,vz,masse,groupid,v,density,density_alt")
file.close()
if __name__ == '__main__':
main()