Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flake8 warnings #97

Merged
merged 9 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[flake8]
max-line-length = 120
max-line-length = 120
ignore = E266, W503
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
5 changes: 2 additions & 3 deletions lcls_tools/common/beam_calcs/sol_calc/sol_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion lcls_tools/common/controls/pyepics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 3 additions & 4 deletions lcls_tools/common/data_analysis/fitting/fit_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
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


# 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?
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions lcls_tools/common/devices/profile_monitor/profile_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions lcls_tools/common/image_processing/image_processing.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
1 change: 0 additions & 1 deletion lcls_tools/common/logger/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from .logger import custom_logger
4 changes: 1 addition & 3 deletions lcls_tools/common/matlab2py/cor_plot/cor_plot_mat_scan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import scipy.io as sio
import numpy as np

FIT = [
"Gaussian",
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lcls_tools/common/matlab2py/emit_scan/mat_emit_scan.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scipy.io as sio
import numpy as np
import os

VAL = "val"
Expand Down Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion lcls_tools/common/matlab2py/image/mat_image.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import scipy.ndimage as snd
from numpy import ndarray
import numpy as np
import scipy.io as sio
Expand Down
2 changes: 1 addition & 1 deletion lcls_tools/superconducting/scLinac.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ numpy
scipy
matplotlib
pyepics
pyyaml
requests
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from lcls_tools.common.data_analysis.archiver import (
Archiver,
ArchiverData,
ARCHIVER_URL_FORMATTER,
)
from datetime import datetime, timedelta
import requests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Built in
import sys
import unittest
import inspect

Expand Down
12 changes: 9 additions & 3 deletions tests/unit_tests/lcls_tools/common/devices/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
import unittest
import os
import numpy as np
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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


Expand Down
Loading