How to use the flavio.np_prediction function in flavio

To help you get started, we’ve selected a few flavio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flav-io / flavio / flavio / physics / bdecays / test_bll.py View on Github external
def BR(c10, c10p, cS, cSp, cP, cPp):
            list_wc = {'C10_bsmumu' :  c10,
                 'C10p_bsmumu': c10p,
                 'CS_bsmumu'  : cS,
                 'CSp_bsmumu' : cSp,
                 'CP_bsmumu'  : cP,
                 'CPp_bsmumu' : cPp,
                 'C9_bsmumu'  : 0.,
                 'C9p_bsmumu' : 0.}
            wc = flavio.WilsonCoefficients()
            wc.set_initial(list_wc, scale=160 )

            BR_flavio    = flavio.np_prediction('BR(Bs->mumu)', wc)
            BR_Amsterdam = BR_Amsterdam_Bs_mumu(par, list_wc)

            return {'flavio': BR_flavio, 'Amsterdam': BR_Amsterdam}
github flav-io / flavio / flavio / physics / mudecays / test_muegamma.py View on Github external
def test_tauegamma_implementation(self):
        input_dict_list=[{
        'Cgamma_mue':np.random.random()*1e-8*exp(1j*2*pi*np.random.random()),
        'Cgamma_emu':np.random.random()*1e-8*exp(1j*2*pi*np.random.random()),
        } for i in range(10)]
        BRs = np.array([
            flavio.np_prediction(
                'BR(mu->egamma)',
                Wilson(input_dict, 100,  'WET', 'flavio')
            )
            for input_dict in input_dict_list
        ])
        compare_BRs = np.array([
            compare_BR(
                Wilson(input_dict, 100,  'WET', 'flavio'),
                'mu', 'e',
            )
            for input_dict in input_dict_list
        ])
        self.assertAlmostEqual(np.max(np.abs(1-BRs/compare_BRs)), 0, delta=0.005)
github flav-io / flavio / flavio / physics / bdecays / test_bll.py View on Github external
def test_bsll_lfv(self):
        # test for errors
        self.assertEqual(flavio.sm_prediction('BR(B0->emu)'), 0)
        self.assertEqual(flavio.sm_prediction('BR(Bs->taumu)'), 0)
        self.assertEqual(flavio.sm_prediction('BR(B0->emu,mue)'), 0)
        self.assertEqual(flavio.sm_prediction('BR(Bs->mutau,taumu)'), 0)
        wc = flavio.WilsonCoefficients()
        wc.set_initial({'C10_bdemu': 1, 'C10_bdmue': 2}, scale=4.8)
        self.assertAlmostEqual(flavio.np_prediction('BR(B0->mue)', wc)
                        /flavio.np_prediction('BR(B0->emu)', wc), 4)
        self.assertAlmostEqual(flavio.np_prediction('BR(B0->emu,mue)', wc)
                        /flavio.np_prediction('BR(B0->emu)', wc), 5)
github flav-io / flavio / flavio / physics / wdecays / test_wdecays.py View on Github external
def test_np(self):
        v = 246.22
        from wilson import Wilson
        w = Wilson({'phil3_11': -0.5 / v**2}, 91.1876, 'SMEFT', 'Warsaw')
        self.assertAlmostEqual(flavio.np_prediction('BR(W->enu)', w), 10.83e-2 / 2, delta=0.15e-2)
github flav-io / flavio / flavio / physics / taudecays / test_taulgamma.py View on Github external
def test_tauegamma_implementation(self):
        input_dict_list=[{
        'Cgamma_taue':np.random.random()*1e-8*exp(1j*2*pi*np.random.random()),
        'Cgamma_etau':np.random.random()*1e-8*exp(1j*2*pi*np.random.random()),
        } for i in range(10)]
        BRs = np.array([
            flavio.np_prediction(
                'BR(tau->egamma)',
                Wilson(input_dict, 100,  'WET', 'flavio')
            )
            for input_dict in input_dict_list
        ])
        compare_BRs = np.array([
            compare_BR(
                Wilson(input_dict, 100,  'WET', 'flavio'),
                'tau', 'e',
            )
            for input_dict in input_dict_list
        ])
        self.assertAlmostEqual(np.max(np.abs(1-BRs/compare_BRs)), 0, delta=0.002)
github flav-io / flavio / flavio / test_functions.py View on Github external
def test_functions(self):
        o = Observable('test_obs')
        o.arguments = ['x']
        def f(wc_obj, par_dict, x):
            return x
        pr  = Prediction('test_obs', f )
        wc_obj = None
        self.assertEqual(flavio.sm_prediction('test_obs', 7), 7)
        self.assertEqual(flavio.np_prediction('test_obs', x=7, wc_obj=wc_obj), 7)
        self.assertEqual(flavio.sm_uncertainty('test_obs', 7), 0)
        self.assertEqual(flavio.np_uncertainty('test_obs', x=7, wc_obj=wc_obj), 0)
        self.assertEqual(flavio.sm_uncertainty('test_obs', 7, threads=2), 0)
        self.assertEqual(flavio.np_uncertainty('test_obs', x=7, wc_obj=wc_obj, threads=2), 0)
        # delete dummy instance
        Observable.del_instance('test_obs')
github flav-io / flavio / flavio / physics / mdms / test_al.py View on Github external
def test_amu_NP(self):
        w = Wilson({'C7_mumu': 1e-3}, 1.0, 'WET-3', 'flavio')
        e = sqrt(4 * pi * par['alpha_e'])
        m = par['m_mu']
        p = 4 * par['GF'] / sqrt(2) * e / 16 / pi**2 * m
        pre = p * 4 * m / e
        a = pre * 1e-3
        self.assertAlmostEqual(flavio.np_prediction('a_mu', w) - amu_SM,
                               a,
                               delta=0.01 * abs(a))
github flav-io / flavio / flavio / plots / plotfunctions.py View on Github external
obs = flavio.classes.Observable[obs_name]
    if not obs.arguments or len(obs.arguments) != 1:
        raise ValueError(r"Only observables that depend on a single parameter are allowed")
    step = (x_max-x_min)/(steps-1)
    x_arr = np.arange(x_min, x_max+step, step)
    step = (x_max-x_min)/(steps_err-1)
    x_err_arr = np.arange(x_min, x_max+step, step)
    # fix to avoid bounds_error in interp1d due to lack of numerical precision
    x_err_arr[-1] = x_arr[-1]
    if wc is None:
        wc = flavio.physics.eft._wc_sm # SM Wilson coefficients
        obs_err_arr = [flavio.sm_uncertainty(obs_name, x, threads=threads) for x in x_err_arr]
        obs_arr = [flavio.sm_prediction(obs_name, x) for x in x_arr]
    else:
        obs_err_arr = [flavio.np_uncertainty(obs_name, wc, x, threads=threads) for x in x_err_arr]
        obs_arr = [flavio.np_prediction(obs_name, wc, x) for x in x_arr]
    ax = plt.gca()
    plot_args = plot_args or {}
    fill_args = fill_args or {}
    if label is not None:
        plot_args['label'] = label
    if 'alpha' not in fill_args:
        fill_args['alpha'] = 0.5
    ax.plot(x_arr, scale_factor * np.asarray(obs_arr), **plot_args)
    interp_err = scipy.interpolate.interp1d(x_err_arr, obs_err_arr,
                                            kind='quadratic')
    obs_err_arr_int = interp_err(x_arr)
    ax.fill_between(x_arr,
                    scale_factor * np.asarray(obs_arr - obs_err_arr_int),
                    scale_factor * np.asarray(obs_arr + obs_err_arr_int),
                    **fill_args)
github flav-io / flavio / flavio / plots / plotfunctions.py View on Github external
Wilson coefficients
    - `q2steps` (optional): number of $q^2$ steps. Defaults to 100. Less is
      faster but less precise.

    Additional keyword arguments are passed to the matplotlib plot function,
    e.g. 'c' for colour.
    """
    obs = flavio.classes.Observable[obs_name]
    if obs.arguments != ['q2']:
        raise ValueError(r"Only observables that depend on $q^2$ (and nothing else) are allowed")
    q2_arr = np.arange(q2min, q2max, (q2max-q2min)/(q2steps-1))
    if wc is None:
        wc = flavio.physics.eft._wc_sm # SM Wilson coefficients
        obs_arr = [flavio.sm_prediction(obs_name, q2) for q2 in q2_arr]
    else:
        obs_arr = [flavio.np_prediction(obs_name, wc, q2) for q2 in q2_arr]
    ax = plt.gca()
    if 'c' not in kwargs and 'color' not in kwargs:
        kwargs['c'] = 'k'
    ax.plot(q2_arr, obs_arr, **kwargs)