def create_livariables_from_cbc_params(cbc_params): livars = li.Variables() cbc_params_dict = cbc_params._asdict() for name, value in cbc_params_dict.items(): if value is None: pass elif name == 'rightascension': li.AddREAL8Variable(livars, name, value, li.LALINFERENCE_PARAM_CIRCULAR) elif name == 'LAL_APPROXIMANT': li.AddINT4Variable(livars, name, value, li.LALINFERENCE_PARAM_LINEAR) elif name == 'LAL_PNORDER': li.AddINT4Variable(livars, name, value, li.LALINFERENCE_PARAM_LINEAR) elif name == 'LAL_AMPORDER': li.AddINT4Variable(livars, name, value, li.LALINFERENCE_PARAM_LINEAR) else: li.AddREAL8Variable(livars, name, value, li.LALINFERENCE_PARAM_LINEAR) return livars
def criteria(gamma0, gamma1, gamma2, gamma3): vars = lalinf.Variables() no_vary = lalinf.lalinference.LALINFERENCE_PARAM_FIXED lalinf.lalinference.AddREAL8Variable(vars, "SDgamma0", gamma0, no_vary ) lalinf.lalinference.AddREAL8Variable(vars, "SDgamma1", gamma1, no_vary) lalinf.lalinference.AddREAL8Variable(vars, "SDgamma2", gamma2, no_vary) lalinf.lalinference.AddREAL8Variable(vars, "SDgamma3", gamma3, no_vary) lalinf.lalinference.AddREAL8Variable(vars, "mass1", 1.4 , no_vary) lalinf.lalinference.AddREAL8Variable(vars, "mass2", 1.4 , no_vary) a = lal.CreateStringVector("Hi") process_ptable = lalinf.ParseCommandLineStringVector(a) success_param = lalinf.EOSPhysicalCheck(vars, process_ptable) if success_param == 0: return True else : return False
def __init__(self,init=None): """ Wrapper to present a LALInferenceVariable as a dict. Parameters ---------- init : dict Initialise with the given dictionary. If init is itself a LALInferenceVariables C struct then the wrapper will wrap around it but not reallocate memory """ self.owner=True # Python should manage the object's memory if isinstance(init,li.Variables): self.v=init self.owner=False else: self.v=li.Variables() if init: self.update(init)
def init_ifoData(ifoData): ifoData.modelDomain = lalsimulation.LAL_SIM_DOMAIN_FREQUENCY id = ifoData while id is not None: # Set the model domain to the frequency domain id.modelDomain = lalsimulation.LAL_SIM_DOMAIN_FREQUENCY # Create some vectors to store the waveforms in freqData = id.freqData id.freqModelhPlus = lal.CreateCOMPLEX16FrequencySeries( "freqModelhPlus", freqData.epoch, freqData.f0, freqData.deltaF, freqData.sampleUnits, freqData.data.length) id.freqModelhCross = lal.CreateCOMPLEX16FrequencySeries( "freqModelhCross", freqData.epoch, freqData.f0, freqData.deltaF, freqData.sampleUnits, freqData.data.length) #Initialise the lalinference variables on the ifoData id.modelParams = li.Variables() id = id.next
def create_cbc_prior_function( trigtime, component_min=1., component_max=5., massratio_min=0.2, massratio_max=0.25, distance_min=1., distance_max=100., trigtime_window=1., ): """ Generates two closures; one will calculate the log(prior) for a given set of parameters (uses LALInferenceInspiralPriorNormalised) and the other will do a random draw from the same prior. """ # Create a LALInferenceVariables representing the prior function parameters # i.e. the min/max values corresponding to the prior bounds for each # parameter. prior_args = li.Variables() time_width = trigtime_window # in seconds # TODO: fix so this uses full inspiral prior with cuts on mass ratio/total mass # These are the prior function parameters specifying various bounds # on the parameters. prior_args_list = [ #('component',component_min,component_max,li.LALINFERENCE_REAL8_t), #('massratio',massratio_min,massratio_max,li.LALINFERENCE_REAL8_t), ('mass1', component_min, component_max, li.LALINFERENCE_REAL8_t), ('mass2', component_min, component_max, li.LALINFERENCE_REAL8_t), ('distance', distance_min, distance_max, li.LALINFERENCE_REAL8_t), ('inclination', 0, np.pi, li.LALINFERENCE_REAL8_t), ('phase', 0., 2. * np.pi, li.LALINFERENCE_REAL8_t), ('time', trigtime - time_width / 2., trigtime + time_width / 2., li.LALINFERENCE_REAL8_t), ('polarisation', 0., np.pi, li.LALINFERENCE_REAL8_t), ('rightascension', 0., 2. * np.pi, li.LALINFERENCE_REAL8_t), ('declination', -np.pi / 2., np.pi / 2., li.LALINFERENCE_REAL8_t), ] # Initialise the prior function parameters for param_name, param_min, param_max, param_type in prior_args_list: LALInferenceAddMinMaxPrior(prior_args, param_name, param_min, param_max, param_type) #li.AddREAL8Variable(prior_args,'MTotMax',2.*component_max-component_min,li.LALINFERENCE_PARAM_FIXED) # These are the actual run parameters in_params_args = [ ('mass1', ), ('mass2', ), ('distance', ), ('inclination', ), ('phase', ), ('time', ), ('polarisation', ), ('rightascension', ), ('declination', ), ] # Pre-allocate a list to transfer the run parameters in/out of # LALInference functions. in_params = li.Variables() for (param_name, ) in in_params_args: li.AddREAL8Variable(in_params, param_name, 0., li.LALINFERENCE_PARAM_LINEAR) # Create a dummy LALInferenceRunState to hold the prior args to pass # to the prior functions. dummy_rs = li.RunState() dummy_rs.priorArgs = prior_args # Initialise a GSL random number generator li_gsl_rng = lal.gsl_rng("mt19937", int(time.time())) def logp(params_in): for (param_name, ), param_val in zip(in_params_args, params_in): li.SetREAL8Variable(in_params, param_name, param_val) # Call the prior functions and return the normalised prior value return li.InspiralPrior(dummy_rs, in_params) def draw_from_prior(): li.DrawFromPrior(in_params, prior_args, li_gsl_rng) params_out = [] for (param_name, ) in in_params_args: params_out.append(li.GetREAL8Variable(in_params, param_name)) return cbc_params_sub(*params_out) return logp, draw_from_prior