コード例 #1
0
ファイル: chromatic.py プロジェクト: pylhc/omc3
def calculate_w_and_phi(betas, dpps, input_files, measure_input, plane):
    columns = [f"{pref}{DELTA}{col}{plane}" for pref in ("", ERR) for col in ("BET", "ALF")]
    joined = betas[0].loc[:, columns]
    for i, beta in enumerate(betas[1:]):
        joined = pd.merge(joined, beta.loc[:, columns], how="inner", left_index=True,
                          right_index=True, suffixes=('', '__' + str(i + 1)))
    for column in columns:
        joined.rename(columns={column: column + '__0'}, inplace=True)
    joined = pd.merge(joined,
                      betas[np.argmin(np.abs(dpps))].loc[:, [f"ALF{plane}", f"{ERR}ALF{plane}"]],
                      how="inner",
                      left_index=True, right_index=True)
    for col in ("BET", "ALF"):
        fit = np.polyfit(np.repeat(dpps, 2),
                         np.repeat(input_files.get_data(joined, f"{DELTA}{col}{plane}").T, 2,
                                   axis=0), 1, cov=True)
        joined[f"D{col}{plane}"] = fit[0][-2, :].T
        joined[f"{ERR}D{col}{plane}"] = np.sqrt(fit[1][-2, -2, :].T)
    a = joined.loc[:, f"DBET{plane}"].to_numpy()
    aerr = joined.loc[:, f"{ERR}DBET{plane}"].to_numpy()
    b = joined.loc[:, f"DALF{plane}"].to_numpy() - joined.loc[:, f"ALF{plane}"].to_numpy() * joined.loc[:,
                                                                                     f"DBET{plane}"].to_numpy()
    berr = np.sqrt(df_prod(joined, f"{ERR}DALF{plane}", f"{ERR}DALF{plane}") +
                   np.square(df_prod(joined, f"{ERR}ALF{plane}", f"DBET{plane}")) +
                   np.square(df_prod(joined, f"ALF{plane}", f"{ERR}DBET{plane}")))
    w = np.sqrt(np.square(a) + np.square(b))
    joined[f"W{plane}"] = w
    joined[f"{ERR}W{plane}"] = np.sqrt(np.square(a * aerr / w) + np.square(b * berr / w))
    joined[f"PHI{plane}"] = np.arctan2(b, a) / (2 * np.pi)
    joined[f"{ERR}PHI{plane}"] = 1 / (1 + np.square(a / b)) * np.sqrt(
        np.square(aerr / b) + np.square(berr * a / np.square(b))) / (2 * np.pi)
    output_df = pd.merge(measure_input.accelerator.model.loc[:,
                         ["S", f"MU{plane}", f"BET{plane}", f"ALF{plane}", f"W{plane}",
                          f"PHI{plane}"]],
                         joined.loc[:,
                         [f"{pref}{col}{plane}" for pref in ("", ERR) for col in ("W", "PHI")]],
                         how="inner", left_index=True,
                         right_index=True, suffixes=(MDL, ''))
    output_df.rename(columns={"SMDL": "S"}, inplace=True)
    return output_df
コード例 #2
0
def test_df_prod_ratio():
    a, b = _arand(), _arand()
    prod = toolbox.df_prod(*_df(a, b))
    ratio = toolbox.df_ratio(*_df(prod, b))
    assert _numerically_equal(a, ratio)
コード例 #3
0
def test_df_prod_one(random, ones):
    assert all(random == toolbox.df_prod(*_df(random, ones)))
コード例 #4
0
def test_df_prod_zero(random, zeros):
    assert not sum(toolbox.df_prod(*_df(random, zeros)))