Getting started with SMRT

The following procedure explains how to get SMRT running on your personal computer.

Step 1. Install Python and dependencies

SMRT is developed with one of the highest stable version of Python (3.9 as of July 2022) but also work with python 3.6 or higher. Anaconda is the recommended distribution to get Python as it contains numerous packages needed for scientific computations and analysis. This is an open source distribution available for Linux, Windows and MacOS. Alternatively, you can install Python with the main package manager of your system (e.g. apt-get on Debian/Ubuntu, rpm on Fedora, homebrew on MacOS, ...) or visit https://wwww.python.org/ for more information. Anaconda provides good performance because it distributes numpy and scipy using the MKL library which provides highly-optimized LAPACK functions. These functions are heavily used in SMRT. Actually >80% of the computation time is for solving eigenvalue problems with LAPACK, the reason why SMRT is only slightly slower than a RT Fortran code.

To keep your system clean we highly recommend to create a virtual environment for the following installation either via conda create or virtualenv.

The main python packages to install are: numpy, scipy, pandas, xarray. With the Anaconda distribution, use the Anaconda navigator or the conda command:

conda install numpy scipy xarray pandas

Using pip, it is similar:

pip install numpy scipy xarray pandas

In addition, it is likely you will want to plot graph with for instance matplotlib, bokeh or plot.ly.

To download and keep up-to-date SMRT, it is recommended to use the version control software Git that can be installed using the package manager of your system. Here are some instructions for installing git. This simple guide to using git may also be helpful but the two needed commands are given below.

Step 2. Get SMRT code

SMRT code is hosted on github. To get the code clone the repository with:

git clone https://github.com/smrt-model/smrt.git

Alternatively, download directly the code with the large green button on github.

Please note the Licence (LGPL) and disclaimer as this governs what you are allowed to do with SMRT! To get ready for using SMRT, you must install the required external packages.

Because SMRT is not formally installed in your system, it is necessary to inform Python where the code is. Under Linux, this is done by using the following command (in every terminal or better to put in ~/.bashrc file)

export PYTHONPATH=$PYTHONPATH:/the/full/path/to/smrt

where /the/full/path/to/smrt is the SMRT top directory, i.e. the directory that contains README.md, requirements.txt, etc.

Step 3. A first example

This simple script sets up a simple, one-layer snowpack with exponential microstructure. The Improved Born Approximation (IBA) and Discrete Ordinates Radiative Transfer model (DORT) are used to simulate the AMSR-E 37V channel:

from smrt import make_snowpack, make_model, sensor_list

# prepare inputs
thickness = [100]
corr_length = [5e-5]
temperature = [270]
density = [320]

# create the snowpack
snowpack = make_snowpack(thickness=thickness,
                         microstructure_model="exponential",
                         density=density,
                         temperature=temperature,
                         corr_length=corr_length)

# create the sensor
radiometer = sensor_list.amsre('37V')

# create the model
m = make_model("iba", "dort")

# run the model
result = m.run(radiometer, snowpack)

# outputs
print(result.TbV())

Copy this code into a new file called "first-smrt.py" somewhere on your filesystem (generally NOT in the smrt directory) and execute the code with the python command or by clicking on the file depending on your system:

python first-smrt.py

If you get an ImportError, it is likely that python does not find the smrt directory. Check that $PYTHONPATH is properly set.

The result of this computation should be 268.21 K. To adapt this to multiple layers, extend the size of the snowpack parameter arrays (e.g. below should give a brightness temperature of 240.12 K if used in place of the snowpack above)

thickness = [1, 99]
corr_length = [5e-5, 3e-4]
temperature = [270, 260]
density = [320, 350]

Last Recommendations: Staying up to date

If you have cloned SMRT with git, you don't need to use clone again to get the last version, just move to the smrt directory and execute:

git pull

We recommend to always get the latest version as we constantly correct bugs and improve the code. See git documentation how to revert to a past version.

Going further with the tutorials

There are many ways in which to use SMRT. Here's a list of examples:

  1. Sensitivity study with a list of snowpacks

  2. Use wrapper to call MEMLS

  3. Figure in the GMD paper