Using the LSST Science Pipelines in notebooks (LSST kernel)¶
The LSST kernel includes the LSST Science Pipelines, making it a convenient way to work with LSST’s software. The version of the LSST Science Pipelines that’s preinstalled corresponds to the image you selected at log in.
This page describes how to use the LSST kernel and configure EUPS package set ups and environment variables with the ~/notebooks/.user_setups configuration file.
Create a new notebook with the LSST kernel¶
- From the file browser, click the + button (or type
command
-shift
-L
) to open the launcher. - Under the Notebook heading, click on the LSST icon.
Now the LSST Science Pipelines are available for you to import and use.
For example, in a notebook cell, import lsst.afw
and check the version:
from lsst import afw
afw.version.__version__
With the LSST kernel you don’t run the loadLSST.bash
and setup
commands that are needed for command-line usage. The LSST kernel does this for you. You can still customize how packages are set up, see Customizing the EUPS package setup (~/notebooks/.user_setups).
See also
The JupyterLab Notebooks documentation has more information on creating and using notebooks.
Switch an opened notebook to the LSST kernel¶
You can open existing notebooks by double clicking on their icons in the JupyterLab file browser. JupyterLab automatically opens notebooks in the same kernel that they were created with. If you’re opening an notebooks that wasn’t created in the Notebook Aspect, you may need to switch the kernel to LSST:
- Look for the kernel name in the notebook’s upper right menu bar. It should read LSST. If it is Python 3 (the default kernel) you’ll need to switch it.
- Click on the kernel name and select LSST from the menu.
Customizing the EUPS package setup (~/notebooks/.user_setups)¶
When the LSST kernel starts up, it activates the LSST environment and sets up lsst_distrib
(the top-level EUPS package of the LSST Science Pipelines).
You can customize what packages are set up by creating and editing a ~/notebooks/.user_setups
file.
Setting up a local package¶
The main use for ~/notebooks/.user_setups
is setting up a package that you’ve locally cloned and built.
For example, if your package is the ~/notebooks/my_package
directory, add this line to ~/notebooks/.user_setups
:
setup -k -r ~/notebooks/my_package
Note
You need to compile an LSST Science Pipelines package first with scons before using it.
See: Tutorial: developing LSST Science Pipelines packages in the Notebook Aspect.
Export environment variables for notebooks¶
The ~/notebooks/.user_setups
file is sourced by bash.
This means you can include any valid bash syntax.
For example, you can define environment variables that are accessible from notebooks:
export MYVAR="My env var"
Note
Environment variables exported from ~/.bashrc and ~/.bash_profile are not accessible from notebooks.
You need to export those variables from ~/notebooks/.user_setups
instead.
Tip: source ~/notebooks/.user_setups to verify it¶
Since ~/notebooks/.user_setups
is a bash script, it’s sensitive to syntax errors.
You won’t be alerted to syntax errors when you start a new notebook kernel, though.
The best way to check that your ~/notebooks/.user_setups
file is correct is by sourcing it from a terminal:
source ~/notebooks/.user_setups
Note
If ~/notebooks/.user_setups
includes a setup command, ensure that you have set up the LSST environment in the terminal first.
Updating ~/notebooks/.user_setups for a running notebook kernel¶
If you need to change package setups or environment variables for an already-opened notebook, follow these steps:
- Edit and save the
~/notebooks/.user_setups
file. - Return to your notebook’s tab and restart the kernel (Kernel → Restart Kernel).
You’ll need to rerun your notebook’s cells after restarting the kernel.