Skip to content

Commit e122700

Browse files
authored
extend black and flake8 line length to 100 characters (as for pylint), and re-lint code (#132)
1 parent 9f4469f commit e122700

File tree

17 files changed

+100
-281
lines changed

17 files changed

+100
-281
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[flake8]
2-
max-line-length = 88
2+
max-line-length = 100
33
extend-ignore = E203

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repos:
1515
rev: 22.3.0
1616
hooks:
1717
- id: black
18-
args: [--line-length=79]
18+
args: [--line-length=100]
1919
- repo: https://github.com/PyCQA/flake8
2020
rev: 5.0.4
2121
hooks:

sed/binning/binning.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,12 @@ def bin_partition(
112112
bins, axes, ranges = simplify_binning_arguments(bins, axes, ranges)
113113
else:
114114
if not isinstance(bins, list) or not (
115-
all(isinstance(x, int) for x in bins)
116-
or all(isinstance(x, np.ndarray) for x in bins)
115+
all(isinstance(x, int) for x in bins) or all(isinstance(x, np.ndarray) for x in bins)
117116
):
118117
raise TypeError(
119118
"bins needs to be of type 'List[int] or List[np.ndarray]' if tests are skipped!",
120119
)
121-
if not (isinstance(axes, list)) or not all(
122-
isinstance(axis, str) for axis in axes
123-
):
120+
if not (isinstance(axes, list)) or not all(isinstance(axis, str) for axis in axes):
124121
raise TypeError(
125122
"axes needs to be of type 'List[str]' if tests are skipped!",
126123
)
@@ -187,8 +184,7 @@ def bin_partition(
187184
)
188185
else:
189186
raise ValueError(
190-
f"No binning method {hist_mode} available. Please choose between "
191-
f"numba and numpy.",
187+
f"No binning method {hist_mode} available. Please choose between " f"numba and numpy.",
192188
)
193189

194190
if return_edges:
@@ -309,8 +305,7 @@ def bin_dataframe(
309305
else:
310306
bins = cast(List[int], bins)
311307
coords = {
312-
ax: np.linspace(r[0], r[1], n, endpoint=False)
313-
for ax, r, n in zip(axes, ranges, bins)
308+
ax: np.linspace(r[0], r[1], n, endpoint=False) for ax, r, n in zip(axes, ranges, bins)
314309
}
315310

316311
full_shape = tuple(axis.size for axis in coords.values())

sed/binning/numba_bin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ def numba_histogramdd(
226226
# normalize the range argument
227227
if ranges is None:
228228
raise ValueError(
229-
"must define a value for ranges when bins is"
230-
" the number of bins",
229+
"must define a value for ranges when bins is the number of bins",
231230
)
232231
if num_cols == 1 and isinstance(ranges[0], (int, float)):
233232
ranges = (ranges,)

sed/binning/utils.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ def simplify_binning_arguments(
2525
],
2626
axes: Sequence[str] = None,
2727
ranges: Sequence[Tuple[float, float]] = None,
28-
) -> Tuple[
29-
Union[List[int], List[np.ndarray]],
30-
List[str],
31-
List[Tuple[float, float]],
32-
]:
28+
) -> Tuple[Union[List[int], List[np.ndarray]], List[str], List[Tuple[float, float]]]:
3329
"""Convert the flexible input for defining bins into a
3430
simple "axes" "bins" "ranges" tuple.
3531
@@ -106,9 +102,7 @@ def simplify_binning_arguments(
106102
# we got tuples as bins, expand to bins and ranges
107103
if all(isinstance(x, tuple) for x in bins):
108104
bins = cast(Sequence[tuple], bins)
109-
assert (
110-
len(bins[0]) == 3
111-
), "Tuples as bins need to have format (start, end, num_bins)."
105+
assert len(bins[0]) == 3, "Tuples as bins need to have format (start, end, num_bins)."
112106
ranges = []
113107
bins_ = []
114108
for tpl in bins:
@@ -177,11 +171,7 @@ def bin_centers_to_bin_edges(bin_centers: np.ndarray) -> np.ndarray:
177171
bin_edges = np.append(
178172
bin_edges,
179173
bin_centers[len(bin_centers) - 1]
180-
+ (
181-
bin_centers[len(bin_centers) - 1]
182-
- bin_centers[len(bin_centers) - 2]
183-
)
184-
/ 2,
174+
+ (bin_centers[len(bin_centers) - 1] - bin_centers[len(bin_centers) - 2]) / 2,
185175
)
186176

187177
return bin_edges

sed/calibrator/delay.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,7 @@ def append_delay_axis(
140140
) / 2 ** self._config.get("delay", {}).get("adc_binning", 2)
141141

142142
if "delay_range" not in calibration.keys():
143-
if (
144-
"delay_range_mm" not in calibration.keys()
145-
or "time0" not in calibration.keys()
146-
):
143+
if "delay_range_mm" not in calibration.keys() or "time0" not in calibration.keys():
147144
if datafile is not None:
148145
try:
149146
ret = extract_delay_stage_parameters(
@@ -176,9 +173,7 @@ def append_delay_axis(
176173
if "delay_range" in calibration.keys():
177174
df[delay_column] = calibration["delay_range"][0] + (
178175
df[adc_column] - calibration["adc_range"][0]
179-
) * (
180-
calibration["delay_range"][1] - calibration["delay_range"][0]
181-
) / (
176+
) * (calibration["delay_range"][1] - calibration["delay_range"][0]) / (
182177
calibration["adc_range"][1] - calibration["adc_range"][0]
183178
)
184179
else:

sed/calibrator/energy.py

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -524,12 +524,7 @@ def view( # pylint: disable=dangerous-default-value
524524
for itr, trace in enumerate(traces):
525525
if align:
526526
ax.plot(
527-
xaxis
528-
+ sign
529-
* (
530-
self.biases[itr]
531-
- self.biases[self.calibration["refid"]]
532-
),
527+
xaxis + sign * (self.biases[itr] - self.biases[self.calibration["refid"]]),
533528
trace,
534529
ls="--",
535530
linewidth=1,
@@ -593,12 +588,7 @@ def view( # pylint: disable=dangerous-default-value
593588
trace = traces[itr, :]
594589
if align:
595590
fig.line(
596-
xaxis
597-
+ sign
598-
* (
599-
self.biases[itr]
600-
- self.biases[self.calibration["refid"]]
601-
),
591+
xaxis + sign * (self.biases[itr] - self.biases[self.calibration["refid"]]),
602592
trace,
603593
color=color,
604594
line_dash="solid",
@@ -711,11 +701,7 @@ def append_energy_axis(
711701

712702
# try to determine calibration type if not provided
713703
if "calib_type" not in calibration:
714-
if (
715-
"t0" in calibration
716-
and "d" in calibration
717-
and "E0" in calibration
718-
):
704+
if "t0" in calibration and "d" in calibration and "E0" in calibration:
719705
calibration["calib_type"] = "fit"
720706
if "energy_scale" not in calibration:
721707
calibration["energy_scale"] = "kinetic"
@@ -936,19 +922,17 @@ def adjust_energy_correction(
936922
x_center_slider = ipw.FloatSlider(
937923
value=x_center,
938924
min=0,
939-
max=self._config.get("momentum", {}).get(
940-
"detector_ranges",
941-
[[0, 2048], [0, 2048]],
942-
)[0][1],
925+
max=self._config.get("momentum", {}).get("detector_ranges", [[0, 2048], [0, 2048]])[0][
926+
1
927+
],
943928
step=1,
944929
)
945930
y_center_slider = ipw.FloatSlider(
946931
value=x_center,
947932
min=0,
948-
max=self._config.get("momentum", {}).get(
949-
"detector_ranges",
950-
[[0, 2048], [0, 2048]],
951-
)[1][1],
933+
max=self._config.get("momentum", {}).get("detector_ranges", [[0, 2048], [0, 2048]])[1][
934+
1
935+
],
952936
step=1,
953937
)
954938

@@ -1330,9 +1314,7 @@ def correction_function(
13301314
(
13311315
1
13321316
- np.sqrt(
1333-
1
1334-
- ((x - center[0]) ** 2 + (y - center[1]) ** 2)
1335-
/ diameter**2,
1317+
1 - ((x - center[0]) ** 2 + (y - center[1]) ** 2) / diameter**2,
13361318
)
13371319
)
13381320
* 100
@@ -1345,11 +1327,7 @@ def correction_function(
13451327
100000
13461328
* amplitude
13471329
/ (gamma * np.pi)
1348-
* (
1349-
gamma**2
1350-
/ ((x - center[0]) ** 2 + (y - center[1]) ** 2 + gamma**2)
1351-
- 1
1352-
)
1330+
* (gamma**2 / ((x - center[0]) ** 2 + (y - center[1]) ** 2 + gamma**2) - 1)
13531331
)
13541332

13551333
elif correction_type == "Gaussian":
@@ -1360,8 +1338,7 @@ def correction_function(
13601338
/ np.sqrt(2 * np.pi * sigma**2)
13611339
* (
13621340
np.exp(
1363-
-((x - center[0]) ** 2 + (y - center[1]) ** 2)
1364-
/ (2 * sigma**2),
1341+
-((x - center[0]) ** 2 + (y - center[1]) ** 2) / (2 * sigma**2),
13651342
)
13661343
- 1
13671344
)
@@ -1942,9 +1919,7 @@ def tof2ev(
19421919

19431920
# m_e/2 [eV] bin width [s]
19441921
energy = (
1945-
2.84281e-12
1946-
* sign
1947-
* (tof_distance / (t * binwidth * 2**binning - time_offset)) ** 2
1922+
2.84281e-12 * sign * (tof_distance / (t * binwidth * 2**binning - time_offset)) ** 2
19481923
+ energy_offset
19491924
)
19501925

sed/calibrator/momentum.py

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,7 @@ def coordinate_transform(
758758
ret="displacement",
759759
**kwds,
760760
)
761-
elif (
762-
transform_type == "scaling_auto"
763-
): # Compare scaling to a reference image
761+
elif transform_type == "scaling_auto": # Compare scaling to a reference image
764762
pass
765763
elif transform_type == "shearing":
766764
rdisp, cdisp = sym.shearingDF(
@@ -792,9 +790,7 @@ def coordinate_transform(
792790
)
793791

794792
# Resample image in the deformation field
795-
if (
796-
image is self.slice
797-
): # resample using all previous displacement fields
793+
if image is self.slice: # resample using all previous displacement fields
798794
total_rdeform = ndi.map_coordinates(
799795
self.rdeform_field,
800796
[rdeform, cdeform],
@@ -1419,12 +1415,8 @@ def calibrate(
14191415
try:
14201416
self.calibration["rstart"] = self.bin_ranges[0][0]
14211417
self.calibration["cstart"] = self.bin_ranges[1][0]
1422-
self.calibration["rstep"] = (
1423-
self.bin_ranges[0][1] - self.bin_ranges[0][0]
1424-
) / nrows
1425-
self.calibration["cstep"] = (
1426-
self.bin_ranges[1][1] - self.bin_ranges[1][0]
1427-
) / ncols
1418+
self.calibration["rstep"] = (self.bin_ranges[0][1] - self.bin_ranges[0][0]) / nrows
1419+
self.calibration["cstep"] = (self.bin_ranges[1][1] - self.bin_ranges[1][0]) / ncols
14281420
except (AttributeError, IndexError):
14291421
pass
14301422

@@ -1521,57 +1513,40 @@ def gather_correction_metadata(self) -> dict:
15211513
metadata["registration"] = self.adjust_params
15221514
metadata["registration"]["depends_on"] = (
15231515
"/entry/process/registration/tranformations/rot_z"
1524-
if "angle" in metadata["registration"]
1525-
and metadata["registration"]["angle"]
1516+
if "angle" in metadata["registration"] and metadata["registration"]["angle"]
15261517
else "/entry/process/registration/tranformations/trans_y"
1527-
if "xtrans" in metadata["registration"]
1528-
and metadata["registration"]["xtrans"]
1518+
if "xtrans" in metadata["registration"] and metadata["registration"]["xtrans"]
15291519
else "/entry/process/registration/tranformations/trans_x"
1530-
if "ytrans" in metadata["registration"]
1531-
and metadata["registration"]["ytrans"]
1520+
if "ytrans" in metadata["registration"] and metadata["registration"]["ytrans"]
15321521
else "."
15331522
)
15341523
if (
1535-
"ytrans" in metadata["registration"]
1536-
and metadata["registration"]["ytrans"]
1524+
"ytrans" in metadata["registration"] and metadata["registration"]["ytrans"]
15371525
): # swapped definitions
15381526
metadata["registration"]["trans_x"] = {}
1539-
metadata["registration"]["trans_x"]["value"] = metadata[
1540-
"registration"
1541-
]["ytrans"]
1527+
metadata["registration"]["trans_x"]["value"] = metadata["registration"]["ytrans"]
15421528
metadata["registration"]["trans_x"]["type"] = "translation"
15431529
metadata["registration"]["trans_x"]["units"] = "pixel"
15441530
metadata["registration"]["trans_x"]["vector"] = np.asarray(
15451531
[1.0, 0.0, 0.0],
15461532
)
15471533
metadata["registration"]["trans_x"]["depends_on"] = "."
1548-
if (
1549-
"xtrans" in metadata["registration"]
1550-
and metadata["registration"]["xtrans"]
1551-
):
1534+
if "xtrans" in metadata["registration"] and metadata["registration"]["xtrans"]:
15521535
metadata["registration"]["trans_y"] = {}
1553-
metadata["registration"]["trans_y"]["value"] = metadata[
1554-
"registration"
1555-
]["xtrans"]
1536+
metadata["registration"]["trans_y"]["value"] = metadata["registration"]["xtrans"]
15561537
metadata["registration"]["trans_y"]["type"] = "translation"
15571538
metadata["registration"]["trans_y"]["units"] = "pixel"
15581539
metadata["registration"]["trans_y"]["vector"] = np.asarray(
15591540
[0.0, 1.0, 0.0],
15601541
)
15611542
metadata["registration"]["trans_y"]["depends_on"] = (
15621543
"/entry/process/registration/tranformations/trans_x"
1563-
if "ytrans" in metadata["registration"]
1564-
and metadata["registration"]["ytrans"]
1544+
if "ytrans" in metadata["registration"] and metadata["registration"]["ytrans"]
15651545
else "."
15661546
)
1567-
if (
1568-
"angle" in metadata["registration"]
1569-
and metadata["registration"]["angle"]
1570-
):
1547+
if "angle" in metadata["registration"] and metadata["registration"]["angle"]:
15711548
metadata["registration"]["rot_z"] = {}
1572-
metadata["registration"]["rot_z"]["value"] = metadata[
1573-
"registration"
1574-
]["angle"]
1549+
metadata["registration"]["rot_z"]["value"] = metadata["registration"]["angle"]
15751550
metadata["registration"]["rot_z"]["type"] = "rotation"
15761551
metadata["registration"]["rot_z"]["units"] = "degrees"
15771552
metadata["registration"]["rot_z"]["vector"] = np.asarray(
@@ -1582,11 +1557,9 @@ def gather_correction_metadata(self) -> dict:
15821557
)
15831558
metadata["registration"]["rot_z"]["depends_on"] = (
15841559
"/entry/process/registration/tranformations/trans_y"
1585-
if "xtrans" in metadata["registration"]
1586-
and metadata["registration"]["xtrans"]
1560+
if "xtrans" in metadata["registration"] and metadata["registration"]["xtrans"]
15871561
else "/entry/process/registration/tranformations/trans_x"
1588-
if "ytrans" in metadata["registration"]
1589-
and metadata["registration"]["ytrans"]
1562+
if "ytrans" in metadata["registration"] and metadata["registration"]["ytrans"]
15901563
else "."
15911564
)
15921565

@@ -1659,10 +1632,7 @@ def append_k_axis(
16591632
calibration[key] = value
16601633

16611634
try:
1662-
(
1663-
df[new_x_column],
1664-
df[new_y_column],
1665-
) = detector_coordiantes_2_k_koordinates(
1635+
(df[new_x_column], df[new_y_column]) = detector_coordiantes_2_k_koordinates(
16661636
r_det=df[x_column],
16671637
c_det=df[y_column],
16681638
r_start=calibration["rstart"],

0 commit comments

Comments
 (0)