Setting up your computer environment for working with COS data#

Learning Goals#

This Notebook is designed to walk the user (you) through:

1. Setting up a conda environment for working with COS data

- 1.1. Installing conda

- 1.2. Creating a conda environment

2. Setting up the Git repo of COS tutorials (optional)

3. Downloading up-to-date reference files

- 3.1. Downloading the most recent context

- 3.2. Downloading an older context

0. Introduction#

The Cosmic Origins Spectrograph (COS) is an ultraviolet spectrograph on-board the Hubble Space Telescope (HST) with capabilities in the near ultraviolet (NUV) and far ultraviolet (FUV).

This tutorial will walk you through setting up a Python environment for COS data analysis on your computer.

Notes for those new to Python/Jupyter/Coding:#

  • You will frequently see exclamation points (!) or dollar signs ($) at the beginning of a line of code. These are not part of the actual commands. The exclamation points tell a Jupyter Notebook to pass the following line to the command line, and the dollar sign merely indicates the start of a terminal prompt.

  • Similarly, when a variable or argument in a line of code is surrounded by sharp brackets, like <these words are>, this is an indication that the variable or argument is something which you should change to suit your data.

  • If you install the full Anaconda distribution with the Anaconda Navigator tool, (see Section 1) you will also have access to a graphical interface (AKA a way to use windows and a point-and-click interface instead of the terminal for installing packages and managing environments).

Other notes:#

  • It is sometimes preferable to use another package manager - pip - to install necessary packages, however conda can be used to create Python environments as well as install packages. You may see both pip and conda used in these Notebooks.

1. Setting up a conda environment for working with COS data#

1.1. Installing conda#

You may already have a working conda tool. To check whether you have conda installed, open a terminal window and type conda -V, conda --version, or run the next cell. If your conda is installed and working, the terminal or cell will return the version of conda.

!conda -V

If you receive a message that the command is unknown or not found, you must install conda. We recommend installing either the Anaconda or Minicoda distributions. See this page for instructions, and install either of the following:

Conda Distribution (with link to download)

Short Description

Size

Anaconda Distribution

More beginner friendly, with lots of extras you likely won’t use

~ 3 GB

Miniconda Distribution

Bare-bones conda distribution, which allows you to download only what you need

~ 400 MB

Mamba Distribution

Similar to Miniconda, rewritten in C++. Allows for faster speeds over conda for resolving environment dependencies.

~ 85 MB

1.2. Creating a conda environment#

conda allows for separate sets of packages to be installed on the same system in different environments, and for these environments to be shared so that other users can install the packages you used to get your code running. These packages are vital parts of your programming toolkit, and allow you to avoid “reinventing the wheel” by leveraging other peoples’ code. Thus, packages should be treated as any resource created by other person, and cited to avoid plagiarizing.

One package which is often necessary for working with COS data is calcos, which runs the CalCOS data pipeline. However, this package will not, by default, be installed on your computer. We will install CalCOS, as well as all the packages you will need to run any of these COS Notebooks.

Open your terminal app, likely Terminal or iTerm on a Mac or Windows Terminal or Powershell on Windows. We’ll begin by adding the conda-forge channel to conda’s channel list. This enables conda to look in the right place to find all the packages we want to install.

$ conda config --add channels conda-forge

Now we can create our new environment. We’ll call it cos_analysis_env, and initialize it with Python version 3.10.

$ conda create -n cos_analysis_env python=3.10

Allow conda to install some necessary packages (when prompted, type y then enter/return). Then, conda will need a few minutes, depending on your internet speed to complete the installation. After this installation finishes, you can see all of your environments with:

$ conda env list

Now, activate your new environment with:

$ conda activate cos_analysis_env

Note that you will need to activate your environment every time you open a new terminal or shell using conda activate cos_analysis_env. You can also do this automatically by appending conda activate cos_analysis_env to the end of your .bashrc or equivalent file. You must activate your desired conda environment before starting a Jupyter Notebook kernel in that terminal.

Finally, install CalCOS, COSTools, CRDS, and some other packages we’ll need using pip:

$ pip install calcos costools crds notebook jupyterlab matplotlib astroquery

Note that this will also likely take a few minutes to install as well.

Testing our installation#

We can test our installation by importing some of these packages. From the command line, try running:

$ python --version; python -c "import numpy, calcos, costools, crds; print('Imports succesful')"

This should return:

Python 3.10.4    # (or a similar version number)
Imports successful

Installing other packages#

We can add any other packages we need with this command:

$ pip install <first package name> <second package name> ... <last package name>

Now, go ahead and install the specutils package, which is briefly discussed in the ViewData.ipynb Notebook, using the following command:

$ pip install specutils

We’ll finish our installations by using the pip install command to download SciPy and Pandas:

pip install pandas scipy

2. Setting up the git repo of other COS tutorials (optional for some Notebooks)#

While most of the tutorial Notebooks can generally be downloaded and run independently, this is not true at present for ViewData.ipynb, which needs both the Scripts and ViewData directories installed side-by-side. For the best experience, we recommend cloning the entire repository of Notebooks.

You almost certainly have the git command line tool installed. To test it, type git --version into the command line, which should respond with a version number. If you don’t have Git installed, follow the instructions to install it here.

All of the tutorial Notebooks are hosted at this GitHub repo.

Clicking on the green “Code” button on this GitHub page gives you several options for downloading the code. Enter the directory that will store the downloaded notebooks, then copy either the https or ssh text under the Clone heading and type into your command line:

$ git clone <the text you copied> without the <>.

This will create a new directory that contains all of the tutorial notebooks you just cloned.