From dd3ab6c8074c7fc937c30ecd812797f2d93dbba3 Mon Sep 17 00:00:00 2001 From: matt Date: Fri, 20 Oct 2023 23:19:37 +0100 Subject: [PATCH 1/8] ignore too many hashes for block-comment, and contraversial line break before binary operator --- .flake8 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.flake8 b/.flake8 index 79a16af7..7b4d0d27 100644 --- a/.flake8 +++ b/.flake8 @@ -1,2 +1,3 @@ [flake8] -max-line-length = 120 \ No newline at end of file +max-line-length = 120 +ignore = E266, W503 \ No newline at end of file From 86b8e718d100d222df78a3740eef8e7ed6bffe8d Mon Sep 17 00:00:00 2001 From: matt Date: Fri, 20 Oct 2023 23:19:49 +0100 Subject: [PATCH 2/8] flake8 fixes --- lcls_tools/common/beam_calcs/sol_calc/sol_calc.py | 5 ++--- lcls_tools/common/controls/pyepics/utils.py | 2 +- lcls_tools/common/data_analysis/fitting/fit_gaussian.py | 7 +++---- lcls_tools/common/devices/magnet/magnet.py | 2 -- lcls_tools/common/devices/magnet/magnet_constants.py | 2 +- .../common/devices/profile_monitor/profile_monitor.py | 3 +-- lcls_tools/common/image_processing/image_processing.py | 2 -- lcls_tools/common/logger/__init__.py | 1 - lcls_tools/common/matlab2py/cor_plot/cor_plot_mat_scan.py | 4 +--- lcls_tools/common/matlab2py/emit_scan/mat_emit_scan.py | 3 +-- lcls_tools/common/matlab2py/image/mat_image.py | 1 - lcls_tools/superconducting/scLinac.py | 3 ++- .../lcls_tools/common/data_analysis/test_archiver.py | 1 - .../common/devices/profile_monitor/test_profile_monitor.py | 1 - .../common/image_processing/test_image_processing.py | 1 - .../common/matlab2py/cor_plot/test_cor_plot_mat_scan.py | 1 - .../common/matlab2py/emit_scan/test_mat_emit_scan.py | 1 - 17 files changed, 12 insertions(+), 28 deletions(-) diff --git a/lcls_tools/common/beam_calcs/sol_calc/sol_calc.py b/lcls_tools/common/beam_calcs/sol_calc/sol_calc.py index 473ce7b1..76bf2f3b 100644 --- a/lcls_tools/common/beam_calcs/sol_calc/sol_calc.py +++ b/lcls_tools/common/beam_calcs/sol_calc/sol_calc.py @@ -24,8 +24,8 @@ class SolCalc(object): - def __init__(self, l, e_gun, d): - self._l = l # Leff + def __init__(self, l_eff, e_gun, d): + self._l = l_eff # Leff self._e_gun = e_gun # MeV self._d = d # distance from sol exit and bpm self._K = None @@ -189,6 +189,5 @@ def gen_y_arr(self): def calc_offsets(self): """Solve the problem""" - r = np.array(self._x_vals + self._y_vals) self._results = pinv(np.vstack((self._x_arrays, self._y_arrays))) return self._results diff --git a/lcls_tools/common/controls/pyepics/utils.py b/lcls_tools/common/controls/pyepics/utils.py index 4c49faac..8491160b 100644 --- a/lcls_tools/common/controls/pyepics/utils.py +++ b/lcls_tools/common/controls/pyepics/utils.py @@ -105,6 +105,6 @@ def put( callback_data=callback_data, ) - if retry and (status is not 1): + if retry and (status != 1): print(f"{self} put not successful, using caput") self.caput(value) diff --git a/lcls_tools/common/data_analysis/fitting/fit_gaussian.py b/lcls_tools/common/data_analysis/fitting/fit_gaussian.py index 757c33c7..846523c0 100755 --- a/lcls_tools/common/data_analysis/fitting/fit_gaussian.py +++ b/lcls_tools/common/data_analysis/fitting/fit_gaussian.py @@ -11,7 +11,7 @@ from numpy import argsort, power, exp, zeros from scipy.optimize import curve_fit from operator import itemgetter -from time import time + NUM_BUCKS = 10 DEBUG = False @@ -19,7 +19,7 @@ # An unfortunate consequence of defining step as max/numbucks is that the # maximum point is in its own bucket (bucket 10), which would break a lot of -# shit, so it necessitates the error checking +# stuff, so it necessitates the error checking def get_bucket(val, step): bucket = int(floor(val / step)) return bucket if bucket < 10 else 9 # TODO: should this use NUM_BUCKS? @@ -80,7 +80,7 @@ def get_slope(x1, y1, x2, y2): # Idea to add a line instead of a really short, fat gaussian was all Ahemd. # Thanks, yo. You're great. def find_line(zero_runs, runs, xdata, ydata): - x1, y1, x2, y2, m, b = (0, 0, 0, 0, 0, 0) + x1, y1, x2, y2, m, _ = (0, 0, 0, 0, 0, 0) # This condition should only be possible if there are peaks on one or both # extremes, or if there is no peak @@ -198,7 +198,6 @@ def get_runs(data, step): # A whole rigmarole to collapse multiple pedestals. # It assumes that the pedestal is the bucket with the most elements def adjust_data(data, step): - start = time() normalized_adjustment = 0 bucket_count = zeros(NUM_BUCKS) diff --git a/lcls_tools/common/devices/magnet/magnet.py b/lcls_tools/common/devices/magnet/magnet.py index 4489db80..461624c7 100644 --- a/lcls_tools/common/devices/magnet/magnet.py +++ b/lcls_tools/common/devices/magnet/magnet.py @@ -1,10 +1,8 @@ #!/usr/local/lcls/package/python/current/bin/python -import epics from epics import PV import lcls_tools.common.devices.magnet.magnet_constants as mc from inspect import getmembers -from time import sleep def get_magnets(): diff --git a/lcls_tools/common/devices/magnet/magnet_constants.py b/lcls_tools/common/devices/magnet/magnet_constants.py index 3eefd2cd..41aa5dca 100644 --- a/lcls_tools/common/devices/magnet/magnet_constants.py +++ b/lcls_tools/common/devices/magnet/magnet_constants.py @@ -30,7 +30,7 @@ def create_mag_dict(base, tol, length): MAGNETS = { - #'SOL1B': create_mag_dict('SOLN:GUNB:212', 0.002, 0.1342), + # 'SOL1B': create_mag_dict('SOLN:GUNB:212', 0.002, 0.1342), "SOL2B": create_mag_dict("SOLN:GUNB:823", 0.002, 0.135), "SOL1B": create_mag_dict("QUAD:LI22:201", 0.05, 0.1), } diff --git a/lcls_tools/common/devices/profile_monitor/profile_monitor.py b/lcls_tools/common/devices/profile_monitor/profile_monitor.py index ce08c581..0956eef4 100644 --- a/lcls_tools/common/devices/profile_monitor/profile_monitor.py +++ b/lcls_tools/common/devices/profile_monitor/profile_monitor.py @@ -2,11 +2,10 @@ from epics import PV import lcls_tools.common.devices.profile_monitor.profmon_constants as pc -from inspect import getmembers from time import sleep from threading import Thread from numpy import array_equal -from functools import partial + # Implementation needs to be thought out, just a POC diff --git a/lcls_tools/common/image_processing/image_processing.py b/lcls_tools/common/image_processing/image_processing.py index 7ff10f78..6f1e1ac7 100644 --- a/lcls_tools/common/image_processing/image_processing.py +++ b/lcls_tools/common/image_processing/image_processing.py @@ -1,10 +1,8 @@ import numpy as np import scipy.ndimage as snd -from scipy.optimize import curve_fit from scipy import asarray import matplotlib.pyplot as plt import lcls_tools.common.data_analysis.fitting.fit_gaussian as fg -from time import time def fliplr(image): diff --git a/lcls_tools/common/logger/__init__.py b/lcls_tools/common/logger/__init__.py index d97e66cf..e69de29b 100644 --- a/lcls_tools/common/logger/__init__.py +++ b/lcls_tools/common/logger/__init__.py @@ -1 +0,0 @@ -from .logger import custom_logger diff --git a/lcls_tools/common/matlab2py/cor_plot/cor_plot_mat_scan.py b/lcls_tools/common/matlab2py/cor_plot/cor_plot_mat_scan.py index 477de03a..d14de6e8 100644 --- a/lcls_tools/common/matlab2py/cor_plot/cor_plot_mat_scan.py +++ b/lcls_tools/common/matlab2py/cor_plot/cor_plot_mat_scan.py @@ -1,6 +1,5 @@ import os import scipy.io as sio -import numpy as np FIT = [ "Gaussian", @@ -211,10 +210,9 @@ def _unpack_prof(self, data): idx = self._fields.index(PROF) prof = data[idx] - names = prof.dtype.names prof_pvs = dict() for pv in prof: - if isinstance(pv[0][0][0], unicode): # one sample + if isinstance(pv[0][0][0], bytes): # one sample prof_pvs[str(pv[0][0][0])] = pv else: # Multiple samples prof_pvs[str(pv[0][0][0][0])] = pv diff --git a/lcls_tools/common/matlab2py/emit_scan/mat_emit_scan.py b/lcls_tools/common/matlab2py/emit_scan/mat_emit_scan.py index 315493c6..68f37dad 100644 --- a/lcls_tools/common/matlab2py/emit_scan/mat_emit_scan.py +++ b/lcls_tools/common/matlab2py/emit_scan/mat_emit_scan.py @@ -1,5 +1,4 @@ import scipy.io as sio -import numpy as np import os VAL = "val" @@ -301,7 +300,7 @@ def _unpack_twiss_pv(self, data): temp2 = dict() for i, name in enumerate(names): if name != UNITS: - if isinstance(val[0][i][0], unicode): + if isinstance(val[0][i][0], bytes): temp2[name] = str(val[0][i][0]) else: temp2[name] = val[0][i][0] diff --git a/lcls_tools/common/matlab2py/image/mat_image.py b/lcls_tools/common/matlab2py/image/mat_image.py index 518d4e01..a9750917 100644 --- a/lcls_tools/common/matlab2py/image/mat_image.py +++ b/lcls_tools/common/matlab2py/image/mat_image.py @@ -1,4 +1,3 @@ -import scipy.ndimage as snd from numpy import ndarray import numpy as np import scipy.io as sio diff --git a/lcls_tools/superconducting/scLinac.py b/lcls_tools/superconducting/scLinac.py index e2a77d69..2bda99fb 100644 --- a/lcls_tools/superconducting/scLinac.py +++ b/lcls_tools/superconducting/scLinac.py @@ -1696,7 +1696,8 @@ def __init__( stepper_class=StepperTuner, piezo_class=Piezo, ): - # type: (str, Linac, Type[Cavity], Type[Magnet], Type[Rack], bool, Type[SSA], Type[StepperTuner], Type[Piezo]) -> None + # _type: (str, Linac, Type[Cavity], Type[Magnet], Type[Rack], + # bool, Type[SSA], Type[StepperTuner], Type[Piezo],) -> None """ Parameters ---------- diff --git a/tests/unit_tests/lcls_tools/common/data_analysis/test_archiver.py b/tests/unit_tests/lcls_tools/common/data_analysis/test_archiver.py index 615d6067..8f1e33a1 100644 --- a/tests/unit_tests/lcls_tools/common/data_analysis/test_archiver.py +++ b/tests/unit_tests/lcls_tools/common/data_analysis/test_archiver.py @@ -2,7 +2,6 @@ from lcls_tools.common.data_analysis.archiver import ( Archiver, ArchiverData, - ARCHIVER_URL_FORMATTER, ) from datetime import datetime, timedelta import requests diff --git a/tests/unit_tests/lcls_tools/common/devices/profile_monitor/test_profile_monitor.py b/tests/unit_tests/lcls_tools/common/devices/profile_monitor/test_profile_monitor.py index d45391f0..6b19bbb4 100644 --- a/tests/unit_tests/lcls_tools/common/devices/profile_monitor/test_profile_monitor.py +++ b/tests/unit_tests/lcls_tools/common/devices/profile_monitor/test_profile_monitor.py @@ -1,5 +1,4 @@ # Built in -import sys import unittest import inspect diff --git a/tests/unit_tests/lcls_tools/common/image_processing/test_image_processing.py b/tests/unit_tests/lcls_tools/common/image_processing/test_image_processing.py index 5734347f..b453b945 100644 --- a/tests/unit_tests/lcls_tools/common/image_processing/test_image_processing.py +++ b/tests/unit_tests/lcls_tools/common/image_processing/test_image_processing.py @@ -1,4 +1,3 @@ -import sys import unittest import os import numpy as np diff --git a/tests/unit_tests/lcls_tools/common/matlab2py/cor_plot/test_cor_plot_mat_scan.py b/tests/unit_tests/lcls_tools/common/matlab2py/cor_plot/test_cor_plot_mat_scan.py index 23552ca3..6cee1f41 100644 --- a/tests/unit_tests/lcls_tools/common/matlab2py/cor_plot/test_cor_plot_mat_scan.py +++ b/tests/unit_tests/lcls_tools/common/matlab2py/cor_plot/test_cor_plot_mat_scan.py @@ -1,6 +1,5 @@ import os import unittest -import numpy as np from lcls_tools.common.matlab2py.cor_plot.cor_plot_mat_scan import ( CorPlotMatScan as CPMS, ) diff --git a/tests/unit_tests/lcls_tools/common/matlab2py/emit_scan/test_mat_emit_scan.py b/tests/unit_tests/lcls_tools/common/matlab2py/emit_scan/test_mat_emit_scan.py index 5e05fa29..e6667a78 100644 --- a/tests/unit_tests/lcls_tools/common/matlab2py/emit_scan/test_mat_emit_scan.py +++ b/tests/unit_tests/lcls_tools/common/matlab2py/emit_scan/test_mat_emit_scan.py @@ -1,6 +1,5 @@ import os import unittest -import numpy as np from lcls_tools.common.matlab2py.emit_scan.mat_emit_scan import MatEmitScan as MES From 3b87ed531468fc480717e51573900ffae04ee49e Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 23 Oct 2023 18:31:17 +0100 Subject: [PATCH 3/8] remove lambda for flake8 --- tests/unit_tests/lcls_tools/common/devices/test_device.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit_tests/lcls_tools/common/devices/test_device.py b/tests/unit_tests/lcls_tools/common/devices/test_device.py index 0b678021..c0716e66 100644 --- a/tests/unit_tests/lcls_tools/common/devices/test_device.py +++ b/tests/unit_tests/lcls_tools/common/devices/test_device.py @@ -126,9 +126,9 @@ def mock_callback(message: str) -> None: print(f"callback: {message}") # Add different callbacks to Device - first_callback = lambda: mock_callback("first") - second_callback = lambda: mock_callback("second") - third_callback = lambda: mock_callback("third") + first_callback = mock_callback("first") + second_callback = mock_callback("second") + third_callback = mock_callback("third") self.device.add_callback_to_pv( "bact", first_callback, From 28646752d604ef028c874e1b698183f6f4b966c8 Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 23 Oct 2023 18:40:19 +0100 Subject: [PATCH 4/8] changing unittest command, change from python-app to python-package workflow. --- .github/workflows/{python-app.yml => python-package.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{python-app.yml => python-package.yml} (96%) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-package.yml similarity index 96% rename from .github/workflows/python-app.yml rename to .github/workflows/python-package.yml index 636618a9..f0e9be08 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-package.yml @@ -36,4 +36,4 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with unittest run: | - unittest discover + python -m unittest discover . From 6182c73ec150f3bdbde894f2c3196148cc966609 Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 23 Oct 2023 18:44:50 +0100 Subject: [PATCH 5/8] add requirements for workflow install step --- requirements.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements.txt b/requirements.txt index 31f1091b..7d4bce85 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,5 @@ numpy scipy matplotlib pyepics +pyyaml +requests From b12f46f102654a1d47674e65d36e08206bcc4973 Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 23 Oct 2023 18:51:27 +0100 Subject: [PATCH 6/8] make callback a callable for test to pass --- .../lcls_tools/common/devices/test_device.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/unit_tests/lcls_tools/common/devices/test_device.py b/tests/unit_tests/lcls_tools/common/devices/test_device.py index c0716e66..e0bbff0f 100644 --- a/tests/unit_tests/lcls_tools/common/devices/test_device.py +++ b/tests/unit_tests/lcls_tools/common/devices/test_device.py @@ -126,9 +126,15 @@ def mock_callback(message: str) -> None: print(f"callback: {message}") # Add different callbacks to Device - first_callback = mock_callback("first") - second_callback = mock_callback("second") - third_callback = mock_callback("third") + def first_callback(): + mock_callback("first") + + def second_callback(): + mock_callback("second") + + def third_callback(): + mock_callback("third") + self.device.add_callback_to_pv( "bact", first_callback, From 49a4fc4ce4fa87fa2c2ed20fe659b426f87217dc Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 23 Oct 2023 19:16:58 +0100 Subject: [PATCH 7/8] add exception for line-length --- lcls_tools/superconducting/scLinac.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lcls_tools/superconducting/scLinac.py b/lcls_tools/superconducting/scLinac.py index 2bda99fb..2848bbcc 100644 --- a/lcls_tools/superconducting/scLinac.py +++ b/lcls_tools/superconducting/scLinac.py @@ -1696,8 +1696,7 @@ def __init__( stepper_class=StepperTuner, piezo_class=Piezo, ): - # _type: (str, Linac, Type[Cavity], Type[Magnet], Type[Rack], - # bool, Type[SSA], Type[StepperTuner], Type[Piezo],) -> None + # type: (str, Linac, Type[Cavity], Type[Magnet], Type[Rack], bool, Type[SSA], Type[StepperTuner], Type[Piezo],) -> None # noqa: E501 """ Parameters ---------- From 06dc30dbf5fb000a58f8faf0ded47f00f55787a7 Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 23 Oct 2023 22:30:47 +0100 Subject: [PATCH 8/8] remove unnecessary file --- .../common/devices/magnet/magnet_constants.py | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 lcls_tools/common/devices/magnet/magnet_constants.py diff --git a/lcls_tools/common/devices/magnet/magnet_constants.py b/lcls_tools/common/devices/magnet/magnet_constants.py deleted file mode 100644 index 41aa5dca..00000000 --- a/lcls_tools/common/devices/magnet/magnet_constants.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/local/lcls/package/python/current/bin/python - -CTRL = [ - "Ready", - "TRIM", - "PERTURB", - "BCON_TO_BDES", - "SAVE_BDES", - "LOAD_BDES", - "UNDO_BDES", - "DAC_ZERO", - "CALIB", - "STDZ", - "RESET", -] - - -def create_mag_dict(base, tol, length): - mag_dict = { - "bctrl": base + ":BCTRL", - "bact": base + ":BACT", - "bdes": base + ":BDES", - "bcon": base + ":BCON", - "ctrl": base + ":CTRL", - "tol": tol, - "length": length, - } - - return mag_dict - - -MAGNETS = { - # 'SOL1B': create_mag_dict('SOLN:GUNB:212', 0.002, 0.1342), - "SOL2B": create_mag_dict("SOLN:GUNB:823", 0.002, 0.135), - "SOL1B": create_mag_dict("QUAD:LI22:201", 0.05, 0.1), -}