Skip to content
Snippets Groups Projects
Commit c4bf98ea authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Correctly read the number of particles when >2^32 in the IC combination...

Correctly read the number of particles when >2^32 in the IC combination script. Also add an option to specify the compression level.
parent 247b1220
Branches
Tags
No related merge requests found
#!/usr/bin/env python #!/usr/bin/env python
""" """
Usage: Usage:
combine_ics.py input_file.0.hdf5 merged_file.hdf5 combine_ics.py input_file.0.hdf5 merged_file.hdf5 gzip_level
This file combines Gadget-2 type 2 (i.e. hdf5) initial condition files This file combines Gadget-2 type 2 (i.e. hdf5) initial condition files
into a single file that can be digested by SWIFT. into a single file that can be digested by SWIFT.
...@@ -11,6 +11,9 @@ the DM particles is handled. No unit conversions are applied nor are ...@@ -11,6 +11,9 @@ the DM particles is handled. No unit conversions are applied nor are
any scale-factors or h-factors changed. any scale-factors or h-factors changed.
The script applies some compression and checksum filters to the output The script applies some compression and checksum filters to the output
to save disk space. to save disk space.
The last argument `gzip_level` is used to specify the level of compression
to apply to all the fields in the file. Use 0 to cancel all coompression.
The default value is `4`.
This file is part of SWIFT. This file is part of SWIFT.
Copyright (C) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk) Copyright (C) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk)
...@@ -35,6 +38,11 @@ import sys ...@@ -35,6 +38,11 @@ import sys
import h5py as h5 import h5py as h5
import numpy as np import numpy as np
# Store the compression level
gzip_level = 4
if sys.argc > 3:
gzip_level = sys.argv[3]
# First, we need to collect some information from the master file # First, we need to collect some information from the master file
main_file_name = str(sys.argv[1])[:-7] main_file_name = str(sys.argv[1])[:-7]
print("Merging snapshots files with name", main_file_name) print("Merging snapshots files with name", main_file_name)
...@@ -45,19 +53,19 @@ grp_header = master_file["/Header"] ...@@ -45,19 +53,19 @@ grp_header = master_file["/Header"]
num_files = grp_header.attrs["NumFilesPerSnapshot"] num_files = grp_header.attrs["NumFilesPerSnapshot"]
tot_num_parts = grp_header.attrs["NumPart_Total"] tot_num_parts = grp_header.attrs["NumPart_Total"]
tot_num_parts_high_word = grp_header.attrs["NumPart_Total"] tot_num_parts_high_word = grp_header.attrs["NumPart_Total_HighWord"]
entropy_flag = grp_header.attrs["Flag_Entropy_ICs"] entropy_flag = grp_header.attrs["Flag_Entropy_ICs"]
box_size = grp_header.attrs["BoxSize"] box_size = grp_header.attrs["BoxSize"]
time = grp_header.attrs["Time"] time = grp_header.attrs["Time"]
# Combine the low- and high-words # Combine the low- and high-words
tot_num_parts = tot_num_parts.astype(np.int64)
for i in range(6): for i in range(6):
tot_num_parts[i] += np.int64(tot_num_parts_high_word[i]) << 32 tot_num_parts[i] += (np.int64(tot_num_parts_high_word[i]) << 32)
# Some basic information # Some basic information
print("Reading", tot_num_parts, "particles from", num_files, "files.") print("Reading", tot_num_parts, "particles from", num_files, "files.")
# Check whether there is a mass table # Check whether there is a mass table
DM_mass = 0.0 DM_mass = 0.0
mtable = grp_header.attrs.get("MassTable") mtable = grp_header.attrs.get("MassTable")
...@@ -105,7 +113,7 @@ def create_set(grp, name, size, dim, dtype): ...@@ -105,7 +113,7 @@ def create_set(grp, name, size, dim, dtype):
dtype=dtype, dtype=dtype,
chunks=True, chunks=True,
compression="gzip", compression="gzip",
compression_opts=4, compression_opts=gzip_level,
shuffle=True, shuffle=True,
fletcher32=True, fletcher32=True,
maxshape=(size,), maxshape=(size,),
...@@ -117,7 +125,7 @@ def create_set(grp, name, size, dim, dtype): ...@@ -117,7 +125,7 @@ def create_set(grp, name, size, dim, dtype):
dtype=dtype, dtype=dtype,
chunks=True, chunks=True,
compression="gzip", compression="gzip",
compression_opts=4, compression_opts=gzip_level,
shuffle=True, shuffle=True,
fletcher32=True, fletcher32=True,
maxshape=(size, dim), maxshape=(size, dim),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment