Skip to content

Commit

Permalink
trying to test arc-by-arc
Browse files Browse the repository at this point in the history
  • Loading branch information
JoschD committed Dec 5, 2024
1 parent 296fca6 commit 28dd058
Show file tree
Hide file tree
Showing 20 changed files with 1,326 additions and 1,213 deletions.
1 change: 1 addition & 0 deletions omc3/correction/arc_by_arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def identify_closest_arc_bpm_to_ip(ip, side, beam, bpms):
bpm = f'BPM.{ii}{side}{ip}.B{beam}'
if bpm in bpms:
return bpm
# TODO: else!


def get_left_right_pair(arc, beam, bpms):
Expand Down
2 changes: 1 addition & 1 deletion omc3/correction/model_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
def diff_twiss_parameters(model_a: tfs.TfsDataFrame,
model_b: tfs.TfsDataFrame,
parameters: Sequence[str] = None) -> tfs.TfsDataFrame:
"""Create a TfsDataFrame containing of the given parameters between
"""Create a TfsDataFrame containing the difference of the given parameters between
model_a and model_b."""
# preparation ---
if parameters is None:
Expand Down
18 changes: 13 additions & 5 deletions omc3/madx_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,20 @@ def _raise_madx_error(log=None, file=None):
message = "MADX run failed."
if log is not None:
try:
with open(log, "r") as f:
content = f.readlines()
if content[-1].startswith("+="):
message += f" '{content[-1].replace('+=+=+=', '').strip()}'."
except (IOError, IndexError):
content = Path(log).read_text()
except IOError:
pass
else:
if "warning: Twiss failed: MAD-X continues" in content:
message += " At least one twiss failed."

try:
last_line = content.splitlines()[-1]
except IndexError:
pass
else:
if last_line.startswith("+="):
message += f" '{last_line.replace('+=+=+=', '').strip()}'."

if file is not None:
message += f" Run on File: '{file}'."
Expand Down
14 changes: 12 additions & 2 deletions omc3/scripts/fake_measurement_from_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,23 +435,30 @@ def append_model(df: pd.DataFrame, df_model: pd.DataFrame, parameter: str,
def _get_data(twiss: tfs.TfsDataFrame, model: tfs.TfsDataFrame = None,
add_coupling: bool = False) -> Tuple[tfs.TfsDataFrame, tfs.TfsDataFrame]:
""" Gets the input data as TfsDataFrames. """
LOG.debug("Loading data.")
# Helper ---
def try_reading(df_or_path):
try:
return tfs.read(df_or_path, index=NAME)
except TypeError:
return df_or_path

# ---
LOG.debug("Loading data.")
# do twiss ---
twiss = try_reading(twiss)
if add_coupling:
twiss = add_coupling_to_model(twiss)

# do model ---
if model is None:
model = twiss.copy()
else:
model = try_reading(model)
if add_coupling:
model = add_coupling_to_model(model)

# intersect index ---
index = twiss.index.intersection(model.index)
twiss, model = twiss.loc[index, :], model.loc[index, :]
return twiss, model


Expand Down Expand Up @@ -481,6 +488,9 @@ def _get_loop_parameters(parameters: Sequence[str], errors: Sequence[float]) ->
def _get_random_errors(errors: np.array, values: np.array) -> np.array:
""" Creates normal distributed error-values that will not be lower than EPSILON. """
LOG.debug("Calculating normal distributed random errors.")
if any(errors == 0):
raise ValueError("Errors were requested but given relative error was zero.")

random_errors = np.zeros_like(errors)
too_small = np.ones_like(errors, dtype=bool)
n_too_small = 1
Expand Down
Loading

0 comments on commit 28dd058

Please sign in to comment.