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

Added average grain width measurement to disordered tracing #999

Merged
merged 28 commits into from
Dec 4, 2024
Merged
Changes from 5 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
992ebf4
initial testing
tcatley Nov 8, 2024
c0b7b60
further testing
tcatley Nov 11, 2024
4e74d58
testing
tcatley Nov 12, 2024
47f09c0
package: Unpin topoly version
ns-rse Nov 11, 2024
e115d0d
tests: Peg pytest-regtest to 2.3.1 as failing on OSX
ns-rse Nov 11, 2024
f84f198
added dna width measurement in disordered tracing
tcatley Nov 14, 2024
8ce3932
[pre-commit.ci] Fixing issues with pre-commit
pre-commit-ci[bot] Nov 14, 2024
c8b8294
Merge branch 'main' into ns-rse/994-unpin-topoly
ns-rse Nov 15, 2024
39305c5
tests(processing): Update regression test targets to include dna width
tcatley Nov 15, 2024
3ed5d53
tests(processing): Update regression test targets to include dna widt…
tcatley Nov 15, 2024
b0e72da
ci: Adds a Pull Request template
ns-rse Nov 15, 2024
1706c7c
ci: Clarify docs to be updated in PR template
ns-rse Nov 15, 2024
ec786ef
initial testing
tcatley Nov 8, 2024
0b76fa7
further testing
tcatley Nov 11, 2024
ec27115
testing
tcatley Nov 12, 2024
d81f92c
added dna width measurement in disordered tracing
tcatley Nov 14, 2024
8ffed0d
[pre-commit.ci] Fixing issues with pre-commit
pre-commit-ci[bot] Nov 14, 2024
0fb3067
tests(processing): Update regression test targets to include dna width
tcatley Nov 15, 2024
9e2d0f5
tests(processing): Update regression test targets to include dna widt…
tcatley Nov 15, 2024
b90f2af
tests(tracing): Split and update tests of disordered traces
ns-rse Nov 18, 2024
a99c9f0
tests(processing): Update tests to account for grain_width_mean
ns-rse Nov 18, 2024
c97bee4
Merge branch 'main' into tcatley/dna-width
ns-rse Nov 18, 2024
6226b27
Merge branch 'tcatley/dna-width' into ns-rse/999-split-and-update-tests
ns-rse Nov 18, 2024
c813dda
Merge pull request #1002 from AFM-SPM/ns-rse/999-split-and-update-tests
ns-rse Nov 18, 2024
7acb413
added basic square tests for calculate_dna_width()
MaxGamill-Sheffield Nov 19, 2024
3eab5ca
chg result to expected
MaxGamill-Sheffield Nov 19, 2024
52b5101
style: Tidying calculate_dna_width()
ns-rse Dec 4, 2024
8d38ae8
Merge pull request #1035 from AFM-SPM/ns-rse/dna-width-tidy
ns-rse Dec 4, 2024
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
18 changes: 18 additions & 0 deletions topostats/tracing/disordered_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -254,6 +255,17 @@ def smooth_mask(
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.
ns-rse marked this conversation as resolved.
Show resolved Hide resolved
"""
# Code will go here
dist_trans = distance_transform_edt(smoothed_mask)
comb = np.where(pruned_skeleton == 1, dist_trans, 0)

return comb[comb != 0].mean() * 2 * px2nm
ns-rse marked this conversation as resolved.
Show resolved Hide resolved


def trace_image_disordered( # pylint: disable=too-many-arguments,too-many-locals
image: npt.NDArray,
Expand Down Expand Up @@ -363,6 +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,
}

# remap the cropped images back onto the original
Expand Down
Loading