Features that compare two compartments (e.g. overlap).
Source code in navis/morpho/ivscc.py
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319 | class OverlapFeatures(Features):
"""Features that compare two compartments (e.g. overlap)."""
# Compartments to compare
compartments = ("axon", "basal_dendrite", "apical_dendrite")
def extract_features(self):
# Iterate over compartments
for c1 in self.compartments:
if c1 in self.neuron.nodes.label.values:
c1_nodes = self.neuron.nodes[self.neuron.nodes.label == c1]
elif comp_to_label.get(c1, c1) in self.neuron.nodes.label.values:
c1_nodes = self.neuron.nodes[
self.neuron.nodes.label == comp_to_label[c1]
]
else:
continue
for c2 in self.compartments:
if c1 == c2:
continue
if c2 in self.neuron.nodes.label.values:
c2_nodes = self.neuron.nodes[self.neuron.nodes.label == c2]
elif comp_to_label.get(c2, c2) in self.neuron.nodes.label.values:
c2_nodes = self.neuron.nodes[
self.neuron.nodes.label == comp_to_label[c2]
]
else:
continue
# Calculate % of nodes of a given compartment type above/overlapping/below the
# full y-extent of another compartment type
self.features[f"{c1}_frac_above_{c2}"] = (
c1_nodes.y > c2_nodes.y.max()
).sum() / len(c1_nodes)
self.features[f"{c1}_frac_intersect_{c2}"] = (
(c1_nodes.y >= c2_nodes.y.min()) & (c1_nodes.y <= c2_nodes.y.max())
).sum() / len(c1_nodes)
self.features[f"{c1}_frac_below_{c2}"] = (
c1_nodes.y < c2_nodes.y.min()
).sum() / len(c1_nodes)
# Calculate earth mover's distance (EMD) between the two compartments
if f"{c2}_emd_with_{c1}" not in self.features:
self.features[f"{c1}_emd_with_{c2}"] = wasserstein_distance(
c1_nodes.y, c2_nodes.y
)
return self.features
|