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 untyped typing checks #316

Merged
merged 2 commits into from
Jan 7, 2024
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
6 changes: 3 additions & 3 deletions sed/calibrator/momentum.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def __init__(
self.mdist: float = np.nan
self.mcvdist: float = np.nan
self.mvvdist: float = np.nan
self.cvdist: float = np.nan
self.vvdist: float = np.nan
self.cvdist: np.ndarray = np.array(np.nan)
self.vvdist: np.ndarray = np.array(np.nan)
self.rdeform_field: np.ndarray = None
self.cdeform_field: np.ndarray = None
self.rdeform_field_bkp: np.ndarray = None
Expand Down Expand Up @@ -573,7 +573,7 @@ def apply_func(apply: bool): # pylint: disable=unused-argument

plt.show()

def calc_geometric_distances(self):
def calc_geometric_distances(self) -> None:
"""Calculate geometric distances involving the center and the vertices.
Distances calculated include center-vertex and nearest-neighbor vertex-vertex
distances.
Expand Down
10 changes: 6 additions & 4 deletions tests/calibrator/test_delay.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"""
import os
from importlib.util import find_spec
from typing import Any
from typing import Dict

import dask.dataframe
import numpy as np
Expand All @@ -16,7 +18,7 @@
file = package_dir + "/../tests/data/loader/mpes/Scan0030_2.h5"


def test_delay_parameters_from_file():
def test_delay_parameters_from_file() -> None:
"""Test the option to extract the delay parameters from a file"""
config = parse_config(
config={
Expand Down Expand Up @@ -45,7 +47,7 @@ def test_delay_parameters_from_file():
assert "delay_range_mm" in metadata["calibration"]


def test_delay_parameters_from_delay_range():
def test_delay_parameters_from_delay_range() -> None:
"""Test the option to extract the delay parameters from a delay range"""
# from keywords
config = parse_config(
Expand Down Expand Up @@ -78,7 +80,7 @@ def test_delay_parameters_from_delay_range():
assert metadata["calibration"]["adc_range"] == (100, 1000)


def test_delay_parameters_from_delay_range_mm():
def test_delay_parameters_from_delay_range_mm() -> None:
"""Test the option to extract the delay parameters from a mm range + t0"""
# from keywords
config = parse_config(
Expand Down Expand Up @@ -107,7 +109,7 @@ def test_delay_parameters_from_delay_range_mm():
collect_metadata=False,
)
dc = DelayCalibrator(config=config)
calibration = {"delay_range_mm": (1, 15)}
calibration: Dict[str, Any] = {"delay_range_mm": (1, 15)}
with pytest.raises(NotImplementedError):
dc.append_delay_axis(df, calibration=calibration)
calibration["time0"] = 1
Expand Down
43 changes: 18 additions & 25 deletions tests/calibrator/test_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
biases = np.asarray(next(reader))


def test_bin_data_and_read_biases_from_files():
def test_bin_data_and_read_biases_from_files() -> None:
"""Test binning the data and extracting the bias values from the files"""
config = parse_config(
config={"dataframe": {"tof_binning": 2}, "energy": {"bias_key": "@KTOF:Lens:Sample:V"}},
Expand Down Expand Up @@ -77,7 +77,7 @@ def test_bin_data_and_read_biases_from_files():
ec.bin_data(data_files=files)


def test_energy_calibrator_from_arrays_norm():
def test_energy_calibrator_from_arrays_norm() -> None:
"""Test loading the energy, bias and tof traces into the class"""
config = parse_config(
config={"dataframe": {"tof_binning": 2}},
Expand All @@ -97,7 +97,7 @@ def test_energy_calibrator_from_arrays_norm():
assert np.max(ec.traces_normed[i, :]) == 1


def test_feature_extract():
def test_feature_extract() -> None:
"""Test generating the ranges, and extracting the features"""
config = parse_config(
config={"dataframe": {"tof_binning": 2}},
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_feature_extract():
)


def test_adjust_ranges():
def test_adjust_ranges() -> None:
"""Test the interactive function for adjusting the feature ranges"""
config = parse_config(
config={"dataframe": {"tof_binning": 2}},
Expand Down Expand Up @@ -170,7 +170,7 @@ def test_adjust_ranges():
"energy_scale, calibration_method",
itertools.product(energy_scales, calibration_methods),
)
def test_calibrate_append(energy_scale: str, calibration_method: str):
def test_calibrate_append(energy_scale: str, calibration_method: str) -> None:
"""Test if the calibration routines generate the correct slope of energy vs. tof,
and the application to the data frame.

Expand Down Expand Up @@ -225,7 +225,7 @@ def test_calibrate_append(energy_scale: str, calibration_method: str):
"calib_type, calib_dict",
zip(calib_types, calib_dicts),
)
def test_append_energy_axis_from_dict_kwds(calib_type: str, calib_dict: dict):
def test_append_energy_axis_from_dict_kwds(calib_type: str, calib_dict: dict) -> None:
"""Function to test if the energy calibration is correctly applied using a dict or
kwd parameters.

Expand Down Expand Up @@ -256,7 +256,7 @@ def test_append_energy_axis_from_dict_kwds(calib_type: str, calib_dict: dict):
assert metadata["calibration"]["calib_type"] == calib_type


def test_append_energy_axis_raises():
def test_append_energy_axis_raises() -> None:
"""Test if apply_correction raises the correct errors"""
config = parse_config(config={}, folder_config={}, user_config={}, system_config={})
loader = get_loader(loader_name="mpes", config=config)
Expand All @@ -271,7 +271,7 @@ def test_append_energy_axis_raises():
)


def test_append_tof_ns_axis():
def test_append_tof_ns_axis() -> None:
"""Function to test if the tof_ns calibration is correctly applied.
TODO: add further tests once the discussion about units is done.
"""
Expand Down Expand Up @@ -342,7 +342,7 @@ def test_append_tof_ns_axis():
"correction_type, correction_kwd",
zip(correction_types, correction_kwds),
)
def test_energy_correction(correction_type: str, correction_kwd: dict):
def test_energy_correction(correction_type: str, correction_kwd: dict) -> None:
"""Function to test if all energy correction functions generate symmetric curves
with the maximum at the cetner x/y.

Expand Down Expand Up @@ -425,9 +425,7 @@ def test_energy_correction(correction_type: str, correction_kwd: dict):
"correction_type",
correction_types,
)
def test_adjust_energy_correction_raises(
correction_type: str,
):
def test_adjust_energy_correction_raises(correction_type: str) -> None:
"""Function to test if the adjust_energy_correction function raises the correct errors.

Args:
Expand Down Expand Up @@ -469,10 +467,7 @@ def test_adjust_energy_correction_raises(
"correction_type, correction_kwd",
zip(correction_types, correction_kwds),
)
def test_energy_correction_from_dict_kwds(
correction_type: str,
correction_kwd: dict,
):
def test_energy_correction_from_dict_kwds(correction_type: str, correction_kwd: dict) -> None:
"""Function to test if the energy correction is correctly applied using a dict or
kwd parameters.

Expand Down Expand Up @@ -534,9 +529,7 @@ def test_energy_correction_from_dict_kwds(
"correction_type",
correction_types,
)
def test_apply_energy_correction_raises(
correction_type: str,
):
def test_apply_energy_correction_raises(correction_type: str) -> None:
"""Function to test if the apply_energy_correction raises the correct errors.

Args:
Expand Down Expand Up @@ -572,7 +565,7 @@ def test_apply_energy_correction_raises(
assert config["dataframe"]["corrected_tof_column"] in df.columns


def test_add_offsets_functionality():
def test_add_offsets_functionality() -> None:
"""test the add_offsets function"""
config = parse_config(
config={
Expand Down Expand Up @@ -631,17 +624,17 @@ def test_add_offsets_functionality():
loader=get_loader("flash", config=config),
)
t_df = dask.dataframe.from_pandas(df.copy(), npartitions=2)
res, meta = ec.add_offsets(t_df, **params) # pylint disable=unexpected-keyword-arg
res, meta = ec.add_offsets(t_df, **params) # type: ignore[arg-type] # pylint disable=unexpected-keyword-arg
np.testing.assert_allclose(res["energy"].values, exp_vals.values)
params["applied"] = True
assert meta == params

# test with different energy scale


def test_add_offset_raises():
def test_add_offset_raises() -> None:
"""test if add_offset raises the correct errors"""
cfg_dict = {
cfg_dict: Dict[str, Any] = {
"energy": {
"calibration": {
"energy_scale": "kinetic",
Expand Down Expand Up @@ -705,9 +698,9 @@ def test_add_offset_raises():
_ = ec.add_offsets(t_df)


def test_align_dld_sectors():
def test_align_dld_sectors() -> None:
"""test functionality and error handling of align_dld_sectors"""
cfg_dict = {
cfg_dict: Dict[str, Any] = {
"dataframe": {
"tof_column": "dldTimeSteps",
"sector_id_column": "dldSectorId",
Expand Down
16 changes: 8 additions & 8 deletions tests/calibrator/test_momentum.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
momentum_map = np.asarray(momentum_map_list).T


def test_bin_data_and_slice_image():
def test_bin_data_and_slice_image() -> None:
"""Test binning the data and slicing of the image"""
config = parse_config(
config={"core": {"loader": "mpes"}},
Expand All @@ -51,7 +51,7 @@ def test_bin_data_and_slice_image():
assert sed_processor.mc.slice.shape == (512, 512)


def test_feature_extract():
def test_feature_extract() -> None:
"""Testextracting the feature from a 2D slice"""
config = parse_config(
config={"core": {"loader": "mpes"}},
Expand All @@ -73,7 +73,7 @@ def test_feature_extract():
"include_center",
[True, False],
)
def test_splinewarp(include_center: bool):
def test_splinewarp(include_center: bool) -> None:
"""Test the generation of the splinewarp etimate.

Args:
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_splinewarp(include_center: bool):
assert len(mc.ptargs) == len(mc.prefs)


def test_pose_correction():
def test_pose_correction() -> None:
"""Test the adjustment of the pose correction."""
config = parse_config(
config={"core": {"loader": "mpes"}},
Expand All @@ -128,7 +128,7 @@ def test_pose_correction():
assert np.all(np.array([mc.cdeform_field, mc.rdeform_field]) != dfield)


def test_apply_correction():
def test_apply_correction() -> None:
"""Test the application of the distortion correction to the dataframe."""
config = parse_config(
config={"core": {"loader": "mpes"}},
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_apply_correction():
def test_apply_registration(
transformations: Dict[Any, Any],
depends_on: Dict[Any, Any],
):
) -> None:
"""Test the application of the distortion correction to the dataframe."""
config = parse_config(
config={"core": {"loader": "mpes"}},
Expand Down Expand Up @@ -311,7 +311,7 @@ def test_apply_registration(
)


def test_momentum_calibration_equiscale():
def test_momentum_calibration_equiscale() -> None:
"""Test the calibration using one point and the k-distance,
and application to the dataframe.
"""
Expand Down Expand Up @@ -344,7 +344,7 @@ def test_momentum_calibration_equiscale():
np.testing.assert_equal(metadata["calibration"][key], value)


def test_momentum_calibration_two_points():
def test_momentum_calibration_two_points() -> None:
"""Test the calibration using two k-points, and application to the dataframe."""
config = parse_config(
config={"core": {"loader": "mpes"}},
Expand Down
82 changes: 0 additions & 82 deletions tests/loader/flash/test_data.ipynb

This file was deleted.

Loading