1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
(sample-data-contribution-guide)=
## Sample Data
This contribution point allows plugin developers to contribute sample data
that will be accessible in the napari interface via the `File > Open Sample`
menu, or via the command line with `viewer.open_sample`.
Sample data can be useful for demonstrating the functionality of a given plugin.
It can take the form of a **Sample Data URI** that points to a static resource
(such as a file included in the plugin distribution, or a remote resource),
or **Sample Data Function** that generates layer data on demand.
Note that unlike reader contributions, sample data contributions are
**always** expected to return data, so returning `[(None,)]`
will cause an error.
### Sample Data example
::::{tab-set}
:::{tab-item} npe2
**python implementation**
```python
# example_plugin.some_module
{{ 'sample_data'|example_implementation }}
```
**manifest**
See [Sample Data contribution reference](contributions-sample-data)
for field details.
```yaml
{{ 'sample_data'|example_contribution }}
```
:::
:::{tab-item} napari-plugin-engine
```{admonition} Deprecated!
This demonstrates the now-deprecated `napari-plugin-engine` pattern.
```
**python implementation**
[hook specification](https://napari.org/stable/plugins/npe1.html#napari.plugins.hook_specifications.napari_provide_sample_data)
```python
import numpy as np
from napari_plugin_engine import napari_hook_implementation
def _generate_random_data(shape=(512, 512)):
data = np.random.rand(*shape)
return [(data, {'name': 'random data'})]
@napari_hook_implementation
def napari_provide_sample_data():
return {
'random data': _generate_random_data,
'random image': 'https://picsum.photos/1024',
'sample_key': {
'display_name': 'Some Random Data (512 x 512)'
'data': _generate_random_data,
}
}
```
:::
::::
|