Skip to content

Extend black and flake8 line length to 100 characters #132

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

Merged
merged 1 commit into from
Jul 18, 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
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[flake8]
max-line-length = 88
max-line-length = 100
extend-ignore = E203
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
rev: 22.3.0
hooks:
- id: black
args: [--line-length=79]
args: [--line-length=100]
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
Expand Down
13 changes: 4 additions & 9 deletions sed/binning/binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,12 @@ def bin_partition(
bins, axes, ranges = simplify_binning_arguments(bins, axes, ranges)
else:
if not isinstance(bins, list) or not (
all(isinstance(x, int) for x in bins)
or all(isinstance(x, np.ndarray) for x in bins)
all(isinstance(x, int) for x in bins) or all(isinstance(x, np.ndarray) for x in bins)
):
raise TypeError(
"bins needs to be of type 'List[int] or List[np.ndarray]' if tests are skipped!",
)
if not (isinstance(axes, list)) or not all(
isinstance(axis, str) for axis in axes
):
if not (isinstance(axes, list)) or not all(isinstance(axis, str) for axis in axes):
raise TypeError(
"axes needs to be of type 'List[str]' if tests are skipped!",
)
Expand Down Expand Up @@ -187,8 +184,7 @@ def bin_partition(
)
else:
raise ValueError(
f"No binning method {hist_mode} available. Please choose between "
f"numba and numpy.",
f"No binning method {hist_mode} available. Please choose between " f"numba and numpy.",
)

if return_edges:
Expand Down Expand Up @@ -309,8 +305,7 @@ def bin_dataframe(
else:
bins = cast(List[int], bins)
coords = {
ax: np.linspace(r[0], r[1], n, endpoint=False)
for ax, r, n in zip(axes, ranges, bins)
ax: np.linspace(r[0], r[1], n, endpoint=False) for ax, r, n in zip(axes, ranges, bins)
}

full_shape = tuple(axis.size for axis in coords.values())
Expand Down
3 changes: 1 addition & 2 deletions sed/binning/numba_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ def numba_histogramdd(
# normalize the range argument
if ranges is None:
raise ValueError(
"must define a value for ranges when bins is"
" the number of bins",
"must define a value for ranges when bins is the number of bins",
)
if num_cols == 1 and isinstance(ranges[0], (int, float)):
ranges = (ranges,)
Expand Down
16 changes: 3 additions & 13 deletions sed/binning/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def simplify_binning_arguments(
],
axes: Sequence[str] = None,
ranges: Sequence[Tuple[float, float]] = None,
) -> Tuple[
Union[List[int], List[np.ndarray]],
List[str],
List[Tuple[float, float]],
]:
) -> Tuple[Union[List[int], List[np.ndarray]], List[str], List[Tuple[float, float]]]:
"""Convert the flexible input for defining bins into a
simple "axes" "bins" "ranges" tuple.

Expand Down Expand Up @@ -106,9 +102,7 @@ def simplify_binning_arguments(
# we got tuples as bins, expand to bins and ranges
if all(isinstance(x, tuple) for x in bins):
bins = cast(Sequence[tuple], bins)
assert (
len(bins[0]) == 3
), "Tuples as bins need to have format (start, end, num_bins)."
assert len(bins[0]) == 3, "Tuples as bins need to have format (start, end, num_bins)."
ranges = []
bins_ = []
for tpl in bins:
Expand Down Expand Up @@ -177,11 +171,7 @@ def bin_centers_to_bin_edges(bin_centers: np.ndarray) -> np.ndarray:
bin_edges = np.append(
bin_edges,
bin_centers[len(bin_centers) - 1]
+ (
bin_centers[len(bin_centers) - 1]
- bin_centers[len(bin_centers) - 2]
)
/ 2,
+ (bin_centers[len(bin_centers) - 1] - bin_centers[len(bin_centers) - 2]) / 2,
)

return bin_edges
9 changes: 2 additions & 7 deletions sed/calibrator/delay.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ def append_delay_axis(
) / 2 ** self._config.get("delay", {}).get("adc_binning", 2)

if "delay_range" not in calibration.keys():
if (
"delay_range_mm" not in calibration.keys()
or "time0" not in calibration.keys()
):
if "delay_range_mm" not in calibration.keys() or "time0" not in calibration.keys():
if datafile is not None:
try:
ret = extract_delay_stage_parameters(
Expand Down Expand Up @@ -176,9 +173,7 @@ def append_delay_axis(
if "delay_range" in calibration.keys():
df[delay_column] = calibration["delay_range"][0] + (
df[adc_column] - calibration["adc_range"][0]
) * (
calibration["delay_range"][1] - calibration["delay_range"][0]
) / (
) * (calibration["delay_range"][1] - calibration["delay_range"][0]) / (
calibration["adc_range"][1] - calibration["adc_range"][0]
)
else:
Expand Down
51 changes: 13 additions & 38 deletions sed/calibrator/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,7 @@ def view( # pylint: disable=dangerous-default-value
for itr, trace in enumerate(traces):
if align:
ax.plot(
xaxis
+ sign
* (
self.biases[itr]
- self.biases[self.calibration["refid"]]
),
xaxis + sign * (self.biases[itr] - self.biases[self.calibration["refid"]]),
trace,
ls="--",
linewidth=1,
Expand Down Expand Up @@ -593,12 +588,7 @@ def view( # pylint: disable=dangerous-default-value
trace = traces[itr, :]
if align:
fig.line(
xaxis
+ sign
* (
self.biases[itr]
- self.biases[self.calibration["refid"]]
),
xaxis + sign * (self.biases[itr] - self.biases[self.calibration["refid"]]),
trace,
color=color,
line_dash="solid",
Expand Down Expand Up @@ -711,11 +701,7 @@ def append_energy_axis(

# try to determine calibration type if not provided
if "calib_type" not in calibration:
if (
"t0" in calibration
and "d" in calibration
and "E0" in calibration
):
if "t0" in calibration and "d" in calibration and "E0" in calibration:
calibration["calib_type"] = "fit"
if "energy_scale" not in calibration:
calibration["energy_scale"] = "kinetic"
Expand Down Expand Up @@ -936,19 +922,17 @@ def adjust_energy_correction(
x_center_slider = ipw.FloatSlider(
value=x_center,
min=0,
max=self._config.get("momentum", {}).get(
"detector_ranges",
[[0, 2048], [0, 2048]],
)[0][1],
max=self._config.get("momentum", {}).get("detector_ranges", [[0, 2048], [0, 2048]])[0][
1
],
step=1,
)
y_center_slider = ipw.FloatSlider(
value=x_center,
min=0,
max=self._config.get("momentum", {}).get(
"detector_ranges",
[[0, 2048], [0, 2048]],
)[1][1],
max=self._config.get("momentum", {}).get("detector_ranges", [[0, 2048], [0, 2048]])[1][
1
],
step=1,
)

Expand Down Expand Up @@ -1330,9 +1314,7 @@ def correction_function(
(
1
- np.sqrt(
1
- ((x - center[0]) ** 2 + (y - center[1]) ** 2)
/ diameter**2,
1 - ((x - center[0]) ** 2 + (y - center[1]) ** 2) / diameter**2,
)
)
* 100
Expand All @@ -1345,11 +1327,7 @@ def correction_function(
100000
* amplitude
/ (gamma * np.pi)
* (
gamma**2
/ ((x - center[0]) ** 2 + (y - center[1]) ** 2 + gamma**2)
- 1
)
* (gamma**2 / ((x - center[0]) ** 2 + (y - center[1]) ** 2 + gamma**2) - 1)
)

elif correction_type == "Gaussian":
Expand All @@ -1360,8 +1338,7 @@ def correction_function(
/ np.sqrt(2 * np.pi * sigma**2)
* (
np.exp(
-((x - center[0]) ** 2 + (y - center[1]) ** 2)
/ (2 * sigma**2),
-((x - center[0]) ** 2 + (y - center[1]) ** 2) / (2 * sigma**2),
)
- 1
)
Expand Down Expand Up @@ -1942,9 +1919,7 @@ def tof2ev(

# m_e/2 [eV] bin width [s]
energy = (
2.84281e-12
* sign
* (tof_distance / (t * binwidth * 2**binning - time_offset)) ** 2
2.84281e-12 * sign * (tof_distance / (t * binwidth * 2**binning - time_offset)) ** 2
+ energy_offset
)

Expand Down
64 changes: 17 additions & 47 deletions sed/calibrator/momentum.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,7 @@ def coordinate_transform(
ret="displacement",
**kwds,
)
elif (
transform_type == "scaling_auto"
): # Compare scaling to a reference image
elif transform_type == "scaling_auto": # Compare scaling to a reference image
pass
elif transform_type == "shearing":
rdisp, cdisp = sym.shearingDF(
Expand Down Expand Up @@ -792,9 +790,7 @@ def coordinate_transform(
)

# Resample image in the deformation field
if (
image is self.slice
): # resample using all previous displacement fields
if image is self.slice: # resample using all previous displacement fields
total_rdeform = ndi.map_coordinates(
self.rdeform_field,
[rdeform, cdeform],
Expand Down Expand Up @@ -1419,12 +1415,8 @@ def calibrate(
try:
self.calibration["rstart"] = self.bin_ranges[0][0]
self.calibration["cstart"] = self.bin_ranges[1][0]
self.calibration["rstep"] = (
self.bin_ranges[0][1] - self.bin_ranges[0][0]
) / nrows
self.calibration["cstep"] = (
self.bin_ranges[1][1] - self.bin_ranges[1][0]
) / ncols
self.calibration["rstep"] = (self.bin_ranges[0][1] - self.bin_ranges[0][0]) / nrows
self.calibration["cstep"] = (self.bin_ranges[1][1] - self.bin_ranges[1][0]) / ncols
except (AttributeError, IndexError):
pass

Expand Down Expand Up @@ -1521,57 +1513,40 @@ def gather_correction_metadata(self) -> dict:
metadata["registration"] = self.adjust_params
metadata["registration"]["depends_on"] = (
"/entry/process/registration/tranformations/rot_z"
if "angle" in metadata["registration"]
and metadata["registration"]["angle"]
if "angle" in metadata["registration"] and metadata["registration"]["angle"]
else "/entry/process/registration/tranformations/trans_y"
if "xtrans" in metadata["registration"]
and metadata["registration"]["xtrans"]
if "xtrans" in metadata["registration"] and metadata["registration"]["xtrans"]
else "/entry/process/registration/tranformations/trans_x"
if "ytrans" in metadata["registration"]
and metadata["registration"]["ytrans"]
if "ytrans" in metadata["registration"] and metadata["registration"]["ytrans"]
else "."
)
if (
"ytrans" in metadata["registration"]
and metadata["registration"]["ytrans"]
"ytrans" in metadata["registration"] and metadata["registration"]["ytrans"]
): # swapped definitions
metadata["registration"]["trans_x"] = {}
metadata["registration"]["trans_x"]["value"] = metadata[
"registration"
]["ytrans"]
metadata["registration"]["trans_x"]["value"] = metadata["registration"]["ytrans"]
metadata["registration"]["trans_x"]["type"] = "translation"
metadata["registration"]["trans_x"]["units"] = "pixel"
metadata["registration"]["trans_x"]["vector"] = np.asarray(
[1.0, 0.0, 0.0],
)
metadata["registration"]["trans_x"]["depends_on"] = "."
if (
"xtrans" in metadata["registration"]
and metadata["registration"]["xtrans"]
):
if "xtrans" in metadata["registration"] and metadata["registration"]["xtrans"]:
metadata["registration"]["trans_y"] = {}
metadata["registration"]["trans_y"]["value"] = metadata[
"registration"
]["xtrans"]
metadata["registration"]["trans_y"]["value"] = metadata["registration"]["xtrans"]
metadata["registration"]["trans_y"]["type"] = "translation"
metadata["registration"]["trans_y"]["units"] = "pixel"
metadata["registration"]["trans_y"]["vector"] = np.asarray(
[0.0, 1.0, 0.0],
)
metadata["registration"]["trans_y"]["depends_on"] = (
"/entry/process/registration/tranformations/trans_x"
if "ytrans" in metadata["registration"]
and metadata["registration"]["ytrans"]
if "ytrans" in metadata["registration"] and metadata["registration"]["ytrans"]
else "."
)
if (
"angle" in metadata["registration"]
and metadata["registration"]["angle"]
):
if "angle" in metadata["registration"] and metadata["registration"]["angle"]:
metadata["registration"]["rot_z"] = {}
metadata["registration"]["rot_z"]["value"] = metadata[
"registration"
]["angle"]
metadata["registration"]["rot_z"]["value"] = metadata["registration"]["angle"]
metadata["registration"]["rot_z"]["type"] = "rotation"
metadata["registration"]["rot_z"]["units"] = "degrees"
metadata["registration"]["rot_z"]["vector"] = np.asarray(
Expand All @@ -1582,11 +1557,9 @@ def gather_correction_metadata(self) -> dict:
)
metadata["registration"]["rot_z"]["depends_on"] = (
"/entry/process/registration/tranformations/trans_y"
if "xtrans" in metadata["registration"]
and metadata["registration"]["xtrans"]
if "xtrans" in metadata["registration"] and metadata["registration"]["xtrans"]
else "/entry/process/registration/tranformations/trans_x"
if "ytrans" in metadata["registration"]
and metadata["registration"]["ytrans"]
if "ytrans" in metadata["registration"] and metadata["registration"]["ytrans"]
else "."
)

Expand Down Expand Up @@ -1659,10 +1632,7 @@ def append_k_axis(
calibration[key] = value

try:
(
df[new_x_column],
df[new_y_column],
) = detector_coordiantes_2_k_koordinates(
(df[new_x_column], df[new_y_column]) = detector_coordiantes_2_k_koordinates(
r_det=df[x_column],
c_det=df[y_column],
r_start=calibration["rstart"],
Expand Down
Loading