aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2019-01-29 15:59:17 +0800
committerAaron LI <aly@aaronly.me>2019-01-29 15:59:17 +0800
commitb60e1c2232d9f8e187ecb877b323154445b991f6 (patch)
treec276d99610e64cc643c0b2c39b1389027e4201aa
parente02dbad25018386e9ebe38e1495a95b46633ec70 (diff)
downloadfg21sim-b60e1c2232d9f8e187ecb877b323154445b991f6.tar.bz2
clusters/formation: Move history() to mergertree.get_history()
-rw-r--r--fg21sim/extragalactic/clusters/formation.py33
-rw-r--r--fg21sim/extragalactic/clusters/mergertree.py43
2 files changed, 46 insertions, 30 deletions
diff --git a/fg21sim/extragalactic/clusters/formation.py b/fg21sim/extragalactic/clusters/formation.py
index 65e32b6..dc39b62 100644
--- a/fg21sim/extragalactic/clusters/formation.py
+++ b/fg21sim/extragalactic/clusters/formation.py
@@ -17,14 +17,13 @@ References
"""
import logging
-import operator as op
import numpy as np
import scipy.integrate
import scipy.special
import scipy.optimize
-from .mergertree import MergerTree
+from .mergertree import MergerTree, get_history
from ...share import COSMO
@@ -256,14 +255,10 @@ class ClusterFormation:
def history(self, mtree=None, merger_only=False):
"""
- Extract and return all the formation events, e.g., merger and
- accretion.
+ Extract all the formation history (merger and accretion events).
Parameters
----------
- mtree : `~MergerTree`, optional
- The simulated merger tree from which to extract the history.
- Default: ``self.mtree``
merger_only : bool, optional
If ``True``, only extract the merger events.
@@ -275,29 +270,7 @@ class ClusterFormation:
"""
if mtree is None:
mtree = self.mtree
-
- evlist = []
- for main, sub in mtree.itermain():
- z, age, M_main = op.itemgetter("z", "age", "mass")(main)
- if sub:
- # merger
- M_sub = sub["mass"]
- R_mass = M_main / M_sub
- else:
- # accretion
- if merger_only:
- continue
- M_sub, R_mass = None, None
-
- evlist.append({
- "z": z,
- "age": age,
- "M_main": M_main,
- "M_sub": M_sub,
- "R_mass": R_mass,
- })
-
- return evlist
+ return get_history(mtree=mtree, merger_only=merger_only)
def mergers(self, mtree=None):
"""
diff --git a/fg21sim/extragalactic/clusters/mergertree.py b/fg21sim/extragalactic/clusters/mergertree.py
index 609dbee..1df7b2f 100644
--- a/fg21sim/extragalactic/clusters/mergertree.py
+++ b/fg21sim/extragalactic/clusters/mergertree.py
@@ -6,6 +6,7 @@ Merger tree that represents the merging history of a cluster using
the binary tree data structure.
"""
+import operator as op
import logging
from ...utils.io import pickle_dump, pickle_load
@@ -105,6 +106,48 @@ def read_mtree(infile):
return mtree
+def get_history(mtree, merger_only=False):
+ """
+ Extract all the formation history (merger and accretion events).
+
+ Parameters
+ ----------
+ mtree : `~MergerTree`
+ The simulated merger tree from which to extract the history.
+ Default: ``self.mtree``
+ merger_only : bool, optional
+ If ``True``, only extract the merger events.
+
+ Returns
+ -------
+ evlist : list[event]
+ List of events with each element being a dictionary of the
+ event properties.
+ """
+ evlist = []
+ for main, sub in mtree.itermain():
+ z, age, M_main = op.itemgetter("z", "age", "mass")(main)
+ if sub:
+ # merger
+ M_sub = sub["mass"]
+ R_mass = M_main / M_sub
+ else:
+ # accretion
+ if merger_only:
+ continue
+ M_sub, R_mass = None, None
+
+ evlist.append({
+ "z": z,
+ "age": age,
+ "M_main": M_main,
+ "M_sub": M_sub,
+ "R_mass": R_mass,
+ })
+
+ return evlist
+
+
def show_mtree(mtree):
"""
Trace the main cluster and show its formation history.