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

Sylvia whittle/596 zscale grains #597

Merged
merged 5 commits into from
Jun 14, 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
21 changes: 14 additions & 7 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ def test_update_config(caplog) -> None:

@pytest.mark.parametrize(
"image_name, core_set, title, zrange",
[("extracted_channel", False, "Raw Height", KeyError()), ("z_threshed", True, "Height Thresholded", [0, 3])],
[
("extracted_channel", False, "Raw Height", [0, 3]),
("z_threshed", True, "Height Thresholded", [0, 3]),
("grain_image", False, "", [0, 3]), # non-binary image
("grain_mask", False, "", [None, None]), # binary image
("grain_mask_image", False, "", [0, 3]), # non-binary image
],
)
def test_update_plotting_config(
process_scan_config: dict, image_name: str, core_set: bool, title: str, zrange: tuple
Expand All @@ -52,12 +58,13 @@ def test_update_plotting_config(
for each image in the plotting dictionary plot_dict."""
process_scan_config["plotting"] = update_plotting_config(process_scan_config["plotting"])
assert process_scan_config["plotting"]["plot_dict"][image_name]["core_set"] == core_set
assert process_scan_config["plotting"]["plot_dict"][image_name]["title"] == title
if image_name == "extracted_channel":
with pytest.raises(KeyError):
_ = process_scan_config["plotting"]["plot_dict"][image_name]["zrange"]
else:
assert process_scan_config["plotting"]["plot_dict"][image_name]["zrange"] == zrange
# Only check titles for images that have titles. grain_image, grain_mask, grain_mask_image don't
# have titles since they're created dynamically.
if title in ["extracted_channel", "z_threshed"]:
assert process_scan_config["plotting"]["plot_dict"][image_name]["title"] == title
# Ensure that both types (binary, non-binary) of image have the correct z-ranges
# ([None, None] for binary, user defined for non-binary)
assert process_scan_config["plotting"]["plot_dict"][image_name]["zrange"] == zrange


def test_get_thresholds_otsu(image_random: np.ndarray) -> None:
Expand Down
2 changes: 1 addition & 1 deletion topostats/plotting_dictionary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ grain_image:
image_type: "non-binary"
core_set: false
grain_mask:
image_type: "non-binary"
image_type: "binary"
core_set: false
grain_mask_image:
image_type: "non-binary"
Expand Down
6 changes: 4 additions & 2 deletions topostats/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ def update_plotting_config(plotting_config: dict) -> dict:
main_config.pop(opt)
for image, options in plotting_config["plot_dict"].items():
plotting_config["plot_dict"][image] = {**options, **main_config}
if image not in ["z_threshed", "mask_overlay"]:
plotting_config["plot_dict"][image].pop("zrange")
# Make it so that binary images do not have the user-defined z-scale
# applied, but non-binary images do.
if plotting_config["plot_dict"][image]["image_type"] == "binary":
plotting_config["plot_dict"][image]["zrange"] = [None, None]

return plotting_config

Expand Down