Commit de68f8c5 authored by Jesse Mapel's avatar Jesse Mapel Committed by Jesse Mapel
Browse files

Updated kernel

parent cd8f3e67
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
%% Cell type:markdown id: tags:

## Cells

%% Cell type:markdown id: tags:

Cells are isolated blocks of code that can be run individually. Although the code is sequesterd within a cell, the variables created in a cell can be accessed else were. Manipulating cells in jupyter notebook is easy. A cell is what this is,it is where you will be writing your code.  There are two types of cells in this document, markdown cells and code cells. The type of cell can be changed at the top of the notebook in the dropdown menu that shows either Markdown or code.

### Exercise:  Change the type of this cell from markdown to code.

Code cells will be used for all excercises in this tutorial. All cell manipulation tools will be found at the top of the notebook.  To add a cell, push the plus symbol. To move a cell, use the arrow buttons.  To delete a cell, click to the left of the cell and enter dd. To a run a cells contents, press shift and enter.

### Exercise: Move this cell up one and then down one.  Add an extra cell and then delete it.

%% Cell type:markdown id: tags:

## Killing Notebooks

%% Cell type:markdown id: tags:

Notebooks are hosted on the nebula cluster, unless specifically shut down, the job running the jupyter notebook will continue running even if jupyter hub fails. It is important to cancel your jupyter jobs after you are finished.  Select the box next to your notebook in the main jupyter hub tab and click the yellow shutdown button at the top of the page.

%% Cell type:markdown id: tags:

## Kernels

%% Cell type:markdown id: tags:

Jupyter kernels are conda environments that can be accessed within a jupyter notebook
- Click on 'Kernel' tab in top menu
- Go to change 'Change Kernel' and look through the options

%% Cell type:markdown id: tags:

## Anaconda Environments

%% Cell type:markdown id: tags:

Anaconda environments are a collection of python packages that are installed into an isolated environment and can be selectively accessed through activation of that environment. They are particularly helpful because various versions of a program or various combinations of programs in isolated environments do not effect those in another environment.

For example, ASC internally creates anaconda environments for each new release, and release candidate of the ISIS software. If a user would like to access any particular version of ISIS, they would type `conda activate isisx.y.z`, if later they wanted to access a different version they could `conda deactivate && conda activate isisu.v.w` without worrying about cross containination between the two environments.

%% Cell type:markdown id: tags:

## Setting up the workshop kernel

%% Cell type:markdown id: tags:

The default Python 3 kernel that we are using with this notebook does not have all of the software that we will need in it. So, we need to setup a kernel that points to an Anaconda environment with what we will require installed.

Run the following cell to write the kernel specification into your home directory. Once it is there, Jupyterhub will automatically pick it up as an option next time you start a notebook.

%% Cell type:code id: tags:

``` python
from pathlib import Path

kernel_text = """{
 "argv": [
  "/usgs/cpkgs/anaconda3_linux/envs/autocnet/bin/python",
  "/usgs/cpkgs/anaconda3_linux/envs/autocnet_updated/bin/python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "AutoCNet PLIO (workshop)",
 "language": "python"
}
"""

kernel_dir = Path.home() / '.local/share/jupyter/kernels/autocnet_workshop/'
kernel_dir.mkdir(parents=True, exist_ok=True)
kernel_file = kernel_dir / 'kernel.json'

kernel_file.open('w').write(kernel_text)
```

%% Output

    214

%% Cell type:markdown id: tags:

You can also run shell commands in a Jupyter notebook by starting the line with "!". Run the following cell to check that your kernel was installed properly. You should see the same text as the kernel_text variable in the cell above.

%% Cell type:code id: tags:

``` python
!cat ~/.local/share/jupyter/kernels/autocnet_workshop/kernel.json
```

%% Cell type:code id: tags:

``` python
```
+0 −0
Original line number Diff line number Diff line