Loading src/lsst_inaf_agile/util.py +5 −2 Original line number Diff line number Diff line Loading @@ -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 -------- Loading tests/lsst_inaf_agile/test_kelly2013.py +1 −1 Original line number Diff line number Diff line Loading @@ -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") tests/lsst_inaf_agile/test_mbh.py +21 −2 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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__": Loading Loading
src/lsst_inaf_agile/util.py +5 −2 Original line number Diff line number Diff line Loading @@ -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 -------- Loading
tests/lsst_inaf_agile/test_kelly2013.py +1 −1 Original line number Diff line number Diff line Loading @@ -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")
tests/lsst_inaf_agile/test_mbh.py +21 −2 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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__": Loading