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 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 . 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/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..2848bbcc 100644 --- a/lcls_tools/superconducting/scLinac.py +++ b/lcls_tools/superconducting/scLinac.py @@ -1696,7 +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 ---------- 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 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/devices/test_device.py b/tests/unit_tests/lcls_tools/common/devices/test_device.py index 0b678021..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 = lambda: mock_callback("first") - second_callback = lambda: mock_callback("second") - third_callback = lambda: 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, 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