{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Cells"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "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.  \n",
    "\n",
    "### Exercise:  Change the type of this cell from markdown to code.\n",
    "\n",
    "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. \n",
    "\n",
    "### Exercise: Move this cell up one and then down one.  Add an extra cell and then delete it."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Killing Notebooks"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "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",
   "metadata": {},
   "source": [
    "## Kernels"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Jupyter kernels are conda environments that can be accessed within a jupyter notebook\n",
    "- Click on 'Kernel' tab in top menu\n",
    "- Go to change 'Change Kernel' and look through the options"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Anaconda Environments"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "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. \n",
    "\n",
    "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",
   "metadata": {},
   "source": [
    "## Setting up the workshop kernel"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "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.\n",
    "\n",
    "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",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "214"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pathlib import Path\n",
    "\n",
    "kernel_text = \"\"\"{\n",
    " \"argv\": [\n",
    "  \"/usgs/cpkgs/anaconda3_linux/envs/autocnet_updated/bin/python\",\n",
    "  \"-m\",\n",
    "  \"ipykernel_launcher\",\n",
    "  \"-f\",\n",
    "  \"{connection_file}\"\n",
    " ],\n",
    " \"display_name\": \"AutoCNet PLIO (workshop)\",\n",
    " \"language\": \"python\"\n",
    "}\n",
    "\"\"\"\n",
    "\n",
    "kernel_dir = Path.home() / '.local/share/jupyter/kernels/autocnet_workshop/'\n",
    "kernel_dir.mkdir(parents=True, exist_ok=True)\n",
    "kernel_file = kernel_dir / 'kernel.json'\n",
    "\n",
    "kernel_file.open('w').write(kernel_text)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "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",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "!cat ~/.local/share/jupyter/kernels/autocnet_workshop/kernel.json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
