@@ -132,15 +132,23 @@ def extract_halo(self, halo_index: int, filenames: Union[Dict[str, str], None] =
132132 unbound_particles_filename = filenames ["unbound_particles_filename" ]
133133 unbound_parttypes_filename = filenames ["unbound_parttypes_filename" ]
134134
135- number_of_particles = self .offset [halo_index + 1 ] - self .offset [halo_index ]
136- number_of_unbound_particles = (
137- self .offset_unbound [halo_index + 1 ] - self .offset_unbound [halo_index ]
138- )
135+ if halo_index == self .offset .size - 1 : # last halo in catalog
136+ with h5py .File (particles_filename ) as particles_file :
137+ total_particles = particles_file ['Total_num_of_particles_in_all_groups' ][0 ]
138+ number_of_particles = total_particles - self .offset [halo_index ]
139+ with h5py .File (unbound_particles_filename ) as unbound_particles_file :
140+ total_unbound_particles = unbound_particles_file ['Total_num_of_particles_in_all_groups' ][0 ]
141+ number_of_unbound_particles = total_unbound_particles - self .offset_unbound [halo_index ]
142+ else :
143+ number_of_particles = self .offset [halo_index + 1 ] - self .offset [halo_index ]
144+ number_of_unbound_particles = (
145+ self .offset_unbound [halo_index + 1 ] - self .offset_unbound [halo_index ]
146+ )
139147 assert (
140148 number_of_particles + number_of_unbound_particles
141149 == self .group_size [halo_index ]
142150 ), "Something is incorrect in the calculation of group sizes for halo {}. Group_Size: {}, Bound: {}, Unbound: {}" .format (
143- halo_index , number_of_particles , number_of_unbound_particles
151+ halo_index , self . group_size [ halo_index ], number_of_particles , number_of_unbound_particles
144152 )
145153
146154 particles = VelociraptorParticles (
0 commit comments