spatialdata.concatenate#
- spatialdata.concatenate(sdatas, region_key=None, instance_key=None, concatenate_tables=False, obs_names_make_unique=True, modify_tables_inplace=False, **kwargs)#
Concatenate a list of spatial data objects.
- Parameters:
sdatas (
Iterable
[SpatialData
] |dict
[str
,SpatialData
]) – The spatial data objects to concatenate. The names of the elements across theSpatialData
objects must be unique. If they are not unique, you can pass a dictionary with the suffixes as keys and the spatial data objects as values. This will rename the names of eachSpatialElement
to ensure uniqueness of names acrossSpatialData
objects. See more on the notes.region_key (
Optional
[str
] (default:None
)) – The key to use for the region column in the concatenated object. IfNone
and all region_keys are the same, theregion_key
is used.instance_key (
Optional
[str
] (default:None
)) – The key to use for the instance column in the concatenated object. IfNone
and all instance_keys are the same, theinstance_key
is used.concatenate_tables (
bool
(default:False
)) – Whether to merge the tables in case of having the same element name.obs_names_make_unique (
bool
(default:True
)) – Whether to make theobs_names
unique by callingAnnData.obs_names_make_unique()
on each table of the concatenated object. If you passed a dictionary with the suffixes as keys and theSpatialData
objects as values and ifconcatenate_tables
isTrue
, theobs_names
will be made unique by adding the corresponding suffix instead.modify_tables_inplace (
bool
(default:False
)) – Whether to modify the tables in place. IfTrue
, the tables will be modified in place. IfFalse
, the tables will be copied before modification. Copying is enabled by default but can be disabled for performance reasons.kwargs (
Any
) – Seeanndata.concat()
for more details.
- Return type:
- Returns:
: The concatenated
spatialdata.SpatialData
object.
Notes
If you pass a dictionary with the suffixes as keys and the
SpatialData
objects as values, the names of eachSpatialElement
will be renamed to ensure uniqueness of names acrossSpatialData
objects by adding the corresponding suffix. To ensure the matching between existing table annotations, theregion
metadata of each table, and the values of theregion_key
column in each table, will be altered by adding the suffix. In addition, theobs_names
of each table will be altered (a suffix will be added). Finally, a suffix will be added to the name of each table iffrename_tables
isFalse
.If you need more control in the renaming, please give us feedback, as we are still trying to find the right balance between ergonomics and control. Also, you are welcome to copy and adjust the code of
_fix_ensure_unique_element_names()
directly.