From 871a45b2978a13beb16557d6e34172c2feb5e14a Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Wed, 19 Jul 2017 23:59:26 +0800 Subject: clusters/mergertree.py: Add function "show_mtree()" This function traces the main cluster and print its formation history to the screen, for easier illustration and examination. Signed-off-by: Aaron LI --- fg21sim/extragalactic/clusters/mergertree.py | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'fg21sim/extragalactic/clusters') diff --git a/fg21sim/extragalactic/clusters/mergertree.py b/fg21sim/extragalactic/clusters/mergertree.py index 22d1d3b..3ea6165 100644 --- a/fg21sim/extragalactic/clusters/mergertree.py +++ b/fg21sim/extragalactic/clusters/mergertree.py @@ -69,6 +69,38 @@ def read_mtree(infile): return mtree +def show_mtree(mtree): + """ + Trace the main cluster and show its formation history. + """ + def _show_event(main, sub=None, parent=None): + z = main.data["z"] + age = main.data["age"] + mass = main.data["mass"] + info = "[z=%.3f/t=%.2f]" % (z, age) + if sub is None: + # Accretion + info += " %.5g" % mass + if parent is not None: + dM = parent.data["mass"] - mass + info += " (dM=%.5g)" % dM + else: + # Merger + Msub = sub.data["mass"] + Rmass = mass / Msub + info += " %.5g <> %.5g (Rm=%.1f)" % (mass, Msub, Rmass) + return info + + i = 0 + info = _show_event(main=mtree) + print("%2d %s" % (i, info)) + while mtree and mtree.main: + i += 1 + info = _show_event(main=mtree.main, sub=mtree.sub, parent=mtree) + print("%2d %s" % (i, info)) + mtree = mtree.main + + def plot_mtree(mtree, outfile, figsize=(12, 8)): """ Plot the cluster merger tree. -- cgit v1.2.2