spatialdata icon indicating copy to clipboard operation
spatialdata copied to clipboard

Rename SpatialElements

Open Marius1311 opened this issue 1 year ago • 1 comments

Is there an easy way to rename SpatialElements? For example, an image? Not just in memory, but also on disk? I couldn't really find anything in the docs, except for copying the element, creating it with a new name, writing to disk, and deleting the old element both in memory and on disk, but that does seem like an overkill for renaming something. Maybe I'm just missing something here or I have overlooked something

Marius1311 avatar Nov 22 '24 13:11 Marius1311

Hi @Marius1311 thanks for the discussion. Currently there is no API for renaming an element, but indeed it would be useful to have, we will keep this in mind.

If you want to rename images or tables, I suggest to do it outside spatialdata and rename the Zarr folder for the image/table on disk. This applies also for the other elements, with the additional requirement to also eventually modify some metadata.

Precisely:

  • if what is renamed is a points, shapes or labels that is annotated by a table, the table region metadata (adata.uns) needs to be renamed, and also the values of the region_key column.

After this, if you are uploading the data to some cloud storage, you should also regenerate the consolidated metadata. This can be done easily by loading the data and then calling sdata.write_consolidated_metadata().

LucaMarconato avatar Jan 05 '25 20:01 LucaMarconato