forked from wpb-astro/MCSED
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetallicity.py
90 lines (72 loc) · 2.34 KB
/
metallicity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
""" MCSED - metallicity.py
module for handling the free or fixed stellar metallicity parameter
.. moduleauthor:: Will Bowman <[email protected]>
"""
class stellar_metallicity:
'''
Define the stellar metallicity class
stellar metallicity can be treated as a free model parameter
(set metallicity=False in config.py)
or is fixed at a single value Z (where Zsolar=0.019)
(set metallicity=Z in config.py)
'''
def __init__(self, met=-0.39, met_lims=[-1.98, 0.2], met_delta=0.3,
fix_met=False):
''' Initialize this class
Parameters
----------
met : float
the stellar metallicity (in log solar units)
fix_met : bool
treat stellar metallicity as a fixed or free parameter
'''
self.met = met
self.met_lims = met_lims
self.met_delta = met_delta
self.fix_met = fix_met
def get_nparams(self):
''' Return number of parameters '''
if self.fix_met:
return 0
else:
return 1
def get_params(self):
''' Return current parameters '''
l = []
if not self.fix_met:
l.append(self.met)
return l
def get_param_lims(self):
''' Return current parameters limits '''
l = []
if not self.fix_met:
l.append(self.met_lims)
return l
def get_param_deltas(self):
''' Return current parameter deltas '''
l = []
if not self.fix_met:
l.append(self.met_delta)
return l
def get_names(self):
''' Return names of each parameter '''
l = []
if not self.fix_met:
l.append('Log Z')
return l
def prior(self):
''' Uniform prior based on boundaries '''
flag = (self.met >= self.met_lims[0]) * (self.met <= self.met_lims[1])
return flag
def set_parameters_from_list(self, input_list, start_value):
''' Set parameters from a list and a start_value
Parameters
----------
input_list : list
list of input parameters (could be much larger than number of
parameters to be set)
start_value : int
initial index from list to read out parameters
'''
if not self.fix_met:
self.met = input_list[start_value]