Difference between revisions of "UKCA Chemistry and Aerosol Tutorials: Python notebooks"
Line 1: | Line 1: | ||
+ | During these Tutorials several [https://jupyter.org/ Jupyter] notebooks are provided using both [https://ncas-cms.github.io/cf-python/ cf-python] and the [https://scitools-iris.readthedocs.io/en/stable/ Iris] Python libraries. On pre-installed virtual machines these can be found in the |
||
+ | Tutorials/UMvn13.0/notebooks |
||
⚫ | |||
+ | |||
+ | Due to the SSH connection you will be making to these virtual machines, it is better to run jupyter remotely and then connect to it from the browser on your desktop machine. |
||
+ | |||
+ | == How to connect == |
||
+ | |||
+ | # On your VM, change directory using the <tt>cd</tt> command into the directory that you want to run the scripts from, e.g. |
||
+ | : <tt>cd Tutorials/UMvn13.0/notebooks</tt> |
||
+ | # On your VM run the command '''<tt>jnotebook</tt> to start a jupyter notebook server, or '''<tt>jlab</tt>''' to start a jupyter lab server. |
||
+ | # On your desktop machine, run the command '''<tt>jopen</tt>''' to allow it to connect to the VM jupyter server. |
||
+ | # On your desktop machine, connect to the following web address using the '''Firefox''' web browser: |
||
⚫ | |||
+ | |||
+ | |||
+ | == Technical notes == |
||
+ | |||
+ | The above instructions make use of some alias and shortcuts to work. The full details of this are: |
||
+ | |||
+ | === On the virtual machine === |
||
+ | |||
+ | The two alias are set in the <tt>~/.bashrc</tt> file on the VM: |
||
+ | |||
+ | alias jlab="lxterminal -l -e 'export PATH=~/miniconda3/bin:$PATH && jupyter-lab --no-browser --port=4801'" |
||
+ | alias jnotebook="lxterminal -l -e 'export PATH=~/miniconda3/bin:$PATH && jupyter notebook --no-browser --port=4801'" |
||
+ | |||
+ | and the |
||
+ | |||
+ | /home/vagrant/.jupyter/jupyter_notebook_config.py |
||
+ | |||
+ | file has the following setting |
||
+ | |||
+ | c.NotebookApp.token = 'UKCATraining' |
||
+ | |||
+ | This means that when you run the command <tt>jnotebook</tt> or <tt>jlab</tt> you then launch a new terminal pointing to the python installation in the <tt>/home/vagrant/miniconda3/bin</tt> directory. |
||
+ | |||
+ | === On the desktop === |
||
+ | |||
+ | The command <tt>jopen</tt> is set as an alias in the <tt>~/.bashrc</tt> to be |
||
+ | |||
+ | alias jopen='ssh -N -f -L localhost:4801:localhost:4801 ukca' |
||
+ | |||
+ | this is equivalent to |
||
ssh -N -f -L localhost:4801:localhost:4801 -i ~/.ssh/[KEY NAME] ubuntu@[EC2 VM IP ADDRESS] |
ssh -N -f -L localhost:4801:localhost:4801 -i ~/.ssh/[KEY NAME] ubuntu@[EC2 VM IP ADDRESS] |
||
+ | |||
− | ssh -O exit -L localhost:4801:localhost:4801 -i ~/.ssh/[KEY NAME] ubuntu@[EC2 VM IP ADDRESS] |
||
+ | but in the <tt>~/.ssh/config</tt> file there are the following settings |
||
+ | |||
+ | Host ukca |
||
+ | Hostname [EC2 VM IP ADDRESS] |
||
+ | User ubuntu |
||
+ | IdentityFile ~/.ssh/[KEY NAME] |
||
+ | HostKeyAlgorithms ssh-rsa |
Revision as of 15:21, 14 November 2022
During these Tutorials several Jupyter notebooks are provided using both cf-python and the Iris Python libraries. On pre-installed virtual machines these can be found in the
Tutorials/UMvn13.0/notebooks
Due to the SSH connection you will be making to these virtual machines, it is better to run jupyter remotely and then connect to it from the browser on your desktop machine.
How to connect
- On your VM, change directory using the cd command into the directory that you want to run the scripts from, e.g.
- cd Tutorials/UMvn13.0/notebooks
- On your VM run the command jnotebook to start a jupyter notebook server, or jlab to start a jupyter lab server.
- On your desktop machine, run the command jopen to allow it to connect to the VM jupyter server.
- On your desktop machine, connect to the following web address using the Firefox web browser:
Technical notes
The above instructions make use of some alias and shortcuts to work. The full details of this are:
On the virtual machine
The two alias are set in the ~/.bashrc file on the VM:
alias jlab="lxterminal -l -e 'export PATH=~/miniconda3/bin:$PATH && jupyter-lab --no-browser --port=4801'" alias jnotebook="lxterminal -l -e 'export PATH=~/miniconda3/bin:$PATH && jupyter notebook --no-browser --port=4801'"
and the
/home/vagrant/.jupyter/jupyter_notebook_config.py
file has the following setting
c.NotebookApp.token = 'UKCATraining'
This means that when you run the command jnotebook or jlab you then launch a new terminal pointing to the python installation in the /home/vagrant/miniconda3/bin directory.
On the desktop
The command jopen is set as an alias in the ~/.bashrc to be
alias jopen='ssh -N -f -L localhost:4801:localhost:4801 ukca'
this is equivalent to
ssh -N -f -L localhost:4801:localhost:4801 -i ~/.ssh/[KEY NAME] ubuntu@[EC2 VM IP ADDRESS]
but in the ~/.ssh/config file there are the following settings
Host ukca Hostname [EC2 VM IP ADDRESS] User ubuntu IdentityFile ~/.ssh/[KEY NAME] HostKeyAlgorithms ssh-rsa