# Save layer back to spatialdata from napari

**URL:** <https://discourse.scverse.org/t/save-layer-back-to-spatialdata-from-napari/1760>\
**Category:** spatialdata\
**Tags:** napari\
**Created:** [September 14, 2023, 12:29pm UTC](https://discourse.scverse.org/t/save-layer-back-to-spatialdata-from-napari/1760 "2023-09-14T12:29:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![grst](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/grst/32/17_2.png) [@grst](https://discourse.scverse.org/u/grst)\
**Post date:** [September 14, 2023, 12:29pm UTC](https://discourse.scverse.org/t/save-layer-back-to-spatialdata-from-napari/1760/1 "2023-09-14T12:29:05Z")

</div>

I tried to follow the [landmark alignment](https://spatialdata.scverse.org/en/latest/tutorials/notebooks_repo/notebooks/examples/alignment_using_landmarks.html) tutorial and created a “points” layer that highlights some landmark features of the image as shown in the tutorial.

How can I save the points layer back in the spatialdata object? The tutorial suggests Ctrl+E, but that doesn’t seem to do anything.

This happens irrespective of if I open a spatialdata zarr file in napari, or open it by using `Interactive()`.

Versions:  
spatialdata v0.0.12  
napari\_spatialdata v0.2.6  
on Linux installed via pip into a conda env

---

<div class="post-metadata">

**Author:** ![LucaMarconato](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/lucamarconato/32/661_2.png) [@LucaMarconato](https://discourse.scverse.org/u/LucaMarconato)\
**Post date:** [September 14, 2023, 12:45pm UTC](https://discourse.scverse.org/t/save-layer-back-to-spatialdata-from-napari/1760/2 "2023-09-14T12:45:38Z")

</div>

Hi Gregor,

Thanks for reporting!

Please use this branch [GitHub - scverse/napari-spatialdata at spatialdata](https://github.com/scverse/napari-spatialdata/tree/spatialdata) for enabling the feature. Unfortunately there have been some delays in merging the PR.

I’ll update the docs accordingly if we don’t manage to merge it soon enough.

---

<div class="post-metadata">

**Author:** ![grst](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/grst/32/17_2.png) [@grst](https://discourse.scverse.org/u/grst)\
**Post date:** [September 14, 2023, 1:08pm UTC](https://discourse.scverse.org/t/save-layer-back-to-spatialdata-from-napari/1760/3 "2023-09-14T13:08:39Z")

</div>

Thanks for the quick response! Now at least something is happening, but pressing Ctrl+E raises the following error:

```plaintext
Traceback (most recent call last):
  File "<path redacted>lib/python3.10/site-packages/napari/_qt/widgets/qt_viewer_dock_widget.py", line 230, in keyPressEvent
    return self._ref_qt_viewer().keyPressEvent(event)
  File "<path redacted>lib/python3.10/site-packages/napari/_qt/qt_viewer.py", line 1250, in keyPressEvent
    self.canvas._backend._keyEvent(self.canvas.events.key_press, event)
  File "<path redacted>lib/python3.10/site-packages/vispy/app/backends/_qt.py", line 622, in _keyEvent
    func(native=ev, key=key, text=str(ev.text()), modifiers=mod)
  File "<path redacted>lib/python3.10/site-packages/vispy/util/event.py", line 453, in __call__
    self._invoke_callback(cb, event)
  File "<path redacted>lib/python3.10/site-packages/vispy/util/event.py", line 471, in _invoke_callback
    _handle_exception(self.ignore_callback_errors,
  File "<path redacted>lib/python3.10/site-packages/vispy/util/event.py", line 469, in _invoke_callback
    cb(event)
  File "<path redacted>lib/python3.10/site-packages/napari/utils/key_bindings.py", line 545, in on_key_press
    self.press_key(combo)
  File "<path redacted>lib/python3.10/site-packages/napari/utils/key_bindings.py", line 470, in press_key
    generator_or_callback = func()
  File "<path redacted>lib/python3.10/site-packages/napari_spatialdata/_view.py", line 305, in export
    assert len(set(row)) == 1
TypeError: 'numpy.int64' object is not iterable

```

---

<div class="post-metadata">

**Author:** ![LucaMarconato](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/lucamarconato/32/661_2.png) [@LucaMarconato](https://discourse.scverse.org/u/LucaMarconato)\
**Post date:** [September 14, 2023, 1:42pm UTC](https://discourse.scverse.org/t/save-layer-back-to-spatialdata-from-napari/1760/4 "2023-09-14T13:42:12Z")

</div>

Thanks for reporting back. I have just tried again the notebook and I don’t get the error, could you please try the following?

1. run the first 2 cells of the notebook
2. the 3rd cell (`Interactive(visium_sdata)`) needs to be set as a code cell
3. run the 3rd cell
4. napari opens, now create a new points layer
5. add a few points (n \>= 1)
6. press Shift-E. You will see a tooltip in the bottom right interface of napari saying that the data was saved. Note: if you are running napari in a Jupyter Notebook you may see no tooltip, we haven’t investigated yet why this happens.
7. try to print the sdata object (`print(visium_sdata)`), you should see the points.

In your case are you doing something substantially different from this?  
Thanks for reporting.

---

<div class="post-metadata">

**Author:** ![grst](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/grst/32/17_2.png) [@grst](https://discourse.scverse.org/u/grst)\
**Post date:** [September 14, 2023, 2:54pm UTC](https://discourse.scverse.org/t/save-layer-back-to-spatialdata-from-napari/1760/5 "2023-09-14T14:54:35Z")

</div>

I think I did exactly this, but on my own data. I’ll try again with the example data and keep you posted!

---

<div class="post-metadata">

**Author:** ![grst](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/grst/32/17_2.png) [@grst](https://discourse.scverse.org/u/grst)\
**Post date:** [September 15, 2023, 6:52am UTC](https://discourse.scverse.org/t/save-layer-back-to-spatialdata-from-napari/1760/6 "2023-09-15T06:52:44Z")

</div>

Hi @LucaMarconato,

I double-checked: doing exactly what you described with the example data from the notebook results in the same error.

I installed `napari-spatialdata` using

```auto
pip install git+https://github.com/scverse/napari-spatialdata.git@spatialdata

```

as you suggested.

Napari info

```auto
napari: 0.4.18
Platform: Linux-3.10.0-1160.11.1.el7.x86_64-x86_64-with-glibc2.17
Python: 3.10.12 | packaged by conda-forge | (main, Jun 23 2023, 22:40:32) [GCC 12.3.0]
Qt: 5.15.2
PyQt5: 5.15.9
NumPy: 1.22.4
SciPy: 1.11.1
Dask: 2023.7.1
VisPy: 0.12.2
magicgui: 0.7.3
superqt: 0.5.4
in-n-out: 0.1.8
app-model: 0.2.1
npe2: 0.7.2

OpenGL:
- GL version: 4.6.0 NVIDIA 470.129.06
- MAX_TEXTURE_SIZE: 32768

Screens:
- screen 1: resolution 1920x1080, scale 1.0

```

---

<div class="post-metadata">

**Author:** ![LucaMarconato](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/lucamarconato/32/661_2.png) [@LucaMarconato](https://discourse.scverse.org/u/LucaMarconato)\
**Post date:** [November 15, 2023, 7:06am UTC](https://discourse.scverse.org/t/save-layer-back-to-spatialdata-from-napari/1760/7 "2023-11-15T07:06:01Z")

</div>

@grst we merge this PR to main (the shortcut is Shift+E, no need to do Shift+L before). [Saving / exporting new elements back to SpatialData by melonora · Pull Request #168 · scverse/napari-spatialdata · GitHub](https://github.com/scverse/napari-spatialdata/pull/168) Can you please try to see if it works for you now?
