Skip to content

Note

Click here to download the full example code

Visualizing 3D results with Napari

This example demonstrates how to render a steady state result for a 3D scenario using napari.

Running such simulations is computationally expensive and can take a long time to complete. For this reason, we recommend running this simulation on an external machine, store the results in a file and then load them on your local machine for visualization.

Check the gallery example Save and load results to learn how to save and load results.

The following step downloads and loads a simulation executed on an external machine.

import pooch

import neurotechdevkit as ndk

URL = "https://neurotechdevkit.s3.us-west-2.amazonaws.com/result-scenario-2-3d-v4.tz"
known_hash = "919edd0f29bcc956a9c2b3c4c56c28af5495dcdbb93d2d4d7f89078827e6db59"
downloaded_file_path = pooch.retrieve(url=URL, known_hash=known_hash, progressbar=True)
result = ndk.load_result_from_disk(downloaded_file_path)

Out:

  0%|                                               | 0.00/451M [00:00<?, ?B/s]

  0%|                                       | 51.2k/451M [00:00<18:59, 396kB/s]

  0%|                                       | 315k/451M [00:00<05:28, 1.37MB/s]

  0%|                                      | 1.20M/451M [00:00<01:55, 3.89MB/s]

  1%|                                     | 3.60M/451M [00:00<00:46, 9.72MB/s]

  1%|                                     | 6.34M/451M [00:00<00:32, 13.9MB/s]

  2%|                                     | 9.17M/451M [00:00<00:26, 16.6MB/s]

  3%|                                     | 12.0M/451M [00:00<00:23, 18.4MB/s]

  3%|█▎                                    | 14.9M/451M [00:01<00:22, 19.8MB/s]

  4%|█▍                                    | 17.7M/451M [00:01<00:21, 20.4MB/s]

  5%|█▋                                    | 20.5M/451M [00:01<00:19, 21.6MB/s]

  5%|█▉                                    | 23.7M/451M [00:01<00:17, 24.4MB/s]

  6%|██▏                                   | 26.2M/451M [00:01<00:18, 23.1MB/s]

  6%|██▍                                   | 28.6M/451M [00:01<00:18, 23.3MB/s]

  7%|██▋                                   | 31.6M/451M [00:01<00:16, 25.4MB/s]

  8%|██▉                                   | 34.2M/451M [00:01<00:17, 24.3MB/s]

  8%|███                                   | 36.7M/451M [00:01<00:17, 24.0MB/s]

  9%|███▎                                  | 39.6M/451M [00:02<00:16, 25.4MB/s]

  9%|███▌                                  | 42.1M/451M [00:02<00:16, 24.5MB/s]

 10%|███▊                                  | 44.9M/451M [00:02<00:16, 25.1MB/s]

 11%|████                                  | 47.7M/451M [00:02<00:15, 25.8MB/s]

 11%|████▏                                 | 50.3M/451M [00:02<00:15, 25.1MB/s]

 12%|████▌                                 | 53.4M/451M [00:02<00:15, 26.1MB/s]

 12%|████▋                                 | 56.3M/451M [00:02<00:14, 26.7MB/s]

 13%|████▉                                 | 59.0M/451M [00:02<00:15, 25.8MB/s]

 14%|█████▏                                | 61.9M/451M [00:02<00:14, 26.4MB/s]

 14%|█████▍                                | 65.1M/451M [00:02<00:13, 27.9MB/s]

 15%|█████▋                                | 67.9M/451M [00:03<00:14, 26.6MB/s]

 16%|█████▉                                | 70.9M/451M [00:03<00:14, 27.0MB/s]

 16%|██████▏                               | 73.8M/451M [00:03<00:13, 27.8MB/s]

 17%|██████▍                               | 76.6M/451M [00:03<00:15, 23.9MB/s]

 18%|██████▋                               | 79.1M/451M [00:03<00:15, 23.6MB/s]

 18%|██████▊                               | 81.5M/451M [00:03<00:16, 22.6MB/s]

 19%|███████                               | 84.3M/451M [00:03<00:16, 22.5MB/s]

 19%|███████▎                              | 87.4M/451M [00:03<00:15, 23.1MB/s]

 20%|███████▌                              | 90.4M/451M [00:04<00:15, 23.0MB/s]

 21%|███████▉                              | 93.6M/451M [00:04<00:15, 23.6MB/s]

 22%|████████▏                             | 97.2M/451M [00:04<00:14, 25.1MB/s]

 22%|████████▋                              | 101M/451M [00:04<00:13, 26.1MB/s]

 23%|█████████                              | 104M/451M [00:04<00:12, 28.6MB/s]

 24%|█████████▎                             | 107M/451M [00:04<00:12, 27.5MB/s]

 24%|█████████▌                             | 110M/451M [00:04<00:12, 26.9MB/s]

 25%|█████████▊                             | 114M/451M [00:04<00:12, 27.3MB/s]

 26%|██████████▏                            | 117M/451M [00:05<00:11, 27.9MB/s]

 27%|██████████▍                            | 121M/451M [00:05<00:11, 27.8MB/s]

 28%|██████████▊                            | 125M/451M [00:05<00:11, 28.3MB/s]

 28%|███████████                            | 128M/451M [00:05<00:10, 30.5MB/s]

 29%|███████████▎                           | 132M/451M [00:05<00:10, 29.1MB/s]

 30%|███████████▋                           | 134M/451M [00:05<00:11, 28.6MB/s]

 31%|███████████▉                           | 138M/451M [00:05<00:10, 30.3MB/s]

 31%|████████████▏                          | 141M/451M [00:05<00:10, 29.1MB/s]

 32%|████████████▍                          | 144M/451M [00:05<00:10, 28.7MB/s]

 33%|████████████▊                          | 148M/451M [00:06<00:10, 28.9MB/s]

 34%|█████████████                          | 152M/451M [00:06<00:09, 32.0MB/s]

 34%|█████████████▍                         | 155M/451M [00:06<00:09, 30.9MB/s]

 35%|█████████████▋                         | 158M/451M [00:06<00:09, 29.8MB/s]

 36%|█████████████▉                         | 161M/451M [00:06<00:09, 29.4MB/s]

 37%|██████████████▎                        | 166M/451M [00:06<00:09, 30.3MB/s]

 38%|██████████████▋                        | 170M/451M [00:06<00:08, 33.2MB/s]

 38%|██████████████▉                        | 173M/451M [00:06<00:08, 31.7MB/s]

 39%|███████████████▏                       | 176M/451M [00:06<00:08, 31.1MB/s]

 40%|███████████████▌                       | 180M/451M [00:07<00:08, 30.9MB/s]

 41%|███████████████▉                       | 184M/451M [00:07<00:08, 33.3MB/s]

 42%|████████████████▏                      | 187M/451M [00:07<00:08, 32.0MB/s]

 42%|████████████████▍                      | 191M/451M [00:07<00:08, 31.2MB/s]

 43%|████████████████▊                      | 194M/451M [00:07<00:08, 29.8MB/s]

 44%|█████████████████▏                     | 198M/451M [00:07<00:08, 31.1MB/s]

 45%|█████████████████▍                     | 202M/451M [00:07<00:07, 33.3MB/s]

 46%|█████████████████▊                     | 206M/451M [00:07<00:07, 32.2MB/s]

 46%|██████████████████                     | 209M/451M [00:07<00:07, 31.2MB/s]

 47%|██████████████████▍                    | 213M/451M [00:08<00:07, 31.1MB/s]

 48%|██████████████████▋                    | 216M/451M [00:08<00:07, 32.5MB/s]

 49%|██████████████████▉                    | 220M/451M [00:08<00:07, 31.0MB/s]

 49%|███████████████████▎                   | 223M/451M [00:08<00:07, 29.7MB/s]

 50%|███████████████████▌                   | 226M/451M [00:08<00:07, 28.9MB/s]

 51%|███████████████████▊                   | 230M/451M [00:08<00:07, 28.8MB/s]

 52%|████████████████████▏                  | 234M/451M [00:08<00:07, 30.6MB/s]

 53%|████████████████████▌                  | 238M/451M [00:08<00:06, 30.7MB/s]

 54%|████████████████████▉                  | 242M/451M [00:09<00:06, 33.5MB/s]

 54%|█████████████████████▏                 | 246M/451M [00:09<00:06, 32.8MB/s]

 55%|█████████████████████▌                 | 249M/451M [00:09<00:06, 32.3MB/s]

 56%|█████████████████████▊                 | 253M/451M [00:09<00:06, 33.0MB/s]

 57%|██████████████████████                 | 256M/451M [00:09<00:06, 31.6MB/s]

 57%|██████████████████████▍                | 259M/451M [00:09<00:06, 30.6MB/s]

 58%|██████████████████████▋                | 263M/451M [00:09<00:06, 30.5MB/s]

 59%|███████████████████████                | 266M/451M [00:09<00:05, 32.4MB/s]

 60%|███████████████████████▎               | 270M/451M [00:09<00:05, 31.7MB/s]

 61%|███████████████████████▌               | 273M/451M [00:10<00:05, 31.0MB/s]

 62%|███████████████████████▉               | 277M/451M [00:10<00:05, 32.1MB/s]

 62%|████████████████████████▎              | 282M/451M [00:10<00:04, 35.4MB/s]

 63%|████████████████████████▋              | 285M/451M [00:10<00:04, 34.2MB/s]

 64%|████████████████████████▉              | 289M/451M [00:10<00:04, 33.2MB/s]

 65%|█████████████████████████▎             | 293M/451M [00:10<00:04, 34.0MB/s]

 66%|█████████████████████████▊             | 298M/451M [00:10<00:04, 35.0MB/s]

 67%|██████████████████████████             | 302M/451M [00:10<00:04, 36.0MB/s]

 68%|██████████████████████████▍            | 306M/451M [00:10<00:04, 34.8MB/s]

 69%|██████████████████████████▋            | 309M/451M [00:11<00:04, 33.9MB/s]

 69%|███████████████████████████            | 313M/451M [00:11<00:03, 35.9MB/s]

 70%|███████████████████████████▍           | 317M/451M [00:11<00:03, 34.2MB/s]

 71%|███████████████████████████▋           | 320M/451M [00:11<00:03, 32.8MB/s]

 72%|███████████████████████████▉           | 324M/451M [00:11<00:04, 31.6MB/s]

 73%|████████████████████████████▍          | 328M/451M [00:11<00:03, 36.2MB/s]

 74%|████████████████████████████▋          | 332M/451M [00:11<00:03, 35.1MB/s]

 74%|█████████████████████████████          | 336M/451M [00:11<00:03, 33.9MB/s]

 75%|█████████████████████████████▎         | 340M/451M [00:11<00:03, 33.1MB/s]

 76%|█████████████████████████████▊         | 344M/451M [00:12<00:02, 37.1MB/s]

 77%|██████████████████████████████         | 348M/451M [00:12<00:02, 36.0MB/s]

 78%|██████████████████████████████▍        | 352M/451M [00:12<00:02, 34.6MB/s]

 79%|██████████████████████████████▊        | 356M/451M [00:12<00:02, 34.1MB/s]

 80%|███████████████████████████████▏       | 360M/451M [00:12<00:02, 34.0MB/s]

 81%|███████████████████████████████▌       | 364M/451M [00:12<00:02, 33.8MB/s]

 82%|███████████████████████████████▊       | 368M/451M [00:12<00:02, 35.4MB/s]

 82%|████████████████████████████████▏      | 372M/451M [00:12<00:02, 34.8MB/s]

 83%|████████████████████████████████▍      | 375M/451M [00:13<00:02, 33.7MB/s]

 84%|████████████████████████████████▊      | 380M/451M [00:13<00:01, 36.9MB/s]

 85%|█████████████████████████████████▏     | 384M/451M [00:13<00:01, 35.7MB/s]

 86%|█████████████████████████████████▍     | 387M/451M [00:13<00:01, 35.1MB/s]

 87%|█████████████████████████████████▊     | 391M/451M [00:13<00:01, 33.6MB/s]

 88%|██████████████████████████████████▏    | 396M/451M [00:13<00:01, 36.1MB/s]

 89%|██████████████████████████████████▌    | 399M/451M [00:13<00:01, 35.4MB/s]

 89%|██████████████████████████████████▊    | 403M/451M [00:13<00:01, 35.2MB/s]

 90%|███████████████████████████████████▏   | 408M/451M [00:13<00:01, 37.4MB/s]

 91%|███████████████████████████████████▌   | 411M/451M [00:13<00:01, 36.0MB/s]

 92%|███████████████████████████████████▊   | 415M/451M [00:14<00:01, 35.1MB/s]

 93%|████████████████████████████████████▎  | 419M/451M [00:14<00:00, 35.0MB/s]

 94%|████████████████████████████████████▋  | 424M/451M [00:14<00:00, 38.8MB/s]

 95%|█████████████████████████████████████  | 428M/451M [00:14<00:00, 36.3MB/s]

 96%|█████████████████████████████████████▎ | 432M/451M [00:14<00:00, 36.8MB/s]

 97%|█████████████████████████████████████▋ | 436M/451M [00:14<00:00, 36.5MB/s]

 98%|██████████████████████████████████████ | 440M/451M [00:14<00:00, 38.1MB/s]

 98%|██████████████████████████████████████▎| 444M/451M [00:14<00:00, 38.0MB/s]

 99%|██████████████████████████████████████▋| 448M/451M [00:14<00:00, 39.6MB/s]

  0%|                                               | 0.00/451M [00:00<?, ?B/s]
100%|███████████████████████████████████████| 451M/451M [00:00<00:00, 1.56TB/s]
Recreating the scenario for the result from saved metadata...

In order to render the 3D results you will need to install Install napari via pip:

pip install "napari[all]"

Note for Mac M1 users: Qt5 does not support Mac M1, so you will need to install the Qt6 backend instead:

pip install "napari[pyqt6_experimental]"

You can also follow the napari installation instructions: link.

try:
    import napari  # noqa: F401

    assert isinstance(result, ndk.results.SteadyStateResult3D)
    result.render_steady_state_amplitudes_3d()
except ImportError:
    print(
        "napari has not been installed. Please install it with: pip install napari[all]"
    )

Out:

napari has not been installed. Please install it with: pip install napari[all]

If you have napari installed you should see an output like the following:

Opening the napari viewer. The window might not show up on top of your notebook;
look through your open applications if it does not.

If you have napari installed you should have been able to see an image like the following: 3d-visualization

Total running time of the script: ( 0 minutes 26.923 seconds)

Download Python source code: plot_3d.py

Download Jupyter notebook: plot_3d.ipynb

Gallery generated by mkdocs-gallery