{
“cells”: [
{

“cell_type”: “markdown”, “metadata”: {}, “source”: [

“Command line interfacen”, “====================n”, “n”, “xclim provides the xclim command line executable to perform basic indicatorn”, “computation easily without having to start up a full python environment. However, notn”, “all indicators listed in [Climate Indicators](../indicators.rst) are available through this tool.n”, “n”, “Its use is simple. Type the following to see the usage message:”

]

}, {

“cell_type”: “code”, “execution_count”: null, “metadata”: {}, “outputs”: [], “source”: [

“!xclim –help”

]

}, {

“cell_type”: “markdown”, “metadata”: {}, “source”: [

“To list all available indicators, use the "indices" subcommand:”

]

}, {

“cell_type”: “code”, “execution_count”: null, “metadata”: {}, “outputs”: [], “source”: [

“!xclim indices”

]

}, {

“cell_type”: “markdown”, “metadata”: {}, “source”: [

“For more information about a specific indicator, you can either use the info subcommand or directly access the –help message of the indicator. The former gives more information about the metadata while the latter only prints the usage. Note that the module name (atmos, land or seaIce) is mandatory.”

]

}, {

“cell_type”: “code”, “execution_count”: null, “metadata”: {}, “outputs”: [], “source”: [

“!xclim info liquidprcptot”

]

}, {

“cell_type”: “markdown”, “metadata”: {}, “source”: [

“In the usage message, VAR_NAME indicates that the passed argument must match a variable in the input dataset.”

]

}, {

“cell_type”: “code”, “execution_count”: null, “metadata”: {}, “outputs”: [], “source”: [

“import xarray as xrn”, “import numpy as npn”, “import pandas as pdn”, “from pandas.plotting import register_matplotlib_convertersn”, “register_matplotlib_converters()n”, “import warningsn”, “warnings.filterwarnings(‘ignore’, ‘implicitly registered datetime converter’)n”, “%matplotlib inlinen”, “xr.set_options(display_style=’html’)n”, “n”, “time = pd.date_range(‘2000-01-01’, periods=366)n”, “tasmin = xr.DataArray(-5 * np.cos(2 * np.pi * time.dayofyear / 365) + 273.15, dims=("time"), n”, ” coords={‘time’: time}, attrs={‘units’:’K’})n”, “tasmax = xr.DataArray(-5 * np.cos(2 * np.pi * time.dayofyear / 365) + 283.15, dims=("time"),n”, ” coords={‘time’: time}, attrs={‘units’:’K’})n”, “pr = xr.DataArray(np.clip(10 * np.sin(18 * np.pi * time.dayofyear / 365), 0, None), dims=("time"),n”, ” coords={‘time’: time}, attrs={‘units’:’mm/d’})n”, “ds = xr.Dataset({‘tasmin’: tasmin, ‘tasmax’: tasmax, ‘pr’: pr})n”, “ds.to_netcdf(‘example_data.nc’)”

]

}, {

“cell_type”: “markdown”, “metadata”: {}, “source”: [

“Computing indicatorsn”, “——————————-n”, “n”, “So let’s say we have the following toy dataset:”

]

}, {

“cell_type”: “code”, “execution_count”: null, “metadata”: {}, “outputs”: [], “source”: [

“import xarray as xrn”, “ds = xr.open_dataset(‘example_data.nc’)n”, “ds”

]

}, {

“cell_type”: “code”, “execution_count”: null, “metadata”: {}, “outputs”: [], “source”: [

“import matplotlib.pyplot as pltn”, “fig, (axT, axpr) = plt.subplots(1, 2, figsize=(10, 5))n”, “ds.tasmin.plot(label=’tasmin’, ax=axT)n”, “ds.tasmax.plot(label=’tasmax’, ax=axT)n”, “ds.pr.plot(ax=axpr)n”, “axT.legend()”

]

}, {

“cell_type”: “markdown”, “metadata”: {}, “source”: [

“To compute an indicator, say the monthly solid precipitation accumulation, we simply call:”

]

}, {

“cell_type”: “code”, “execution_count”: null, “metadata”: {}, “outputs”: [], “source”: [

“!xclim -i example_data.nc -o out1.nc solidprcptot –pr pr –tas tasmin –freq MS”

]

}, {

“cell_type”: “markdown”, “metadata”: {}, “source”: [

“In this example, we decided to use tasmin for the tas variable. We didn’t need to provide the –pr parameter as our data has the same name. n”, “n”, “Finally, more than one indicators can be computed to the output dataset by simply chaining the calls:”

]

}, {

“cell_type”: “code”, “execution_count”: null, “metadata”: {}, “outputs”: [], “source”: [

“!xclim -i example_data.nc -o out2.nc liquidprcptot –tas tasmin –freq MS tropical_nights –thresh "2 degC" –freq MS”

]

}, {

“cell_type”: “markdown”, “metadata”: {}, “source”: [

“Let’s see the outputs:”

]

}, {

“cell_type”: “code”, “execution_count”: null, “metadata”: {}, “outputs”: [], “source”: [

“ds1 = xr.open_dataset(‘out1.nc’)n”, “ds2 = xr.open_dataset(‘out2.nc’, decode_timedelta=False)n”, “n”, “fig, (axPr, axTn) = plt.subplots(1, 2, figsize=(10, 5))n”, “ds1.solidprcptot.plot(ax=axPr, label=ds1.solidprcptot.long_name)n”, “ds2.liquidprcptot.plot(ax=axPr, label=ds2.liquidprcptot.long_name)n”, “ds2.tropical_nights.plot(ax=axTn, marker=’o’)n”, “axPr.legend()”

]

}, {

“cell_type”: “code”, “execution_count”: null, “metadata”: {}, “outputs”: [], “source”: [

“ds1.close()”

]

}, {

“cell_type”: “code”, “execution_count”: null, “metadata”: {}, “outputs”: [], “source”: [

“ds2.close()”

]

}

], “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.8.8”

}

}, “nbformat”: 4, “nbformat_minor”: 2

}