Unverified Commit 6aa28072 authored by Akke Viitanen's avatar Akke Viitanen
Browse files

add more MBH tests

parent ec42037b
Loading
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -361,8 +361,11 @@ def create_directory(filename: str) -> None:
    """
    Create a directory corresponding to the filename.

    If 'filename' is a directory, then create that directory. If 'filename' is
    an ordinary file, then create the directory that would contain the file.
    Parameters
    ----------
    filename: str
        Filename to create. If filename ends with '/', then a directory is
        created. Otherwise the directory containing 'filename' is created.

    Examples
    --------
+1 −1
Original line number Diff line number Diff line
@@ -39,6 +39,6 @@ class TestKelly2013(TestCase):
        for ax in axes.flatten()[:-2]:
            ax.set_xlim(8.0, 11.0)
            ax.set_ylim(-10.5, -3.0)
        savefig = "data/tests/kelly2013/fig4.pdf"
        savefig = "data/tests/test_kelly2013/fig4.pdf"
        util.create_directory(savefig)
        fig.savefig(savefig, bbox_inches="tight")
+21 −2
Original line number Diff line number Diff line
@@ -6,10 +6,13 @@ import unittest

import matplotlib.pyplot as plt
import numpy as np
from lsst_inaf_agile import mbh
from lsst_inaf_agile import mbh, util


class TestMBH(unittest.TestCase):
    def setUp(self):
        self.dirname = "data/tests/test_mbh/"

    def test_get_occupation_fraction(self):
        logMstar = np.array([8.0, 9.0, 10.0])
        test = mbh.get_occupation_fraction(logMstar)
@@ -25,7 +28,23 @@ class TestMBH(unittest.TestCase):
        ax.set_xlabel(r"$\log (M_\mathrm{star}\,/\,M_\odot)$")
        ax.set_ylabel(r"$f_\mathrm{occ}$")
        ax.legend()
        fig.savefig("data/tests/focc.pdf")
        util.create_directory(self.dirname)
        fig.savefig(f"{self.dirname}/focc.pdf")

    def test_graham2023(self):
        for row in mbh.GRAHAM2023_ROWS:
            log_mstar = np.linspace(9, 12)
            log_mbh = mbh.get_log_mbh_graham2023(log_mstar, which=row)
            plt.plot(log_mstar, log_mbh, label=row)
        plt.xlabel(r"$\log M_\mathrm{star}$")
        plt.ylabel(r"$\log M_\mathrm{BH}$")
        log_mbh_kh13 = mbh.get_log_mbh_kormendy_ho2013(log_mstar)
        plt.plot(log_mstar, log_mbh_kh13, color="k", lw=2, label="KH13")
        log_mbh_kh13 = mbh.get_log_mbh_kormendy_ho2013(log_mstar, from_rv15=True)
        plt.plot(log_mstar, log_mbh_kh13, color="k", lw=2, label="KH13 (RV15)")
        plt.legend(loc="upper left")
        util.create_directory(self.dirname)
        plt.savefig(f"{self.dirname}/graham2023.pdf")


if __name__ == "__main__":