atlannot.merge.common module

Functionality common to all atlas merge strategies.

atlannot.merge.common.atlas_remap(atlas: ndarray, values_from: ndarray, values_to: ndarray) ndarray[source]

Remap atlas values fast.

This only works if

  • values_from contains all unique values in atlas,

  • values_from is sorted.

In other words, it must be that values_from = np.unique(atlas).

Source: https://stackoverflow.com/a/35464758/2804645

Parameters:
  • atlas – The atlas volume to remap. Can be of any shape.

  • values_from – The values to map from. It must be that values_from = np.unique(atlas).

  • values_to – The values to map to. Must have the same shape as values_from.

Returns:

The remapped atlas.

Return type:

np.ndarray

atlannot.merge.common.descendants(region_id, allowed_ids, rm: RegionMeta)[source]

Get all filtered descendant IDs of a given region ID.

A descendant is only accepted if it’s in allowed_ids or is a leaf region.

This is mimicking Dimitri’s algorithm, I’m not sure about why this must be that way.

atlannot.merge.common.replace(array: ndarray, old_value: int, new_value: int) None[source]

Replace integer values in a numpy array.

Parameters:
  • array – An arbitrary numpy array.

  • old_value – The value to replace.

  • new_value – The new value that replaces the old one.