Python Setup

Installaion

Required software includes Python 3 and Conda. The easiest way to install “Conda” would be to install the software “Anaconda.” It consists of a conda-based installer, which bandles in the conda command.

zion server

The server zion has Anaconda3, and you need to install it into your local directory. To activate the anaconda for your environment, please do the folliwng steps. This approach assumes that your shell is Bash (it’s a defalut setting).

$ cp /work1/software/anaconda/Anaconda3-2021.05-Linux-x86_64.sh ./
$ ./Anaconda3-2021.05-Linux-x86_64.sh
$ source ~/.bashrc

Virtual Envionment

There is no perfect software, and software development never ends. By fixing a bug within the software, we continuously update the software. We can confirm the latest software by checking its version. In python, for example, you may find versions after the software name like Python 2.7.0 or Python 3.7.2. The first digit of the version represents a significant update, whereas the last digit is a minor update. Generally, a version of software closely links with the computer environment. Once you update software, you may require an update of the OS as well. Otherwise, the older version doesn’t work anymore. Although we need the software update mainly for security reasons, such an update sometimes causes a problem of software compatibility. To avoid this situation, we recommend using a virtual environment. The following is the procedure to set up the virtual environment.

Initial setup for the virtual environment

Update conda

$ conda update conda

Setup virtual environment

$ conda create -n env_clm python=3.7

Install Packages

Required packages

The basic packages include numpy, pandas, and xarray. Once we install xarray, pandas is also installed automatically.

$ conda install -n env_clm numpy xarray
$ conda install -n env_clm matplotlib cartopy
$ conda install -n env_clm dask

We also use GeoCAT for visualization and data analysis.

$ conda install -n env_clm -c conda-forge -c ncar geocat-comp geocat-viz geocat-f2py netCDF4 eofs

Optional (NetCDF4)

GeoCAT may cause a version conflict with netCDF4. You may avoid this problem by installing NetCDF4 provided by NCAR like below if $ conda install -n evn_clm netCDF4 doesn’t work.

$ conda install -n env_clm -c conda-forge -c ncar netCDF4

Alternatively, you may install PyNIO.

$ conda install -n env_clm -c conda-forge pynio

Activate the virtual environment

Activate the virtual environment named “env_clm”

$ conda activate env_clm

Deactivate the virtual environment

When you want to deactivate the virtual environment, use the following command.

$ conda deactivate

When you want to remove the virtual environment, use the following command.

$ conda env remove --name env_clm

Or you may use the command below for the older version of conda.

$ conda remove -n env_clm --all

Run a python script

To run a python script, we can simply use the command python with a script file name. For example, let’s assume that the script file name is example-v1.py. We will get the result by running the script like this:

$ python example-v1.py