From 47f09c016f915058922a62517bfdf47f33fafa57 Mon Sep 17 00:00:00 2001 From: Neil Shephard Date: Mon, 11 Nov 2024 16:46:05 +0000 Subject: [PATCH 01/13] package: Unpin topoly version Wheels are now available for all OS's and architectures (thanks @prubach :+1: ) Closes #994 --- pyproject.toml | 2 +- .../catenanes_ordered_tracing_data.pkl | Bin 50475 -> 50472 bytes .../catenanes_ordered_tracing_molstats.csv | 8 ++++---- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a6412a3cd62..d6cbc242b75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,7 +55,7 @@ dependencies = [ "snoop", "tensorflow", "tifffile", - "topoly==1.0.2", + "topoly", "tqdm", ] diff --git a/tests/resources/tracing/ordered_tracing/catenanes_ordered_tracing_data.pkl b/tests/resources/tracing/ordered_tracing/catenanes_ordered_tracing_data.pkl index 29949ab9447afddadb52fcbf4bfa456344f4402b..f92b9053f6f6a3fbcd3b1a8c8a54655f239b78b3 100644 GIT binary patch delta 58 zcmZ48#k``6nWcecs_aIVyBVQ+jwy@(c2F^3yBh({eHkru4A*7$t7L=Vg?{ L0%nP>6_Wq}U6T|= delta 61 zcmZ3{#k{(UnWcecs=`K=y Date: Mon, 11 Nov 2024 14:31:24 +0000 Subject: [PATCH 02/13] tests: Peg pytest-regtest to 2.3.1 as failing on OSX Tests using [`pytest-regtest-2.3.2`](https://pypi.org/project/pytest-regtest/#history) are [failing on OSX](https://github.com/AFM-SPM/TopoStats/actions/runs/11780199328/job/32810287345?pr=988) pegging version to `pytest-regtest==2.3.1` to see if this resolves the issue. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d6cbc242b75..a0481ad5618 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,7 +65,7 @@ tests = [ "pytest-cov", "pytest-github-actions-annotate-failures", "pytest-mpl", - "pytest-regtest", + "pytest-regtest==2.3.1", "pytest-testmon", "filetype", ] From b0e72da60b518d3fd6af2bf038b7b4256fdaf641 Mon Sep 17 00:00:00 2001 From: Neil Shephard Date: Fri, 15 Nov 2024 09:43:12 +0000 Subject: [PATCH 03/13] ci: Adds a Pull Request template As [suggested](https://github.com/AFM-SPM/TopoStats/pull/996#issuecomment-2476147390) by @SylviaWhittle we could all do with an _aide memoire_ when making Pull Requests that we have covered everything we should. This Pull Request therefore introduces just such a template to aid contributors in making sure we have covered everything. --- - [ ] Existing tests pass. **N/A** no changes to code base introduced. - [ ] Documentation has been updated and builds. **N/A** no changes to code base introduced. - [x] Pre-commit checks pass. - [ ] New functions/methods have typehints and docstrings. **N/A** no changes to code base introduced. - [ ] New functions/methods have tests which check the intended behaviour is correct. **N/A** no changes to code base introduced. --- .github/pull_request_template.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000000..4e39eab83bc --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,29 @@ +# TopoStats Pull Requests + +Please provide a descriptive summary of the changes your Pull Request introduces. + +The [Software Development](https://afm-spm.github.io/TopoStats/main/contributing.html#software-development) section of +the Contributing Guidelines may be useful if you are unfamiliar with linting, pre-commit, docstrings and testing. + +**NB** - This header should be replaced with the description but please complete the below checklist or a short +description of why a particular item is not relevant. + +--- + +Before submitting a Pull Request please check the following. + +- [ ] Existing tests pass. +- [ ] Documentation has been updated and builds. +- [ ] Pre-commit checks pass. +- [ ] New functions/methods have typehints and docstrings. +- [ ] New functions/methods have tests which check the intended behaviour is correct. + +## Optional + +### `topostats/default_config.yaml` + +If adding options to `topostats/default_config.yaml` please ensure. + +- [ ] There is a comment adjacent to the option explaining what it is and the valid values. +- [ ] A check is made in `topostats/validation.py` to ensure entries are valid. +- [ ] Add the option to the relevant sub-parser in `topostats/entry_point.py`. From 1706c7c972ff10c14767dae74209477e948aec00 Mon Sep 17 00:00:00 2001 From: Neil Shephard Date: Fri, 15 Nov 2024 11:18:24 +0000 Subject: [PATCH 04/13] ci: Clarify docs to be updated in PR template Co-authored-by: Sylvia Whittle <86117496+SylviaWhittle@users.noreply.github.com> --- .github/pull_request_template.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 4e39eab83bc..1e9dcde0b54 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -13,7 +13,8 @@ description of why a particular item is not relevant. Before submitting a Pull Request please check the following. - [ ] Existing tests pass. -- [ ] Documentation has been updated and builds. +- [ ] Documentation has been updated and builds. Remember to update `configuration.md`, `usage.md`, and relevant + processing sections under `advanced.md`. - [ ] Pre-commit checks pass. - [ ] New functions/methods have typehints and docstrings. - [ ] New functions/methods have tests which check the intended behaviour is correct. From ec786ef39c2d06ab5c3c94a1f2239f59b6e533b0 Mon Sep 17 00:00:00 2001 From: TomC Date: Fri, 8 Nov 2024 11:51:49 +0000 Subject: [PATCH 05/13] initial testing --- topostats/tracing/disordered_tracing.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/topostats/tracing/disordered_tracing.py b/topostats/tracing/disordered_tracing.py index 9acce787cd0..b5f7931da02 100644 --- a/topostats/tracing/disordered_tracing.py +++ b/topostats/tracing/disordered_tracing.py @@ -131,6 +131,8 @@ def trace_dna(self): self.pruned_skeleton = self.remove_touching_edge(self.pruned_skeleton) self.disordered_trace = np.argwhere(self.pruned_skeleton == 1) + disorderedTrace.calculate_dna_width(trace=self.disordered_trace, mask=self.smoothed_mask) + if self.disordered_trace is None: LOGGER.warning(f"[{self.filename}] : Grain {self.n_grain} failed to Skeletonise.") self.disordered_trace = None @@ -253,6 +255,22 @@ def smooth_mask( return self.re_add_holes(grain, gauss, holearea_min_max) LOGGER.debug(f"[{self.filename}] : smoothing done by dilation {dilation_iterations}") return self.re_add_holes(grain, dilation, holearea_min_max) + + @staticmethod + def calculate_dna_width(trace: npt.NDArray, mask: npt.NDArray) -> float: + """ + Calculate the average width in metres of the DNA using the trace and mask. + """ + + import matplotlib.pyplot as plt + from scipy.ndimage import distance_transform_edt + # Code will go here + + average_dna_width = 5 + + print(f"@@@@@@@@@@@@ CALCULATING DNA WIDTH") + + return average_dna_width * 1e-9 def trace_image_disordered( # pylint: disable=too-many-arguments,too-many-locals From 0b76fa7e566cf25cb228e3d6a1c7f525ae963b45 Mon Sep 17 00:00:00 2001 From: TomC Date: Mon, 11 Nov 2024 10:26:13 +0000 Subject: [PATCH 06/13] further testing --- topostats/tracing/disordered_tracing.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/topostats/tracing/disordered_tracing.py b/topostats/tracing/disordered_tracing.py index b5f7931da02..8fe17baa43e 100644 --- a/topostats/tracing/disordered_tracing.py +++ b/topostats/tracing/disordered_tracing.py @@ -266,9 +266,11 @@ def calculate_dna_width(trace: npt.NDArray, mask: npt.NDArray) -> float: from scipy.ndimage import distance_transform_edt # Code will go here + + average_dna_width = 5 - print(f"@@@@@@@@@@@@ CALCULATING DNA WIDTH") + print(average_dna_width) return average_dna_width * 1e-9 From ec27115d23ece6b525e1ac09ec2a5e34b1382c00 Mon Sep 17 00:00:00 2001 From: TomC Date: Tue, 12 Nov 2024 12:13:09 +0000 Subject: [PATCH 07/13] testing --- topostats/tracing/disordered_tracing.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/topostats/tracing/disordered_tracing.py b/topostats/tracing/disordered_tracing.py index 8fe17baa43e..568f7424b2d 100644 --- a/topostats/tracing/disordered_tracing.py +++ b/topostats/tracing/disordered_tracing.py @@ -266,12 +266,8 @@ def calculate_dna_width(trace: npt.NDArray, mask: npt.NDArray) -> float: from scipy.ndimage import distance_transform_edt # Code will go here - - average_dna_width = 5 - print(average_dna_width) - return average_dna_width * 1e-9 From d81f92cfa7cbadf81c9d62ae7312d8b03bef7d68 Mon Sep 17 00:00:00 2001 From: TomC Date: Thu, 14 Nov 2024 16:01:52 +0000 Subject: [PATCH 08/13] added dna width measurement in disordered tracing --- topostats/tracing/disordered_tracing.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/topostats/tracing/disordered_tracing.py b/topostats/tracing/disordered_tracing.py index 568f7424b2d..fd25724b66c 100644 --- a/topostats/tracing/disordered_tracing.py +++ b/topostats/tracing/disordered_tracing.py @@ -18,6 +18,7 @@ from topostats.tracing.pruning import prune_skeleton from topostats.tracing.skeletonize import getSkeleton from topostats.utils import convolve_skeleton +from scipy.ndimage import distance_transform_edt LOGGER = logging.getLogger(LOGGER_NAME) @@ -131,8 +132,6 @@ def trace_dna(self): self.pruned_skeleton = self.remove_touching_edge(self.pruned_skeleton) self.disordered_trace = np.argwhere(self.pruned_skeleton == 1) - disorderedTrace.calculate_dna_width(trace=self.disordered_trace, mask=self.smoothed_mask) - if self.disordered_trace is None: LOGGER.warning(f"[{self.filename}] : Grain {self.n_grain} failed to Skeletonise.") self.disordered_trace = None @@ -257,18 +256,16 @@ def smooth_mask( return self.re_add_holes(grain, dilation, holearea_min_max) @staticmethod - def calculate_dna_width(trace: npt.NDArray, mask: npt.NDArray) -> float: + def calculate_dna_width(smoothed_mask: npt.NDArray, pruned_skeleton: npt.NDArray, px2nm: float = 1) -> float: """ Calculate the average width in metres of the DNA using the trace and mask. """ - import matplotlib.pyplot as plt - from scipy.ndimage import distance_transform_edt # Code will go here + dist_trans = distance_transform_edt(smoothed_mask) + comb = np.where(pruned_skeleton==1,dist_trans,0) - average_dna_width = 5 - - return average_dna_width * 1e-9 + return comb[comb!=0].mean() * 2 * px2nm def trace_image_disordered( # pylint: disable=too-many-arguments,too-many-locals @@ -379,6 +376,7 @@ def trace_image_disordered( # pylint: disable=too-many-arguments,too-many-local "grain_endpoints": np.int64((conv_pruned_skeleton == 2).sum()), "grain_junctions": np.int64((conv_pruned_skeleton == 3).sum()), "total_branch_lengths": total_branch_length, + "grain_width": disorderedTrace.calculate_dna_width(disordered_trace_images["smoothed_grain"], disordered_trace_images["pruned_skeleton"], pixel_to_nm_scaling) * 1e-9 } # remap the cropped images back onto the original From 8ffed0dbbf52d555c49461c22bccc507fe2686cf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:08:02 +0000 Subject: [PATCH 09/13] [pre-commit.ci] Fixing issues with pre-commit --- topostats/tracing/disordered_tracing.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/topostats/tracing/disordered_tracing.py b/topostats/tracing/disordered_tracing.py index fd25724b66c..c56c358c0a4 100644 --- a/topostats/tracing/disordered_tracing.py +++ b/topostats/tracing/disordered_tracing.py @@ -11,6 +11,7 @@ import skan import skimage.measure as skimage_measure from scipy import ndimage +from scipy.ndimage import distance_transform_edt from skimage import filters from skimage.morphology import label @@ -18,7 +19,6 @@ from topostats.tracing.pruning import prune_skeleton from topostats.tracing.skeletonize import getSkeleton from topostats.utils import convolve_skeleton -from scipy.ndimage import distance_transform_edt LOGGER = logging.getLogger(LOGGER_NAME) @@ -254,18 +254,17 @@ def smooth_mask( return self.re_add_holes(grain, gauss, holearea_min_max) LOGGER.debug(f"[{self.filename}] : smoothing done by dilation {dilation_iterations}") return self.re_add_holes(grain, dilation, holearea_min_max) - + @staticmethod def calculate_dna_width(smoothed_mask: npt.NDArray, pruned_skeleton: npt.NDArray, px2nm: float = 1) -> float: """ Calculate the average width in metres of the DNA using the trace and mask. """ - # Code will go here dist_trans = distance_transform_edt(smoothed_mask) - comb = np.where(pruned_skeleton==1,dist_trans,0) + comb = np.where(pruned_skeleton == 1, dist_trans, 0) - return comb[comb!=0].mean() * 2 * px2nm + return comb[comb != 0].mean() * 2 * px2nm def trace_image_disordered( # pylint: disable=too-many-arguments,too-many-locals @@ -376,7 +375,12 @@ def trace_image_disordered( # pylint: disable=too-many-arguments,too-many-local "grain_endpoints": np.int64((conv_pruned_skeleton == 2).sum()), "grain_junctions": np.int64((conv_pruned_skeleton == 3).sum()), "total_branch_lengths": total_branch_length, - "grain_width": disorderedTrace.calculate_dna_width(disordered_trace_images["smoothed_grain"], disordered_trace_images["pruned_skeleton"], pixel_to_nm_scaling) * 1e-9 + "grain_width": disorderedTrace.calculate_dna_width( + disordered_trace_images["smoothed_grain"], + disordered_trace_images["pruned_skeleton"], + pixel_to_nm_scaling, + ) + * 1e-9, } # remap the cropped images back onto the original From 0fb3067969c52feaaa2bb5ecbc4b415bfcb15a02 Mon Sep 17 00:00:00 2001 From: TomC Date: Fri, 15 Nov 2024 08:38:00 +0000 Subject: [PATCH 10/13] tests(processing): Update regression test targets to include dna width --- .../test_processing.test_process_scan_above.out | 8 ++++---- .../test_processing.test_process_scan_both.out | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/_regtest_outputs/test_processing.test_process_scan_above.out b/tests/_regtest_outputs/test_processing.test_process_scan_above.out index f7031e304de..5e95e931e7c 100644 --- a/tests/_regtest_outputs/test_processing.test_process_scan_above.out +++ b/tests/_regtest_outputs/test_processing.test_process_scan_above.out @@ -1,7 +1,7 @@ image_size_x_m image_size_y_m image_area_m2 image_size_x_px image_size_y_px image_area_px2 grains_number_above grains_per_m2_above grains_number_below grains_per_m2_below rms_roughness image minicircle_small 1.2646e-07 1.2646e-07 1.5993e-14 64 64 4096 3 1.8758e+14 0 0.0000e+00 6.8208e-10 - centre_x centre_y grain_number radius_min 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 smallest_bounding_area aspect_ratio threshold max_feret min_feret image grain_endpoints grain_junctions total_branch_lengths num_crossings avg_crossing_confidence min_crossing_confidence num_mols writhe_string total_contour_length average_end_to_end_distance -0 7.5100e-08 4.7559e-08 0 3.9431e-09 2.5631e-08 1.6016e-08 1.6680e-08 9.1991e-10 2.6422e-09 1.5338e-09 1.5341e-09 1.0543e-24 6.8721e-16 1.3198e-15 2.0539e-08 5.0379e-08 1.0347e-15 4.0769e-01 above 5.0379e-08 2.0539e-08 minicircle_small 1 1 8.4571e-08 1 NaN NaN 2 6.5881e-08 8.8370e-09 -1 8.0241e-08 7.8677e-08 1 6.8951e-09 2.7188e-08 1.6272e-08 1.6263e-08 9.0630e-10 2.4586e-09 1.6144e-09 1.6264e-09 1.0352e-24 6.3645e-16 1.5931e-15 2.0174e-08 5.1212e-08 1.0332e-15 3.9394e-01 above 5.1262e-08 2.0174e-08 minicircle_small 0 0 7.3054e-08 0 NaN NaN 1 NaN 5.8272e-08 0.0000e+00 -2 4.0012e-08 7.5644e-08 2 9.9461e-09 2.3654e-08 1.7561e-08 1.8364e-08 9.0641e-10 2.1066e-09 1.5939e-09 1.5493e-09 1.1192e-24 7.2236e-16 1.5462e-15 3.3592e-08 4.1496e-08 1.3940e-15 8.0952e-01 above 4.4405e-08 3.2528e-08 minicircle_small 0 0 1.0447e-07 0 NaN NaN 1 NaN 8.7183e-08 0.0000e+00 + centre_x centre_y grain_number radius_min 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 smallest_bounding_area aspect_ratio threshold max_feret min_feret image grain_endpoints grain_junctions total_branch_lengths grain_width num_crossings avg_crossing_confidence min_crossing_confidence num_mols writhe_string total_contour_length average_end_to_end_distance +0 7.5100e-08 4.7559e-08 0 3.9431e-09 2.5631e-08 1.6016e-08 1.6680e-08 9.1991e-10 2.6422e-09 1.5338e-09 1.5341e-09 1.0543e-24 6.8721e-16 1.3198e-15 2.0539e-08 5.0379e-08 1.0347e-15 4.0769e-01 above 5.0379e-08 2.0539e-08 minicircle_small 1 1 8.4571e-08 8.2685e-09 1 NaN NaN 2 6.5881e-08 8.8370e-09 +1 8.0241e-08 7.8677e-08 1 6.8951e-09 2.7188e-08 1.6272e-08 1.6263e-08 9.0630e-10 2.4586e-09 1.6144e-09 1.6264e-09 1.0352e-24 6.3645e-16 1.5931e-15 2.0174e-08 5.1212e-08 1.0332e-15 3.9394e-01 above 5.1262e-08 2.0174e-08 minicircle_small 0 0 7.3054e-08 7.6154e-09 0 NaN NaN 1 NaN 5.8272e-08 0.0000e+00 +2 4.0012e-08 7.5644e-08 2 9.9461e-09 2.3654e-08 1.7561e-08 1.8364e-08 9.0641e-10 2.1066e-09 1.5939e-09 1.5493e-09 1.1192e-24 7.2236e-16 1.5462e-15 3.3592e-08 4.1496e-08 1.3940e-15 8.0952e-01 above 4.4405e-08 3.2528e-08 minicircle_small 0 0 1.0447e-07 7.8033e-09 0 NaN NaN 1 NaN 8.7183e-08 0.0000e+00 diff --git a/tests/_regtest_outputs/test_processing.test_process_scan_both.out b/tests/_regtest_outputs/test_processing.test_process_scan_both.out index bc27d40ab27..e10621542ff 100644 --- a/tests/_regtest_outputs/test_processing.test_process_scan_both.out +++ b/tests/_regtest_outputs/test_processing.test_process_scan_both.out @@ -1,7 +1,7 @@ image_size_x_m image_size_y_m image_area_m2 image_size_x_px image_size_y_px image_area_px2 grains_number_above grains_per_m2_above grains_number_below grains_per_m2_below rms_roughness image minicircle_small 1.2646e-07 1.2646e-07 1.5993e-14 64 64 4096 3 1.8758e+14 0 0.0000e+00 6.8208e-10 - centre_x centre_y grain_number radius_min 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 smallest_bounding_area aspect_ratio threshold max_feret min_feret image grain_endpoints grain_junctions total_branch_lengths total_contour_length average_end_to_end_distance -0 7.5100e-08 4.7559e-08 0 3.9431e-09 2.5631e-08 1.6016e-08 1.6680e-08 9.1991e-10 2.6422e-09 1.5338e-09 1.5341e-09 1.0543e-24 6.8721e-16 1.3198e-15 2.0539e-08 5.0379e-08 1.0347e-15 4.0769e-01 above 5.0379e-08 2.0539e-08 minicircle_small 1.0000e+00 1.0000e+00 8.4571e-08 6.5881e-08 8.8370e-09 -1 8.0241e-08 7.8677e-08 1 6.8951e-09 2.7188e-08 1.6272e-08 1.6263e-08 9.0630e-10 2.4586e-09 1.6144e-09 1.6264e-09 1.0352e-24 6.3645e-16 1.5931e-15 2.0174e-08 5.1212e-08 1.0332e-15 3.9394e-01 above 5.1262e-08 2.0174e-08 minicircle_small 0.0000e+00 0.0000e+00 7.3054e-08 5.8272e-08 0.0000e+00 -2 4.0012e-08 7.5644e-08 2 9.9461e-09 2.3654e-08 1.7561e-08 1.8364e-08 9.0641e-10 2.1066e-09 1.5939e-09 1.5493e-09 1.1192e-24 7.2236e-16 1.5462e-15 3.3592e-08 4.1496e-08 1.3940e-15 8.0952e-01 above 4.4405e-08 3.2528e-08 minicircle_small 0.0000e+00 0.0000e+00 1.0447e-07 8.7183e-08 0.0000e+00 + centre_x centre_y grain_number radius_min 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 smallest_bounding_area aspect_ratio threshold max_feret min_feret image grain_endpoints grain_junctions total_branch_lengths grain_width total_contour_length average_end_to_end_distance +0 7.5100e-08 4.7559e-08 0 3.9431e-09 2.5631e-08 1.6016e-08 1.6680e-08 9.1991e-10 2.6422e-09 1.5338e-09 1.5341e-09 1.0543e-24 6.8721e-16 1.3198e-15 2.0539e-08 5.0379e-08 1.0347e-15 4.0769e-01 above 5.0379e-08 2.0539e-08 minicircle_small 1.0000e+00 1.0000e+00 8.4571e-08 8.2685e-09 6.5881e-08 8.8370e-09 +1 8.0241e-08 7.8677e-08 1 6.8951e-09 2.7188e-08 1.6272e-08 1.6263e-08 9.0630e-10 2.4586e-09 1.6144e-09 1.6264e-09 1.0352e-24 6.3645e-16 1.5931e-15 2.0174e-08 5.1212e-08 1.0332e-15 3.9394e-01 above 5.1262e-08 2.0174e-08 minicircle_small 0.0000e+00 0.0000e+00 7.3054e-08 7.6154e-09 5.8272e-08 0.0000e+00 +2 4.0012e-08 7.5644e-08 2 9.9461e-09 2.3654e-08 1.7561e-08 1.8364e-08 9.0641e-10 2.1066e-09 1.5939e-09 1.5493e-09 1.1192e-24 7.2236e-16 1.5462e-15 3.3592e-08 4.1496e-08 1.3940e-15 8.0952e-01 above 4.4405e-08 3.2528e-08 minicircle_small 0.0000e+00 0.0000e+00 1.0447e-07 7.8033e-09 8.7183e-08 0.0000e+00 From 9e2d0f592ec4de20640d70f7c2db5d2c2f4faa0b Mon Sep 17 00:00:00 2001 From: TomC Date: Fri, 15 Nov 2024 13:03:10 +0000 Subject: [PATCH 11/13] tests(processing): Update regression test targets to include dna width and improved docstring --- topostats/tracing/disordered_tracing.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/topostats/tracing/disordered_tracing.py b/topostats/tracing/disordered_tracing.py index c56c358c0a4..f432f9d0981 100644 --- a/topostats/tracing/disordered_tracing.py +++ b/topostats/tracing/disordered_tracing.py @@ -258,7 +258,21 @@ def smooth_mask( @staticmethod def calculate_dna_width(smoothed_mask: npt.NDArray, pruned_skeleton: npt.NDArray, px2nm: float = 1) -> float: """ - Calculate the average width in metres of the DNA using the trace and mask. + Calculate the mean width in metres of the DNA using the trace and mask. + + Parameters + ---------- + smoothed_mask : npt.NDArray + Smoothed mask to be measured. + pruned_skeleton : npt.NDArray + Pruned skeleton. + px2nm : float + Scaling of pixels to nanometres. + + Returns + ------- + float + Width of grain in metres. """ # Code will go here dist_trans = distance_transform_edt(smoothed_mask) @@ -375,7 +389,7 @@ def trace_image_disordered( # pylint: disable=too-many-arguments,too-many-local "grain_endpoints": np.int64((conv_pruned_skeleton == 2).sum()), "grain_junctions": np.int64((conv_pruned_skeleton == 3).sum()), "total_branch_lengths": total_branch_length, - "grain_width": disorderedTrace.calculate_dna_width( + "grain_width_mean": disorderedTrace.calculate_dna_width( disordered_trace_images["smoothed_grain"], disordered_trace_images["pruned_skeleton"], pixel_to_nm_scaling, From b90f2af14dfe036eae6c746c8d22114b178babbf Mon Sep 17 00:00:00 2001 From: Neil Shephard Date: Mon, 18 Nov 2024 14:21:16 +0000 Subject: [PATCH 12/13] tests(tracing): Split and update tests of disordered traces Splits `test_trace_image_disordered` into two tests, the original compares dictionaries, the newer (suffixed with `_dataframes`) compares the dataframes/csv files that are produced, of which there are two and one needed updating to include the `grain_width_mean` column that #999 introduces. --- ...atenanes_disordered_tracing_grainstats.csv | 3 - .../catenanes_disordered_tracing_stats.csv | 25 ---- .../rep_int_disordered_tracing_grainstats.csv | 2 - .../rep_int_disordered_tracing_stats.csv | 13 -- ..._image_disordered_dataframes[catenane].out | 28 ++++ ...d_dataframes[replication_intermediate].out | 15 ++ tests/tracing/test_disordered_tracing.py | 141 ++++++++++++++---- 7 files changed, 152 insertions(+), 75 deletions(-) delete mode 100644 tests/resources/tracing/disordered_tracing/catenanes_disordered_tracing_grainstats.csv delete mode 100644 tests/resources/tracing/disordered_tracing/catenanes_disordered_tracing_stats.csv delete mode 100644 tests/resources/tracing/disordered_tracing/rep_int_disordered_tracing_grainstats.csv delete mode 100644 tests/resources/tracing/disordered_tracing/rep_int_disordered_tracing_stats.csv create mode 100644 tests/tracing/_regtest_outputs/test_disordered_tracing.test_trace_image_disordered_dataframes[catenane].out create mode 100644 tests/tracing/_regtest_outputs/test_disordered_tracing.test_trace_image_disordered_dataframes[replication_intermediate].out diff --git a/tests/resources/tracing/disordered_tracing/catenanes_disordered_tracing_grainstats.csv b/tests/resources/tracing/disordered_tracing/catenanes_disordered_tracing_grainstats.csv deleted file mode 100644 index dbeceb405dd..00000000000 --- a/tests/resources/tracing/disordered_tracing/catenanes_disordered_tracing_grainstats.csv +++ /dev/null @@ -1,3 +0,0 @@ -,image,grain_number,grain_endpoints,grain_junctions,total_branch_lengths -0,test_image,0,0,14,5.755249825836855e-07 -1,test_image,1,0,12,5.747857998943139e-07 diff --git a/tests/resources/tracing/disordered_tracing/catenanes_disordered_tracing_stats.csv b/tests/resources/tracing/disordered_tracing/catenanes_disordered_tracing_stats.csv deleted file mode 100644 index 4e0198f6f88..00000000000 --- a/tests/resources/tracing/disordered_tracing/catenanes_disordered_tracing_stats.csv +++ /dev/null @@ -1,25 +0,0 @@ -,image,grain_number,branch_distance,branch_type,connected_segments,mean_pixel_value,stdev_pixel_value,min_value,median_value,middle_value -0,test_image,0,29.857677897827887,2,"[1, 2, 6]",2.6683043052890536,0.3576668425125195,1.993486285613394,2.6464969869174926,2.6743964509318303 -1,test_image,0,28.644860587199464,2,"[0, 2, 6]",2.728953130422273,0.21545195325432523,2.5506513793095915,2.6838064728094184,2.6579579145357006 -2,test_image,0,1.8682724368761408,2,"[0, 1, 3, 4]",4.067541277649083,0.16905835685823303,3.7890382980796193,4.138536286707056,4.13958834095104 -3,test_image,0,146.60562184380709,2,"[2, 4, 9]",2.6693913722865377,0.2947637179915079,1.2200007753773205,2.7080175948240655,2.9115862857598005 -4,test_image,0,26.170179495009112,2,"[2, 3, 9]",2.834959559756504,0.3436409841063358,2.535374801513602,2.7607877845412387,2.7651337225310604 -5,test_image,0,224.58506419260596,2,"[6, 7, 10, 11]",2.700995491724554,0.2653435468736685,1.787397162651758,2.7330374920770115,2.2573671026451536 -6,test_image,0,6.9504086553142095,2,"[0, 1, 5, 7]",3.626373814193468,0.6406710041895474,2.588846104614013,3.84195778773634,3.84195778773634 -7,test_image,0,31.203269242513674,2,"[5, 6, 8, 11]",2.843560036090906,0.5572924823368127,2.1307434183593315,2.705164120987648,2.75295411300335 -8,test_image,0,31.286996805637532,2,"[7, 9, 10, 11]",2.7443198761048193,0.3822328907364185,2.4149214282007074,2.653495727717319,2.4706619619066386 -9,test_image,0,5.570136218438069,2,"[3, 4, 8, 10]",2.7308714736136963,0.049010037214155706,2.6525934702850984,2.7378802570467666,2.749457125278597 -10,test_image,0,38.18835899001824,2,"[5, 8, 9, 11]",2.7864423529784395,0.15142352544214144,2.445066671627662,2.7710339081422832,2.6967078592376783 -11,test_image,0,4.59413621843807,2,"[5, 7, 8, 10]",4.126603901043527,0.37133617585304246,3.351114087306773,4.238726491399509,4.238726491399509 -0,test_image,1,37.70035899001824,2,"[1, 2, 3, 6]",2.7732793700561382,0.13491385165238218,2.445066671627662,2.7690167332032654,2.7141994425994813 -1,test_image,1,223.89492797416787,2,"[0, 2, 4, 9]",2.69655183205219,0.26110756906553556,1.8203021919659572,2.7314109425842963,2.2743843560760055 -2,test_image,1,5.08213621843807,2,"[0, 1, 3, 4]",4.029037066510506,0.4638075153095662,3.0770475331177405,4.18502108746829,4.18502108746829 -3,test_image,1,31.001133024075603,2,"[0, 2, 4, 6]",2.746190739871742,0.4020468170580353,2.443926567140926,2.6515637708741715,2.443926567140926 -4,test_image,1,31.405405460951744,2,"[1, 2, 3, 9]",2.8422583900088516,0.5622599874985189,2.1307434183593315,2.694237316611716,2.75295411300335 -5,test_image,1,147.49789428068328,2,"[6, 7, 11]",2.6728103603722104,0.2940846131940484,1.2200007753773205,2.712208521357603,2.9467266502403127 -6,test_image,1,5.77227243687614,2,"[0, 3, 5, 7]",2.7225654392347494,0.051361792194696554,2.6525934702850984,2.7127873939436142,2.7180535973290754 -7,test_image,1,25.682179495009112,2,"[5, 6, 11]",2.85129816853438,0.36309882085275597,2.535374801513602,2.7617733887534093,2.770465264733052 -8,test_image,1,27.870996805637535,2,"[9, 10, 11]",2.7169147220384864,0.1798385572282301,2.5506513793095915,2.6863743944825202,2.6579579145357006 -9,test_image,1,6.9504086553142095,2,"[1, 4, 8, 10]",3.679401125994582,0.5950886464826225,2.6485713386465375,3.84195778773634,3.84195778773634 -10,test_image,1,29.369677897827888,2,"[8, 9, 11]",2.640305654101202,0.3106025836163093,1.993486285613394,2.648283332587627,2.682776277975024 -11,test_image,1,2.558408655314211,2,"[5, 7, 8, 10]",3.974846970762266,0.23923528279875325,3.6040697432150033,4.075122442799481,4.075122442799481 diff --git a/tests/resources/tracing/disordered_tracing/rep_int_disordered_tracing_grainstats.csv b/tests/resources/tracing/disordered_tracing/rep_int_disordered_tracing_grainstats.csv deleted file mode 100644 index f8c476af20b..00000000000 --- a/tests/resources/tracing/disordered_tracing/rep_int_disordered_tracing_grainstats.csv +++ /dev/null @@ -1,2 +0,0 @@ -,image,grain_number,grain_endpoints,grain_junctions,total_branch_lengths -0,test_image,0,0,13,9.685225788725929e-07 diff --git a/tests/resources/tracing/disordered_tracing/rep_int_disordered_tracing_stats.csv b/tests/resources/tracing/disordered_tracing/rep_int_disordered_tracing_stats.csv deleted file mode 100644 index e503c214bb8..00000000000 --- a/tests/resources/tracing/disordered_tracing/rep_int_disordered_tracing_stats.csv +++ /dev/null @@ -1,13 +0,0 @@ -,image,grain_number,branch_distance,branch_type,connected_segments,mean_pixel_value,stdev_pixel_value,min_value,median_value,middle_value -0,test_image,0,172.69207377569276,2,"[1, 2, 3, 8]",2.147391874570661,0.18580255309380492,1.4117732114082249,2.147881683634531,2.193944711921703 -1,test_image,0,338.03541679389866,2,"[0, 2, 7, 11]",2.1261598928571943,0.1841696602430932,1.127883594233125,2.1329128300921694,2.236342991231205 -2,test_image,0,0.6901362184380704,2,"[0, 1, 3, 4]",3.5129004230159246,0.2441665496774352,3.2687338733384856,3.5129004230159246,3.5129004230159246 -3,test_image,0,75.41508335877963,2,"[0, 2, 4, 8]",2.1781050277619003,0.22952699769811186,1.4117732114082249,2.178401374885392,2.2734312397952836 -4,test_image,0,31.893405460951744,2,"[2, 3, 5, 6]",2.1378544765518392,0.338975206263122,1.7555674668849865,2.094437231758162,2.2880045741720902 -5,test_image,0,51.51744873752279,2,"[4, 6, 7]",2.233921716584725,0.23610837345626215,1.7265179765777217,2.206985179983061,2.0220519901178635 -6,test_image,0,1.1781362184380704,2,"[4, 5, 7]",3.4335547526985297,0.29158462263860985,3.0268131230204918,3.578160584306969,3.6956905507681284 -7,test_image,0,153.8275289019402,2,"[1, 5, 6, 11]",2.1708118960130536,0.23399433389250326,1.32021443851052,2.1773699140297205,2.1908233129216366 -8,test_image,0,58.753721174398926,2,"[0, 3, 10, 11]",2.0020290183250613,0.3370066648426065,0.8859157914742134,2.08256912431822,2.247454035474802 -9,test_image,0,38.962222771580166,3,[10],2.2735993718579453,0.17804635219989257,2.0015543670262534,2.2595377460435833,2.2032782158757636 -10,test_image,0,0.488,2,"[8, 9, 11]",2.875087133879444,0.009881348191510873,2.865205785688025,2.875087133879444,2.875087133879444 -11,test_image,0,45.069405460951735,2,"[1, 7, 8, 10]",2.1854926308595277,0.22637773949873832,1.289281969607514,2.227074000531621,2.227074000531621 diff --git a/tests/tracing/_regtest_outputs/test_disordered_tracing.test_trace_image_disordered_dataframes[catenane].out b/tests/tracing/_regtest_outputs/test_disordered_tracing.test_trace_image_disordered_dataframes[catenane].out new file mode 100644 index 00000000000..cadfb618a38 --- /dev/null +++ b/tests/tracing/_regtest_outputs/test_disordered_tracing.test_trace_image_disordered_dataframes[catenane].out @@ -0,0 +1,28 @@ + image grain_number grain_endpoints grain_junctions total_branch_lengths grain_width_mean +0 test_image 0 0 14 5.7552e-07 4.3883e-09 +1 test_image 1 0 12 5.7479e-07 4.4161e-09 + image grain_number branch_distance branch_type connected_segments mean_pixel_value stdev_pixel_value min_value median_value middle_value +0 test_image 0 2.9858e+01 2 [1, 2, 6] 2.6683e+00 3.5767e-01 1.9935e+00 2.6465e+00 2.6744e+00 +1 test_image 0 2.8645e+01 2 [0, 2, 6] 2.7290e+00 2.1545e-01 2.5507e+00 2.6838e+00 2.6580e+00 +2 test_image 0 1.8683e+00 2 [0, 1, 3, 4] 4.0675e+00 1.6906e-01 3.7890e+00 4.1385e+00 4.1396e+00 +3 test_image 0 1.4661e+02 2 [2, 4, 9] 2.6694e+00 2.9476e-01 1.2200e+00 2.7080e+00 2.9116e+00 +4 test_image 0 2.6170e+01 2 [2, 3, 9] 2.8350e+00 3.4364e-01 2.5354e+00 2.7608e+00 2.7651e+00 +5 test_image 0 2.2459e+02 2 [6, 7, 10, 11] 2.7010e+00 2.6534e-01 1.7874e+00 2.7330e+00 2.2574e+00 +6 test_image 0 6.9504e+00 2 [0, 1, 5, 7] 3.6264e+00 6.4067e-01 2.5888e+00 3.8420e+00 3.8420e+00 +7 test_image 0 3.1203e+01 2 [5, 6, 8, 11] 2.8436e+00 5.5729e-01 2.1307e+00 2.7052e+00 2.7530e+00 +8 test_image 0 3.1287e+01 2 [7, 9, 10, 11] 2.7443e+00 3.8223e-01 2.4149e+00 2.6535e+00 2.4707e+00 +9 test_image 0 5.5701e+00 2 [3, 4, 8, 10] 2.7309e+00 4.9010e-02 2.6526e+00 2.7379e+00 2.7495e+00 +10 test_image 0 3.8188e+01 2 [5, 8, 9, 11] 2.7864e+00 1.5142e-01 2.4451e+00 2.7710e+00 2.6967e+00 +11 test_image 0 4.5941e+00 2 [5, 7, 8, 10] 4.1266e+00 3.7134e-01 3.3511e+00 4.2387e+00 4.2387e+00 +0 test_image 1 3.7700e+01 2 [1, 2, 3, 6] 2.7733e+00 1.3491e-01 2.4451e+00 2.7690e+00 2.7142e+00 +1 test_image 1 2.2389e+02 2 [0, 2, 4, 9] 2.6966e+00 2.6111e-01 1.8203e+00 2.7314e+00 2.2744e+00 +2 test_image 1 5.0821e+00 2 [0, 1, 3, 4] 4.0290e+00 4.6381e-01 3.0770e+00 4.1850e+00 4.1850e+00 +3 test_image 1 3.1001e+01 2 [0, 2, 4, 6] 2.7462e+00 4.0205e-01 2.4439e+00 2.6516e+00 2.4439e+00 +4 test_image 1 3.1405e+01 2 [1, 2, 3, 9] 2.8423e+00 5.6226e-01 2.1307e+00 2.6942e+00 2.7530e+00 +5 test_image 1 1.4750e+02 2 [6, 7, 11] 2.6728e+00 2.9408e-01 1.2200e+00 2.7122e+00 2.9467e+00 +6 test_image 1 5.7723e+00 2 [0, 3, 5, 7] 2.7226e+00 5.1362e-02 2.6526e+00 2.7128e+00 2.7181e+00 +7 test_image 1 2.5682e+01 2 [5, 6, 11] 2.8513e+00 3.6310e-01 2.5354e+00 2.7618e+00 2.7705e+00 +8 test_image 1 2.7871e+01 2 [9, 10, 11] 2.7169e+00 1.7984e-01 2.5507e+00 2.6864e+00 2.6580e+00 +9 test_image 1 6.9504e+00 2 [1, 4, 8, 10] 3.6794e+00 5.9509e-01 2.6486e+00 3.8420e+00 3.8420e+00 +10 test_image 1 2.9370e+01 2 [8, 9, 11] 2.6403e+00 3.1060e-01 1.9935e+00 2.6483e+00 2.6828e+00 +11 test_image 1 2.5584e+00 2 [5, 7, 8, 10] 3.9748e+00 2.3924e-01 3.6041e+00 4.0751e+00 4.0751e+00 diff --git a/tests/tracing/_regtest_outputs/test_disordered_tracing.test_trace_image_disordered_dataframes[replication_intermediate].out b/tests/tracing/_regtest_outputs/test_disordered_tracing.test_trace_image_disordered_dataframes[replication_intermediate].out new file mode 100644 index 00000000000..bd9a460f380 --- /dev/null +++ b/tests/tracing/_regtest_outputs/test_disordered_tracing.test_trace_image_disordered_dataframes[replication_intermediate].out @@ -0,0 +1,15 @@ + image grain_number grain_endpoints grain_junctions total_branch_lengths grain_width_mean +0 test_image 0 0 13 9.6852e-07 3.0318e-09 + image grain_number branch_distance branch_type connected_segments mean_pixel_value stdev_pixel_value min_value median_value middle_value +0 test_image 0 1.7269e+02 2 [1, 2, 3, 8] 2.1474e+00 1.8580e-01 1.4118e+00 2.1479e+00 2.1939e+00 +1 test_image 0 3.3804e+02 2 [0, 2, 7, 11] 2.1262e+00 1.8417e-01 1.1279e+00 2.1329e+00 2.2363e+00 +2 test_image 0 6.9014e-01 2 [0, 1, 3, 4] 3.5129e+00 2.4417e-01 3.2687e+00 3.5129e+00 3.5129e+00 +3 test_image 0 7.5415e+01 2 [0, 2, 4, 8] 2.1781e+00 2.2953e-01 1.4118e+00 2.1784e+00 2.2734e+00 +4 test_image 0 3.1893e+01 2 [2, 3, 5, 6] 2.1379e+00 3.3898e-01 1.7556e+00 2.0944e+00 2.2880e+00 +5 test_image 0 5.1517e+01 2 [4, 6, 7] 2.2339e+00 2.3611e-01 1.7265e+00 2.2070e+00 2.0221e+00 +6 test_image 0 1.1781e+00 2 [4, 5, 7] 3.4336e+00 2.9158e-01 3.0268e+00 3.5782e+00 3.6957e+00 +7 test_image 0 1.5383e+02 2 [1, 5, 6, 11] 2.1708e+00 2.3399e-01 1.3202e+00 2.1774e+00 2.1908e+00 +8 test_image 0 5.8754e+01 2 [0, 3, 10, 11] 2.0020e+00 3.3701e-01 8.8592e-01 2.0826e+00 2.2475e+00 +9 test_image 0 3.8962e+01 3 [10] 2.2736e+00 1.7805e-01 2.0016e+00 2.2595e+00 2.2033e+00 +10 test_image 0 4.8800e-01 2 [8, 9, 11] 2.8751e+00 9.8813e-03 2.8652e+00 2.8751e+00 2.8751e+00 +11 test_image 0 4.5069e+01 2 [1, 7, 8, 10] 2.1855e+00 2.2638e-01 1.2893e+00 2.2271e+00 2.2271e+00 diff --git a/tests/tracing/test_disordered_tracing.py b/tests/tracing/test_disordered_tracing.py index 50b868a0e23..d17ce22c850 100644 --- a/tests/tracing/test_disordered_tracing.py +++ b/tests/tracing/test_disordered_tracing.py @@ -7,7 +7,6 @@ import numpy as np import numpy.typing as npt -import pandas as pd import pytest from topostats.io import dict_almost_equal # pylint: disable=no-name-in-module import-error @@ -16,6 +15,7 @@ # pylint: disable=too-many-arguments # pylint: disable=too-many-locals # pylint: disable=too-many-lines +# pylint: disable=too-many-positional-arguments # pylint: disable=unspecified-encoding BASE_DIR = Path.cwd() @@ -1294,9 +1294,7 @@ def test_disordered_trace_grain( "skeletonisation_params", "pruning_params", "expected_disordered_crop_data_filename", - "expected_disordered_tracing_grainstats_filename", "expected_all_images_filename", - "expected_disordered_tracing_stats_filename", ), [ pytest.param( @@ -1326,9 +1324,7 @@ def test_disordered_trace_grain( "method_outlier": "mean_abs", }, "catenanes_disordered_tracing_crop_data.pkl", - "catenanes_disordered_tracing_grainstats.csv", "catenanes_disordered_tracing_all_images.pkl", - "catenanes_disordered_tracing_stats.csv", id="catenane", ), pytest.param( @@ -1358,9 +1354,7 @@ def test_disordered_trace_grain( "method_outlier": "mean_abs", }, "rep_int_disordered_tracing_crop_data.pkl", - "rep_int_disordered_tracing_grainstats.csv", "rep_int_disordered_tracing_all_images.pkl", - "rep_int_disordered_tracing_stats.csv", id="replication intermediate", ), ], @@ -1374,9 +1368,7 @@ def test_trace_image_disordered( skeletonisation_params: dict, pruning_params: dict, expected_disordered_crop_data_filename: str, - expected_disordered_tracing_grainstats_filename: str, expected_all_images_filename: str, - expected_disordered_tracing_stats_filename: str, ) -> None: """Test the trace image disordered method.""" # Load the image @@ -1385,9 +1377,9 @@ def test_trace_image_disordered( ( result_disordered_crop_data, - result_disordered_tracing_grainstats, + _, result_all_images, - result_disordered_tracing_stats, + _, ) = disordered_tracing.trace_image_disordered( image=image, grains_mask=mask, @@ -1407,42 +1399,127 @@ def test_trace_image_disordered( # variable_pruned_skeleton = result_all_images["pruned_skeleton"] # variable_branch_types = result_all_images["branch_types"] - # Update expected values - CHECK RESULTS WITH EXPERT BEFORE UPDATING - # Pickle result_disordered_crop_data + # # Update expected values - CHECK RESULTS WITH EXPERT BEFORE UPDATING + # # Pickle result_disordered_crop_data # with open(DISORDERED_TRACING_RESOURCES / expected_disordered_crop_data_filename, "wb") as f: # pkl.dump(result_disordered_crop_data, f) - # # Save result_disordered_tracing_grainstats as a csv - # result_disordered_tracing_grainstats.to_csv( - # DISORDERED_TRACING_RESOURCES / expected_disordered_tracing_grainstats_filename - # ) - # # Save result_all_images as a pickle # with open(DISORDERED_TRACING_RESOURCES / expected_all_images_filename, "wb") as f: # pkl.dump(result_all_images, f) - # # Save result_disordered_tracing_stats dataframe as a csv - # result_disordered_tracing_stats.to_csv(DISORDERED_TRACING_RESOURCES / expected_disordered_tracing_stats_filename) - # Load expected values with Path.open(DISORDERED_TRACING_RESOURCES / expected_disordered_crop_data_filename, "rb") as f: expected_disordered_crop_data = pkl.load(f) - expected_disordered_tracing_grainstats = pd.read_csv( - DISORDERED_TRACING_RESOURCES / expected_disordered_tracing_grainstats_filename, index_col=0 - ) - with Path.open(DISORDERED_TRACING_RESOURCES / expected_all_images_filename, "rb") as f: expected_all_images = pkl.load(f) - - expected_disordered_tracing_stats = pd.read_csv( - DISORDERED_TRACING_RESOURCES / expected_disordered_tracing_stats_filename, index_col=0 - ) - assert dict_almost_equal(result_disordered_crop_data, expected_disordered_crop_data, abs_tol=1e-11) - pd.testing.assert_frame_equal(result_disordered_tracing_grainstats, expected_disordered_tracing_grainstats) assert dict_almost_equal(result_all_images, expected_all_images, abs_tol=1e-11) - pd.testing.assert_frame_equal(result_disordered_tracing_stats, expected_disordered_tracing_stats) + + +@pytest.mark.parametrize( + ( + "image_filename", + "mask_filename", + "pixel_to_nm_scaling", + "min_skeleton_size", + "mask_smoothing_params", + "skeletonisation_params", + "pruning_params", + ), + [ + pytest.param( + "example_catenanes.npy", + "example_catenanes_labelled_grain_mask_thresholded.npy", + # Pixel to nm scaling + 0.488, + # Min skeleton size + 10, + # Mask smoothing parameters + { + "gaussian_sigma": 2, + "dilation_iterations": 2, + "holearea_min_max": [10, None], + }, + # Skeletonisation parameters + { + "method": "topostats", + "height_bias": 0.6, + }, + # Pruning parameters + { + "method": "topostats", + "max_length": 7.0, + "height_threshold": None, + "method_values": "mid", + "method_outlier": "mean_abs", + }, + id="catenane", + ), + pytest.param( + "example_rep_int.npy", + "example_rep_int_labelled_grain_mask_thresholded.npy", + # Pixel to nm scaling + 0.488, + # Min skeleton size + 10, + # Mask smoothing parameters + { + "gaussian_sigma": 2, + "dilation_iterations": 2, + "holearea_min_max": [10, None], + }, + # Skeletonisation parameters + { + "method": "topostats", + "height_bias": 0.6, + }, + # Pruning parameters + { + "method": "topostats", + "max_length": 20.0, + "height_threshold": None, + "method_values": "mid", + "method_outlier": "mean_abs", + }, + id="replication intermediate", + ), + ], +) +def test_trace_image_disordered_dataframes( + image_filename: str, + mask_filename: str, + pixel_to_nm_scaling: float, + min_skeleton_size: int, + mask_smoothing_params: dict, + skeletonisation_params: dict, + pruning_params: dict, + regtest: callable, +) -> None: + """Test the trace image disordered method produces correct dataframes (/csv files).""" + # Load the image + image = np.load(GENERAL_RESOURCES / image_filename) + mask = np.load(GENERAL_RESOURCES / mask_filename) + + ( + _, + result_disordered_tracing_grainstats, + _, + result_disordered_tracing_stats, + ) = disordered_tracing.trace_image_disordered( + image=image, + grains_mask=mask, + filename="test_image", + pixel_to_nm_scaling=pixel_to_nm_scaling, + min_skeleton_size=min_skeleton_size, + mask_smoothing_params=mask_smoothing_params, + skeletonisation_params=skeletonisation_params, + pruning_params=pruning_params, + pad_width=1, + ) + print(result_disordered_tracing_grainstats.to_string(float_format="{:.4e}".format), file=regtest) + print(result_disordered_tracing_stats.to_string(float_format="{:.4e}".format), file=regtest) @pytest.mark.skip(reason="Awaiting test to be written 2024-10-15.") From a99c9f05bfff79789a69004c8b64cb8986f5e086 Mon Sep 17 00:00:00 2001 From: Neil Shephard Date: Mon, 18 Nov 2024 14:48:15 +0000 Subject: [PATCH 13/13] tests(processing): Update tests to account for grain_width_mean Two final tests needed updating to account for new `grain_width_mean` columns. Also required rebasing onto `main` and `ns-rse/994-unpin-topoly` so the changes look larger than they might. --- .../test_processing.test_process_scan_above.out | 8 ++++---- .../test_processing.test_process_scan_both.out | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/_regtest_outputs/test_processing.test_process_scan_above.out b/tests/_regtest_outputs/test_processing.test_process_scan_above.out index 5e95e931e7c..2403b82d4d5 100644 --- a/tests/_regtest_outputs/test_processing.test_process_scan_above.out +++ b/tests/_regtest_outputs/test_processing.test_process_scan_above.out @@ -1,7 +1,7 @@ image_size_x_m image_size_y_m image_area_m2 image_size_x_px image_size_y_px image_area_px2 grains_number_above grains_per_m2_above grains_number_below grains_per_m2_below rms_roughness image minicircle_small 1.2646e-07 1.2646e-07 1.5993e-14 64 64 4096 3 1.8758e+14 0 0.0000e+00 6.8208e-10 - centre_x centre_y grain_number radius_min 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 smallest_bounding_area aspect_ratio threshold max_feret min_feret image grain_endpoints grain_junctions total_branch_lengths grain_width num_crossings avg_crossing_confidence min_crossing_confidence num_mols writhe_string total_contour_length average_end_to_end_distance -0 7.5100e-08 4.7559e-08 0 3.9431e-09 2.5631e-08 1.6016e-08 1.6680e-08 9.1991e-10 2.6422e-09 1.5338e-09 1.5341e-09 1.0543e-24 6.8721e-16 1.3198e-15 2.0539e-08 5.0379e-08 1.0347e-15 4.0769e-01 above 5.0379e-08 2.0539e-08 minicircle_small 1 1 8.4571e-08 8.2685e-09 1 NaN NaN 2 6.5881e-08 8.8370e-09 -1 8.0241e-08 7.8677e-08 1 6.8951e-09 2.7188e-08 1.6272e-08 1.6263e-08 9.0630e-10 2.4586e-09 1.6144e-09 1.6264e-09 1.0352e-24 6.3645e-16 1.5931e-15 2.0174e-08 5.1212e-08 1.0332e-15 3.9394e-01 above 5.1262e-08 2.0174e-08 minicircle_small 0 0 7.3054e-08 7.6154e-09 0 NaN NaN 1 NaN 5.8272e-08 0.0000e+00 -2 4.0012e-08 7.5644e-08 2 9.9461e-09 2.3654e-08 1.7561e-08 1.8364e-08 9.0641e-10 2.1066e-09 1.5939e-09 1.5493e-09 1.1192e-24 7.2236e-16 1.5462e-15 3.3592e-08 4.1496e-08 1.3940e-15 8.0952e-01 above 4.4405e-08 3.2528e-08 minicircle_small 0 0 1.0447e-07 7.8033e-09 0 NaN NaN 1 NaN 8.7183e-08 0.0000e+00 + centre_x centre_y grain_number radius_min 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 smallest_bounding_area aspect_ratio threshold max_feret min_feret image grain_endpoints grain_junctions total_branch_lengths grain_width_mean num_crossings avg_crossing_confidence min_crossing_confidence num_mols writhe_string total_contour_length average_end_to_end_distance +0 7.5100e-08 4.7559e-08 0 3.9431e-09 2.5631e-08 1.6016e-08 1.6680e-08 9.1991e-10 2.6422e-09 1.5338e-09 1.5341e-09 1.0543e-24 6.8721e-16 1.3198e-15 2.0539e-08 5.0379e-08 1.0347e-15 4.0769e-01 above 5.0379e-08 2.0539e-08 minicircle_small 1 1 8.4571e-08 8.2685e-09 1 NaN NaN 2 6.5881e-08 8.8370e-09 +1 8.0241e-08 7.8677e-08 1 6.8951e-09 2.7188e-08 1.6272e-08 1.6263e-08 9.0630e-10 2.4586e-09 1.6144e-09 1.6264e-09 1.0352e-24 6.3645e-16 1.5931e-15 2.0174e-08 5.1212e-08 1.0332e-15 3.9394e-01 above 5.1262e-08 2.0174e-08 minicircle_small 0 0 7.3054e-08 7.6154e-09 0 NaN NaN 1 NaN 5.8272e-08 0.0000e+00 +2 4.0012e-08 7.5644e-08 2 9.9461e-09 2.3654e-08 1.7561e-08 1.8364e-08 9.0641e-10 2.1066e-09 1.5939e-09 1.5493e-09 1.1192e-24 7.2236e-16 1.5462e-15 3.3592e-08 4.1496e-08 1.3940e-15 8.0952e-01 above 4.4405e-08 3.2528e-08 minicircle_small 0 0 1.0447e-07 7.8033e-09 0 NaN NaN 1 NaN 8.7183e-08 0.0000e+00 diff --git a/tests/_regtest_outputs/test_processing.test_process_scan_both.out b/tests/_regtest_outputs/test_processing.test_process_scan_both.out index e10621542ff..4c0b94999d3 100644 --- a/tests/_regtest_outputs/test_processing.test_process_scan_both.out +++ b/tests/_regtest_outputs/test_processing.test_process_scan_both.out @@ -1,7 +1,7 @@ image_size_x_m image_size_y_m image_area_m2 image_size_x_px image_size_y_px image_area_px2 grains_number_above grains_per_m2_above grains_number_below grains_per_m2_below rms_roughness image minicircle_small 1.2646e-07 1.2646e-07 1.5993e-14 64 64 4096 3 1.8758e+14 0 0.0000e+00 6.8208e-10 - centre_x centre_y grain_number radius_min 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 smallest_bounding_area aspect_ratio threshold max_feret min_feret image grain_endpoints grain_junctions total_branch_lengths grain_width total_contour_length average_end_to_end_distance -0 7.5100e-08 4.7559e-08 0 3.9431e-09 2.5631e-08 1.6016e-08 1.6680e-08 9.1991e-10 2.6422e-09 1.5338e-09 1.5341e-09 1.0543e-24 6.8721e-16 1.3198e-15 2.0539e-08 5.0379e-08 1.0347e-15 4.0769e-01 above 5.0379e-08 2.0539e-08 minicircle_small 1.0000e+00 1.0000e+00 8.4571e-08 8.2685e-09 6.5881e-08 8.8370e-09 -1 8.0241e-08 7.8677e-08 1 6.8951e-09 2.7188e-08 1.6272e-08 1.6263e-08 9.0630e-10 2.4586e-09 1.6144e-09 1.6264e-09 1.0352e-24 6.3645e-16 1.5931e-15 2.0174e-08 5.1212e-08 1.0332e-15 3.9394e-01 above 5.1262e-08 2.0174e-08 minicircle_small 0.0000e+00 0.0000e+00 7.3054e-08 7.6154e-09 5.8272e-08 0.0000e+00 -2 4.0012e-08 7.5644e-08 2 9.9461e-09 2.3654e-08 1.7561e-08 1.8364e-08 9.0641e-10 2.1066e-09 1.5939e-09 1.5493e-09 1.1192e-24 7.2236e-16 1.5462e-15 3.3592e-08 4.1496e-08 1.3940e-15 8.0952e-01 above 4.4405e-08 3.2528e-08 minicircle_small 0.0000e+00 0.0000e+00 1.0447e-07 7.8033e-09 8.7183e-08 0.0000e+00 + centre_x centre_y grain_number radius_min 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 smallest_bounding_area aspect_ratio threshold max_feret min_feret image grain_endpoints grain_junctions total_branch_lengths grain_width_mean total_contour_length average_end_to_end_distance +0 7.5100e-08 4.7559e-08 0 3.9431e-09 2.5631e-08 1.6016e-08 1.6680e-08 9.1991e-10 2.6422e-09 1.5338e-09 1.5341e-09 1.0543e-24 6.8721e-16 1.3198e-15 2.0539e-08 5.0379e-08 1.0347e-15 4.0769e-01 above 5.0379e-08 2.0539e-08 minicircle_small 1.0000e+00 1.0000e+00 8.4571e-08 8.2685e-09 6.5881e-08 8.8370e-09 +1 8.0241e-08 7.8677e-08 1 6.8951e-09 2.7188e-08 1.6272e-08 1.6263e-08 9.0630e-10 2.4586e-09 1.6144e-09 1.6264e-09 1.0352e-24 6.3645e-16 1.5931e-15 2.0174e-08 5.1212e-08 1.0332e-15 3.9394e-01 above 5.1262e-08 2.0174e-08 minicircle_small 0.0000e+00 0.0000e+00 7.3054e-08 7.6154e-09 5.8272e-08 0.0000e+00 +2 4.0012e-08 7.5644e-08 2 9.9461e-09 2.3654e-08 1.7561e-08 1.8364e-08 9.0641e-10 2.1066e-09 1.5939e-09 1.5493e-09 1.1192e-24 7.2236e-16 1.5462e-15 3.3592e-08 4.1496e-08 1.3940e-15 8.0952e-01 above 4.4405e-08 3.2528e-08 minicircle_small 0.0000e+00 0.0000e+00 1.0447e-07 7.8033e-09 8.7183e-08 0.0000e+00