Intro to Jupyter Notebooks and Jupyter Lab#

This workshop takes you through the following topics with hands on exercises:

This guide covers the following topics:

Jupyter notebooks are scripts for interactive computing in the Jupyter Lab app. They enable working in steps to process data by running code captured in isolated cells. We can use Jupyter Lab to write and execute Jupyter Notebooks written in python in combination with napari to interact with image data. This platform extends the analysis capabilities of napari to allow for additions like batch processing, adjusting layer properties, and ML-based (Machine Learning-based) image processing among other things.

Install Jupyter Lab#

  • Review these intro slides from Robert Haase.

  • Close your napari window with File>Close Window.

  • In the terminal (Mac) or Anaconda Prompt (Windows), install Jupyter Lab in the conda environment with your napari install as follows:

    • If needed, activate your conda environment first using the following command:

      conda activate napari-env  
      
    • Otherwise, just use:

      pip install jupyterlab  
      

Create a Jupyter Notebook in Jupyter Lab#

We will follow the 2022 Scipy Workshop to create our jupyter lab books:

  • Open Jupyter Lab:

    • In the terminal (Mac) or Anaconda Prompt (Windows), enter:
      jupyter-lab

    • This utilizes your default web browsing app, such as Chrome, to open an instance of Jupyter Lab.

    • The working directory of this instance of Jupyter lab is the same as the folder you are in in terminal, which is shown on the far right side of the command line.

      • In the example below, I am in the folder Downloads:
        cytodata image

      • To change folders in the terminal enter the command:

          cd File_Tree
      
      • For example:

         cd \Users\username\Downloads  
      

      Note: To find the Filetree of a folder or file:

      • Mac: Open Finder, click View > Show Path Bar > control+left-click the folder/file name and click Copy ‘ ’ as Pathname

      • Windows: Use the Windows Search bar (by default in the lower left of the taskbar), type in the name of the file or folder, then right click the search result and select Copy path.

    • Open a blank Python3 notebook in Jupyter lab by clicking the Python3 notebook icon (see intro slides).

Explore the Viewer with Jupyter Notebooks#

Note: Jupyter Notebooks have the file extension .ipynb.

  • Navigate to lesson1 from 2022 SciPy workshop.

  • Work through the tutorial.

    • Copy, paste, and run the code blocks with the green left edge where noted.

    • Experiment with writing your own code in additional cells.

      Note: Use the Gallery on napari.org to get code snippets for your Jupyter Notebook.

  • Handy Commands:

    • You can run the notebook document step-by-step (one cell a time) by pressing shift + enter.

    • You can run the whole notebook in a single step by clicking on the menu Cell -> Run All.

    • To restart the kernel (i.e. the computational engine), click on the menu Kernel -> Restart. This allows you to start a computation over from scratch (e.g. variables are deleted, open files are closed, etc…). It resets all of the variables that were created in the code so that you can troubleshoot or process new data.

Run a Notebook with an ML-based plugin (machine learning-based plugin)#

To install plugins, we recommend:

  • Opening Plugins>Install/Uninstall Plugins in the napari menu

  • Waiting for the plugin list to populate

  • Searching for the desired plugin in the top search bar

  • Clicking the install button

    Note: Some plugins won’t populate their features until napari has been re-opened.

Read the documentation and install:

  • stardist-napari

  • Navigate to the Stardist lesson from the 2022 SciPy Workshop.

  • In Jupyter Lab, start a blank notebook.

  • Work through the tutorial.

    • Copy, paste, and run code blocks with the green left edge where noted.

    • Follow instructions for running the plugin on the example data.

  • Close Jupyter Lab: In the Jupyter Lab tab, File>Shut Down.

This is the final guide in the workshop. You can find resources on help, how to ask questions, and other resources in Resources.