Skip to content

Commit 48443c7

Browse files
authored
Use imshow in getting_started (#9)
1 parent f090a96 commit 48443c7

File tree

3 files changed

+54
-22
lines changed

3 files changed

+54
-22
lines changed
Loading
-1.71 MB
Loading

docs/tutorials/fundamentals/getting_started.md

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ This command will launch an empty viewer:
3232

3333
![image: an empty napari viewer](../assets/tutorials/launch_cli_empty.png)
3434

35-
Once you have the viewer open you can add images through the `File/Open` dropdown menu
35+
Once you have the viewer open you can add images through the `File -> Open` dropdown menu
3636
or by dragging and dropping images directly on the viewer.
3737
We currently only support files that can be read with [`skimage.io.imread`](https://scikit-image.org/docs/dev/api/skimage.io.html#skimage.io.imread),
3838
such as `tif`, `png`, and `jpg`.
3939
We plan on adding support for more exotic file types shortly - see [issue #379](https://github.com/napari/napari/issues/379) for discussion.
40-
You can also create new empty `points`, `shapes`, and `labels` layers using the new layer buttons in the bottom right of the viewer.
4140

4241
You can also directly load an image into the viewer from the command line by passing the path to the image as an argument as follows
4342

@@ -56,31 +55,54 @@ but we'll be adding support for this functionality soon as discussed in [#379](h
5655

5756
### Python script usage
5857

59-
To launch napari from a python script, inside your script you should import `napari`,
60-
and then create the `Viewer` by adding some data.
58+
To launch napari from a python script, inside your script you can import `napari`,
59+
then create a {class}`Viewer<napari.Viewer>` and {class}`Image<napari.layers.Image>`
60+
layer by adding some image data, using {func}`imshow<napari.imshow>`.
61+
The {class}`Viewer<napari.Viewer>` is representative of the napari viewer GUI
62+
you launch and stores all the data you add to napari. The
63+
{class}`Image<napari.layers.Image>` will store information about the image data
64+
you added.
6165

62-
For example, to add an image and some points inside your script you should include:
66+
For example, to add an image and print the shape of the image layer data,
67+
you can use:
6368

6469
```python
70+
# import sample data
71+
from skimage.data import cells3d
72+
6573
import napari
6674

67-
# create a Viewer and add an image here
68-
viewer = napari.view_image(my_image_data)
75+
# create a `Viewer` and `Image` layer here
76+
viewer, image_layer = napari.imshow(cells3d())
6977

70-
# custom code to add data here
71-
viewer.add_points(my_points_data)
78+
# print shape of image datas
79+
print(image_layer.data.shape)
7280

7381
# start the event loop and show the viewer
7482
napari.run()
7583
```
7684

77-
then run your script from the command line to launch the viewer with your data:
85+
Note that {func}`imshow<napari.imshow>` is a convenience function that is
86+
equivalent to:
87+
88+
```python
89+
# import sample data
90+
from skimage.data import cells3d
91+
92+
import napari
93+
94+
viewer = napari.Viewer()
95+
image_layer = viewer.add_image(cells3d())
96+
```
97+
98+
You can now run your script from the command line to launch the viewer with your data:
7899

79100
```sh
80101
python my_example_script.py
81102
```
82103

83-
See the scripts inside the [`examples`](https://github.com/napari/napari/tree/main/examples) in the main repository for examples of using napari this way.
104+
The [examples gallery](../../gallery) consists of code examples which can be
105+
downloaded as `.py` (and `.ipynb` files) and run as above.
84106

85107
![image: napari launched from a python script](../assets/tutorials/launch_script.png)
86108

@@ -89,14 +111,17 @@ is that you can preprocess your images and add multiple layers before displaying
89111

90112
### IPython console usage
91113

92-
To launch napari from an IPython console import `napari` and create a `Viewer` object.
114+
To launch napari from an IPython console import `napari` and create a
115+
{class}`Viewer<napari.Viewer>` and {class}`Image<napari.layers.Image>` object.
93116

94117
```python
118+
# import sample data
119+
from skimage.data import cells3d
120+
95121
import napari
96-
from skimage.data import astronaut
97122

98-
# create the viewer and display the image
99-
viewer = napari.view_image(astronaut(), rgb=True)
123+
# create a `Viewer` and `Image` layer here
124+
viewer, image_layer = napari.imshow(cells3d())
100125
```
101126

102127
Napari will automatically use the interactive [`%gui qt` event
@@ -112,18 +137,25 @@ and where data changed in the GUI will be accessible in the console.
112137

113138
### Jupyter notebook usage
114139

115-
You can also launch napari from a jupyter notebook,
116-
such as [`examples/notebook.ipynb`](https://github.com/napari/napari/tree/main/examples/notebook.ipynb)
140+
You can also launch napari from a Jupyter notebook. The
141+
[examples gallery](../../gallery), as mentioned above, can also be downloaded as
142+
`.ipynb` which can be run from a Jupyter notebook.
117143

118-
![image: napari launched from a jupyter notebook](../assets/tutorials/launch_jupyter.png)
144+
Below, we launch the [notebook example](https://github.com/napari/napari/tree/main/examples/notebook.ipynb) from a Jupyter notebook.
145+
146+
![image: napari launched from a Jupyter notebook](../assets/tutorials/launch_jupyter.png)
119147

120148
Similar to launching from the IPython console,
121-
an advantage of launching napari from a jupyter notebook
122-
is that you can continue to programmatically interact with the viewer from jupyter notebook,
149+
an advantage of launching napari from a Jupyter notebook
150+
is that you can continue to programmatically interact with the viewer from Jupyter notebook,
123151
including bidirectional communication, where code run in the notebook will update the current viewer
124152
and where data changed in the GUI will be accessible in the notebook.
125153

126154
## Next steps
127155

128-
To learn more about how to use the napari viewer with different types of napari layers
129-
checkout the [viewer tutorial](./viewer) and more of our tutorials listed below.
156+
To learn more about:
157+
158+
* how to use the napari viewer graphical user interface (GUI),
159+
checkout the [viewer tutorial](./viewer)
160+
* how to use the napari viewer with different types of napari layers, see
161+
[layers at a glance](../../guides/layers)

0 commit comments

Comments
 (0)