From 6ce9fd6c5ad0c2a031031619615d8eaa51ea3f32 Mon Sep 17 00:00:00 2001
From: jlanzer <jlanzer@anl.gov>
Date: Wed, 13 Jul 2022 11:04:13 -0500
Subject: [PATCH] added Tully Fisher Module

---
 .../analysis/modules/TullyFisher/__init__.py  |  3 +
 .../TullyFisher/data/Schaye2014/Reese2008.txt | 17 ++++
 .../data/Schaye2014/Ref-L100N1504.txt         | 22 +++++
 .../data/Vogelsberger/BellAndDeJong.txt       | 26 ++++++
 .../TullyFisher/data/Vogelsberger/L25n512.txt | 49 ++++++++++
 .../TullyFisher/data/Vogelsberger/Reyes.txt   | 23 +++++
 .../modules/TullyFisher/tully_fisher.py       | 90 +++++++++++++++++++
 7 files changed, 230 insertions(+)
 create mode 100644 havocc/analysis/modules/TullyFisher/__init__.py
 create mode 100644 havocc/analysis/modules/TullyFisher/data/Schaye2014/Reese2008.txt
 create mode 100644 havocc/analysis/modules/TullyFisher/data/Schaye2014/Ref-L100N1504.txt
 create mode 100644 havocc/analysis/modules/TullyFisher/data/Vogelsberger/BellAndDeJong.txt
 create mode 100644 havocc/analysis/modules/TullyFisher/data/Vogelsberger/L25n512.txt
 create mode 100644 havocc/analysis/modules/TullyFisher/data/Vogelsberger/Reyes.txt
 create mode 100644 havocc/analysis/modules/TullyFisher/tully_fisher.py

diff --git a/havocc/analysis/modules/TullyFisher/__init__.py b/havocc/analysis/modules/TullyFisher/__init__.py
new file mode 100644
index 00000000..769138a6
--- /dev/null
+++ b/havocc/analysis/modules/TullyFisher/__init__.py
@@ -0,0 +1,3 @@
+from .tully_fisher import TullyFisher
+
+__all__ = ["TullyFisher"]
diff --git a/havocc/analysis/modules/TullyFisher/data/Schaye2014/Reese2008.txt b/havocc/analysis/modules/TullyFisher/data/Schaye2014/Reese2008.txt
new file mode 100644
index 00000000..5f939426
--- /dev/null
+++ b/havocc/analysis/modules/TullyFisher/data/Schaye2014/Reese2008.txt
@@ -0,0 +1,17 @@
+#Extracted from The Eagle Project (Schaye 2014) fig.12
+#<Reese 2008>
+# units: log10 Mstar, km/s
+8.708461329170868 1.818812438489958
+8.856657274660304 1.855570861875082
+8.99869400739628 1.8883433758673764
+9.173917107909922 1.930124175116191
+9.397751802080302 1.9876876635783847
+9.617769485361475 2.0405783744512704
+9.842938164537822 2.097497824517404
+10.073378433364887 2.1506193784504273
+10.289351647217668 2.2078455663608905
+10.489706509425313 2.2552849541515014
+10.704279268617258 2.309512709117472
+10.912713625943931 2.359136591640992
+11.135939230100384 2.4188844494091213
+11.429666125434196 2.49258263642527
\ No newline at end of file
diff --git a/havocc/analysis/modules/TullyFisher/data/Schaye2014/Ref-L100N1504.txt b/havocc/analysis/modules/TullyFisher/data/Schaye2014/Ref-L100N1504.txt
new file mode 100644
index 00000000..856db137
--- /dev/null
+++ b/havocc/analysis/modules/TullyFisher/data/Schaye2014/Ref-L100N1504.txt
@@ -0,0 +1,22 @@
+#Extracted from The Eagle Project (Schaye 2014) fig.12
+# <Ref-L100N1594>
+# units: log10 Mstar, km/s
+8.226861988272178 1.7529374237137998
+8.378972649487482 1.7783288881799344
+8.546247845316739 1.8086059595894721
+8.742114555644765 1.8417001922848482
+8.92954547457045 1.8742277268357384
+9.077126369105349 1.9025653361784456
+9.227146371038685 1.936167851922929
+9.397751802080302 1.9703638448231704
+9.571511644239992 2.0101851407952185
+9.739088822348766 2.050811230063215
+9.900049247988594 2.0948764630263463
+10.073378433364887 2.1465890126048133
+10.509955326351825 2.2836652344242685
+10.735288747933918 2.365044356703857
+10.88119164498767 2.431014390421281
+11.00782852835466 2.49258263642527
+11.103772449556745 2.5429580384915758
+
+
diff --git a/havocc/analysis/modules/TullyFisher/data/Vogelsberger/BellAndDeJong.txt b/havocc/analysis/modules/TullyFisher/data/Vogelsberger/BellAndDeJong.txt
new file mode 100644
index 00000000..272252fa
--- /dev/null
+++ b/havocc/analysis/modules/TullyFisher/data/Vogelsberger/BellAndDeJong.txt
@@ -0,0 +1,26 @@
+#Extracted from Vogelsberger 2013 fig. 10
+#<Bell and De Jong 2001>
+#units: log10 Mstar, km/s 
+8.711047015192714 1.7734796693280057
+8.770937002580618 1.7907032238375735
+8.841329264638176 1.80809404884653
+8.922469593748664 1.822715350609696
+9.004354579325513 1.844869294924799
+9.107768401592368 1.8687970409617705
+9.19135394664418 1.8869462919844904
+9.275706588863327 1.9068069393382143
+9.360833368199883 1.929982963361724
+9.446741389212292 1.9518679975028599
+9.517121853718468 1.9660678182441416
+9.58255374804693 1.985161736726932
+9.676019731984995 2.0076724703493007
+9.753675849734735 2.0271704419519425
+10.001818659845174 2.086807884769456
+10.11668822524517 2.1138735469451326
+10.209533021263312 2.137843807627826
+10.291470917260808 2.1586059680238185
+10.374066416185542 2.1795697649017525
+10.469273272307285 2.204284987586815
+10.565353878903423 2.2256924067385153
+10.637992553617577 2.2436906520906703
+10.735621562903297 2.2673061354784645
diff --git a/havocc/analysis/modules/TullyFisher/data/Vogelsberger/L25n512.txt b/havocc/analysis/modules/TullyFisher/data/Vogelsberger/L25n512.txt
new file mode 100644
index 00000000..625e824f
--- /dev/null
+++ b/havocc/analysis/modules/TullyFisher/data/Vogelsberger/L25n512.txt
@@ -0,0 +1,49 @@
+#Extracted from Vogelsberger 2013 fig. 10
+#<L25n512>
+#units: log10 Mstar, km/s 
+6.35610693074021 1.292293983755277
+6.403461435304848 1.314337123430209
+6.454853223354038 1.337833326517612
+6.525259562536368 1.3694485803207757
+6.60774265661763 1.3950531344686177
+6.702739765122398 1.4097364661888063
+6.7758499278208575 1.4177067855577898
+6.8536696686995 1.4360942821750506
+6.9403040584379365 1.458239434241046
+7.044103110720833 1.4878989058097187
+7.1494545796074 1.51206023833202
+7.272973352751863 1.5366139160512786
+7.398626119077099 1.5603091213452807
+7.517859885263732 1.5767318194122442
+7.604201512434529 1.5907628857873202
+7.717929802104956 1.60880133520724
+7.833359009859974 1.6218110399922625
+7.92332410277825 1.6336096995704639
+8.014322432898293 1.6481469124581858
+8.115628151834839 1.664153269157643
+8.265272260060735 1.6898151826295105
+8.408068647939006 1.7172553443026757
+8.563105067940393 1.7437361131545155
+8.706074680769028 1.7706252261243753
+8.831238744213803 1.7950351852922057
+8.927565518643874 1.8168526948256123
+9.024942977778645 1.8389353822932124
+9.154691294543182 1.8703027878484644
+9.296915431929582 1.9098809224873998
+9.441349114630452 1.9455899298926318
+9.631922717907472 1.9899641205112655
+9.815128342011306 2.038631588219515
+10.001818659845174 2.093541637236433
+10.134032078071453 2.137843807627826
+10.279725364711055 2.1901278882303834
+10.421561123752614 2.238275949637697
+10.553295746476186 2.283800765612568
+10.698906126081262 2.335888725645269
+10.821781648899155 2.4007381145581643
+10.97109649534659 2.453516259060047
+11.122471531519981 2.4913504676685414
+11.192548044869119 2.5256963937805597
+11.288818999050838 2.5687781376286534
+11.379418840899858 2.6104913901331885
+11.516683776348124 2.665732915935183
+11.609112375730401 2.698133201892511
\ No newline at end of file
diff --git a/havocc/analysis/modules/TullyFisher/data/Vogelsberger/Reyes.txt b/havocc/analysis/modules/TullyFisher/data/Vogelsberger/Reyes.txt
new file mode 100644
index 00000000..a7644461
--- /dev/null
+++ b/havocc/analysis/modules/TullyFisher/data/Vogelsberger/Reyes.txt
@@ -0,0 +1,23 @@
+#Extracted from Vogelsberger 2013 fig. 10
+#<Reyes+ 2011>
+#units: log10 Mstar, km/s 
+8.706074680769028 1.7117318943719682
+8.796012526664192 1.7353299460835374
+8.881806771826009 1.7592533221326463
+8.968437833952397 1.7835065074626235
+9.055913875159947 1.8095508854773816
+9.144243137176634 1.8359755870981023
+9.233433942118301 1.861286470763921
+9.323494693272778 1.8869462919844906
+9.414433875891573 1.9129598612365497
+9.506260057989369 1.940894634417717
+9.598981891151244 1.9692373364679086
+9.692608111347816 1.9963853756270276
+9.78714753975831 2.0239076794908297
+9.88260908360167 2.0518094076978572
+10.186242244315505 2.137843807627826
+10.279725364711055 2.169062539956189
+10.385919762254904 2.198965382890768
+10.48123540115945 2.229280468441269
+10.595559521192722 2.263656870871209
+10.692799105979807 2.2930162443889195
diff --git a/havocc/analysis/modules/TullyFisher/tully_fisher.py b/havocc/analysis/modules/TullyFisher/tully_fisher.py
new file mode 100644
index 00000000..4c315132
--- /dev/null
+++ b/havocc/analysis/modules/TullyFisher/tully_fisher.py
@@ -0,0 +1,90 @@
+from pathlib import Path
+from typing import List, Mapping, Tuple
+import numpy as np
+from matplotlib.axes import Axes
+from matplotlib.figure import Figure
+
+from ...binned_median_stats_template import BinnedMedianStatsTemplateStep
+from ....data_provider import DataProvider
+from ...analysis_template import DataProviderRequirement, register_analysis_module
+from .... import global_state
+
+
+@register_analysis_module
+class TullyFisher(BinnedMedianStatsTemplateStep):
+    # this will contain the information for plotting (x,y) and how to get the x and y
+
+    analysis_name = "Halo Mass VS cirular velocty"
+    x_quantity: str = "log_stellar_mass"
+    y_quantity: str = "max_cir_vel"
+    x_default_range: Tuple[float] = [9.0, 12.0]
+    x_is_log: bool = True
+
+    @staticmethod
+    def default_config() -> dict:
+        # gets raw data, quantiles, average and bins
+        default_dict = super(TullyFisher, TullyFisher).default_config()
+        return default_dict
+
+    @property
+    def data_provider_requirements(self) -> List[DataProviderRequirement]:
+        return [
+            DataProviderRequirement(
+                "GalaxyProperties",
+                {"variables_galaxy_properties": ["gal_mass_star", "gal_max_cir_vel"]},
+            ),
+        ]
+
+    def _prepare_rawdata_step(
+        self, step: int, *, data_providers: List[DataProvider], **kwargs
+    ) -> Mapping[str, np.ndarray]:
+        # Read, filter, and sort catalogs
+        galdata = data_providers["GalaxyProperties"].data["catalog"]
+
+        stellar_mass = galdata["gal_mass_star"]
+        max_cir_vel = galdata["gal_max_cir_vel"]
+
+        mask = (stellar_mass > 0) & (max_cir_vel > 0)
+        h = global_state.cosmology.hubble
+        return {
+            "log_stellar_mass": np.log10(stellar_mass[mask] / h),
+            "max_cir_vel": max_cir_vel[mask],
+        }
+
+    def decorate_step(self, step: int, plot: Tuple[Figure, Axes], **kwargs) -> None:
+        super().decorate_step(step, plot, **kwargs)
+        fig, ax = plot
+
+        data = np.loadtxt(Path(__file__).parent / "data/Schaye2014/Ref-L100N1504.txt")
+        ref_x = 10 ** data[:, 0]  # in Msun
+        ref_y = 10 ** data[:, 1]
+        ax.plot(ref_x, ref_y, color="tab:green", label="EAGLE Ref-L100N1504")
+
+        data2 = np.loadtxt(Path(__file__).parent / "data/Schaye2014/Reese2008.txt")
+        reese_x = 10 ** data2[:, 0]  # in Msun
+        reese_y = 10 ** data2[:, 1]
+        ax.plot(reese_x, reese_y, color="blue", label="Reese+ 2008")
+
+        reyes = np.loadtxt(Path(__file__).parent / "data/Vogelsberger/Reyes.txt")
+        reyes_x = 10 ** reyes[:, 0]
+        reyes_y = 10 ** reyes[:, 1]
+        ax.plot(reyes_x, reyes_y, color="black", label="Reyes+ 2011")
+
+        bell = np.loadtxt(Path(__file__).parent / "data/Vogelsberger/BellAndDeJong.txt")
+        bell_x = 10 ** bell[:, 0]
+        bell_y = 10 ** bell[:, 1]
+        ax.plot(bell_x, bell_y, color="purple", label=r"Bell \& De Jong 2001")
+
+        L25n512 = np.loadtxt(Path(__file__).parent / "data/Vogelsberger/L25n512.txt")
+        n512_x = 10 ** L25n512[:, 0]
+        n512_y = 10 ** L25n512[:, 1]
+        ax.plot(n512_x, n512_y, color="yellow", label="Vogelsberger+ 2013 L25n512")
+
+        ax.set(
+            xlabel=r"$M_\mathrm{star}\quad[M_\odot]$",
+            xscale="log",
+            xlim=10 ** np.array(self.config["log_stellar_mass_range"]),
+            ylabel=r"$\log_{10} v_\mathrm{cir} \quad[km s^{-1}]$",
+            yscale="log",
+        )
+        ax.legend()
-- 
GitLab