{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Example usage\n", "\n", "To use `malta` in a project:" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "A simple run of constant emissons of 10 Gg of CFC-11 with zero initial conditions from 2010-2020 inclusive could be:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from malta import model\n", "\n", "start_year = 2010\n", "end_year = 2021\n", "species = \"CFC11\"\n", "\n", "# Set up and run model\n", "years = np.array([str(yr) for yr in range(start_year,end_year)])\n", "emistot = np.repeat(10, len(years))\n", "emissions = model.create_emissions(species, emistot)\n", "sink = model.create_sink(species)\n", "ds_out = model.run_model(years, emissions, sink) " ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "It is then simple to plot the outputs using the simple plotting tools for xarray's datasets:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ds_out.burden.plot()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Or, for example, the global mean mole fraction at the surface could be plot using the 'weighted' functionality:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ds_out[species][:,0,:].weighted(np.cos(np.deg2rad(ds_out.lat))).mean(\"lat\").plot()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "To change how the emissions are distributed in space, we can allocate this by, for example:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "emissions = model.create_emissions(species, emistot, distribute=\"gdp\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "which distributes the 10 Gg of emissions by the latitudinal dependence on gdp." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Initial conditions (of dimensions altitude x latitude) can be passed to the model using the `ics` keyword, for example using the final mole fraction from the previous run:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ics = ds_out[f\"{species}_end\"][-1,:,:]\n", "ds_out = model.run_model(years, emissions, sink, ics=ics) \n", "ds_out[species][:,0,:].weighted(np.cos(np.deg2rad(ds_out.lat))).mean(\"lat\").plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By far the slowest part of transport is the convection scheme as it involves solving a matrix. \\\n", "If you want to speed up the run, there is little loss of accurace for many long-lived substances (lifetime of a year or more) by turning off the convective scheme by setting `ics=False`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ds_out = model.run_model(years, emissions, sink, ics=ics, convection=False) \n", "ds_out[species][:,0,:].weighted(np.cos(np.deg2rad(ds_out.lat))).mean(\"lat\").plot()" ] } ], "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.9.16" } }, "nbformat": 4, "nbformat_minor": 4 }