Skip to content

Commit 2fa5357

Browse files
committed
add another simple SFH (constant uniform disc)
1 parent 892fb90 commit 2fa5357

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

cogsworth/sfh.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,17 @@ def get_metallicity(self):
459459
return np.repeat(self.Z_all, self.size) * u.dimensionless_unscaled
460460

461461

462+
class ConstantUniformDisc(BurstUniformDisc):
463+
"""A simple star formation history, with all stars formed at a constant rate between ``t_burst``
464+
and the present day in a uniform disc with height ``z_max`` and radius ``R_max`` disc, all with
465+
metallicity ``Z``.
466+
467+
Based on :class:`BurstUniformDisc`.
468+
"""
469+
def draw_lookback_times(self, size=None, component=None):
470+
return np.random.uniform(0, self.t_burst.value, size) * self.t_burst.unit
471+
472+
462473
class Wagg2022(StarFormationHistory):
463474
"""A semi-empirical model defined in
464475
`Wagg+2022 <https://ui.adsabs.harvard.edu/abs/2021arXiv211113704W/abstract>`_

cogsworth/tests/test_sfh.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ def test_burst_uniform_disc(self):
5858
self.assertTrue(np.all(g.rho <= 20 * u.kpc))
5959
self.assertTrue(np.all(g.Z == 0.02))
6060

61+
def test_constant_uniform_disc(self):
62+
"""Ensure the constant uniform disc class works"""
63+
g = sfh.ConstantUniformDisc(size=10000,
64+
t_burst=5 * u.Gyr,
65+
R_max=20 * u.kpc,
66+
z_max=1 * u.kpc,
67+
Z=0.02)
68+
self.assertTrue(np.all(g.tau <= 5 * u.Gyr))
69+
self.assertTrue(np.all(g.z <= 1 * u.kpc))
70+
self.assertTrue(np.all(g.rho <= 20 * u.kpc))
71+
self.assertTrue(np.all(g.Z == 0.02))
72+
6173
def test_bad_inputs(self):
6274
"""Ensure the classes fail with bad input"""
6375
g = sfh.Wagg2022(size=None, immediately_sample=False)

0 commit comments

Comments
 (0)