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

Make ID remapping functions importable without any side effects

This commit is contained in:
glatterf42 2022-05-03 11:00:07 +02:00
parent 805f2caf84
commit d70929ffb2

View file

@ -1,31 +1,32 @@
import numpy as np
test_particle = np.array([127, 0, 1])
# maximum_test = np.array([127, 127, 127]) #this works, Nres - 1 is the maximum for (i,j,k)
Nres_1 = 128
Nres_2 = 256
particle_ID_1 = ((test_particle[0] * Nres_1) + test_particle[1]) * Nres_1 + test_particle[2]
particle_ID_2 = ((test_particle[0] * Nres_2) + test_particle[1]) * Nres_2 + test_particle[2]
print(particle_ID_1, particle_ID_2)
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
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 int(highres_ID)
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
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
return int(lowres_ID)
return lowres_ID
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)
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)
print(particle_ID_1, particle_ID_1_converted, particle_ID_1_converted_converted)
Nres_1 = 128
Nres_2 = 256
particle_ID_1 = ((test_particle[0] * Nres_1) + test_particle[1]) * Nres_1 + test_particle[2]
particle_ID_2 = ((test_particle[0] * Nres_2) + test_particle[1]) * Nres_2 + test_particle[2]
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)
print(particle_ID_1, particle_ID_1_converted, particle_ID_1_converted_converted)