Skip to content

Commit 75a3cff

Browse files
authored
Merge pull request #49 from xuanxu/new-imf
Add Kroupa 2001 IMF
2 parents 367550a + 96df81c commit 75a3cff

File tree

6 files changed

+40
-19
lines changed

6 files changed

+40
-19
lines changed

README.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Starmatrix reads a config file where several options can be set in yaml format::
6868

6969
z: 0.0200 # metallicity
7070
sol_ab: as09 # solar abundances
71-
imf: kroupa # initial mass function (IMF)
71+
imf: kroupa2002 # initial mass function (IMF)
7272
imf_m_low: 0.15 # lower mass limit for the IMF
7373
imf_m_up: 100 # upper mass limit for the IMF
7474
total_time_steps: 300 # number of time steps (will result in a Q Matrix per step)
@@ -99,11 +99,12 @@ The ``imf`` param in the config file can be set to use any of the predefined IMF
9999
:starburst: Starburst 1999 (a Salpeter with mass limits in [1, 120])
100100
:miller_scalo: Miller & Scalo 1979
101101
:ferrini: Ferrini, Palla & Penco 1998
102-
:kroupa: Kroupa 2002
102+
:kroupa2001: Kroupa 2001
103+
:kroupa2002: Kroupa 2002
103104
:chabrier: Chabrier 2003
104105
:maschberger: Maschberger 2012
105106

106-
The default value is ``kroupa``. If you want to use your own IMF you can do so subclassing the `IMF class`_.
107+
The default value is ``kroupa2002``. If you want to use your own IMF you can do so subclassing the `IMF class`_.
107108

108109
.. _`IMF class`: https://github.com/xuanxu/starmatrix/blob/main/src/starmatrix/imfs.py#L35-L68
109110

docs/configuration.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ The ``imf`` param in the config file can be set to use any of the predefined IMF
4444
:starburst: Starburst 1999 (a Salpeter with mass limits in [1, 120])
4545
:miller_scalo: Miller & Scalo 1979
4646
:ferrini: Ferrini, Palla & Penco 1998
47-
:kroupa: Kroupa 2002
47+
:kroupa2001: Kroupa 2001
48+
:kroupa2002: Kroupa 2002
4849
:chabrier: Chabrier 2003
4950
:maschberger: Maschberger 2012
5051

51-
The default value is ``kroupa``. If you want to use your own IMF you can do so subclassing the `IMF class`_.
52+
The default value is ``kroupa2002``. If you want to use your own IMF you can do so subclassing the `IMF class`_.
5253

5354
.. _`IMF class`: https://github.com/xuanxu/starmatrix/blob/main/src/starmatrix/imfs.py#L20-L40
5455

src/starmatrix/imfs.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Miller & Scalo 1979
88
* Ferrini, Palla & Penco 1998
99
* Starburst 1999
10-
* Kroupa 2002
10+
* Kroupa 2001 & 2002
1111
* Chabrier 2003
1212
* Maschberger 2012
1313
@@ -25,7 +25,8 @@ def select_imf(name, params={}):
2525
"starburst": Starburst,
2626
"chabrier": Chabrier,
2727
"ferrini": Ferrini,
28-
"kroupa": Kroupa,
28+
"kroupa2002": Kroupa2002,
29+
"kroupa2001": Kroupa2001,
2930
"miller_scalo": MillerScalo,
3031
"maschberger": Maschberger
3132
}
@@ -120,7 +121,7 @@ def description(self):
120121
return "IMF Ferrini, Palla & Penco 1998"
121122

122123

123-
class Kroupa(IMF):
124+
class Kroupa2002(IMF):
124125
def m_phi(self, m):
125126
if 0.015 <= m < 0.08:
126127
return m * (m ** -0.35)
@@ -137,6 +138,21 @@ def description(self):
137138
return "IMF from Kroupa 2002"
138139

139140

141+
class Kroupa2001(IMF):
142+
def m_phi(self, m):
143+
if 0.015 <= m < 0.08:
144+
return m * (m ** -0.35)
145+
elif 0.08 <= m < 0.5:
146+
return m * 0.08 * (m ** -1.3)
147+
elif 0.5 <= m:
148+
return m * 0.04 * (m ** -2.3)
149+
else:
150+
return 0
151+
152+
def description(self):
153+
return "IMF from Kroupa 2001"
154+
155+
140156
class Chabrier(IMF):
141157
def m_phi(self, m):
142158
if m <= 1:

src/starmatrix/sample_input/params.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# All configurable parameters:
22
# z -> Metallicity. Default value: 0.02
33
# sol_ab -> Solar abundances data (*). Default value: as09
4-
# imf -> Initial Mass function to use (*). Default value: kroupa
4+
# imf -> Initial Mass function to use (*). Default value: kroupa2002
55
# imf_alpha -> If IMF is salpeter/starburst, this extra param is needed. Defaults to 2.35
66
# imf_m_low -> Lower limit (in solar masses) for the IMF. Default value: 0.15
77
# imf_m_up -> Upper limit (in solar masses) for the IMF. Default value: 100
@@ -28,7 +28,8 @@
2828
# starburst = Starburst 1999 (special case of Salpeter in [1, 120])
2929
# chabrier = Chabrier 2003
3030
# ferrini = Ferrini, Palla & Penco 1998
31-
# kroupa = Kroupa 2002 (default)
31+
# kroupa2001 = Kroupa 2001
32+
# kroupa2002 = Kroupa 2002 (default)
3233
# miller_scalo = Miller & Scalo 1979
3334
# maschberger = Maschberger 2012
3435
# ]
@@ -79,7 +80,7 @@
7980

8081
z: 0.02
8182
sol_ab: as09
82-
imf: kroupa
83+
imf: kroupa2002
8384
m_max: 40.0
8485
dtd_sn: rlp
8586
expelled_elements_filename: ejections.dat

src/starmatrix/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
default = {
1313
"z": 0.02,
1414
"sol_ab": "as09",
15-
"imf": "kroupa",
15+
"imf": "kroupa2002",
1616
"imf_alpha": 2.35,
1717
"imf_m_low": 0.15,
1818
"imf_m_up": 100,
@@ -32,7 +32,7 @@
3232
}
3333

3434
valid_values = {
35-
"imf": ["salpeter", "starburst", "chabrier", "ferrini", "kroupa", "miller_scalo", "maschberger"],
35+
"imf": ["salpeter", "starburst", "chabrier", "ferrini", "kroupa2001", "kroupa2002", "miller_scalo", "maschberger"],
3636
"dtd_sn": ["rlp", "maoz", "castrillo", "greggio", "chen", "greggio-CDD04", "greggio-CDD1",
3737
"greggio-WDD04", "greggio-WDD1", "greggio-SDCH", "greggio-SDSCH",
3838
"strolger-fit1", "strolger-fit2", "strolger-fit3", "strolger-fit4", "strolger-fit5", "strolger-optimized"],

src/starmatrix/tests/test_imfs.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44
import starmatrix.settings as settings
55
from starmatrix.imfs import select_imf, IMF
6-
from starmatrix.imfs import Salpeter, Starburst, Chabrier, Ferrini, Kroupa, MillerScalo, Maschberger
6+
from starmatrix.imfs import Salpeter, Starburst, Chabrier, Ferrini, Kroupa2001, Kroupa2002, MillerScalo, Maschberger
77

88

99
@pytest.fixture
@@ -15,8 +15,8 @@ def available_imfs():
1515

1616

1717
def test_select_imf():
18-
strings = ["salpeter", "starburst", "chabrier", "ferrini", "kroupa", "miller_scalo", "maschberger"]
19-
classes = [Salpeter, Starburst, Chabrier, Ferrini, Kroupa, MillerScalo, Maschberger]
18+
strings = ["salpeter", "starburst", "chabrier", "ferrini", "kroupa2001", "kroupa2002", "miller_scalo", "maschberger"]
19+
classes = [Salpeter, Starburst, Chabrier, Ferrini, Kroupa2001, Kroupa2002, MillerScalo, Maschberger]
2020

2121
for i in range(len(strings)):
2222
imf_instance = select_imf(strings[i])
@@ -47,9 +47,11 @@ def test_imf_is_zero_if_no_positive_mass(available_imfs):
4747
assert select_imf(imf).for_mass(mass) > 0.0
4848

4949

50-
def test_minimum_mass_value_for_kroupa_imf():
51-
assert select_imf("kroupa").for_mass(0.014) == 0.0
52-
assert select_imf("kroupa").for_mass(0.015) > 0.0
50+
def test_minimum_mass_value_for_kroupa_imfs():
51+
assert select_imf("kroupa2001").for_mass(0.014) == 0.0
52+
assert select_imf("kroupa2001").for_mass(0.015) > 0.0
53+
assert select_imf("kroupa2002").for_mass(0.014) == 0.0
54+
assert select_imf("kroupa2002").for_mass(0.015) > 0.0
5355

5456

5557
def test_for_mass_is_normalized(available_imfs):

0 commit comments

Comments
 (0)