Skip to content

Commit 8e33faa

Browse files
committed
TopoStats classes - Grains
The `Grains` class now works with `TopoStats` classes, however...because `GrainCrops` was used in `TopoStats` and this work meant `TopoStats` was used by `Grains` we introduced a circular dependency which Python, reasonably, complains about. The solution has been to move the class definitions to their own modules `topostats.classes`, but that wasn't without some issues since there are static methods of the `Grains` class that were used _within_ `GrainCrop`. For now these have been moved to the `utils` module and I've started writing tests for them (as they didn't appear to have any). As a consequence this commit has a lot of things moving around which _will_ make it a pain to review, but hopefully this will be worth it. For now the whole test suite does _not_ pass all tests because the integration tests where the pipeline is run end-to-end fails. No attempt has been made to correct this yet because ultimately we would like to simply update the `TopoStats` objects and pass them around and that will only be addressed once each processing step/class has been refactored to work with these. Subsequent modules should be a little easier to refactor now that the circular dependencies have been broken.
1 parent e91b7fa commit 8e33faa

File tree

10 files changed

+353
-1118
lines changed

10 files changed

+353
-1118
lines changed

tests/conftest.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
from skimage.morphology import skeletonize
2020

2121
import topostats
22+
from topostats.classes import GrainCrop, GrainCropsDirection, ImageGrainCrops, TopoStats
2223
from topostats.filters import Filters
23-
from topostats.grains import GrainCrop, GrainCropsDirection, Grains, ImageGrainCrops
24+
25+
# from topostats.grains import GrainCrop, GrainCropsDirection, Grains, ImageGrainCrops
26+
from topostats.grains import Grains
2427
from topostats.grainstats import GrainStats
2528
from topostats.io import LoadScans, read_yaml
2629
from topostats.plotting import TopoSum
@@ -472,7 +475,7 @@ def imagegraincrops_catenanes(graincrops_above_catenanes: GrainCropsDirection) -
472475
@pytest.fixture()
473476
def topostats_catenanes_2_4_0(imagegraincrops_catenanes) -> topostats.TopoStats:
474477
"""TopoStats object of example catenanes."""
475-
return topostats.TopoStats(
478+
return TopoStats(
476479
image_grain_crops=imagegraincrops_catenanes,
477480
filename="example_catenanes.spm",
478481
pixel_to_nm_scaling=0.488,
@@ -514,7 +517,7 @@ def imagegraincrops_rep_int(graincrops_above_rep_int: GrainCropsDirection) -> Im
514517
@pytest.fixture()
515518
def topostats_rep_int_2_4_0(imagegraincrops_rep_int) -> topostats.TopoStats:
516519
"""TopoStats object of example rep_int."""
517-
return topostats.TopoStats(
520+
return TopoStats(
518521
image_grain_crops=imagegraincrops_rep_int,
519522
filename="example_rep_int.spm",
520523
pixel_to_nm_scaling=0.488,
@@ -741,10 +744,16 @@ def minicircle_grain_gaussian_filter(minicircle_masked_quadratic_removal: Filter
741744
@pytest.fixture()
742745
def minicircle_grains(minicircle_grain_gaussian_filter: Filters, grains_config: dict) -> Grains:
743746
"""Grains object based on filtered minicircle."""
744-
return Grains(
747+
# TEMPORARY - This will be replaced when we have all modules working and start passing around TopoStats objects in
748+
# their entirety
749+
topostats_object = TopoStats(
745750
image=minicircle_grain_gaussian_filter.images["gaussian_filtered"],
746751
filename=minicircle_grain_gaussian_filter.filename,
747752
pixel_to_nm_scaling=minicircle_grain_gaussian_filter.pixel_to_nm_scaling,
753+
img_path=Path.cwd(),
754+
)
755+
return Grains(
756+
topostats_object=topostats_object,
748757
**grains_config,
749758
)
750759

tests/test_filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77
from skimage.filters import gaussian # pylint: disable=no-name-in-module
88

9-
from topostats import TopoStats
9+
from topostats.classes import TopoStats
1010
from topostats.filters import Filters
1111

1212
# pylint: disable=protected-access

0 commit comments

Comments
 (0)