ShapeWorks
  • Home

Getting Started

  • Shapes, What & From Where?
  • Shape Modeling Workflow
  • ShapeWorks Success Stories
  • ShapeWorks Interfaces
  • Examples
  • How-Tos

For Users

  • How to Install ShapeWorks?
  • How to Cite ShapeWorks?
  • Revelant Papers

Workflow

  • How to Groom Your Dataset?
  • How to Optimize Your Shape Model?
  • How to Analyze Your Shape Model?

What is New?

  • New in ShapeWorksStudio
  • ShapeWorks Takes ~85% Less Memory
  • ShapeWorks Directly on Meshes
  • ShapeWorks Command
  • Shape Model Evaluation
  • ShapeWorks in Python

ShapeWorks Studio

  • Getting Started With ShapeWorks Studio

ShapeWorks in Python

  • Getting Started with Juypter Notebooks
    • What is a Notebook?
    • What is Jupyter Notebook?
    • ShapeWorks installs Jupyter for you
    • Starting the Jupyter Notebook server
    • Creating a notebook
    • Running notebook cells
    • Having multiple cells
    • Styling and navigation
    • Notebook keyboard shortcuts
  • Setting up ShapeWorks Environment
  • Getting Started with Segmentations
  • Getting Started with Meshes
  • Getting Started with Exploring Segmentations
  • Getting Started with Grooming Segmentations
  • Getting Started with Data Augmentation
  • Getting Started with Shape Cohort Generation

Deep Learning & SSMs

  • PyTorch GPU Support for ShapeWorks
  • Data Augmentation for Deep Learning
  • SSMs Directly from Images

Use Cases

  • Getting Started with Use Cases
  • Ellipsoid: Basic Example
  • Ellipsoid: Cutting Planes
  • Fixed Domains: SSM on New Shapes
  • Left Atrium: SSM from Segmentations
  • Femur: SSM from Meshes
  • Femur with Cutting Planes
  • Femur Mesh: SSM directly from meshes
  • Lumps: SSM directly from meshes
  • Right Ventricle: Highly Variable Shapes
  • Femur SSM Directly from Images

For Developers

  • How to Build ShapeWorks from Source?
  • How to Contribute to ShapeWorks?
  • How to Add ShapeWorks Commands?
  • How to Add Python APIs?
  • How to Add and Run Unit Tests?
  • How to Add New Use Cases?
  • How to Add New Datasets?
  • How to Add New Notebooks?
  • When Modifying Existing Datasets
  • Getting Started with Documentation
  • Getting Started with GitHub Actions
  • Getting Started with Markdown
  • Adding to PATH Environment Variable

ShapeWorks Tools

  • ShapeWorks Commands

About

  • Meet ShapeWorkers!
  • Release Notes
  • License
  • Contact Us
ShapeWorks
  • Docs »
  • ShapeWorks in Python »
  • Getting Started with Juypter Notebooks
  • Edit on GitHub

Getting Started with Jupyter Notebooks¶

What is a Notebook?¶

A notebook is a single document where you can run code, display and visualize its output, add explanations enriched with images, charts, and equations, making your code more transparent, interpretable, reproducible, and shareable.

What is Jupyter Notebook?¶

The Jupyter Notebook is a powerful tool to interactively prototype and present ideas and workflows.

The Jupyter Notebook is an open source web application that enables you to create documents that contain runnable code, text, equations, and visualizations.

Jupyter supports IPython kernel to allow you to write/prototype programs in Python. You can also use other kernels (e.g., R and Julia .. etc) with Jupyter notebooks.

The Jupyter Notebook combines three components:

  • Notebook web app: An interactive web application to edit code in the browser, run code from the browser, see the results of running the code in the browser, create and use interactive widgets, and author narrative text and equations.
  • Kernels: Processes launched by the notebook web app that runs code in a specific language and handles interactive widgets and tab completion. The default kernel runs Python code.
  • Notebook documents: Documents that contain visible content in the notebook web app, including inputs and outputs of an interactive session, narrative text, equations, and images, and rich media representations of objects. Each notebook document has its own kernel. Notebook documents are files with a .ipynb extension Internally, notebook documents are json data with binary output encoded.

ShapeWorks installs Jupyter for you¶

The Jupyter Notebook is not included with Python. The conda_installs script the comes with ShapeWorks (conda_installs.sh for Mac OS and Linux and conda_installs.bat for Window) installs Jupyter Notebook for you.

ShapeWorks also installs and enables for you

  • a spell checker extension for the text cells
  • a table of content extension to easily navigate notebooks

Starting the Jupyter Notebook server¶

Now that you have run conda_installs - only needed once by running:

source conda_installs.sh

To get the server started, all you need to do is

  • open up your terminal
  • go to the folder where you would like to save your notebooks in
  • activate shapeworks environment by running conda activate shapeworks
  • launch the notebook server by running jupyter notebook

Note: Notebooks for demonstrating ShapeWorks tools are located in Examples/Python/notebooks/tutorials. We recommend that you create a folder in Examples/Python/notebooks/ directory for your own notebooks.

This will launch the Jupyter server. Your default browser will then start or open a new tab to this local URL: http://localhost:8888/tree

Your browser should now look something like this:

Creating a notebook¶

So far, you have started a notebook server and create the folder where you will save your notebooks. Let's now create an actual Notebook document.

This is in fact a click away, all you need to do is click on the new button in the upper right and choose the type of file (notebook) you want to create.

The word Untitled beside the Jupyter logo is the name of your notebooks. You can move your mouse over the word Untitled and click on the text to rename your notebook to a more descriptive name that reflects the purpose of your notebook.

Running notebook cells¶

A Jupyter notebook can have both text (written in markdown) and code cells. When you create a new cell, it defaults to be a code cell running the kernel you chose for your notebook.

Below is a simple Python code that prints Hello ShapeWorks!. Running a cell means that you will execute the chunk of code in that cell. To run a cell, you can do either of the below:

  • click Cell from the Jupyter menu then click Run Cells
  • click the cell and hit the Run button in the bar below the Jupyter menu
  • press Shift + Enter if you prefer keyboard shortcuts

Having multiple cells¶

Typically, we divide our code and text into logical chunks, each in a cell, for readability. Cells can be run in order and share variables and libraries imports. You can also run cells in non-sequential order, especially when you are prototyping your notebook.

If a code cell is not yet executed, you will find an empty square braces In [ ] to the left of the cell. Once it is executed, this will auto fill with a number that indicates the order that you ran the cells.

Styling and navigation¶

Jupyter notebook supports Markdown, a simple markup language that enables simple formatting for section headers, code samples, weblinks, and images, yet is still readable as plain text.

To create a text cell, create a new cell and set its type to Markdown using the drop-down menu in the top icon bar. Start writing your text with markdown styling, for example:

User _underscore_ for italics and **double asterisks** for bold.

Then run the cell (e.g. press Shift + Enter).

Notebook keyboard shortcuts¶

  • Esc + H: displays a complete list of keyboard shortcuts
  • Esc + A: insert new cell above the current cell
  • Esc + B: insert new cell below the current cell
  • Esc + D + D: delete current cell
  • Esc + Z: undo
  • Shift + enter: run current cell and move to next
  • To show a function's argument list (i.e., signature), use ( then shift-tab
  • Use shift-tab-tab to show more help for a function
  • To show the help of a function, use help(function) or function?
  • To show all functions supported by an object, use dot-tab after the variable name
Next Previous

Copyright © 1998 - 2020 Scientific Computing and Imaging Institute. All rights reserved. This project is supported by the National Institutes of Health under grant numbers NIBIB-U24EB029011, NIAMS-R01AR076120, NHLBI-R01HL135568, NIBIB-R01EB016701, and NIGMS-P41GM103545. Software maintenance and support are provided within the funding period.

Built with MkDocs using a theme provided by Read the Docs.
GitHub « Previous Next »