Skip to content

Commit

Permalink
Map to closest core in case centroid in mapping dict was "missed" by …
Browse files Browse the repository at this point in the history
…MALDI scan
  • Loading branch information
alex-l-kong committed Aug 29, 2024
1 parent 4a6ad62 commit 7540686
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/maldi_tools/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import json
import os
import warnings
from functools import partial
from operator import itemgetter
from pathlib import Path
Expand Down Expand Up @@ -431,10 +432,19 @@ def map_coordinates_to_core_name(
"Region",
]
if region_match.shape[0] == 0:
raise ValueError(
core_centroid_distances: pd.Series = np.sqrt(
(region_core_info["x"] - center_point["x"]) ** 2
+ (region_core_info["y"] - center_point["y"]) ** 2
)
region_match = region_core_info.iloc[core_centroid_distances.idxmin(), 0]

# TODO: add an error threshold of a few pixels, shouldn't naively map everything
warnings.warn(
f"Could not find mapping of core {core['name']} to any location on the slide, "
"please verify that you positioned the central point of the core correctly "
"using the TSAI tiler, or that you've set the right poslog file."
"using the TSAI tiler, or that you've set the right poslog file.\n\n"
f"The closest region to the core's centroid is {region_match.values[0]}, "
"using this as finalized mapping."
)

core_region_mapping[region_match.values[0]] = core["name"]
Expand Down

0 comments on commit 7540686

Please sign in to comment.