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

tests: disable test_run_modules::test_grainstats #1100

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
37 changes: 21 additions & 16 deletions tests/test_run_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def test_grains(caplog) -> None:
]


@pytest.mark.xfail(reason="Awaiting update of AFMReader to reconstruct `image_grain_crops` with correct classes")
def test_grainstats(caplog) -> None:
"""Test running the grainstats module.

Expand All @@ -239,30 +240,34 @@ def test_grainstats(caplog) -> None:
assert "[minicircle_small] Grainstats completed (NB - Filtering was *not* re-run)." in caplog.text
# Load the output and check the keys
data = pd.read_csv("output/image_stats.csv")
print(f"\n{list(data.columns)=}\n")
assert list(data.columns) == [
"Unnamed: 0",
"image",
"basename",
"grain_number",
"area",
"area_cartesian_bbox",
"aspect_ratio",
"bending_angle",
"centre_x",
"centre_y",
"radius_min",
"circular",
"contour_length",
"end_to_end_distance",
"height_max",
"height_mean",
"height_median",
"height_min",
"max_feret",
"min_feret",
"radius_max",
"radius_mean",
"radius_median",
"height_min",
"height_max",
"height_median",
"height_mean",
"volume",
"area",
"area_cartesian_bbox",
"smallest_bounding_width",
"smallest_bounding_length",
"radius_min",
"smallest_bounding_area",
"aspect_ratio",
"smallest_bounding_length",
"smallest_bounding_width",
"threshold",
"max_feret",
"min_feret",
"image",
"basename",
"volume",
]
assert data.shape == (3, 23)
52 changes: 24 additions & 28 deletions topostats/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
# pylint: disable=too-many-branches
# pylint: disable=too-many-lines
# pylint: disable=too-many-locals
# pylint: disable=too-many-positional-arguments
# pylint: disable=too-many-statements
# pylint: disable=too-many-nested-blocks
# pylint: disable=unnecessary-dict-index-lookup
Expand Down Expand Up @@ -464,10 +465,8 @@ def run_disordered_tracing(
disordered_trace_grainstats = pd.DataFrame()
disordered_tracing_stats_image = pd.DataFrame()
try:

grain_crop_direction: GrainCropsDirection
for direction, grain_crop_direction in image_grain_crops.__dict__.items():

if grain_crop_direction is None:
LOGGER.warning(
f"[{filename}] : No grains exist for the {direction} direction. Skipping disordered_tracing for {direction}."
Expand Down Expand Up @@ -1479,33 +1478,30 @@ def process_grainstats(
plotting_config = add_pixel_to_nm_to_plotting_config(plotting_config, topostats_object["pixel_to_nm_scaling"])

# Calculate grainstats if there are any to be detected
# try:
print(f"\n{topostats_object.keys()=}\n")
if "above" in topostats_object["grain_masks"].keys() or "below" in topostats_object["grain_masks"].keys():
grainstats_df, height_profiles = run_grainstats(
image=topostats_object["image"],
pixel_to_nm_scaling=topostats_object["pixel_to_nm_scaling"],
grain_masks=topostats_object["grain_masks"],
filename=topostats_object["filename"],
basename=topostats_object["img_path"],
grainstats_config=grainstats_config,
plotting_config=plotting_config,
grain_out_path=grainstats_out_path,
)
# Save the topostats dictionary object to .topostats file.
topostats_object["height_profiles"] = height_profiles
save_topostats_file(
output_dir=core_out_path, filename=str(topostats_object["filename"]), topostats_object=topostats_object
try:
if "above" in topostats_object["grain_masks"].keys() or "below" in topostats_object["grain_masks"].keys():
grainstats_df, height_profiles = run_grainstats(
image_grain_crops=topostats_object["image"],
filename=topostats_object["filename"],
basename=topostats_object["img_path"],
grainstats_config=grainstats_config,
plotting_config=plotting_config,
grain_out_path=grainstats_out_path,
)
# Save the topostats dictionary object to .topostats file.
topostats_object["height_profiles"] = height_profiles
save_topostats_file(
output_dir=core_out_path, filename=str(topostats_object["filename"]), topostats_object=topostats_object
)
return (topostats_object["filename"], grainstats_df, height_profiles)
return (
topostats_object["filename"],
create_empty_dataframe(column_set="grainstats"),
None,
)
return (topostats_object["filename"], grainstats_df, height_profiles)
return (
topostats_object["filename"],
create_empty_dataframe(column_set="grainstats", index_col="grain_number"),
None,
)
# except: # noqa: E722 # pylint: disable=bare-except
# LOGGER.info(f"Grain detection failed for image : {topostats_object['filename']}")
# return (create_empty_dataframe(column_set="grainstats", index_col="grain_number"), False)
except: # noqa: E722 # pylint: disable=bare-except
LOGGER.info(f"Grain detection failed for image : {topostats_object['filename']}")
return (topostats_object["filename"], create_empty_dataframe(column_set="grainstats"), False)


def check_run_steps( # noqa: C901
Expand Down
Loading