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

simplify particle ID remapping

This commit is contained in:
Lukas Winkler 2022-05-03 11:07:22 +02:00
parent d70929ffb2
commit 5efb6bf2ea

View file

@ -1,19 +1,14 @@
import numpy as np
def get_highres_ID_from_lowres(particle_ID: int, Nres_low: int, Nres_high: int):
particle_k = particle_ID % Nres_low
particle_j = ((particle_ID - particle_k) // Nres_low) % Nres_low
particle_i = ((particle_ID - particle_k) // Nres_low - particle_j) // Nres_low
highres_ID = ((particle_i * Nres_high) + particle_j) * Nres_high + particle_k
return highres_ID
def get_lowres_ID_from_highres(particle_ID: int, Nres_low: int, Nres_high: int):
particle_k = particle_ID % Nres_high
particle_j = ((particle_ID - particle_k) // Nres_high) % Nres_high
particle_i = ((particle_ID - particle_k) // Nres_high - particle_j) // Nres_high
lowres_ID = ((particle_i * Nres_low) + particle_j) * Nres_low + particle_k
def convert_ID_between_resolutions(particle_ID: int, Nres_from: int, Nres_to: int):
particle_k = particle_ID % Nres_from
particle_j = ((particle_ID - particle_k) // Nres_from) % Nres_from
particle_i = ((particle_ID - particle_k) // Nres_from - particle_j) // Nres_from
lowres_ID = ((particle_i * Nres_to) + particle_j) * Nres_to + particle_k
return lowres_ID
if __name__ == "__main__":
test_particle = np.array([0, 127, 127])
# maximum_test = np.array([127, 127, 127]) #this works, Nres - 1 is the maximum for (i,j,k)
@ -26,7 +21,7 @@ if __name__ == "__main__":
print(particle_ID_1, particle_ID_2)
particle_ID_1_converted = get_highres_ID_from_lowres(particle_ID_1, Nres_1, Nres_2)
particle_ID_1_converted_converted = get_lowres_ID_from_highres(particle_ID_1_converted, Nres_1, Nres_2)
particle_ID_1_converted = convert_ID_between_resolutions(particle_ID_1, Nres_1, Nres_2)
particle_ID_1_converted_converted = convert_ID_between_resolutions(particle_ID_1_converted, Nres_2, Nres_1)
print(particle_ID_1, particle_ID_1_converted, particle_ID_1_converted_converted)