2import lalinference
as li
8 Wrapper to present a LALInferenceVariable as a dict.
13 Initialise
with the given dictionary.
14 If init
is itself a LALInferenceVariables C struct
15 then the wrapper will wrap around it but
not reallocate memory
18 if isinstance(init,li.Variables):
26 if li.CheckVariable(self.
v, key):
27 li.RemoveVariable(self.
v, key)
31 if type(value)==float:
32 li.AddREAL8Variable(self.
v, key, value, li.LALINFERENCE_PARAM_LINEAR)
33 elif type(value)==int:
34 li.AddINT4Variable(self.
v, key, value, li.LAINFERENCE_PARAM_LINEAR)
36 raise TypeError(
'Unsupported type: ',key, self.
type(key))
38 if li.CheckVariable(self.
v, key):
39 if self.
type(key)==li.LALINFERENCE_REAL8_t:
40 return li.GetREAL8Variable(self.
v, key)
41 elif self.
type(key)==li.LALINFERENCE_INT4_t:
42 return li.GetINT4Variable(self.
v, key)
43 elif self.
type(key)==li.LALINFERENCE_UINT4_t:
44 return li.GetUINT4Variable(self.
v, key)
46 raise(TypeError(
'Unsupported type: ',key,self.
type(key)))
52 return self.
v.dimension
55 li.ClearVariables(self.
v)
57 return 'LIVariablesWrap('+repr(dict(self))+
')'
59 return str(dict(self))
62 Return the lalinference variable's varyType
67 The name of the variable to look up
71 varytype : lalinference.varyType (e.g. lalinference.LALINFERENCE_PARAM_FIXED)
73 if not li.CheckVariable(self.
v, key):
75 return li.GetVariableVaryType(self.
v, key)
78 Return the lalinference variable's varyType
83 The name of the variable to look up
87 type : the LALInference type (e.g. lalinference.LALINFERENCE_REAL8_t)
89 if not li.CheckVariable(self.
v, key):
91 return li.GetVariableType(self.
v, key)
114 Class to wrap a LALInference CBC analysis
115 state, and expose the likelihood
and prior
116 methods to python programs
123 List of command line arguments that will be used to
124 set up the lalinference state. (similar to argv)
126 strvec = lal.CreateStringVector(argv[0])
128 strvec=lal.AppendString2Vector(strvec, a)
129 procParams=li.ParseStringVector(strvec)
130 self.
state = li.InitRunState(procParams)
131 self.
state.commandLine=procParams
132 li.InitCBCThreads(self.
state,1)
135 li.InjectInspiralSignal(self.
state.data, self.
state.commandLine)
136 li.ApplyCalibrationErrors(self.
state.data, procParams)
137 if li.GetProcParamVal(procParams,
'--roqtime_steps'):
138 li.SetupROQdata(self.
state.data, procParams)
139 li.InitCBCPrior(self.
state)
140 li.InitLikelihood(self.
state)
141 li.InitCBCThreads(self.
state,1)
146 Log-likelihood function from LALInference
151 Dict-like object of sampling parameters, will
152 be automatically converted
for lalinference
163 self.
state.threads.model.currentParams=liv.v
164 return li.MarginalisedPhaseLogLikelihood(liv.v, self.
state.data, self.
state.threads.model)
168 Log-prior function from LALInference
173 Dict-like object of sampling parameters, will
174 be automatically converted
for lalinference
185 return li.InspiralPrior(self.
state, liv.v, self.
state.threads.model)
189 Parameter names from the LALInference model. Includes
190 those which are fixed
194 A list of parameter names
201 Parameter names from the LALInference model. Includes
202 only those which are varied
in the sampling.
206 A list of parameter names
209 return [p
for p
in pars
if pars.varyType(p)==li.LALINFERENCE_PARAM_LINEAR
210 or pars.varyType(p)==li.LALINFERENCE_PARAM_CIRCULAR
215 Bounds of the sampling parameters.
219 A dict of (low,high) pairs, indexed by parameter name
220 e.g. {'declination' : (0, 3.14159), ...}
226 low = libounds[p+
'_min']
227 high = libounds[p+
'_max']
228 bounds[p]=(low, high)
Class to wrap a LALInference CBC analysis state, and expose the likelihood and prior methods to pytho...
def log_prior(self, params)
Log-prior function from LALInference.
def prior_bounds(self)
Bounds of the sampling parameters.
def params(self)
Parameter names from the LALInference model.
def sampling_params(self)
Parameter names from the LALInference model.
def log_likelihood(self, params)
Log-likelihood function from LALInference.
def varyType(self, key)
Return the lalinference variable's varyType.
def __delitem__(self, key)
def __getitem__(self, key)
def type(self, key)
Return the lalinference variable's varyType.
def __setitem__(self, key, value)
def __init__(self, init=None)
Wrapper to present a LALInferenceVariable as a dict.