Skip to content

Commit

Permalink
add example notebook to documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
whitetuft committed Feb 22, 2024
1 parent aef5356 commit 5d87227
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 2 deletions.
26 changes: 24 additions & 2 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,30 @@ From within pyrtlib folder run the following docker command to build the docker
$ docker build --pull --rm -f "Dockerfile" -t pyrtlib:latest "."
$ docker run --rm -it pyrtlib:latest
To test run the exaple script from within the docker image
To test run the example script from within the docker image

.. code-block:: console
$ root@993587e5fea9:/home/dev/pyrtlib# python3 hello_spectrum.py
$ root@993587e5fea9:/home/dev/pyrtlib# python3 hello_spectrum.py
My first run with PyRTlib (Colab Notebook)
==========================================

To run the example script in a Google Colab Notebook, you can use the following code:

.. code-block:: console
!pip install pyrtlib
!python3 hello_spectrum.py
.. note::

The example script is available at `this link <https://colab.research.google.com/github/SatCloP/pyrtlib/blob/main/docs/source/notebook/first_run.ipynb>`_.

.. _`this link`:

.. code-block:: console
!wget https://raw.githubusercontent.com/SatCloP/pyrtlib/main/pyrtlib/hello_spectrum.py
!python3 hello_spectrum.py
124 changes: 124 additions & 0 deletions docs/source/notebook/first_run.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/SatCloP/pyrtlib/blob/main/docs/source/notebook/first_run.ipynb)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# My first test with PyRTlib"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Installing PyRTlib via pip"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install pyrtlib"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Import necessary packages"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# This requires jupyter-matplotlib a.k.a. ipympl.\n",
"# ipympl can be install via pip or conda.\n",
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"plt.rcParams.update({'font.size': 15})\n",
"import matplotlib.ticker as ticker\n",
"from matplotlib.ticker import ScalarFormatter\n",
"import numpy as np\n",
"import pandas as pd\n",
"np.seterr('raise')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pyrtlib import __version__\n",
"from pyrtlib.absorption_model import H2OAbsModel, O2AbsModel\n",
"from pyrtlib.climatology import AtmosphericProfiles as atmp\n",
"from pyrtlib.tb_spectrum import TbCloudRTE\n",
"from pyrtlib.utils import ppmv2gkg, mr2rh, get_frequencies_sat\n",
"import time"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"z, p, _, t, md = atmp.gl_atm(atmp.TROPICAL)\n",
"\n",
"gkg = ppmv2gkg(md[:, atmp.H2O], atmp.H2O)\n",
"rh = mr2rh(p, t, gkg)[0] / 100\n",
"\n",
"frq = np.arange(20, 1001, 1)\n",
"\n",
"rte = TbCloudRTE(z, p, t, rh, frq)\n",
"rte.init_absmdl('R22SD')\n",
"O2AbsModel.model = 'R22'\n",
"O2AbsModel.set_ll()\n",
"df = rte.execute()\n",
"df = df.set_index(frq)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df.plot(figsize=(25, 8), linewidth=3, xlabel=\"Frequency [GHz]\", ylabel=\"Brightness Temperature [K]\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.10"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 5d87227

Please sign in to comment.