Skip to content

Commit

Permalink
Add safety iteration limiter to BH halo assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
apontzen committed Mar 13, 2024
1 parent 6bb32e3 commit 541e5de
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tangos/tools/changa_bh_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,17 @@ def _get_bh_halo_assignments(self, pynbody_snapshot):
if 'hostHalo' in pynbody_halos.get_dummy_halo(0).properties:
bh_halos = bh_cen_halos
continue_searching = True
iteration_count = 0

# recursively substitute the halos with their parents
while continue_searching:
if iteration_count > 10:
logger.warn("BH halo assignment did not converge after 10 iterations, suggesting a problem with the parent/child relationships")
logger.warn("Check the BH assignment to halos carefully")
break

iteration_count += 1

# find the parent halos of the bh_cen_halos
bh_halos_new = [pynbody_halos.get_dummy_halo(i).properties['hostHalo'] for i in bh_halos]

Expand All @@ -194,6 +203,7 @@ def _get_bh_halo_assignments(self, pynbody_snapshot):

# but if the parent is -1, record the original halo number
bh_halos = [bh_halos_new[i] if bh_halos_new[i] != -1 else bh_halos[i] for i in range(len(bh_halos))]

else:
bh_halos = None

Expand Down

0 comments on commit 541e5de

Please sign in to comment.