{ "cells": [ { "cell_type": "markdown", "id": "42082fbc", "metadata": {}, "source": [ "# Absorption by a single species" ] }, { "cell_type": "code", "execution_count": null, "id": "a3eae4ea-0aca-4502-9043-54e2ca6fcab9", "metadata": {}, "outputs": [], "source": [ "import pyarts\n", "import numpy as np\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "id": "952fa30f-9620-493b-9a69-7ea46d0ae9b7", "metadata": {}, "source": [ "## Select absorption species" ] }, { "cell_type": "code", "execution_count": null, "id": "b1943594-5e27-4c9c-831c-c575bbc08c6c", "metadata": {}, "outputs": [], "source": [ "species = \"O2-66\" # Main isotope of O2" ] }, { "cell_type": "markdown", "id": "df821a5e-11df-4000-a66f-b19ce8a431d1", "metadata": {}, "source": [ "## Activate the recipe for this species\n", "\n", "See [SingleSpeciesAbsorption](pyarts.recipe.rst#pyarts.recipe.SingleSpeciesAbsorption)." ] }, { "cell_type": "code", "execution_count": null, "id": "79c18bda-7f10-42cb-87b0-ba636cef37f9", "metadata": {}, "outputs": [], "source": [ "absorption = pyarts.recipe.SingleSpeciesAbsorption(species=species)" ] }, { "cell_type": "markdown", "id": "da679d8d-8eef-4437-b299-7c85487df39a", "metadata": {}, "source": [ "## Select a single temperature, a VMR value, and a range of pressures" ] }, { "cell_type": "code", "execution_count": null, "id": "ebf13038-90c1-44dc-93ad-63d4d3da105b", "metadata": {}, "outputs": [], "source": [ "atm = pyarts.arts.AtmPoint()\n", "atm.set_species_vmr(\"O2\", 0.2095)\n", "atm.temperature = 273\n", "ps = np.logspace(5, -2, 8)" ] }, { "cell_type": "markdown", "id": "75ad1d98", "metadata": {}, "source": [ "## Select frequency range" ] }, { "cell_type": "code", "execution_count": null, "id": "d81cde68", "metadata": {}, "outputs": [], "source": [ "line_f0 = 118750348044.712 # Lowest energy absorption line\n", "f = np.linspace(-500e6, 500e6, 1001) + line_f0 # Some range around it" ] }, { "cell_type": "markdown", "id": "25eafbd8", "metadata": {}, "source": [ "## Use the recipe and convert the results to cross-sections" ] }, { "cell_type": "code", "execution_count": null, "id": "b998604b-98aa-4f46-bf78-288d65ffb78e", "metadata": {}, "outputs": [], "source": [ "xsec = []\n", "for p in ps:\n", " atm.pressure = p\n", " xsec.append(absorption(f, atm) / atm.number_density(species))\n", "xsec = np.array(xsec)" ] }, { "cell_type": "markdown", "id": "fc2607ca", "metadata": {}, "source": [ "## Plot the results" ] }, { "cell_type": "code", "execution_count": null, "id": "680f3d50", "metadata": {}, "outputs": [], "source": [ "plt.semilogy((f - line_f0) / 1e6, xsec.T)\n", "plt.xlabel(\"Frequency offset [MHz]\")\n", "plt.ylabel(\"Cross-section [$m^2$]\")\n", "plt.title(\"Cross-section of O$_2$ 16-16\")\n", "plt.ylim(ymin=1e-3 * np.min(xsec))\n", "plt.legend(\n", " [f\"P: $10^{'{'}{round(np.log10(x))}{'}'}$\" for x in ps],\n", " ncols=4,\n", " loc=\"lower center\",\n", ")" ] }, { "cell_type": "markdown", "id": "dd66bb3c", "metadata": {}, "source": [ "## Integration test by ensuring some statistics look good" ] }, { "cell_type": "code", "execution_count": null, "id": "f372371b", "metadata": {}, "outputs": [], "source": [ "assert np.isclose(6.792977548868407e-28 / xsec.mean(), 1)\n", "assert np.isclose(5.43981642113382e-24 / xsec.sum(), 1)\n", "assert np.isclose(1.3359834491781882e-24 / xsec.max(), 1)\n", "assert np.isclose(2.537911691540087e-26 / xsec.std(), 1)\n", "assert np.isclose(8.236637542411964e-35 / xsec.min(), 1)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12.6" } }, "nbformat": 4, "nbformat_minor": 5 }