Skip to content

Commit d4ce2fd

Browse files
committed
Various fixes
1 parent 2c7a7cb commit d4ce2fd

5 files changed

Lines changed: 138 additions & 61 deletions

File tree

SOAP/catalogue_readers/read_subfind_eagle.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def read_subfind_catalogue(comm, basename, a_unit, registry, boxsize):
117117
)
118118

119119
# Store initial search radius
120-
search_radius = (5 * data["Subhalo/VmaxRadius"] / h) * swift_cmpc
120+
search_radius_cmpc = np.minimum((5 * data["Subhalo/VmaxRadius"] / h), 5)
121+
search_radius = search_radius_cmpc * swift_cmpc
121122

122123
local_halo = {
123124
"cofp": cofp,

SOAP/compression/make_virtual_snapshot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,5 @@ def replace_path(old_path):
360360
absolute_paths=args.absolute_paths,
361361
discard_duplicate_datasets=args.discard_duplicate_datasets,
362362
)
363+
364+
print(f"Done!")

misc/convert_eagle.py

Lines changed: 78 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
99
mpirun -- python convert_eagle.py \
1010
--snapshot-basename=SNAPSHOT \
11+
--particledata-basename=PARTICLE_DATA \
12+
--subfind-basename=SUBFIND \
1113
--output-basename=OUTPUT \
1214
--membership-basename=MEMBERSHIP
1315
14-
where SNAPSHOT is the EAGLE snapshot (use the particledata_*** files,
15-
since the normal snapshots don't store SubGroupNumber), and OUTPUT &
16+
where SNAPSHOT is the EAGLE snapshot (the snapshots_*** files),
17+
PARTICLE_DATA are the EAGLE membership files (the particledata_*** files,
18+
since the normal snapshots don't store SubGroupNumber), SUBFIND are
19+
the SubFind catalogues (the subfind_tab_*** files), and OUTPUT &
1620
MEMBERSHIP are the names of the output files. You must run with
1721
the same number of ranks as input files.
1822
@@ -82,11 +86,21 @@
8286
"name without the .{file_nr}.hdf5 suffix)"
8387
),
8488
)
89+
parser.add_argument(
90+
"--particledata-basename",
91+
type=str,
92+
required=True,
93+
help=(
94+
"The basename for the particle data files (the files which "
95+
"contain the GroupNumber and SubGroupNumber values for bound "
96+
"particles. For EAGLE these are separate to the snapshots."
97+
),
98+
)
8599
parser.add_argument(
86100
"--subfind-basename",
87101
type=str,
88102
required=True,
89-
help=("The basename for the subfind files"),
103+
help="The basename for the subfind files",
90104
)
91105
parser.add_argument(
92106
"--output-basename",
@@ -102,6 +116,7 @@
102116
)
103117
args = parser.parse_args()
104118
snap_filename = args.snap_basename + ".{file_nr}.hdf5"
119+
particledata_filename = args.particledata_basename + ".{file_nr}.hdf5"
105120
subfind_filename = args.subfind_basename + ".{file_nr}.hdf5"
106121
output_filename = args.output_basename + ".{file_nr}.hdf5"
107122
membership_filename = args.membership_basename + ".{file_nr}.hdf5"
@@ -132,7 +147,7 @@
132147
h = comm.bcast(h)
133148
box_size_cmpc = comm.bcast(box_size_cmpc)
134149

135-
assert comm_size == n_file
150+
assert comm_size <= n_file
136151

137152
# Specify the unit system of the output SWIFT snapshot
138153
if comm_rank == 0:
@@ -281,13 +296,6 @@
281296
"description": None,
282297
"conversion_factor": None,
283298
},
284-
"GroupNumber": {
285-
"swift_name": "FOFGroupIDs",
286-
"exponents": {"L": 0, "M": 0, "T": 0, "t": 0},
287-
"a_exponent": None,
288-
"description": None,
289-
"conversion_factor": None,
290-
},
291299
"ParticleIDs": {
292300
"swift_name": "ParticleIDs",
293301
"exponents": {"L": 0, "M": 0, "T": 0, "t": 0},
@@ -380,13 +388,6 @@
380388
"description": "Particle mass",
381389
"conversion_factor": None,
382390
},
383-
"GroupNumber": {
384-
"swift_name": "FOFGroupIDs",
385-
"exponents": {"L": 0, "M": 0, "T": 0, "t": 0},
386-
"a_exponent": None,
387-
"description": None,
388-
"conversion_factor": None,
389-
},
390391
"ParticleIDs": {
391392
"swift_name": "ParticleIDs",
392393
"exponents": {"L": 0, "M": 0, "T": 0, "t": 0},
@@ -417,13 +418,6 @@
417418
"description": None,
418419
"conversion_factor": None,
419420
},
420-
"GroupNumber": {
421-
"swift_name": "FOFGroupIDs",
422-
"exponents": {"L": 0, "M": 0, "T": 0, "t": 0},
423-
"a_exponent": None,
424-
"description": None,
425-
"conversion_factor": None,
426-
},
427421
"ParticleIDs": {
428422
"swift_name": "ParticleIDs",
429423
"exponents": {"L": 0, "M": 0, "T": 0, "t": 0},
@@ -506,13 +500,6 @@
506500
"description": None,
507501
"conversion_factor": None,
508502
},
509-
"GroupNumber": {
510-
"swift_name": "FOFGroupIDs",
511-
"exponents": {"L": 0, "M": 0, "T": 0, "t": 0},
512-
"a_exponent": None,
513-
"description": None,
514-
"conversion_factor": None,
515-
},
516503
"ParticleIDs": {
517504
"swift_name": "ParticleIDs",
518505
"exponents": {"L": 0, "M": 0, "T": 0, "t": 0},
@@ -607,6 +594,9 @@
607594
snap_file = phdf5.MultiFile(
608595
snap_filename, file_nr_attr=("Header", "NumFilesPerSnapshot"), comm=comm
609596
)
597+
particledata_file = phdf5.MultiFile(
598+
particledata_filename, file_nr_attr=("Header", "NumFilesPerSnapshot"), comm=comm
599+
)
610600
# Load the SubFind catalogue and create an array that links the GroupNumber
611601
# and SubGroupNumber of a subhalo to its index within the subhalo catalogue
612602
# (for creating the membership files)
@@ -656,6 +646,15 @@
656646
elements_per_file[1:] -= elements_per_file[:-1]
657647
assert np.sum(elements_per_file) == np.sum(cell_counts[ptype])
658648

649+
# Each rank writes the files assigned to it by MultiFile, so it
650+
# must hold the concatenation of the data of those files.
651+
elements_per_rank = np.zeros(comm_size, dtype=elements_per_file.dtype)
652+
for rank in range(comm_size):
653+
first = snap_file.first_file_on_rank[rank]
654+
num = snap_file.num_files_on_rank[rank]
655+
elements_per_rank[rank] = np.sum(elements_per_file[first : first + num])
656+
assert np.sum(elements_per_rank) == np.sum(elements_per_file)
657+
659658
# Calculate offsets of the first particle in each cell
660659
cell_files[ptype] = np.repeat(np.arange(n_file), cells_per_file)
661660
absolute_offset = np.cumsum(cell_counts[ptype]) - cell_counts[ptype]
@@ -703,7 +702,7 @@
703702
attrs.update(unit_attrs)
704703

705704
# Write to the output file
706-
arr = psort.repartition(arr, elements_per_file, comm=comm)
705+
arr = psort.repartition(arr, elements_per_rank, comm=comm)
707706
if create_output_file:
708707
mode = "w"
709708
create_output_file = False
@@ -750,7 +749,7 @@
750749
attrs.update(unit_attrs)
751750

752751
# Write to the output file
753-
arr = psort.repartition(arr, elements_per_file, comm=comm)
752+
arr = psort.repartition(arr, elements_per_rank, comm=comm)
754753
if create_output_file:
755754
mode = "w"
756755
create_output_file = False
@@ -765,44 +764,77 @@
765764
attrs={"ElementMassFractions": attrs},
766765
)
767766

767+
768+
# Load the GroupNumber and SubGroupNumber of particles by matching
769+
# the snapshot_* files with the particledata_* files
770+
snap_ids = snap_file.read(f"PartType{ptype}/ParticleIDs")
771+
particledata_ids = particledata_file.read(f"PartType{ptype}/ParticleIDs")
772+
idx = psort.parallel_match(snap_ids, particledata_ids, comm=comm)
773+
774+
# EAGLE uses a value of 2^30 to indicate unbound particles
775+
# Particles missing from the particledata_* files are always unbound
776+
particledata_sub_group_nr = particledata_file.read(f"PartType{ptype}/SubGroupNumber")
777+
sub_group_nr = 1073741824 * np.ones(snap_ids.shape[0], dtype=np.int32)
778+
sub_group_nr[idx != -1] = psort.fetch_elements(
779+
particledata_sub_group_nr,
780+
idx[idx != -1],
781+
comm=comm,
782+
)
783+
784+
# Negative values indicate that the particle is not part of a FoF,
785+
# but is within the SO group of a FoF (the FoF it is part of is the positive
786+
# value, e.g. -10 means it is within the SO of FoF 10)
787+
particledata_group_nr = particledata_file.read(f"PartType{ptype}/GroupNumber")
788+
particledata_group_nr[particledata_group_nr < 0] = 1073741824
789+
group_nr = 1073741824 * np.ones(snap_ids.shape[0], dtype=np.int32)
790+
group_nr[idx != -1] = psort.fetch_elements(
791+
particledata_group_nr,
792+
idx[idx != -1],
793+
comm=comm,
794+
)
795+
768796
# Create a subhalo id for each particle by combining the
769797
# group number and subgroup number
770-
sub_group = snap_file.read(f"PartType{ptype}/SubGroupNumber")
771-
subhalo = snap_file.read(f"PartType{ptype}/GroupNumber").astype(np.int64)
798+
subhalo = group_nr.astype(np.int64)
772799
subhalo <<= 32
773-
subhalo += sub_group.astype(np.int64)
774-
# Indicate unbound particles with -1
775-
bound = sub_group != 1073741824
800+
subhalo += sub_group_nr.astype(np.int64)
801+
# For SOAP we want unbound particles to be indicated with a value of -1
802+
bound = sub_group_nr != 1073741824
776803
subhalo[np.logical_not(bound)] = -1
777804
# Get SubFind index of bound particles
778805
subhalo[bound] = psort.parallel_match(subhalo[bound], subfind_id, comm=comm)
779806
assert np.all(subhalo[bound] != -1)
780807

781-
# Sort, add units, and write to file (same as for other properties)
808+
# Sort values spatially (same as for other properties)
782809
subhalo = psort.fetch_elements(subhalo, order, comm=comm)
810+
group_nr = psort.fetch_elements(group_nr, order, comm=comm)
811+
# Add units, and write to file
783812
units = unyt.Unit("dimensionless", registry=reg)
784813
unit_attrs = swift_units.attributes_from_units(units, False, 0)
785-
attrs = {
814+
subhalo_attrs = {
786815
"Description": (
787816
"Unique identifier of the subhalo this particle is "
788817
"bound to. This is a combination of the GroupNumber and"
789818
"the SubGroupNumber. -1 if the particle is not bound"
790819
)
791820
}
792-
attrs.update(unit_attrs)
793-
subhalo = psort.repartition(subhalo, elements_per_file, comm=comm)
821+
subhalo_attrs.update(unit_attrs)
822+
fof_attrs = {"Description": "FoF group number particle is in"}
823+
fof_attrs.update(unit_attrs)
824+
subhalo = psort.repartition(subhalo, elements_per_rank, comm=comm)
825+
group_nr = psort.repartition(group_nr, elements_per_rank, comm=comm)
794826
if create_membership_file:
795827
mode = "w"
796828
create_membership_file = False
797829
else:
798830
mode = "r+"
799831
snap_file.write(
800-
{"GroupNr_bound": subhalo},
832+
{"GroupNr_bound": subhalo, "FOFGroupIDs": group_nr},
801833
elements_per_file,
802834
filenames=membership_filename,
803835
mode=mode,
804836
group=f"PartType{ptype}",
805-
attrs={"GroupNr_bound": attrs},
837+
attrs={"GroupNr_bound": subhalo_attrs, "FOFGroupIDs": fof_attrs},
806838
)
807839

808840
# Add headers to the snapshots
@@ -813,7 +845,7 @@
813845
header = outfile.create_group("Header")
814846
for name, value in swift_header.items():
815847
header.attrs[name] = value
816-
n_part = np.zeros(max(ptypes) + 1)
848+
n_part = np.zeros(max(ptypes) + 1, dtype=np.int64)
817849
for ptype in ptypes:
818850
n_part[ptype] = outfile[f"PartType{ptype}/Coordinates"].shape[0]
819851
header.attrs["NumPart_ThisFile"] = n_part

parameter_files/EAGLE.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Parameters:
99
# Location of the Swift snapshots:
1010
Snapshots:
1111
# Use {snap_nr:04d} for the snapshot number and {file_nr} for the file number.
12-
filename: "{sim_dir}/{sim_name}/swift_snapshots/swift_{snap_nr:03d}/snap_{snap_nr:03d}.{file_nr}.hdf5"
12+
filename: "{sim_dir}/{sim_name}/snapshots/snap_{snap_nr:03d}/snap_{snap_nr:03d}.{file_nr}.hdf5"
1313

1414
# Which halo finder we're using, and base name for halo finder output files
1515
HaloFinder:

0 commit comments

Comments
 (0)