Skip to content

Commit

Permalink
Add warning for tune == nattune
Browse files Browse the repository at this point in the history
Fixes #209
  • Loading branch information
Mael-Le-Garrec committed Oct 6, 2020
1 parent 411beee commit f92126a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions harmonic_analysis/harpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ def harpy(harpy_input, bpm_matrix_x, usv_x, bpm_matrix_y, usv_y):
tunes = (pandas_dfs["X"]["TUNEX"].mean(),
pandas_dfs["Y"]["TUNEY"].mean(),
tunez)
nattunes = (pandas_dfs["X"]["NATTUNEX"].mean(),
pandas_dfs["Y"]["NATTUNEY"].mean())

# Log as an error in tune == nattune
if tunes[0] == nattunes[0]:
LOGGER.error('Tune and nattune for plane X are equal: {}'.format(tunes[0]))
if tunes[1] == nattunes[1]:
LOGGER.error('Tune and nattune for plane Y are equal: {}'.format(tunes[1]))

n_turns = bpm_matrix_x.shape[1]
for plane in ("X", "Y"):
Expand All @@ -116,6 +124,7 @@ def harpy(harpy_input, bpm_matrix_x, usv_x, bpm_matrix_y, usv_y):
resonances_freqs,
pandas_dfs[plane],
n_turns)

yield pandas_dfs[plane], spectr[plane], bad_bpms_summaries[plane]


Expand Down
15 changes: 15 additions & 0 deletions harmonic_analysis/io_handlers/input_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
from os.path import abspath, dirname
import argparse
from optics_measurements.optics_input import _get_optics_parser, OpticsInput
import logging
from model import manager

LOGGER = logging.getLogger(__name__)


def parse_args(args=None):
main_parser = _get_main_parser()
Expand Down Expand Up @@ -288,6 +291,13 @@ def __init__(self):

@staticmethod
def init_from_options(options):
def check_tune_overlap(tune, nattune, plane, tolerance):
if abs(tune - nattune) < 2 * tolerance:
msg = ("Windows for tune and natural tune in plane {} overlap "
"for tolerance {}. This could lead to both tunes being "
"found at the same frequency").format(plane, tolerance)
LOGGER.warning(msg)

self = HarpyInput()
self.tunex = options.tunex
self.tuney = options.tuney
Expand All @@ -301,6 +311,11 @@ def init_from_options(options):
self.no_tune_clean = options.no_tune_clean
self.tune_clean_limit = options.tune_clean_limit
self.is_free_kick = options.is_free_kick

# Check there's no overlap for the tune and nattune
check_tune_overlap(self.tunex, self.nattunex, 'x', self.tolerance)
check_tune_overlap(self.tuney, self.nattuney, 'y', self.tolerance)

return self


Expand Down

0 comments on commit f92126a

Please sign in to comment.