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

Report distance from track origin #158

Merged
merged 3 commits into from
Dec 18, 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
33 changes: 30 additions & 3 deletions brainglobe_segmentation/tracks/analysis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pandas as pd
from scipy.spatial.distance import euclidean

from brainglobe_segmentation.tracks.fit import spline_fit

Expand Down Expand Up @@ -103,6 +104,18 @@ def run_track_analysis(
return spline


def get_distances(spline, voxel_size=10):
"""
For a given spline, calculate the distance between each point.
Assumes a customisable isotropic voxel size (default 10) in microns.
"""
distances = [0]
for i in range(len(spline) - 1):
distance = round(euclidean(spline[i], spline[i + 1]) * voxel_size, 3)
distances.append(distances[i] + distance)
return distances


def analyse_track_anatomy(annotations_layer_image, atlas, spline, file_path):
"""
For a given spline, find the atlas region that each
Expand All @@ -124,8 +137,16 @@ def analyse_track_anatomy(annotations_layer_image, atlas, spline, file_path):
except KeyError:
spline_regions.append(None)

distances = get_distances(spline, voxel_size=atlas.resolution[0])

df = pd.DataFrame(
columns=["Position", "Region ID", "Region acronym", "Region name"]
columns=[
"Index",
"Distance from first position [um]",
"Region ID",
"Region acronym",
"Region name",
]
)
for idx, spline_region in enumerate(spline_regions):
if spline_region is None:
Expand All @@ -135,7 +156,10 @@ def analyse_track_anatomy(annotations_layer_image, atlas, spline, file_path):
pd.DataFrame(
[
{
"Position": idx,
"Index": idx,
"Distance from first position [um]": distances[
idx
],
"Region ID": "Not found in brain",
"Region acronym": "Not found in brain",
"Region name": "Not found in brain",
Expand All @@ -152,7 +176,10 @@ def analyse_track_anatomy(annotations_layer_image, atlas, spline, file_path):
pd.DataFrame(
[
{
"Position": idx,
"Index": idx,
"Distance from first position [um]": distances[
idx
],
"Region ID": spline_region["id"],
"Region acronym": spline_region["acronym"],
"Region name": spline_region["name"],
Expand Down
Loading
Loading