예제 #1
0
def calculate(meas_input, tunes, phase_dict, header_dict, plane):
    """
    Calculates betas and alphas from phase advances.

    Args:
        meas_input: `OpticsInput` object
        tunes: `TuneDict` contains measured tunes.
        phase_dict: contains measured phase advances.
        header_dict:  dictionary of header items common for all output files.
        plane: marking the horizontal or vertical plane, **X** or **Y**.

    Returns:
        `BetaDict` object containing specific `TfsDataFrame` with results.
    """
    meas_and_model_tunes = (tunes[plane]["Q"], tunes[plane]["QM"] % 1) \
        if meas_input.compensation == "none" else (tunes[plane]["QF"], tunes[plane]["QFM"] % 1)

    if meas_input.three_bpm_method:
        beta_df = three_bpm_method(meas_input, phase_dict, plane,
                                   meas_and_model_tunes)
        error_method = METH_3BPM
    else:
        beta_df, error_method = n_bpm_method(meas_input, phase_dict, plane,
                                             meas_and_model_tunes)
    LOGGER.info(f"Errors from {error_method}")
    rmsbb = stats.weighted_rms(
        beta_df.loc[:, f"{DELTA}BET{plane}"].to_numpy(),
        errors=beta_df.loc[:, f"{ERR}{DELTA}BET{plane}"].to_numpy()) * 100
    LOGGER.info(f" - RMS beta beat: {rmsbb:.3f}%")
    header = _get_header(header_dict, error_method, meas_input.range_of_bpms,
                         rmsbb)
    return beta_df, header
예제 #2
0
def test_nanhandling():
    vector = np.array([355., 0., 5., np.nan])
    assert stats.circular_nanmean(vector) == stats.circular_mean(vector[:-1])
    assert stats.weighted_nanmean(vector) == stats.weighted_mean(vector[:-1])
    assert stats.weighted_nanrms(vector) == stats.weighted_rms(vector[:-1])
    vector = np.array([[355., 0., 5., 0.], [355., 0., 5., 0.],
                       [355., 0., 5., np.nan]])
    assert np.all(
        stats.circular_nanerror(vector, axis=1) == stats.circular_error(
            vector[:, :-1], axis=1))
예제 #3
0
def evaluate_accuracy(meas_path):
    for f in [f for f in listdir(meas_path) if (isfile(join(meas_path, f)) and (".tfs" in f))]:
        a = tfs.read(join(meas_path, f))
        cols = [column for column in a.columns.to_numpy() if column.startswith('DELTA')]
        if f == "normalised_dispersion_x.tfs":
            cols.remove("DELTADX")
        for col in cols:
            rms = stats.weighted_rms(a.loc[:, col].to_numpy(), errors=a.loc[:, f"ERR{col}"].to_numpy())
            if col[5] in LIMITS.keys():
                assert rms < LIMITS[col[5]], "\nFile: {:25}  Column: {:15}   RMS: {:.6f}".format(f, col, rms)
            else:
                assert rms < DEFAULT_LIMIT, "\nFile: {:25}  Column: {:15}   RMS: {:.6f}".format(f, col, rms)
            print(f"\nFile: {f:25}  Column: {col[5:]:15}   RMS:    {rms:.6f}")
예제 #4
0
def evaluate_accuracy(meas_path, limits):
    for f in meas_path.glob(
            "*.tfs"
    ):  # maybe a simple list of files to test wouldn't be too bad?
        if "f10" in f.name or "phase_driven" in f.name:
            continue
        df = tfs.read(f)
        cols = df.columns[df.columns.str.startswith('DELTA')]
        for col in cols:
            if f.name.startswith('normalised_dispersion') and col.startswith(
                    'DELTAD'):
                continue

            rms = stats.weighted_rms(data=df.loc[:, col].to_numpy(),
                                     errors=df.loc[:, f"ERR{col}"].to_numpy())
            assert rms < limits[
                col[5:-1]], f"\n{f.name:25}  {col:15}   RMS: {rms:.1e}"
            LOG.info(f"{f.name:25}  {col[5:]:15}   RMS: {rms:.1e}")
    assert ((meas_path / f"{SPECIAL_PHASE_NAME}x.tfs").is_file()
            and (meas_path / f"{SPECIAL_PHASE_NAME}y.tfs").is_file())