Skip to content

Commit

Permalink
DPP parameter fixes (#476)
Browse files Browse the repository at this point in the history
* fixes #477
  • Loading branch information
JoschD authored Dec 4, 2024
1 parent f57314a commit 9fb4261
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# OMC3 Changelog

#### 2024-11-21 - v0.20.3 - _jdilly_

- Fixed:
- `analyse_dpp` issues in `beta_from_amplitude`, `chromatic_beating` and `dispersion`.
Skips `dispersion` calculation if `NaN`s are present.

#### 2024-11-21 - v0.20.2 - _jdilly_, _awegsche_

- Added:
Expand Down
2 changes: 1 addition & 1 deletion omc3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
__title__ = "omc3"
__description__ = "An accelerator physics tools package for the OMC team at CERN."
__url__ = "https://github.com/pylhc/omc3"
__version__ = "0.20.2"
__version__ = "0.20.3"
__author__ = "pylhc"
__author_email__ = "pylhc@github.com"
__license__ = "MIT"
Expand Down
6 changes: 4 additions & 2 deletions omc3/hole_in_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def hole_in_one_entrypoint(opt, rest):
Action: ``store_true``
- **analyse_dpp** *(float)*: Filter files to analyse by this value
(in analysis for tune, phase, rdt and crdt)..
(in analysis for tune, phase, rdt and crdt). Use `None` for no filtering.
Flags: **--analyse_dpp**
Default: ``0``
Expand Down Expand Up @@ -617,7 +617,9 @@ def optics_params():
params.add_parameter(name="chromatic_beating", action="store_true",
help="Calculate chromatic beatings: W, PHI and coupling")
params.add_parameter(name="analyse_dpp", type=iotools.OptionalFloat, default=OPTICS_DEFAULTS["analyse_dpp"],
help="Filter files to analyse by this value (in analysis for tune, phase, rdt and crdt).")
help="Filter files to analyse by this value (in analysis for tune, phase, rdt and crdt). "
"Use `None` for no filtering"
)
return params


Expand Down
3 changes: 1 addition & 2 deletions omc3/optics_measurements/beta_from_amplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ def beta_from_amplitude(meas_input, input_files, plane, tunes):
df = pd.DataFrame(meas_input.accelerator.model).loc[:, ["S", f"MU{plane}", f"BET{plane}"]]
df.rename(columns={f"MU{plane}": f"MU{plane}{MDL}",
f"BET{plane}": f"BET{plane}{MDL}"}, inplace=True)
dpp_value = meas_input.dpp if "dpp" in meas_input.keys() else 0
df = pd.merge(df, input_files.joined_frame(plane, [f"AMP{plane}", f"MU{plane}"], dpp_value=dpp_value),
df = pd.merge(df, input_files.joined_frame(plane, [f"AMP{plane}", f"MU{plane}"], dpp_value=meas_input.analyse_dpp),
how='inner', left_index=True, right_index=True)
df['COUNT'] = len(input_files.get_columns(df, f"AMP{plane}"))

Expand Down
2 changes: 1 addition & 1 deletion omc3/optics_measurements/data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def dpp_frames(self, plane: str, dpp_value: float | None):

dpp_dfs = [self[plane][i] for i in self.dpp_frames_indices(plane, dpp_value)]
if len(dpp_dfs) == 0:
raise ValueError(f"No data found for dp/p {dpp}")
raise ValueError(f"No data found for dp/p {dpp_value} in plane {plane}")
return dpp_dfs

def dpp_frames_indices(self, plane: str, dpp_value: float | None):
Expand Down
12 changes: 10 additions & 2 deletions omc3/optics_measurements/dispersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
)
from omc3.optics_measurements import dpp
from omc3.utils import stats
import logging

if TYPE_CHECKING:
from generic_parser import DotDict

from omc3.optics_measurements.data_models import InputFiles


LOGGER = logging.getLogger(__name__)


def calculate_orbit(meas_input: DotDict, input_files: InputFiles, header, plane):
"""
Calculates orbit.
Expand Down Expand Up @@ -277,8 +281,12 @@ def _get_delta_columns(df, plane):
return df


def _is_single_dpp_bin(dpps: Sequence[float], tolerance: float = dpp.DPP_BIN_TOLERANCE) -> bool:
def _is_single_dpp_bin(dpps: Sequence[float]) -> bool:
""" Checks if the files would be grouped into a single dpp-bin
by :func:`omc3.optics_measurements.dpp._compute_ranges`. """
# alternatively: len(omc3.optics_measurements.dpp._compute_ranges(dpps, tolerance)) == 1
return np.abs(np.max(dpps) - np.min(dpps)) <= 2 * tolerance
if any(np.isnan(dpps)):
LOGGER.warning("DPPs contain NaN values. Skipping dispersion calculation.")
return True # i.e. skip dispersion calculation

return np.abs(np.max(dpps) - np.min(dpps)) <= 2 * dpp.DPP_BIN_TOLERANCE
2 changes: 1 addition & 1 deletion omc3/optics_measurements/measure_optics.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def chromatic_beating(input_files: InputFiles, measure_input: DotDict, tune_dict
betas = []
for dpp_val in dpps:
dpp_meas_input = deepcopy(measure_input)
dpp_meas_input["dpp"] = dpp_val
dpp_meas_input["analyse_dpp"] = dpp_val
phase_res, out_dfs = phase.calculate(dpp_meas_input, input_files, tune_dict, plane)
beta_df, _ = beta_from_phase.calculate(dpp_meas_input, tune_dict, phase_res[phase.COMPENSATED], {}, plane)
betas.append(beta_df)
Expand Down

0 comments on commit 9fb4261

Please sign in to comment.