defined a main function for the scripts so they can be also used as modules

This commit is contained in:
Mayeul Aubin 2025-05-20 10:42:57 +02:00
parent a485db9465
commit a693da3db0
3 changed files with 356 additions and 153 deletions

View file

@ -58,6 +58,47 @@ def gather_density(A, folder, tile_base, Np_tile, dpm, buffer, N_TILES):
def gather_tiles(folder, tile_base, L, Np, N_TILES, buffer):
"""
Gather sCOLA tiles into a single density field.
Parameters
----------
folder : str
Folder containing the tiles.
tile_base : str
Base name of the tiles.
L : float
Size of the box in Mpc/h.
Np : int
Number of cells per dimension for the full box.
N_TILES : int
Number of tiles per dimension.
buffer : int
Buffer size for the density field of tiles.
"""
Np_tile = Np//N_TILES
dpm = L/Np_tile
print("Memory allocation for the grid...")
A=np.zeros((Np,Np,Np), dtype=np.float32)
print("Starting to read the tiles...")
gather_density(A, folder, tile_base, Np_tile, dpm, buffer, N_TILES)
print("Finished reading the tiles.")
A=density_to_delta(A,-1)
print("Converting to field...")
F=Field(L,L,L, 0.,0.,0., 1, Np,Np,Np, 1., A)
print("Saving field...")
F.write(folder+"../results/final_density_sCOLA.h5")
print("Density field saved to", folder+"../results/final_density_sCOLA.h5")
print("Done.")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Gather density from tiles.")
@ -80,17 +121,4 @@ if __name__ == "__main__":
Np_tile = Np//N_TILES
dpm = L/Np_tile
print("Memory allocation for the grid...")
A=np.zeros((Np,Np,Np), dtype=np.float32)
print("Starting to read the tiles...")
gather_density(A, folder, tile_base, Np_tile, dpm, buffer, N_TILES)
print("Finished reading the tiles.")
A=density_to_delta(A,-1)
print("Converting to field...")
F=Field(L,L,L, 0.,0.,0., 1, Np,Np,Np, 1., A)
print("Saving field...")
F.write(folder+"../results/final_density_sCOLA.h5")
gather_tiles(folder, tile_base, L, Np, N_TILES, buffer)