Skip to content

Commit

Permalink
chore: fix linting errors
Browse files Browse the repository at this point in the history
Fixes a bunch of linting errors, some notes left in place for tasks to be completed (e.g. see #899).
  • Loading branch information
ns-rse committed Sep 13, 2024
1 parent 0a51d25 commit 7259eef
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 182 deletions.
1 change: 1 addition & 0 deletions .markdownlint-cli2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ config:
html:
allowed_elements:
- div
- br

# Globs
globs:
Expand Down
170 changes: 115 additions & 55 deletions tests/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ def test_process_scan_below(regtest, tmp_path, process_scan_config: dict, load_s
process_scan_config["grains"]["threshold_std_dev"]["below"] = 0.8
process_scan_config["grains"]["smallest_grain_size_nm2"] = 10
process_scan_config["grains"]["absolute_area_threshold"]["below"] = [1, 1000000000]

process_scan_config["grains"]["direction"] = "below"
img_dic = load_scan_data.img_dict
_, results, img_stats = process_scan(
_, results, img_stats, _, _ = process_scan(
topostats_object=img_dic["minicircle_small"],
base_dir=BASE_DIR,
filter_config=process_scan_config["filter"],
grains_config=process_scan_config["grains"],
grainstats_config=process_scan_config["grainstats"],
dnatracing_config=process_scan_config["dnatracing"],
disordered_tracing_config=process_scan_config["disordered_tracing"],
nodestats_config=process_scan_config["nodestats"],
ordered_tracing_config=process_scan_config["ordered_tracing"],
splining_config=process_scan_config["splining"],
plotting_config=process_scan_config["plotting"],
output_dir=tmp_path,
)
Expand All @@ -57,13 +59,16 @@ def test_process_scan_above(regtest, tmp_path, process_scan_config: dict, load_s
process_scan_config["grains"]["absolute_area_threshold"]["below"] = [1, 1000000000]

img_dic = load_scan_data.img_dict
_, results, img_stats = process_scan(
_, results, img_stats, _, _ = process_scan(
topostats_object=img_dic["minicircle_small"],
base_dir=BASE_DIR,
filter_config=process_scan_config["filter"],
grains_config=process_scan_config["grains"],
grainstats_config=process_scan_config["grainstats"],
dnatracing_config=process_scan_config["dnatracing"],
disordered_tracing_config=process_scan_config["disordered_tracing"],
nodestats_config=process_scan_config["nodestats"],
ordered_tracing_config=process_scan_config["ordered_tracing"],
splining_config=process_scan_config["splining"],
plotting_config=process_scan_config["plotting"],
output_dir=tmp_path,
)
Expand All @@ -82,13 +87,16 @@ def test_process_scan_both(regtest, tmp_path, process_scan_config: dict, load_sc

process_scan_config["grains"]["direction"] = "both"
img_dic = load_scan_data.img_dict
_, results, img_stats = process_scan(
_, results, img_stats, _, _ = process_scan(
topostats_object=img_dic["minicircle_small"],
base_dir=BASE_DIR,
filter_config=process_scan_config["filter"],
grains_config=process_scan_config["grains"],
grainstats_config=process_scan_config["grainstats"],
dnatracing_config=process_scan_config["dnatracing"],
disordered_tracing_config=process_scan_config["disordered_tracing"],
nodestats_config=process_scan_config["nodestats"],
ordered_tracing_config=process_scan_config["ordered_tracing"],
splining_config=process_scan_config["splining"],
plotting_config=process_scan_config["plotting"],
output_dir=tmp_path,
)
Expand Down Expand Up @@ -130,13 +138,16 @@ def test_save_cropped_grains(
process_scan_config["plotting"]["savefig_dpi"] = 50

img_dic = load_scan_data.img_dict
_, _, _ = process_scan(
_, _, _, _, _ = process_scan(
topostats_object=img_dic["minicircle_small"],
base_dir=BASE_DIR,
filter_config=process_scan_config["filter"],
grains_config=process_scan_config["grains"],
grainstats_config=process_scan_config["grainstats"],
dnatracing_config=process_scan_config["dnatracing"],
disordered_tracing_config=process_scan_config["disordered_tracing"],
nodestats_config=process_scan_config["nodestats"],
ordered_tracing_config=process_scan_config["ordered_tracing"],
splining_config=process_scan_config["splining"],
plotting_config=process_scan_config["plotting"],
output_dir=tmp_path,
)
Expand Down Expand Up @@ -175,13 +186,16 @@ def test_save_format(process_scan_config: dict, load_scan_data: LoadScans, tmp_p
process_scan_config["plotting"] = update_plotting_config(process_scan_config["plotting"])

img_dic = load_scan_data.img_dict
_, _, _ = process_scan(
_, _, _, _, _ = process_scan(
topostats_object=img_dic["minicircle_small"],
base_dir=BASE_DIR,
filter_config=process_scan_config["filter"],
grains_config=process_scan_config["grains"],
grainstats_config=process_scan_config["grainstats"],
dnatracing_config=process_scan_config["dnatracing"],
disordered_tracing_config=process_scan_config["disordered_tracing"],
nodestats_config=process_scan_config["nodestats"],
ordered_tracing_config=process_scan_config["ordered_tracing"],
splining_config=process_scan_config["splining"],
plotting_config=process_scan_config["plotting"],
output_dir=tmp_path,
)
Expand All @@ -194,78 +208,110 @@ def test_save_format(process_scan_config: dict, load_scan_data: LoadScans, tmp_p
assert guess.extension == extension


# noqa: PLR0913
# pylint: disable=too-many-arguments
@pytest.mark.parametrize(
("filter_run", "grains_run", "grainstats_run", "dnatracing_run", "log_msg"),
("filter_run", "grains_run", "grainstats_run", "dnatracing_run", "nodestats_run", "splining_run", "log_msg"),
[
(
pytest.param(
False,
False,
False,
True,
False,
False,
"DNA tracing enabled but Grainstats disabled. Please check your configuration file.",
id="DNA tracing enabled but no Grainstats, Grains or Filters",
),
(
pytest.param(
False,
False,
True,
True,
False,
False,
"DNA tracing enabled but Grains disabled. Please check your configuration file.",
id="DNA tracing and Grainstats enabled but no Grains or Filters",
),
(
pytest.param(
False,
True,
True,
True,
False,
False,
"DNA tracing enabled but Filters disabled. Please check your configuration file.",
id="DNA tracing, Grains and Grainstats enabled but no Filters",
),
(
pytest.param(
False,
False,
True,
False,
False,
False,
"Grainstats enabled but Grains disabled. Please check your configuration file.",
id="Grainstats enabled but no Grains or Filters",
),
(
pytest.param(
False,
True,
True,
False,
False,
False,
"Grainstats enabled but Filters disabled. Please check your configuration file.",
id="Grains enabled and Grainstats but no Filters",
),
(
pytest.param(
False,
True,
False,
False,
False,
False,
"Grains enabled but Filters disabled. Please check your configuration file.",
id="Grains enabled but not Filters",
),
(
pytest.param(
True,
False,
False,
False,
False,
False,
"Configuration run options are consistent, processing can proceed.",
id="Consistent configuration upto Filters",
),
(
pytest.param(
True,
True,
False,
False,
False,
False,
"Configuration run options are consistent, processing can proceed.",
id="Consistent configuration upto Grains",
),
(
pytest.param(
True,
True,
True,
False,
False,
False,
"Configuration run options are consistent, processing can proceed.",
id="Consistent configuration upto Grainstats",
),
(
pytest.param(
True,
True,
True,
True,
False,
False,
"Configuration run options are consistent, processing can proceed.",
id="Consistent configuration upto DNA tracing",
),
],
)
Expand All @@ -274,15 +320,17 @@ def test_check_run_steps(
grains_run: bool,
grainstats_run: bool,
dnatracing_run: bool,
nodestats_run: bool,
splining_run: bool,
log_msg: str,
caplog,
) -> None:
"""Test the logic which checks whether enabled processing options are consistent."""
check_run_steps(filter_run, grains_run, grainstats_run, dnatracing_run)
check_run_steps(filter_run, grains_run, grainstats_run, dnatracing_run, nodestats_run, splining_run)
assert log_msg in caplog.text


# noqa: disable=too-many-arguments
# noqa: PLR0913
# pylint: disable=too-many-arguments
@pytest.mark.parametrize(
("filter_run", "grains_run", "grainstats_run", "dnatracing_run", "log_msg1", "log_msg2"),
Expand Down Expand Up @@ -357,13 +405,16 @@ def test_process_stages(
process_scan_config["grains"]["run"] = grains_run
process_scan_config["grainstats"]["run"] = grainstats_run
process_scan_config["dnatracing"]["run"] = dnatracing_run
_, _, _ = process_scan(
_, _, _, _, _ = process_scan(
topostats_object=img_dic["minicircle_small"],
base_dir=BASE_DIR,
filter_config=process_scan_config["filter"],
grains_config=process_scan_config["grains"],
grainstats_config=process_scan_config["grainstats"],
dnatracing_config=process_scan_config["dnatracing"],
disordered_tracing_config=process_scan_config["disordered_tracing"],
nodestats_config=process_scan_config["nodestats"],
ordered_tracing_config=process_scan_config["ordered_tracing"],
splining_config=process_scan_config["splining"],
plotting_config=process_scan_config["plotting"],
output_dir=tmp_path,
)
Expand All @@ -377,13 +428,16 @@ def test_process_scan_no_grains(process_scan_config: dict, load_scan_data: LoadS
img_dic = load_scan_data.img_dict
process_scan_config["grains"]["threshold_std_dev"]["above"] = 1000
process_scan_config["filter"]["remove_scars"]["run"] = False
_, _, _ = process_scan(
_, _, _, _, _ = process_scan(
topostats_object=img_dic["minicircle_small"],
base_dir=BASE_DIR,
filter_config=process_scan_config["filter"],
grains_config=process_scan_config["grains"],
grainstats_config=process_scan_config["grainstats"],
dnatracing_config=process_scan_config["dnatracing"],
disordered_tracing_config=process_scan_config["disordered_tracing"],
nodestats_config=process_scan_config["nodestats"],
ordered_tracing_config=process_scan_config["ordered_tracing"],
splining_config=process_scan_config["splining"],
plotting_config=process_scan_config["plotting"],
output_dir=tmp_path,
)
Expand All @@ -406,13 +460,16 @@ def test_process_scan_align_grainstats_dnatracing(
process_scan_config["filter"]["remove_scars"]["run"] = False
process_scan_config["grains"]["absolute_area_threshold"]["above"] = [150, 3000]
process_scan_config["dnatracing"]["min_skeleton_size"] = 50
_, results, _ = process_scan(
_, results, _, _, _ = process_scan(
topostats_object=img_dic["minicircle_small"],
base_dir=BASE_DIR,
filter_config=process_scan_config["filter"],
grains_config=process_scan_config["grains"],
grainstats_config=process_scan_config["grainstats"],
dnatracing_config=process_scan_config["dnatracing"],
disordered_tracing_config=process_scan_config["disordered_tracing"],
nodestats_config=process_scan_config["nodestats"],
ordered_tracing_config=process_scan_config["ordered_tracing"],
splining_config=process_scan_config["splining"],
plotting_config=process_scan_config["plotting"],
output_dir=tmp_path,
)
Expand Down Expand Up @@ -489,6 +546,7 @@ def test_run_grainstats(process_scan_config: dict, tmp_path: Path) -> None:
pixel_to_nm_scaling=0.4940029296875,
grain_masks=grain_masks,
filename="dummy filename",
basename=RESOURCES,
grainstats_config=process_scan_config["grainstats"],
plotting_config=process_scan_config["plotting"],
grain_out_path=tmp_path,
Expand All @@ -499,28 +557,30 @@ def test_run_grainstats(process_scan_config: dict, tmp_path: Path) -> None:
assert len(grainstats_df.columns) == 21


def test_run_dnatracing(process_scan_config: dict, tmp_path: Path) -> None:
"""Test the dnatracing_wrapper function of processing.py."""
flattened_image = np.load("./tests/resources/minicircle_cropped_flattened.npy")
mask_above = np.load("./tests/resources/minicircle_cropped_masks_above.npy")
mask_below = np.load("./tests/resources/minicircle_cropped_masks_below.npy")
grain_masks = {"above": mask_above, "below": mask_below}

dnatracing_df, grain_trace_data = run_dnatracing(
image=flattened_image,
grain_masks=grain_masks,
pixel_to_nm_scaling=0.4940029296875,
image_path=tmp_path,
filename="dummy filename",
core_out_path=tmp_path,
grain_out_path=tmp_path,
dnatracing_config=process_scan_config["dnatracing"],
plotting_config=process_scan_config["plotting"],
results_df=pd.read_csv("./tests/resources/minicircle_cropped_grainstats.csv"),
)

assert isinstance(grain_trace_data, dict)
assert list(grain_trace_data.keys()) == ["above", "below"]
assert isinstance(dnatracing_df, pd.DataFrame)
assert dnatracing_df.shape[0] == 13
assert len(dnatracing_df.columns) == 26
# ns-rse 2024-09-11 : Test disabled as run_dnatracing() has been removed in refactoring, needs updating/replacing to
# reflect the revised workflow/functions.
# def test_run_dnatracing(process_scan_config: dict, tmp_path: Path) -> None:
# """Test the dnatracing_wrapper function of processing.py."""
# flattened_image = np.load("./tests/resources/minicircle_cropped_flattened.npy")
# mask_above = np.load("./tests/resources/minicircle_cropped_masks_above.npy")
# mask_below = np.load("./tests/resources/minicircle_cropped_masks_below.npy")
# grain_masks = {"above": mask_above, "below": mask_below}

# dnatracing_df, grain_trace_data = run_dnatracing(
# image=flattened_image,
# grain_masks=grain_masks,
# pixel_to_nm_scaling=0.4940029296875,
# image_path=tmp_path,
# filename="dummy filename",
# core_out_path=tmp_path,
# grain_out_path=tmp_path,
# dnatracing_config=process_scan_config["dnatracing"],
# plotting_config=process_scan_config["plotting"],
# results_df=pd.read_csv("./tests/resources/minicircle_cropped_grainstats.csv"),
# )

# assert isinstance(grain_trace_data, dict)
# assert list(grain_trace_data.keys()) == ["above", "below"]
# assert isinstance(dnatracing_df, pd.DataFrame)
# assert dnatracing_df.shape[0] == 13
# assert len(dnatracing_df.columns) == 26
Loading

0 comments on commit 7259eef

Please sign in to comment.