diff --git a/docs/_downloads/plot_1_recipe.ipynb b/docs/_downloads/plot_1_recipe.ipynb deleted file mode 100644 index 8b0ec7545e..0000000000 --- a/docs/_downloads/plot_1_recipe.ipynb +++ /dev/null @@ -1,227 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Calculating global mean temperature timeseries\n\nIn this recipe we will calculate and plot monthly and annual global mean temperature timeseries.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "1. Import cf-python and cf-plot:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import cfplot as cfp\n\nimport cf" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "2. Read the field constructs:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "f = cf.read(\"~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc\")\nprint(f)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "3. Select near surface temperature by index and look at its contents:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "temp = f[1]\nprint(temp)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "4. Select latitude and longitude dimensions by identities, with two different techniques:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "lon = temp.coordinate(\"long_name=longitude\")\nlat = temp.coordinate(\"Y\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "5. Print the description of near surface temperature using the dump method to show properties of all constructs:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "temp.dump()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "6. Latitude and longitude dimension coordinate cell bounds are absent, which are created and set:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "a = lat.create_bounds()\nlat.set_bounds(a)\nlat.dump()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "b = lon.create_bounds()\nlon.set_bounds(b)\nlon.dump()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "print(b.array)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "7. Time dimension coordinate cell bounds are similarly created and set for cell sizes of one calendar month:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "time = temp.coordinate(\"long_name=time\")\nc = time.create_bounds(cellsize=cf.M())\ntime.set_bounds(c)\ntime.dump()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "8. Calculate and plot the area weighted mean surface temperature for each time:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "global_avg = temp.collapse(\"area: mean\", weights=True)\ncfp.lineplot(global_avg, color=\"red\", title=\"Global mean surface temperature\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "9. Calculate and plot the annual global mean surface temperature:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "annual_global_avg = global_avg.collapse(\"T: mean\", group=cf.Y())\ncfp.lineplot(\n annual_global_avg,\n color=\"red\",\n title=\"Annual global mean surface temperature\",\n)" - ] - } - ], - "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.10" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/_downloads/plot_1_recipe.py b/docs/_downloads/plot_1_recipe.py deleted file mode 100644 index 93b9dde417..0000000000 --- a/docs/_downloads/plot_1_recipe.py +++ /dev/null @@ -1,77 +0,0 @@ -""" -Calculating global mean temperature timeseries -============================================== - -In this recipe we will calculate and plot monthly and annual global mean temperature timeseries. -""" - -# %% -# 1. Import cf-python and cf-plot: - -import cfplot as cfp - -import cf - -# %% -# 2. Read the field constructs: - -f = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc") -print(f) - -# %% -# 3. Select near surface temperature by index and look at its contents: - -temp = f[1] -print(temp) - -# %% -# 4. Select latitude and longitude dimensions by identities, with two different techniques: - -lon = temp.coordinate("long_name=longitude") -lat = temp.coordinate("Y") - -# %% -# 5. Print the description of near surface temperature using the dump method to show properties of all constructs: - -temp.dump() - -# %% -# 6. Latitude and longitude dimension coordinate cell bounds are absent, which are created and set: - -a = lat.create_bounds() -lat.set_bounds(a) -lat.dump() - -# %% - -b = lon.create_bounds() -lon.set_bounds(b) -lon.dump() - -# %% - -print(b.array) - -# %% -# 7. Time dimension coordinate cell bounds are similarly created and set for cell sizes of one calendar month: - -time = temp.coordinate("long_name=time") -c = time.create_bounds(cellsize=cf.M()) -time.set_bounds(c) -time.dump() - -# %% -# 8. Calculate and plot the area weighted mean surface temperature for each time: - -global_avg = temp.collapse("area: mean", weights=True) -cfp.lineplot(global_avg, color="red", title="Global mean surface temperature") - -# %% -# 9. Calculate and plot the annual global mean surface temperature: - -annual_global_avg = global_avg.collapse("T: mean", group=cf.Y()) -cfp.lineplot( - annual_global_avg, - color="red", - title="Annual global mean surface temperature", -) diff --git a/docs/_downloads/plot_2_recipe.ipynb b/docs/_downloads/plot_2_recipe.ipynb deleted file mode 100644 index 474afce62e..0000000000 --- a/docs/_downloads/plot_2_recipe.ipynb +++ /dev/null @@ -1,274 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Calculating and plotting the global average temperature anomalies\n\nIn this recipe we will calculate and plot the global average temperature anomalies.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "1. Import cf-python and cf-plot:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import cfplot as cfp\n\nimport cf" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "2. Read the field constructs:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "f = cf.read(\"~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc\")\nprint(f)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "3. Select near surface temperature by index and look at its contents:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "temp = f[1]\nprint(temp)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "4. Select latitude and longitude dimensions by identities, with two different techniques:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "lon = temp.coordinate(\"long_name=longitude\")\nlat = temp.coordinate(\"Y\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "5. Print the description of near surface temperature to show properties of all constructs:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "temp.dump()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "6. Latitude and longitude dimension coordinate cell bounds are absent, which are created and set:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "a = lat.create_bounds()\nlat.set_bounds(a)\nlat.dump()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "b = lon.create_bounds()\nlon.set_bounds(b)\nlon.dump()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "print(b.array)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "7. Time dimension coordinate cell bounds are similarly created and set for cell sizes of one calendar month:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "time = temp.coordinate(\"long_name=time\")\nc = time.create_bounds(cellsize=cf.M())\ntime.set_bounds(c)\ntime.dump()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "8. Calculate the area weighted mean surface temperature for each time using the collapse method:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "global_avg = temp.collapse(\"area: mean\", weights=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "9. Calculate the annual global mean surface temperature:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "annual_global_avg = global_avg.collapse(\"T: mean\", group=cf.Y())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "10. The temperature values are averaged for the climatological period of 1961-1990 by defining a subspace within these years using `cf.wi` query instance over subspace and doing a statistical collapse with the collapse method:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "annual_global_avg_61_90 = annual_global_avg.subspace(\n T=cf.year(cf.wi(1961, 1990))\n)\nprint(annual_global_avg_61_90)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "temp_clim = annual_global_avg_61_90.collapse(\"T: mean\")\nprint(temp_clim)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "11. The temperature anomaly is then calculated by subtracting these climatological temperature values from the annual global average temperatures and plotted:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "temp_anomaly = annual_global_avg - temp_clim\ncfp.lineplot(\n temp_anomaly,\n color=\"red\",\n title=\"Global Average Temperature Anomaly (1901-2021)\",\n ylabel=\"1961-1990 climatology difference \",\n yunits=\"degree Celcius\",\n)" - ] - } - ], - "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.10" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/_downloads/plot_2_recipe.py b/docs/_downloads/plot_2_recipe.py deleted file mode 100644 index 902c796788..0000000000 --- a/docs/_downloads/plot_2_recipe.py +++ /dev/null @@ -1,96 +0,0 @@ -""" -Calculating and plotting the global average temperature anomalies -================================================================= - -In this recipe we will calculate and plot the global average temperature anomalies. -""" - -# %% -# 1. Import cf-python and cf-plot: - -import cfplot as cfp - -import cf - -# %% -# 2. Read the field constructs: - -f = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc") -print(f) - -# %% -# 3. Select near surface temperature by index and look at its contents: - -temp = f[1] -print(temp) - -# %% -# 4. Select latitude and longitude dimensions by identities, with two different techniques: - -lon = temp.coordinate("long_name=longitude") -lat = temp.coordinate("Y") - -# %% -# 5. Print the description of near surface temperature to show properties of all constructs: - -temp.dump() - -# %% -# 6. Latitude and longitude dimension coordinate cell bounds are absent, which are created and set: - -a = lat.create_bounds() -lat.set_bounds(a) -lat.dump() - -# %% - -b = lon.create_bounds() -lon.set_bounds(b) -lon.dump() - -# %% - -print(b.array) - -# %% -# 7. Time dimension coordinate cell bounds are similarly created and set for cell sizes of one calendar month: - -time = temp.coordinate("long_name=time") -c = time.create_bounds(cellsize=cf.M()) -time.set_bounds(c) -time.dump() - -# %% -# 8. Calculate the area weighted mean surface temperature for each time using the collapse method: - -global_avg = temp.collapse("area: mean", weights=True) - -# %% -# 9. Calculate the annual global mean surface temperature: - -annual_global_avg = global_avg.collapse("T: mean", group=cf.Y()) - -# %% -# 10. The temperature values are averaged for the climatological period of 1961-1990 by defining a subspace within these years using `cf.wi` query instance over subspace and doing a statistical collapse with the collapse method: - -annual_global_avg_61_90 = annual_global_avg.subspace( - T=cf.year(cf.wi(1961, 1990)) -) -print(annual_global_avg_61_90) - -# %% - -temp_clim = annual_global_avg_61_90.collapse("T: mean") -print(temp_clim) - -# %% -# 11. The temperature anomaly is then calculated by subtracting these climatological temperature values from the annual global average temperatures and plotted: - -temp_anomaly = annual_global_avg - temp_clim -cfp.lineplot( - temp_anomaly, - color="red", - title="Global Average Temperature Anomaly (1901-2021)", - ylabel="1961-1990 climatology difference ", - yunits="degree Celcius", -) diff --git a/docs/_downloads/plot_3_recipe.ipynb b/docs/_downloads/plot_3_recipe.ipynb deleted file mode 100644 index 946165dad4..0000000000 --- a/docs/_downloads/plot_3_recipe.ipynb +++ /dev/null @@ -1,133 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Plotting global mean temperatures spatially\n\nIn this recipe, we will plot the global mean temperature spatially.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "1. Import cf-python and cf-plot:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import cfplot as cfp\n\nimport cf" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "2. Read the field constructs:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "f = cf.read(\"~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc\")\nprint(f)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "3. Select near surface temperature by index and look at its contents:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "temp = f[1]\nprint(temp)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "4. Average the monthly mean surface temperature values by the time axis using the collapse method:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "global_avg = temp.collapse(\"mean\", axes=\"long_name=time\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "5. Plot the global mean surface temperatures:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "cfp.con(global_avg, lines=False, title=\"Global mean surface temperature\")" - ] - } - ], - "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.10" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/_downloads/plot_3_recipe.py b/docs/_downloads/plot_3_recipe.py deleted file mode 100644 index 25633b1c54..0000000000 --- a/docs/_downloads/plot_3_recipe.py +++ /dev/null @@ -1,35 +0,0 @@ -""" -Plotting global mean temperatures spatially -=========================================== - -In this recipe, we will plot the global mean temperature spatially. -""" - -# %% -# 1. Import cf-python and cf-plot: - -import cfplot as cfp - -import cf - -# %% -# 2. Read the field constructs: - -f = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc") -print(f) - -# %% -# 3. Select near surface temperature by index and look at its contents: - -temp = f[1] -print(temp) - -# %% -# 4. Average the monthly mean surface temperature values by the time axis using the collapse method: - -global_avg = temp.collapse("mean", axes="long_name=time") - -# %% -# 5. Plot the global mean surface temperatures: - -cfp.con(global_avg, lines=False, title="Global mean surface temperature") diff --git a/docs/_downloads/plot_4_recipe.ipynb b/docs/_downloads/plot_4_recipe.ipynb deleted file mode 100644 index 90e0ecb17e..0000000000 --- a/docs/_downloads/plot_4_recipe.ipynb +++ /dev/null @@ -1,137 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Comparing two datasets with different resolutions using regridding\n\nIn this recipe, we will regrid two different datasets with different resolutions. An example use case could be one where the observational dataset with a higher resolution needs to be regridded to that of the model dataset so that they can be compared with each other.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "1. Import cf-python:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import cf" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "2. Read the field constructs:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "obs = cf.read(\"~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc\", chunks=None)\nprint(obs)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "model = cf.read(\n \"~/recipes/tas_Amon_HadGEM3-GC3-1_hist-1p0_r3i1p1f2_gn_185001-201412.nc\"\n)\nprint(model)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "3. Select observation and model temperature fields by identity and index respectively, and look at their contents:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "obs_temp = obs.select_field(\"long_name=near-surface temperature\")\nprint(obs_temp)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "model_temp = model[0]\nprint(model_temp)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "4. Regrid observational data to that of the model data and create a new low resolution observational data using bilinear interpolation:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "obs_temp_regrid = obs_temp.regrids(model_temp, method=\"linear\")\nprint(obs_temp_regrid)" - ] - } - ], - "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.10" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/_downloads/plot_4_recipe.py b/docs/_downloads/plot_4_recipe.py deleted file mode 100644 index cc3b298412..0000000000 --- a/docs/_downloads/plot_4_recipe.py +++ /dev/null @@ -1,40 +0,0 @@ -""" -Comparing two datasets with different resolutions using regridding -================================================================== - -In this recipe, we will regrid two different datasets with different resolutions. An example use case could be one where the observational dataset with a higher resolution needs to be regridded to that of the model dataset so that they can be compared with each other. -""" - -# %% -# 1. Import cf-python: - -import cf - -# %% -# 2. Read the field constructs: - -obs = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc", chunks=None) -print(obs) - -# %% - -model = cf.read( - "~/recipes/tas_Amon_HadGEM3-GC3-1_hist-1p0_r3i1p1f2_gn_185001-201412.nc" -) -print(model) - -# %% -# 3. Select observation and model temperature fields by identity and index respectively, and look at their contents: - -obs_temp = obs.select_field("long_name=near-surface temperature") -print(obs_temp) - -# %% - -model_temp = model[0] -print(model_temp) - -# %% -# 4. Regrid observational data to that of the model data and create a new low resolution observational data using bilinear interpolation: -obs_temp_regrid = obs_temp.regrids(model_temp, method="linear") -print(obs_temp_regrid) diff --git a/docs/_downloads/plot_5_recipe.ipynb b/docs/_downloads/plot_5_recipe.ipynb deleted file mode 100644 index 676f954707..0000000000 --- a/docs/_downloads/plot_5_recipe.ipynb +++ /dev/null @@ -1,159 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Plotting wind vectors overlaid on precipitation data\n\nIn this recipe we will plot wind vectors, derived from northward and eastward wind components, over precipitation data.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "1. Import cf-python and cf-plot:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import cfplot as cfp\n\nimport cf" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "2. Read the field constructs:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "f1 = cf.read(\"~/recipes/northward.nc\")\nprint(f1)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "f2 = cf.read(\"~/recipes/eastward.nc\")\nprint(f2)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "f3 = cf.read(\"~/recipes/monthly_precipitation.nc\")\nprint(f3)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "3. Select wind vectors and precipitation data by index and look at their contents:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "v = f1[0]\nprint(v)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "u = f2[0]\nprint(u)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pre = f3[0]\nprint(pre)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "4. Plot the wind vectors on top of precipitation data for June 1995 by creating a subspace with a date-time object and using [cfplot.con](http://ajheaps.github.io/cf-plot/con.html). Here [cfplot.gopen](http://ajheaps.github.io/cf-plot/gopen.html) is used to define the parts of the plot area, which is closed by [cfplot.gclose](http://ajheaps.github.io/cf-plot/gclose.html); [cfplot.cscale](http://ajheaps.github.io/cf-plot/cscale.html) is used to choose one of the colour maps amongst many available; [cfplot.levs](http://ajheaps.github.io/cf-plot/levs.html) is used to set the contour levels for precipitation data; and [cfplot.vect](http://ajheaps.github.io/cf-plot/vect.html) is used to plot the wind vectors for June 1995:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "june_95 = cf.year(1995) & cf.month(6)\ncfp.gopen()\ncfp.cscale(\"precip4_11lev\")\ncfp.levs(step=100)\ncfp.con(\n pre.subspace(T=june_95),\n lines=False,\n title=\"June 1995 monthly global precipitation\",\n)\ncfp.vect(\n u=u.subspace(T=june_95),\n v=v.subspace(T=june_95),\n key_length=10,\n scale=35,\n stride=5,\n)\ncfp.gclose()" - ] - } - ], - "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.10" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/_downloads/plot_5_recipe.py b/docs/_downloads/plot_5_recipe.py deleted file mode 100644 index 2f1b4eab0a..0000000000 --- a/docs/_downloads/plot_5_recipe.py +++ /dev/null @@ -1,64 +0,0 @@ -""" -Plotting wind vectors overlaid on precipitation data -==================================================== - -In this recipe we will plot wind vectors, derived from northward and eastward wind components, over precipitation data. -""" - -# %% -# 1. Import cf-python and cf-plot: - -import cfplot as cfp - -import cf - -# %% -# 2. Read the field constructs: - -f1 = cf.read("~/recipes/northward.nc") -print(f1) - -# %% - -f2 = cf.read("~/recipes/eastward.nc") -print(f2) - -# %% - -f3 = cf.read("~/recipes/monthly_precipitation.nc") -print(f3) - -# %% -# 3. Select wind vectors and precipitation data by index and look at their contents: -v = f1[0] -print(v) - -# %% - -u = f2[0] -print(u) - -# %% - -pre = f3[0] -print(pre) - -# %% -# 4. Plot the wind vectors on top of precipitation data for June 1995 by creating a subspace with a date-time object and using `cfplot.con `_. Here `cfplot.gopen `_ is used to define the parts of the plot area, which is closed by `cfplot.gclose `_; `cfplot.cscale `_ is used to choose one of the colour maps amongst many available; `cfplot.levs `_ is used to set the contour levels for precipitation data; and `cfplot.vect `_ is used to plot the wind vectors for June 1995: -june_95 = cf.year(1995) & cf.month(6) -cfp.gopen() -cfp.cscale("precip4_11lev") -cfp.levs(step=100) -cfp.con( - pre.subspace(T=june_95), - lines=False, - title="June 1995 monthly global precipitation", -) -cfp.vect( - u=u.subspace(T=june_95), - v=v.subspace(T=june_95), - key_length=10, - scale=35, - stride=5, -) -cfp.gclose() diff --git a/docs/_downloads/plot_6_recipe.ipynb b/docs/_downloads/plot_6_recipe.ipynb deleted file mode 100644 index 6ad67ada2d..0000000000 --- a/docs/_downloads/plot_6_recipe.ipynb +++ /dev/null @@ -1,205 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Converting from rotated latitude-longitude to regular latitude-longitude\n\nIn this recipe, we will be regridding from a rotated latitude-longitude source domain to a regular latitude-longitude destination domain.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "1. Import cf-python, cf-plot and numpy:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import cfplot as cfp\nimport numpy as np\n\nimport cf" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "2. Read the field constructs using read function:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "f = cf.read(\"~/recipes/au952a.pd20510414.pp\")\nprint(f)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "3. Select the field by index and print its description to show properties of all constructs:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "gust = f[0]\ngust.dump()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "4. Access the time coordinate of the gust field and retrieve the datetime values of the time coordinate:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "print(gust.coordinate(\"time\").datetime_array)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "5. Create a new instance of the `cf.dt` class with a specified year, month, day, hour, minute, second and microsecond. Then store the result in the variable ``test``:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "test = cf.dt(2051, 4, 14, 1, 30, 0, 0)\nprint(test)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "6. Plot the wind gust by creating a subspace for the specified variable ``test`` using [cfplot.con](http://ajheaps.github.io/cf-plot/con.html). Here [cfplot.mapset](http://ajheaps.github.io/cf-plot/mapset.html) is used to set the mapping parameters like setting the map resolution to 50m:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "cfp.mapset(resolution=\"50m\")\ncfp.con(gust.subspace(T=test), lines=False)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "7. To see the rotated pole data on the native grid, the above steps are repeated and projection is set to rotated in [cfplot.mapset](http://ajheaps.github.io/cf-plot/mapset.html):\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "cfp.mapset(resolution=\"50m\", proj=\"rotated\")\ncfp.con(gust.subspace(T=test), lines=False)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "8. Create dimension coordinates for the destination grid with the latitude and longitude values for Europe. [np.linspace](https://numpy.org/doc/stable/reference/generated/numpy.linspace.html) generates evenly spaced values between the specified latitude and longitude range. Bounds of the target longitude and target latitude are created and spherical regridding is then performed on the gust variable by passing the target latitude and target longitude as arguments. The method also takes an argument ``'linear'`` which specifies the type of regridding method to use. The description of the ``regridded_data`` is finally printed to show properties of all its constructs:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "target_latitude = cf.DimensionCoordinate(\n data=cf.Data(np.linspace(34, 72, num=10), \"degrees_north\")\n)\ntarget_longitude = cf.DimensionCoordinate(\n data=cf.Data(np.linspace(-25, 45, num=10), \"degrees_east\")\n)\n\nlon_bounds = target_longitude.create_bounds()\nlat_bounds = target_latitude.create_bounds()\n\ntarget_longitude.set_bounds(lon_bounds)\ntarget_latitude.set_bounds(lat_bounds)\n\nregridded_data = gust.regrids((target_latitude, target_longitude), \"linear\")\nregridded_data.dump()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "9. Step 6 is similarly repeated for the ``regridded_data`` to plot the wind gust on a regular latitude-longitude domain:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "cfp.mapset(resolution=\"50m\")\ncfp.con(regridded_data.subspace(T=test), lines=False)" - ] - } - ], - "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.10" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/_downloads/plot_6_recipe.py b/docs/_downloads/plot_6_recipe.py deleted file mode 100644 index 4ca43fad6b..0000000000 --- a/docs/_downloads/plot_6_recipe.py +++ /dev/null @@ -1,70 +0,0 @@ -""" -Converting from rotated latitude-longitude to regular latitude-longitude -======================================================================== - -In this recipe, we will be regridding from a rotated latitude-longitude source domain to a regular latitude-longitude destination domain. -""" - -# %% -# 1. Import cf-python, cf-plot and numpy: - -import cfplot as cfp -import numpy as np - -import cf - -# %% -# 2. Read the field constructs using read function: - -f = cf.read("~/recipes/au952a.pd20510414.pp") -print(f) - -# %% -# 3. Select the field by index and print its description to show properties of all constructs: - -gust = f[0] -gust.dump() - -# %% -# 4. Access the time coordinate of the gust field and retrieve the datetime values of the time coordinate: - -print(gust.coordinate("time").datetime_array) - -# %% -# 5. Create a new instance of the `cf.dt` class with a specified year, month, day, hour, minute, second and microsecond. Then store the result in the variable ``test``: -test = cf.dt(2051, 4, 14, 1, 30, 0, 0) -print(test) - -# %% -# 6. Plot the wind gust by creating a subspace for the specified variable ``test`` using `cfplot.con `_. Here `cfplot.mapset `_ is used to set the mapping parameters like setting the map resolution to 50m: -cfp.mapset(resolution="50m") -cfp.con(gust.subspace(T=test), lines=False) - -# %% -# 7. To see the rotated pole data on the native grid, the above steps are repeated and projection is set to rotated in `cfplot.mapset `_: -cfp.mapset(resolution="50m", proj="rotated") -cfp.con(gust.subspace(T=test), lines=False) - -# %% -# 8. Create dimension coordinates for the destination grid with the latitude and longitude values for Europe. `np.linspace `_ generates evenly spaced values between the specified latitude and longitude range. Bounds of the target longitude and target latitude are created and spherical regridding is then performed on the gust variable by passing the target latitude and target longitude as arguments. The method also takes an argument ``'linear'`` which specifies the type of regridding method to use. The description of the ``regridded_data`` is finally printed to show properties of all its constructs: - -target_latitude = cf.DimensionCoordinate( - data=cf.Data(np.linspace(34, 72, num=10), "degrees_north") -) -target_longitude = cf.DimensionCoordinate( - data=cf.Data(np.linspace(-25, 45, num=10), "degrees_east") -) - -lon_bounds = target_longitude.create_bounds() -lat_bounds = target_latitude.create_bounds() - -target_longitude.set_bounds(lon_bounds) -target_latitude.set_bounds(lat_bounds) - -regridded_data = gust.regrids((target_latitude, target_longitude), "linear") -regridded_data.dump() - -# %% -# 9. Step 6 is similarly repeated for the ``regridded_data`` to plot the wind gust on a regular latitude-longitude domain: -cfp.mapset(resolution="50m") -cfp.con(regridded_data.subspace(T=test), lines=False) diff --git a/docs/_downloads/plot_7_recipe.ipynb b/docs/_downloads/plot_7_recipe.ipynb deleted file mode 100644 index 07d376286c..0000000000 --- a/docs/_downloads/plot_7_recipe.ipynb +++ /dev/null @@ -1,151 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Plotting members of a model ensemble\n\nIn this recipe, we will plot the members of a model ensemble.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "1. Import cf-python and cf-plot:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import cfplot as cfp\n\nimport cf" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "2. Read the field constructs using read function and store it in the variable ``f``. The * in the filename is a wildcard character which means the function reads all files in the directory that match the specified pattern. [0:5] selects the first five elements of the resulting list:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "f = cf.read(\"~/recipes/realization/PRMSL.1941_mem*.nc\")[0:5]\nprint(f)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "3. The description of one of the fields from the list shows ``'realization'`` as a property by which the members of the model ensemble are labelled:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "f[1].dump()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "4. An ensemble of the members is then created by aggregating the data in ``f`` along a new ``'realization'`` axis using the cf.aggregate function, and storing the result in the variable ``ensemble``. ``'relaxed_identities=True'`` allows for missing coordinate identities to be inferred. [0] selects the first element of the resulting list. ``id%realization`` now shows as an auxiliary coordinate for the ensemble:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "ensemble = cf.aggregate(\n f, dimension=(\"realization\",), relaxed_identities=True\n)[0]\nprint(ensemble)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "5. To see the constructs for the ensemble, print the *constructs* attribute:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "print(ensemble.constructs)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "6. Loop over the realizations in the ensemble using the *range* function and the *domain_axis* to determine the size of the realization dimension. For each realization, extract a subspace of the ensemble using the *subspace* method and the ``'id%realization'`` keyword argument along a specific latitude and longitude and plot the realizations from the 4D field using [cfplot.lineplot](http://ajheaps.github.io/cf-plot/lineplot.html).\nA moving average of the ensemble along the time axis, with a window size of 90 (i.e. an approximately 3-month moving average) is calculated using the *moving_window* method. The ``mode='nearest'`` parameter is used to specify how to pad the data outside of the time range. The *squeeze* method removes any dimensions of size 1 from the field to produce a 2D field:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "cfp.gopen()\n\nfor realization in range(1, ensemble.domain_axis(\"id%realization\").size + 1):\n cfp.lineplot(\n ensemble.subspace(\n **{\"id%realization\": realization}, latitude=[0], longitude=[0]\n ).squeeze(),\n label=f\"Member {realization}\",\n linewidth=1.0,\n )\n\ncfp.lineplot(\n ensemble.moving_window(\n method=\"mean\", window_size=90, axis=\"T\", mode=\"nearest\"\n )[0, :, 0, 0].squeeze(),\n label=\"Ensemble mean\",\n linewidth=2.0,\n color=\"black\",\n title=\"Model Ensemble Pressure\",\n)\n\ncfp.gclose()" - ] - } - ], - "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.10" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/_downloads/plot_7_recipe.py b/docs/_downloads/plot_7_recipe.py deleted file mode 100644 index 5bb5802190..0000000000 --- a/docs/_downloads/plot_7_recipe.py +++ /dev/null @@ -1,65 +0,0 @@ -""" -Plotting members of a model ensemble -==================================== - -In this recipe, we will plot the members of a model ensemble. -""" - -# %% -# 1. Import cf-python and cf-plot: - -import cfplot as cfp - -import cf - -# %% -# 2. Read the field constructs using read function and store it in the variable ``f``. The * in the filename is a wildcard character which means the function reads all files in the directory that match the specified pattern. [0:5] selects the first five elements of the resulting list: - -f = cf.read("~/recipes/realization/PRMSL.1941_mem*.nc")[0:5] -print(f) - -# %% -# 3. The description of one of the fields from the list shows ``'realization'`` as a property by which the members of the model ensemble are labelled: - -f[1].dump() - -# %% -# 4. An ensemble of the members is then created by aggregating the data in ``f`` along a new ``'realization'`` axis using the cf.aggregate function, and storing the result in the variable ``ensemble``. ``'relaxed_identities=True'`` allows for missing coordinate identities to be inferred. [0] selects the first element of the resulting list. ``id%realization`` now shows as an auxiliary coordinate for the ensemble: - -ensemble = cf.aggregate( - f, dimension=("realization",), relaxed_identities=True -)[0] -print(ensemble) - - -# %% -# 5. To see the constructs for the ensemble, print the *constructs* attribute: - -print(ensemble.constructs) - -# %% -# 6. Loop over the realizations in the ensemble using the *range* function and the *domain_axis* to determine the size of the realization dimension. For each realization, extract a subspace of the ensemble using the *subspace* method and the ``'id%realization'`` keyword argument along a specific latitude and longitude and plot the realizations from the 4D field using `cfplot.lineplot `_. -# A moving average of the ensemble along the time axis, with a window size of 90 (i.e. an approximately 3-month moving average) is calculated using the *moving_window* method. The ``mode='nearest'`` parameter is used to specify how to pad the data outside of the time range. The *squeeze* method removes any dimensions of size 1 from the field to produce a 2D field: - -cfp.gopen() - -for realization in range(1, ensemble.domain_axis("id%realization").size + 1): - cfp.lineplot( - ensemble.subspace( - **{"id%realization": realization}, latitude=[0], longitude=[0] - ).squeeze(), - label=f"Member {realization}", - linewidth=1.0, - ) - -cfp.lineplot( - ensemble.moving_window( - method="mean", window_size=90, axis="T", mode="nearest" - )[0, :, 0, 0].squeeze(), - label="Ensemble mean", - linewidth=2.0, - color="black", - title="Model Ensemble Pressure", -) - -cfp.gclose() diff --git a/docs/_downloads/plot_8_recipe.ipynb b/docs/_downloads/plot_8_recipe.ipynb deleted file mode 100644 index 7e37b71747..0000000000 --- a/docs/_downloads/plot_8_recipe.ipynb +++ /dev/null @@ -1,212 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Plotting statistically significant temperature trends with stippling\n\nIn this recipe, we will analyse and plot temperature trends from the HadCRUT.5.0.1.0 dataset for two different time periods. The plotted maps also include stippling, which is used to highlight areas where the temperature trends are statistically significant.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "1. Import cf-python, cf-plot, numpy and scipy.stats:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import cfplot as cfp\nimport numpy as np\nimport scipy.stats as stats\n\nimport cf" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "2. Three functions are defined:\n\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* ``linear_trend(data, time_axis)``: This function calculates the linear regression slope and p-value for the input data along the time axis. It takes two arguments: ``'data'``, which represents the temperature anomalies or any other data you want to analyse, and ``'time_axis'``, which represents the corresponding time points for the data. The function uses the [stats.linregress](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.linregress.html) method from the [scipy.stats](https://docs.scipy.org/doc/scipy/reference/stats.html) library to calculate the slope and p-value of the linear regression. It returns these two values as a tuple:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "def linear_trend(data, time_axis):\n slope, _, _, p_value, _ = stats.linregress(time_axis, data)\n return slope, p_value" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* ``create_trend_stipple_obj(temp_data, input_data)``: This function creates a new object with the input data provided and *collapses* the time dimension by taking the mean. It takes two arguments: ``'temp_data'``, which represents the temperature data object, and ``'input_data'``, which is the data to be set in the new object. The function creates a copy of the ``'temp_data'`` object by selecting the first element using index and *squeezes* it to remove the size 1 axis. It then sets the input data with the ``'Y'`` (latitude) and ``'X'`` (longitude) axes, and then *collapses* the time dimension using the ``\"T: mean\"`` operation:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "def create_trend_stipple_obj(temp_data, input_data):\n trend_stipple_obj = temp_data[0].squeeze()\n trend_stipple_obj.set_data(input_data, axes=[\"Y\", \"X\"])\n return trend_stipple_obj" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* ``process_subsets(subset_mask)``: This function processes the subsets of data by applying the ``linear_trend`` function along a specified axis. It takes one argument, ``'subset_mask'``, which is a boolean mask representing the time points to be considered in the analysis. The function first extracts the masked subset of data and then applies the ``linear_trend`` function along the time axis (axis 0) using the [numpy.ma.apply_along_axis](https://numpy.org/doc/stable/reference/generated/numpy.ma.apply_along_axis.html) function. The result is an array containing the slope and p-value for each grid point in the dataset:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "def process_subsets(subset_mask):\n subset_data = masked_data[subset_mask, :, :]\n return np.ma.apply_along_axis(\n linear_trend, 0, subset_data, time_axis[subset_mask]\n )" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "3. Read the field constructs:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "temperature_data = cf.read(\n \"~/recipes/HadCRUT.5.0.1.0.analysis.anomalies.ensemble_mean.nc\"\n)[0]\nprint(temperature_data)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "4. Calculate the annual mean temperature anomalies. The ``'weights=True'`` argument is used take the varying lengths of months into account which ensures that the calculated mean is more accurate. A masked array is created for the annual mean temperature anomalies, masking any invalid values:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "annual_temperature = temperature_data.collapse(\n \"T: mean\", weights=True, group=cf.Y()\n)\ntime_axis = annual_temperature.coordinate(\"T\").year.array\nmasked_data = np.ma.masked_invalid(annual_temperature.array)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "5. Define two time periods for analysis: 1850-2020 and 1980-2020, along with a significance level (alpha) of 0.05:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "time_periods = [(1850, 2020, \"sub_1850_2020\"), (1980, 2020, \"sub_1980_2020\")]\nalpha = 0.05\nresults = {}" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "6. Loop through the time periods, processing the subsets, calculating trend p-values, and creating stipple objects. For each time period, the script calculates the trends and p-values using the ``process_subsets`` function. If the p-value is less than the significance level (alpha = 0.05), a stippling mask is created. The script then creates a new object for the trend and stippling mask using the ``create_trend_stipple_obj`` function:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "for start, end, prefix in time_periods:\n subset_mask = (time_axis >= start) & (time_axis <= end)\n subset_trend_pvalue = process_subsets(subset_mask)\n results[prefix + \"_trend_pvalue\"] = subset_trend_pvalue\n results[prefix + \"_stipple\"] = subset_trend_pvalue[1] < alpha\n results[prefix + \"_trend\"] = create_trend_stipple_obj(\n temperature_data, subset_trend_pvalue[0]\n )\n results[prefix + \"_stipple_obj\"] = create_trend_stipple_obj(\n temperature_data, results[prefix + \"_stipple\"]\n )" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "7. Create two plots - one for the 1850-2020 time period and another for the 1980-2020 time period using [cfplot.con](http://ajheaps.github.io/cf-plot/con.html).\nThe results are multiplied by 10 so that each plot displays the temperature trend in K/decade with stippling to indicate areas where the trend is statistically significant (p-value < 0.05).\nHere [cfplot.gopen](http://ajheaps.github.io/cf-plot/gopen.html) is used to define the parts of the plot area with two rows and one column, and setting the bottom margin to 0.2.\nIt is closed by [cfplot.gclose](http://ajheaps.github.io/cf-plot/gclose.html);\n[cfplot.gpos](http://ajheaps.github.io/cf-plot/gpos.html) is used to set the plotting position of both the plots;\n[cfplot.mapset](http://ajheaps.github.io/cf-plot/mapset.html) is used to set the map projection to Robinson;\n[cfplot.cscale](http://ajheaps.github.io/cf-plot/cscale.html) is used to choose one of the colour maps amongst many available;\n[cfplot.levs](http://ajheaps.github.io/cf-plot/levs.html) is used to set the contour levels;\nand [cfplot.stipple](http://ajheaps.github.io/cf-plot/stipple.html) is used to add stippling to show statistically significant areas:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "cfp.gopen(rows=2, columns=1, bottom=0.2)\n\ncfp.gpos(1)\ncfp.mapset(proj=\"robin\")\ncfp.cscale(\"temp_19lev\")\ncfp.levs(min=-1, max=1, step=0.1)\ncfp.con(\n results[\"sub_1850_2020_trend\"] * 10,\n lines=False,\n colorbar=None,\n title=\"Temperature Trend 1850-2020\",\n)\ncfp.stipple(\n results[\"sub_1850_2020_stipple_obj\"],\n min=1,\n max=1,\n size=5,\n color=\"k\",\n marker=\".\",\n)\n\ncfp.gpos(2)\ncfp.mapset(proj=\"robin\")\ncfp.cscale(\"temp_19lev\")\ncfp.levs(min=-1, max=1, step=0.1)\ncfp.con(\n results[\"sub_1980_2020_trend\"] * 10,\n lines=False,\n title=\"Temperature Trend 1980-2020\",\n colorbar_position=[0.1, 0.1, 0.8, 0.02],\n colorbar_orientation=\"horizontal\",\n colorbar_title=\"K/decade\",\n)\ncfp.stipple(\n results[\"sub_1980_2020_stipple_obj\"],\n min=1,\n max=1,\n size=5,\n color=\"k\",\n marker=\".\",\n)\n\ncfp.gclose()" - ] - } - ], - "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.10" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/_downloads/plot_8_recipe.py b/docs/_downloads/plot_8_recipe.py deleted file mode 100644 index 010707e14a..0000000000 --- a/docs/_downloads/plot_8_recipe.py +++ /dev/null @@ -1,142 +0,0 @@ -""" -Plotting statistically significant temperature trends with stippling -==================================================================== - -In this recipe, we will analyse and plot temperature trends from the HadCRUT.5.0.1.0 dataset for two different time periods. The plotted maps also include stippling, which is used to highlight areas where the temperature trends are statistically significant. -""" - -# %% -# 1. Import cf-python, cf-plot, numpy and scipy.stats: - -import cfplot as cfp -import numpy as np -import scipy.stats as stats - -import cf - -# %% -# 2. Three functions are defined: - -# %% -# * ``linear_trend(data, time_axis)``: This function calculates the linear regression slope and p-value for the input data along the time axis. It takes two arguments: ``'data'``, which represents the temperature anomalies or any other data you want to analyse, and ``'time_axis'``, which represents the corresponding time points for the data. The function uses the `stats.linregress `_ method from the `scipy.stats `_ library to calculate the slope and p-value of the linear regression. It returns these two values as a tuple: - - -def linear_trend(data, time_axis): - slope, _, _, p_value, _ = stats.linregress(time_axis, data) - return slope, p_value - - -# %% -# * ``create_trend_stipple_obj(temp_data, input_data)``: This function creates a new object with the input data provided and *collapses* the time dimension by taking the mean. It takes two arguments: ``'temp_data'``, which represents the temperature data object, and ``'input_data'``, which is the data to be set in the new object. The function creates a copy of the ``'temp_data'`` object by selecting the first element using index and *squeezes* it to remove the size 1 axis. It then sets the input data with the ``'Y'`` (latitude) and ``'X'`` (longitude) axes, and then *collapses* the time dimension using the ``"T: mean"`` operation: - - -def create_trend_stipple_obj(temp_data, input_data): - trend_stipple_obj = temp_data[0].squeeze() - trend_stipple_obj.set_data(input_data, axes=["Y", "X"]) - return trend_stipple_obj - - -# %% -# * ``process_subsets(subset_mask)``: This function processes the subsets of data by applying the ``linear_trend`` function along a specified axis. It takes one argument, ``'subset_mask'``, which is a boolean mask representing the time points to be considered in the analysis. The function first extracts the masked subset of data and then applies the ``linear_trend`` function along the time axis (axis 0) using the `numpy.ma.apply_along_axis `_ function. The result is an array containing the slope and p-value for each grid point in the dataset: - - -def process_subsets(subset_mask): - subset_data = masked_data[subset_mask, :, :] - return np.ma.apply_along_axis( - linear_trend, 0, subset_data, time_axis[subset_mask] - ) - - -# %% -# 3. Read the field constructs: - -temperature_data = cf.read( - "~/recipes/HadCRUT.5.0.1.0.analysis.anomalies.ensemble_mean.nc" -)[0] -print(temperature_data) - -# %% -# 4. Calculate the annual mean temperature anomalies. The ``'weights=True'`` argument is used take the varying lengths of months into account which ensures that the calculated mean is more accurate. A masked array is created for the annual mean temperature anomalies, masking any invalid values: - -annual_temperature = temperature_data.collapse( - "T: mean", weights=True, group=cf.Y() -) -time_axis = annual_temperature.coordinate("T").year.array -masked_data = np.ma.masked_invalid(annual_temperature.array) - -# %% -# 5. Define two time periods for analysis: 1850-2020 and 1980-2020, along with a significance level (alpha) of 0.05: - -time_periods = [(1850, 2020, "sub_1850_2020"), (1980, 2020, "sub_1980_2020")] -alpha = 0.05 -results = {} - -# %% -# 6. Loop through the time periods, processing the subsets, calculating trend p-values, and creating stipple objects. For each time period, the script calculates the trends and p-values using the ``process_subsets`` function. If the p-value is less than the significance level (alpha = 0.05), a stippling mask is created. The script then creates a new object for the trend and stippling mask using the ``create_trend_stipple_obj`` function: - -for start, end, prefix in time_periods: - subset_mask = (time_axis >= start) & (time_axis <= end) - subset_trend_pvalue = process_subsets(subset_mask) - results[prefix + "_trend_pvalue"] = subset_trend_pvalue - results[prefix + "_stipple"] = subset_trend_pvalue[1] < alpha - results[prefix + "_trend"] = create_trend_stipple_obj( - temperature_data, subset_trend_pvalue[0] - ) - results[prefix + "_stipple_obj"] = create_trend_stipple_obj( - temperature_data, results[prefix + "_stipple"] - ) - -# %% -# 7. Create two plots - one for the 1850-2020 time period and another for the 1980-2020 time period using `cfplot.con `_. -# The results are multiplied by 10 so that each plot displays the temperature trend in K/decade with stippling to indicate areas where the trend is statistically significant (p-value < 0.05). -# Here `cfplot.gopen `_ is used to define the parts of the plot area with two rows and one column, and setting the bottom margin to 0.2. -# It is closed by `cfplot.gclose `_; -# `cfplot.gpos `_ is used to set the plotting position of both the plots; -# `cfplot.mapset `_ is used to set the map projection to Robinson; -# `cfplot.cscale `_ is used to choose one of the colour maps amongst many available; -# `cfplot.levs `_ is used to set the contour levels; -# and `cfplot.stipple `_ is used to add stippling to show statistically significant areas: - -cfp.gopen(rows=2, columns=1, bottom=0.2) - -cfp.gpos(1) -cfp.mapset(proj="robin") -cfp.cscale("temp_19lev") -cfp.levs(min=-1, max=1, step=0.1) -cfp.con( - results["sub_1850_2020_trend"] * 10, - lines=False, - colorbar=None, - title="Temperature Trend 1850-2020", -) -cfp.stipple( - results["sub_1850_2020_stipple_obj"], - min=1, - max=1, - size=5, - color="k", - marker=".", -) - -cfp.gpos(2) -cfp.mapset(proj="robin") -cfp.cscale("temp_19lev") -cfp.levs(min=-1, max=1, step=0.1) -cfp.con( - results["sub_1980_2020_trend"] * 10, - lines=False, - title="Temperature Trend 1980-2020", - colorbar_position=[0.1, 0.1, 0.8, 0.02], - colorbar_orientation="horizontal", - colorbar_title="K/decade", -) -cfp.stipple( - results["sub_1980_2020_stipple_obj"], - min=1, - max=1, - size=5, - color="k", - marker=".", -) - -cfp.gclose() diff --git a/docs/_downloads/plot_9_recipe.ipynb b/docs/_downloads/plot_9_recipe.ipynb deleted file mode 100644 index a2cc7084bc..0000000000 --- a/docs/_downloads/plot_9_recipe.ipynb +++ /dev/null @@ -1,234 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Plotting a joint histogram\n\nIn this recipe, we will be creating a joint histogram of PM2.5 mass \nconcentration and 2-metre temperature.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "1. Import cf-python, numpy and matplotlib.pyplot:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import matplotlib.pyplot as plt\nimport numpy as np\n\nimport cf" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "2. Read the field constructs using read function:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "f = cf.read(\"~/recipes/levtype_sfc.nc\")\nprint(f)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "3. Select the PM2.5 mass concentration and 2-metre temperature fields by\nindex and print the description to show properties of all constructs:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pm25_field = f[2]\npm25_field.dump()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "temp_field = f[3]\ntemp_field.dump()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "4. Convert the units to degree celsius for the temperature field:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "temp_field.units = \"degC\"\ntemp_field.get_property(\"units\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "5. Digitize the PM2.5 mass concentration and 2-metre temperature fields.\nThis step counts the number of values in each of the 10 equally sized bins\nspanning the range of the values. The ``'return_bins=True'`` argument makes \nsure that the calculated bins are also returned:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pm25_indices, pm25_bins = pm25_field.digitize(10, return_bins=True)\ntemp_indices, temp_bins = temp_field.digitize(10, return_bins=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "6. Create a joint histogram of the digitized fields:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "joint_histogram = cf.histogram(pm25_indices, temp_indices)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "7. Get histogram data from the ``joint_histogram``:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "histogram_data = joint_histogram.array" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "8. Calculate bin centers for PM2.5 and temperature bins:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pm25_bin_centers = [(a + b) / 2 for a, b in pm25_bins]\ntemp_bin_centers = [(a + b) / 2 for a, b in temp_bins]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "9. Create grids for PM2.5 and temperature bins using [numpy.meshgrid](https://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html):\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "temp_grid, pm25_grid = np.meshgrid(temp_bin_centers, pm25_bin_centers)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "10. Plot the joint histogram using [matplotlib.pyplot.pcolormesh](https://matplotlib.org/stable/api/_as_gen/\nmatplotlib.pyplot.pcolormesh.html). Use [cf.Field.unique](https://ncas-cms.github.io/cf-python/method/cf.Field.unique.html) to get\nthe unique data array values and show the bin boundaries as ticks on the\nplot. ``'style='plain'`` in [matplotlib.axes.Axes.ticklabel_format](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.ticklabel_format.html) \ndisables the scientific notation on the y-axis:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "plt.pcolormesh(temp_grid, pm25_grid, histogram_data, cmap=\"viridis\")\nplt.xlabel(\"2-metre Temperature (degC)\")\nplt.ylabel(\"PM2.5 Mass Concentration (kg m**-3)\")\nplt.xticks(temp_bins.unique().array, rotation=45)\nplt.yticks(pm25_bins.unique().array)\nplt.colorbar(label=\"Frequency\")\nplt.title(\"Joint Histogram of PM2.5 and 2-metre Temperature\", y=1.05)\nplt.ticklabel_format(style=\"plain\")\nplt.show()" - ] - } - ], - "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.9" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/_downloads/plot_9_recipe.py b/docs/_downloads/plot_9_recipe.py deleted file mode 100644 index 2bb7e57b43..0000000000 --- a/docs/_downloads/plot_9_recipe.py +++ /dev/null @@ -1,82 +0,0 @@ -""" -Plotting a joint histogram -========================== - -In this recipe, we will be creating a joint histogram of PM2.5 mass -concentration and 2-metre temperature. -""" - -# %% -# 1. Import cf-python, numpy and matplotlib.pyplot: - -import matplotlib.pyplot as plt -import numpy as np - -import cf - -# %% -# 2. Read the field constructs using read function: -f = cf.read("~/recipes/levtype_sfc.nc") -print(f) - -# %% -# 3. Select the PM2.5 mass concentration and 2-metre temperature fields by -# index and print the description to show properties of all constructs: -pm25_field = f[2] -pm25_field.dump() - -# %% - -temp_field = f[3] -temp_field.dump() - -# %% -# 4. Convert the units to degree celsius for the temperature field: -temp_field.units = "degC" -temp_field.get_property("units") - -# %% -# 5. Digitize the PM2.5 mass concentration and 2-metre temperature fields. -# This step counts the number of values in each of the 10 equally sized bins -# spanning the range of the values. The ``'return_bins=True'`` argument makes -# sure that the calculated bins are also returned: -pm25_indices, pm25_bins = pm25_field.digitize(10, return_bins=True) -temp_indices, temp_bins = temp_field.digitize(10, return_bins=True) - -# %% -# 6. Create a joint histogram of the digitized fields: -joint_histogram = cf.histogram(pm25_indices, temp_indices) - -# %% -# 7. Get histogram data from the ``joint_histogram``: -histogram_data = joint_histogram.array - -# %% -# 8. Calculate bin centers for PM2.5 and temperature bins: -pm25_bin_centers = [(a + b) / 2 for a, b in pm25_bins] -temp_bin_centers = [(a + b) / 2 for a, b in temp_bins] - - -# %% -# 9. Create grids for PM2.5 and temperature bins using `numpy.meshgrid -# `_: -temp_grid, pm25_grid = np.meshgrid(temp_bin_centers, pm25_bin_centers) - -# %% -# 10. Plot the joint histogram using `matplotlib.pyplot.pcolormesh -# `_. Use `cf.Field.unique -# `_ to get -# the unique data array values and show the bin boundaries as ticks on the -# plot. ``'style='plain'`` in `matplotlib.axes.Axes.ticklabel_format -# `_ -# disables the scientific notation on the y-axis: -plt.pcolormesh(temp_grid, pm25_grid, histogram_data, cmap="viridis") -plt.xlabel("2-metre Temperature (degC)") -plt.ylabel("PM2.5 Mass Concentration (kg m**-3)") -plt.xticks(temp_bins.unique().array, rotation=45) -plt.yticks(pm25_bins.unique().array) -plt.colorbar(label="Frequency") -plt.title("Joint Histogram of PM2.5 and 2-metre Temperature", y=1.05) -plt.ticklabel_format(style="plain") -plt.show() diff --git a/docs/_images/sphx_glr_plot_1_recipe_001.png b/docs/_images/sphx_glr_plot_1_recipe_001.png deleted file mode 100644 index 6e9c93290d..0000000000 Binary files a/docs/_images/sphx_glr_plot_1_recipe_001.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_1_recipe_002.png b/docs/_images/sphx_glr_plot_1_recipe_002.png deleted file mode 100644 index 1e9102fcb5..0000000000 Binary files a/docs/_images/sphx_glr_plot_1_recipe_002.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_1_recipe_thumb.png b/docs/_images/sphx_glr_plot_1_recipe_thumb.png deleted file mode 100644 index 1e8b4a672a..0000000000 Binary files a/docs/_images/sphx_glr_plot_1_recipe_thumb.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_1_recipe_thumb1.png b/docs/_images/sphx_glr_plot_1_recipe_thumb1.png deleted file mode 100644 index 1e8b4a672a..0000000000 Binary files a/docs/_images/sphx_glr_plot_1_recipe_thumb1.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_2_recipe_001.png b/docs/_images/sphx_glr_plot_2_recipe_001.png deleted file mode 100644 index bff4e3fe38..0000000000 Binary files a/docs/_images/sphx_glr_plot_2_recipe_001.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_2_recipe_thumb.png b/docs/_images/sphx_glr_plot_2_recipe_thumb.png deleted file mode 100644 index c640c77abb..0000000000 Binary files a/docs/_images/sphx_glr_plot_2_recipe_thumb.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_2_recipe_thumb1.png b/docs/_images/sphx_glr_plot_2_recipe_thumb1.png deleted file mode 100644 index c640c77abb..0000000000 Binary files a/docs/_images/sphx_glr_plot_2_recipe_thumb1.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_3_recipe_001.png b/docs/_images/sphx_glr_plot_3_recipe_001.png deleted file mode 100644 index d079b2b2d6..0000000000 Binary files a/docs/_images/sphx_glr_plot_3_recipe_001.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_3_recipe_thumb.png b/docs/_images/sphx_glr_plot_3_recipe_thumb.png deleted file mode 100644 index 225dceb82f..0000000000 Binary files a/docs/_images/sphx_glr_plot_3_recipe_thumb.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_3_recipe_thumb1.png b/docs/_images/sphx_glr_plot_3_recipe_thumb1.png deleted file mode 100644 index 3e7d3a6f70..0000000000 Binary files a/docs/_images/sphx_glr_plot_3_recipe_thumb1.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_4_recipe_thumb.png b/docs/_images/sphx_glr_plot_4_recipe_thumb.png deleted file mode 100644 index 8a5fed589d..0000000000 Binary files a/docs/_images/sphx_glr_plot_4_recipe_thumb.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_4_recipe_thumb1.png b/docs/_images/sphx_glr_plot_4_recipe_thumb1.png deleted file mode 100644 index 8a5fed589d..0000000000 Binary files a/docs/_images/sphx_glr_plot_4_recipe_thumb1.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_5_recipe_001.png b/docs/_images/sphx_glr_plot_5_recipe_001.png deleted file mode 100644 index de25d6ddd5..0000000000 Binary files a/docs/_images/sphx_glr_plot_5_recipe_001.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_5_recipe_thumb.png b/docs/_images/sphx_glr_plot_5_recipe_thumb.png deleted file mode 100644 index 245eb949e6..0000000000 Binary files a/docs/_images/sphx_glr_plot_5_recipe_thumb.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_5_recipe_thumb1.png b/docs/_images/sphx_glr_plot_5_recipe_thumb1.png deleted file mode 100644 index 9501e8d140..0000000000 Binary files a/docs/_images/sphx_glr_plot_5_recipe_thumb1.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_6_recipe_001.png b/docs/_images/sphx_glr_plot_6_recipe_001.png deleted file mode 100644 index c7a826937f..0000000000 Binary files a/docs/_images/sphx_glr_plot_6_recipe_001.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_6_recipe_002.png b/docs/_images/sphx_glr_plot_6_recipe_002.png deleted file mode 100644 index a0ed9d71ed..0000000000 Binary files a/docs/_images/sphx_glr_plot_6_recipe_002.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_6_recipe_003.png b/docs/_images/sphx_glr_plot_6_recipe_003.png deleted file mode 100644 index 9a4e6a0afc..0000000000 Binary files a/docs/_images/sphx_glr_plot_6_recipe_003.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_6_recipe_thumb.png b/docs/_images/sphx_glr_plot_6_recipe_thumb.png deleted file mode 100644 index d1c090cdb7..0000000000 Binary files a/docs/_images/sphx_glr_plot_6_recipe_thumb.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_8_recipe_001.png b/docs/_images/sphx_glr_plot_8_recipe_001.png deleted file mode 100644 index eb13dcf636..0000000000 Binary files a/docs/_images/sphx_glr_plot_8_recipe_001.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_8_recipe_thumb.png b/docs/_images/sphx_glr_plot_8_recipe_thumb.png deleted file mode 100644 index ad2f9a4321..0000000000 Binary files a/docs/_images/sphx_glr_plot_8_recipe_thumb.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_9_recipe_001.png b/docs/_images/sphx_glr_plot_9_recipe_001.png deleted file mode 100644 index 2330660991..0000000000 Binary files a/docs/_images/sphx_glr_plot_9_recipe_001.png and /dev/null differ diff --git a/docs/_images/sphx_glr_plot_9_recipe_thumb.png b/docs/_images/sphx_glr_plot_9_recipe_thumb.png deleted file mode 100644 index 08777ffcb3..0000000000 Binary files a/docs/_images/sphx_glr_plot_9_recipe_thumb.png and /dev/null differ diff --git a/docs/recipes/plot_1_recipe.html b/docs/recipes/plot_1_recipe.html deleted file mode 100644 index b809f24905..0000000000 --- a/docs/recipes/plot_1_recipe.html +++ /dev/null @@ -1,334 +0,0 @@ - - - - - - - - Calculating global mean temperature timeseries — Documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
- - -
- - -
-

Calculating global mean temperature timeseriesΒΆ

-

In this recipe we will calculate and plot monthly and annual global mean temperature timeseries.

-
    -
  1. Import cf-python and cf-plot:

  2. -
-
import cfplot as cfp
-
-import cf
-
-
-
    -
  1. Read the field constructs:

  2. -
-
f = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc")
-print(f)
-
-
-
[<CF Field: ncvar%stn(long_name=time(1452), long_name=latitude(360), long_name=longitude(720))>,
- <CF Field: long_name=near-surface temperature(long_name=time(1452), long_name=latitude(360), long_name=longitude(720)) degrees Celsius>]
-
-
-
    -
  1. Select near surface temperature by index and look at its contents:

  2. -
-
temp = f[1]
-print(temp)
-
-
-
Field: long_name=near-surface temperature (ncvar%tmp)
------------------------------------------------------
-Data            : long_name=near-surface temperature(long_name=time(1452), long_name=latitude(360), long_name=longitude(720)) degrees Celsius
-Dimension coords: long_name=time(1452) = [1901-01-16 00:00:00, ..., 2021-12-16 00:00:00] gregorian
-                : long_name=latitude(360) = [-89.75, ..., 89.75] degrees_north
-                : long_name=longitude(720) = [-179.75, ..., 179.75] degrees_east
-
-
-
    -
  1. Select latitude and longitude dimensions by identities, with two different techniques:

  2. -
-
lon = temp.coordinate("long_name=longitude")
-lat = temp.coordinate("Y")
-
-
-
    -
  1. Print the description of near surface temperature using the dump method to show properties of all constructs:

  2. -
-
-
-
-----------------------------------------------------
-Field: long_name=near-surface temperature (ncvar%tmp)
------------------------------------------------------
-Conventions = 'CF-1.4'
-_FillValue = 9.96921e+36
-comment = 'Access to these data is available to any registered CEDA user.'
-contact = 'support@ceda.ac.uk'
-correlation_decay_distance = 1200.0
-history = 'Fri 29 Apr 14:35:01 BST 2022 : User f098 : Program makegridsauto.for
-           called by update.for'
-institution = 'Data held at British Atmospheric Data Centre, RAL, UK.'
-long_name = 'near-surface temperature'
-missing_value = 9.96921e+36
-references = 'Information on the data is available at
-              http://badc.nerc.ac.uk/data/cru/'
-source = 'Run ID = 2204291347. Data generated from:tmp.2204291209.dtb'
-title = 'CRU TS4.06 Mean Temperature'
-units = 'degrees Celsius'
-
-Data(long_name=time(1452), long_name=latitude(360), long_name=longitude(720)) = [[[--, ..., --]]] degrees Celsius
-
-Domain Axis: long_name=latitude(360)
-Domain Axis: long_name=longitude(720)
-Domain Axis: long_name=time(1452)
-
-Dimension coordinate: long_name=time
-    calendar = 'gregorian'
-    long_name = 'time'
-    units = 'days since 1900-1-1'
-    Data(long_name=time(1452)) = [1901-01-16 00:00:00, ..., 2021-12-16 00:00:00] gregorian
-
-Dimension coordinate: long_name=latitude
-    long_name = 'latitude'
-    units = 'degrees_north'
-    Data(long_name=latitude(360)) = [-89.75, ..., 89.75] degrees_north
-
-Dimension coordinate: long_name=longitude
-    long_name = 'longitude'
-    units = 'degrees_east'
-    Data(long_name=longitude(720)) = [-179.75, ..., 179.75] degrees_east
-
-
-
    -
  1. Latitude and longitude dimension coordinate cell bounds are absent, which are created and set:

  2. -
- -
Dimension coordinate: long_name=latitude
-    long_name = 'latitude'
-    units = 'degrees_north'
-    Data(360) = [-89.75, ..., 89.75] degrees_north
-    Bounds:units = 'degrees_north'
-    Bounds:Data(360, 2) = [[-90.0, ..., 90.0]] degrees_north
-
-
- -
Dimension coordinate: long_name=longitude
-    long_name = 'longitude'
-    units = 'degrees_east'
-    Data(720) = [-179.75, ..., 179.75] degrees_east
-    Bounds:units = 'degrees_east'
-    Bounds:Data(720, 2) = [[-180.0, ..., 180.0]] degrees_east
-
-
-
print(b.array)
-
-
-
[[-180.  -179.5]
- [-179.5 -179. ]
- [-179.  -178.5]
- ...
- [ 178.5  179. ]
- [ 179.   179.5]
- [ 179.5  180. ]]
-
-
-
    -
  1. Time dimension coordinate cell bounds are similarly created and set for cell sizes of one calendar month:

  2. -
-
time = temp.coordinate("long_name=time")
-c = time.create_bounds(cellsize=cf.M())
-time.set_bounds(c)
-time.dump()
-
-
-
Dimension coordinate: long_name=time
-    calendar = 'gregorian'
-    long_name = 'time'
-    units = 'days since 1900-1-1'
-    Data(1452) = [1901-01-16 00:00:00, ..., 2021-12-16 00:00:00] gregorian
-    Bounds:calendar = 'gregorian'
-    Bounds:units = 'days since 1900-1-1'
-    Bounds:Data(1452, 2) = [[1901-01-01 00:00:00, ..., 2022-01-01 00:00:00]] gregorian
-
-
-
    -
  1. Calculate and plot the area weighted mean surface temperature for each time:

  2. -
-
global_avg = temp.collapse("area: mean", weights=True)
-cfp.lineplot(global_avg, color="red", title="Global mean surface temperature")
-
-
-Global mean surface temperature
    -
  1. Calculate and plot the annual global mean surface temperature:

  2. -
-
annual_global_avg = global_avg.collapse("T: mean", group=cf.Y())
-cfp.lineplot(
-    annual_global_avg,
-    color="red",
-    title="Annual global mean surface temperature",
-)
-
-
-Annual global mean surface temperature

Total running time of the script: ( 2 minutes 54.799 seconds)

- -

Gallery generated by Sphinx-Gallery

-
- - -
- -
-
-
-
- - - - - - - \ No newline at end of file diff --git a/docs/recipes/plot_2_recipe.html b/docs/recipes/plot_2_recipe.html deleted file mode 100644 index 0bb78b6e4f..0000000000 --- a/docs/recipes/plot_2_recipe.html +++ /dev/null @@ -1,372 +0,0 @@ - - - - - - - - Calculating and plotting the global average temperature anomalies — Documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
- - -
- - -
-

Calculating and plotting the global average temperature anomaliesΒΆ

-

In this recipe we will calculate and plot the global average temperature anomalies.

-
    -
  1. Import cf-python and cf-plot:

  2. -
-
import cfplot as cfp
-
-import cf
-
-
-
    -
  1. Read the field constructs:

  2. -
-
f = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc")
-print(f)
-
-
-
[<CF Field: ncvar%stn(long_name=time(1452), long_name=latitude(360), long_name=longitude(720))>,
- <CF Field: long_name=near-surface temperature(long_name=time(1452), long_name=latitude(360), long_name=longitude(720)) degrees Celsius>]
-
-
-
    -
  1. Select near surface temperature by index and look at its contents:

  2. -
-
temp = f[1]
-print(temp)
-
-
-
Field: long_name=near-surface temperature (ncvar%tmp)
------------------------------------------------------
-Data            : long_name=near-surface temperature(long_name=time(1452), long_name=latitude(360), long_name=longitude(720)) degrees Celsius
-Dimension coords: long_name=time(1452) = [1901-01-16 00:00:00, ..., 2021-12-16 00:00:00] gregorian
-                : long_name=latitude(360) = [-89.75, ..., 89.75] degrees_north
-                : long_name=longitude(720) = [-179.75, ..., 179.75] degrees_east
-
-
-
    -
  1. Select latitude and longitude dimensions by identities, with two different techniques:

  2. -
-
lon = temp.coordinate("long_name=longitude")
-lat = temp.coordinate("Y")
-
-
-
    -
  1. Print the description of near surface temperature to show properties of all constructs:

  2. -
-
-
-
-----------------------------------------------------
-Field: long_name=near-surface temperature (ncvar%tmp)
------------------------------------------------------
-Conventions = 'CF-1.4'
-_FillValue = 9.96921e+36
-comment = 'Access to these data is available to any registered CEDA user.'
-contact = 'support@ceda.ac.uk'
-correlation_decay_distance = 1200.0
-history = 'Fri 29 Apr 14:35:01 BST 2022 : User f098 : Program makegridsauto.for
-           called by update.for'
-institution = 'Data held at British Atmospheric Data Centre, RAL, UK.'
-long_name = 'near-surface temperature'
-missing_value = 9.96921e+36
-references = 'Information on the data is available at
-              http://badc.nerc.ac.uk/data/cru/'
-source = 'Run ID = 2204291347. Data generated from:tmp.2204291209.dtb'
-title = 'CRU TS4.06 Mean Temperature'
-units = 'degrees Celsius'
-
-Data(long_name=time(1452), long_name=latitude(360), long_name=longitude(720)) = [[[--, ..., --]]] degrees Celsius
-
-Domain Axis: long_name=latitude(360)
-Domain Axis: long_name=longitude(720)
-Domain Axis: long_name=time(1452)
-
-Dimension coordinate: long_name=time
-    calendar = 'gregorian'
-    long_name = 'time'
-    units = 'days since 1900-1-1'
-    Data(long_name=time(1452)) = [1901-01-16 00:00:00, ..., 2021-12-16 00:00:00] gregorian
-
-Dimension coordinate: long_name=latitude
-    long_name = 'latitude'
-    units = 'degrees_north'
-    Data(long_name=latitude(360)) = [-89.75, ..., 89.75] degrees_north
-
-Dimension coordinate: long_name=longitude
-    long_name = 'longitude'
-    units = 'degrees_east'
-    Data(long_name=longitude(720)) = [-179.75, ..., 179.75] degrees_east
-
-
-
    -
  1. Latitude and longitude dimension coordinate cell bounds are absent, which are created and set:

  2. -
- -
Dimension coordinate: long_name=latitude
-    long_name = 'latitude'
-    units = 'degrees_north'
-    Data(360) = [-89.75, ..., 89.75] degrees_north
-    Bounds:units = 'degrees_north'
-    Bounds:Data(360, 2) = [[-90.0, ..., 90.0]] degrees_north
-
-
- -
Dimension coordinate: long_name=longitude
-    long_name = 'longitude'
-    units = 'degrees_east'
-    Data(720) = [-179.75, ..., 179.75] degrees_east
-    Bounds:units = 'degrees_east'
-    Bounds:Data(720, 2) = [[-180.0, ..., 180.0]] degrees_east
-
-
-
print(b.array)
-
-
-
[[-180.  -179.5]
- [-179.5 -179. ]
- [-179.  -178.5]
- ...
- [ 178.5  179. ]
- [ 179.   179.5]
- [ 179.5  180. ]]
-
-
-
    -
  1. Time dimension coordinate cell bounds are similarly created and set for cell sizes of one calendar month:

  2. -
-
time = temp.coordinate("long_name=time")
-c = time.create_bounds(cellsize=cf.M())
-time.set_bounds(c)
-time.dump()
-
-
-
Dimension coordinate: long_name=time
-    calendar = 'gregorian'
-    long_name = 'time'
-    units = 'days since 1900-1-1'
-    Data(1452) = [1901-01-16 00:00:00, ..., 2021-12-16 00:00:00] gregorian
-    Bounds:calendar = 'gregorian'
-    Bounds:units = 'days since 1900-1-1'
-    Bounds:Data(1452, 2) = [[1901-01-01 00:00:00, ..., 2022-01-01 00:00:00]] gregorian
-
-
-
    -
  1. Calculate the area weighted mean surface temperature for each time using the collapse method:

  2. -
-
global_avg = temp.collapse("area: mean", weights=True)
-
-
-
    -
  1. Calculate the annual global mean surface temperature:

  2. -
-
-
-
    -
  1. The temperature values are averaged for the climatological period of 1961-1990 by defining a subspace within these years using cf.wi query instance over subspace and doing a statistical collapse with the collapse method:

  2. -
- -
Field: long_name=near-surface temperature (ncvar%tmp)
------------------------------------------------------
-Data            : long_name=near-surface temperature(long_name=time(30), long_name=latitude(1), long_name=longitude(1)) degrees Celsius
-Cell methods    : area: mean long_name=time(30): mean
-Dimension coords: long_name=time(30) = [1961-07-02 12:00:00, ..., 1990-07-02 12:00:00] gregorian
-                : long_name=latitude(1) = [0.0] degrees_north
-                : long_name=longitude(1) = [0.0] degrees_east
-
-
- -
Field: long_name=near-surface temperature (ncvar%tmp)
------------------------------------------------------
-Data            : long_name=near-surface temperature(long_name=time(1), long_name=latitude(1), long_name=longitude(1)) degrees Celsius
-Cell methods    : area: mean long_name=time(1): mean
-Dimension coords: long_name=time(1) = [1976-01-01 12:00:00] gregorian
-                : long_name=latitude(1) = [0.0] degrees_north
-                : long_name=longitude(1) = [0.0] degrees_east
-
-
-
    -
  1. The temperature anomaly is then calculated by subtracting these climatological temperature values from the annual global average temperatures and plotted:

  2. -
-
temp_anomaly = annual_global_avg - temp_clim
-cfp.lineplot(
-    temp_anomaly,
-    color="red",
-    title="Global Average Temperature Anomaly (1901-2021)",
-    ylabel="1961-1990 climatology difference ",
-    yunits="degree Celcius",
-)
-
-
-Global Average Temperature Anomaly (1901-2021)

Total running time of the script: ( 4 minutes 52.252 seconds)

- -

Gallery generated by Sphinx-Gallery

-
- - -
- -
-
-
-
- - - - - - - \ No newline at end of file diff --git a/docs/recipes/plot_3_recipe.html b/docs/recipes/plot_3_recipe.html deleted file mode 100644 index b8b602a383..0000000000 --- a/docs/recipes/plot_3_recipe.html +++ /dev/null @@ -1,213 +0,0 @@ - - - - - - - - Plotting global mean temperatures spatially — Documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
- - -
- - -
-

Plotting global mean temperatures spatiallyΒΆ

-

In this recipe, we will plot the global mean temperature spatially.

-
    -
  1. Import cf-python and cf-plot:

  2. -
-
import cfplot as cfp
-
-import cf
-
-
-
    -
  1. Read the field constructs:

  2. -
-
f = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc")
-print(f)
-
-
-
[<CF Field: ncvar%stn(long_name=time(1452), long_name=latitude(360), long_name=longitude(720))>,
- <CF Field: long_name=near-surface temperature(long_name=time(1452), long_name=latitude(360), long_name=longitude(720)) degrees Celsius>]
-
-
-
    -
  1. Select near surface temperature by index and look at its contents:

  2. -
-
temp = f[1]
-print(temp)
-
-
-
Field: long_name=near-surface temperature (ncvar%tmp)
------------------------------------------------------
-Data            : long_name=near-surface temperature(long_name=time(1452), long_name=latitude(360), long_name=longitude(720)) degrees Celsius
-Dimension coords: long_name=time(1452) = [1901-01-16 00:00:00, ..., 2021-12-16 00:00:00] gregorian
-                : long_name=latitude(360) = [-89.75, ..., 89.75] degrees_north
-                : long_name=longitude(720) = [-179.75, ..., 179.75] degrees_east
-
-
-
    -
  1. Average the monthly mean surface temperature values by the time axis using the collapse method:

  2. -
-
global_avg = temp.collapse("mean", axes="long_name=time")
-
-
-
    -
  1. Plot the global mean surface temperatures:

  2. -
-
cfp.con(global_avg, lines=False, title="Global mean surface temperature")
-
-
-plot 3 recipe

Total running time of the script: ( 0 minutes 36.820 seconds)

- -

Gallery generated by Sphinx-Gallery

-
- - -
- -
-
-
-
- - - - - - - diff --git a/docs/recipes/plot_4_recipe.html b/docs/recipes/plot_4_recipe.html deleted file mode 100644 index c10bd27988..0000000000 --- a/docs/recipes/plot_4_recipe.html +++ /dev/null @@ -1,239 +0,0 @@ - - - - - - - - Comparing two datasets with different resolutions using regridding — Documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
- - -
- - -
-

Comparing two datasets with different resolutions using regriddingΒΆ

-

In this recipe, we will regrid two different datasets with different resolutions. An example use case could be one where the observational dataset with a higher resolution needs to be regridded to that of the model dataset so that they can be compared with each other.

-
    -
  1. Import cf-python:

  2. -
-
import cf
-
-
-
    -
  1. Read the field constructs:

  2. -
-
obs = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc", chunks=None)
-print(obs)
-
-
-
[<CF Field: ncvar%stn(long_name=time(1452), long_name=latitude(360), long_name=longitude(720))>,
- <CF Field: long_name=near-surface temperature(long_name=time(1452), long_name=latitude(360), long_name=longitude(720)) degrees Celsius>]
-
-
-
model = cf.read(
-    "~/recipes/tas_Amon_HadGEM3-GC3-1_hist-1p0_r3i1p1f2_gn_185001-201412.nc"
-)
-print(model)
-
-
-
[<CF Field: air_temperature(time(1980), latitude(144), longitude(192)) K>]
-
-
-
    -
  1. Select observation and model temperature fields by identity and index respectively, and look at their contents:

  2. -
-
obs_temp = obs.select_field("long_name=near-surface temperature")
-print(obs_temp)
-
-
-
Field: long_name=near-surface temperature (ncvar%tmp)
------------------------------------------------------
-Data            : long_name=near-surface temperature(long_name=time(1452), long_name=latitude(360), long_name=longitude(720)) degrees Celsius
-Dimension coords: long_name=time(1452) = [1901-01-16 00:00:00, ..., 2021-12-16 00:00:00] gregorian
-                : long_name=latitude(360) = [-89.75, ..., 89.75] degrees_north
-                : long_name=longitude(720) = [-179.75, ..., 179.75] degrees_east
-
-
-
model_temp = model[0]
-print(model_temp)
-
-
-
Field: air_temperature (ncvar%tas)
-----------------------------------
-Data            : air_temperature(time(1980), latitude(144), longitude(192)) K
-Cell methods    : time(1980): mean (interval: 1 hour)
-Dimension coords: time(1980) = [1850-01-16 00:00:00, ..., 2014-12-16 00:00:00] 360_day
-                : latitude(144) = [-89.375, ..., 89.375] degrees_north
-                : longitude(192) = [0.9375, ..., 359.0625] degrees_east
-                : height(1) = [1.5] m
-Coord references: grid_mapping_name:latitude_longitude
-
-
-
    -
  1. Regrid observational data to that of the model data and create a new low resolution observational data using bilinear interpolation:

  2. -
- -
Field: long_name=near-surface temperature (ncvar%tmp)
------------------------------------------------------
-Data            : long_name=near-surface temperature(long_name=time(1452), latitude(144), longitude(192)) degrees Celsius
-Dimension coords: long_name=time(1452) = [1901-01-16 00:00:00, ..., 2021-12-16 00:00:00] gregorian
-                : latitude(144) = [-89.375, ..., 89.375] degrees_north
-                : longitude(192) = [0.9375, ..., 359.0625] degrees_east
-Coord references: grid_mapping_name:latitude_longitude
-
-
-

Total running time of the script: ( 0 minutes 3.502 seconds)

- -

Gallery generated by Sphinx-Gallery

-
- - -
- -
-
-
-
- - - - - - - \ No newline at end of file diff --git a/docs/recipes/plot_5_recipe.html b/docs/recipes/plot_5_recipe.html deleted file mode 100644 index 5616bd5bb4..0000000000 --- a/docs/recipes/plot_5_recipe.html +++ /dev/null @@ -1,264 +0,0 @@ - - - - - - - - Plotting wind vectors overlaid on precipitation data — Documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
- - -
- - -
-

Plotting wind vectors overlaid on precipitation dataΒΆ

-

In this recipe we will plot wind vectors, derived from northward and eastward wind components, over precipitation data.

-
    -
  1. Import cf-python and cf-plot:

  2. -
-
import cfplot as cfp
-
-import cf
-
-
-
    -
  1. Read the field constructs:

  2. -
-
f1 = cf.read("~/recipes/northward.nc")
-print(f1)
-
-
-
[<CF Field: northward_wind(time(1980), latitude(144), longitude(192)) m s-1>]
-
-
-
f2 = cf.read("~/recipes/eastward.nc")
-print(f2)
-
-
-
[<CF Field: eastward_wind(time(1980), latitude(144), longitude(192)) m s-1>]
-
-
-
f3 = cf.read("~/recipes/monthly_precipitation.nc")
-print(f3)
-
-
-
[<CF Field: long_name=precipitation(long_name=time(1452), latitude(144), longitude(192)) mm/month>]
-
-
-
    -
  1. Select wind vectors and precipitation data by index and look at their contents:

  2. -
-
v = f1[0]
-print(v)
-
-
-
Field: northward_wind (ncvar%vas)
----------------------------------
-Data            : northward_wind(time(1980), latitude(144), longitude(192)) m s-1
-Cell methods    : area: time(1980): mean
-Dimension coords: time(1980) = [1850-01-16 00:00:00, ..., 2014-12-16 00:00:00] 360_day
-                : latitude(144) = [-89.375, ..., 89.375] degrees_north
-                : longitude(192) = [0.0, ..., 358.125] degrees_east
-                : height(1) = [10.0] m
-
-
-
u = f2[0]
-print(u)
-
-
-
Field: eastward_wind (ncvar%uas)
---------------------------------
-Data            : eastward_wind(time(1980), latitude(144), longitude(192)) m s-1
-Cell methods    : area: time(1980): mean
-Dimension coords: time(1980) = [1850-01-16 00:00:00, ..., 2014-12-16 00:00:00] 360_day
-                : latitude(144) = [-89.375, ..., 89.375] degrees_north
-                : longitude(192) = [0.0, ..., 358.125] degrees_east
-                : height(1) = [10.0] m
-
-
-
pre = f3[0]
-print(pre)
-
-
-
Field: long_name=precipitation (ncvar%pre)
-------------------------------------------
-Data            : long_name=precipitation(long_name=time(1452), latitude(144), longitude(192)) mm/month
-Dimension coords: long_name=time(1452) = [1901-01-16 00:00:00, ..., 2021-12-16 00:00:00] gregorian
-                : latitude(144) = [-89.375, ..., 89.375] degrees_north
-                : longitude(192) = [0.0, ..., 358.125] degrees_east
-
-
-
    -
  1. Plot the wind vectors on top of precipitation data for June 1995 by creating a subspace with a date-time object and using cfplot.con. Here cfplot.gopen is used to define the parts of the plot area, which is closed by cfplot.gclose; cfplot.cscale is used to choose one of the colour maps amongst many available; cfplot.levs is used to set the contour levels for precipitation data; and cfplot.vect is used to plot the wind vectors for June 1995:

  2. -
-
june_95 = cf.year(1995) & cf.month(6)
-cfp.gopen()
-cfp.cscale("precip4_11lev")
-cfp.levs(step=100)
-cfp.con(
-    pre.subspace(T=june_95),
-    lines=False,
-    title="June 1995 monthly global precipitation",
-)
-cfp.vect(
-    u=u.subspace(T=june_95),
-    v=v.subspace(T=june_95),
-    key_length=10,
-    scale=35,
-    stride=5,
-)
-cfp.gclose()
-
-
-plot 5 recipe

Total running time of the script: ( 0 minutes 20.444 seconds)

- -

Gallery generated by Sphinx-Gallery

-
- - -
- -
-
-
-
- - - - - - - \ No newline at end of file diff --git a/docs/recipes/plot_6_recipe.html b/docs/recipes/plot_6_recipe.html deleted file mode 100644 index d580238693..0000000000 --- a/docs/recipes/plot_6_recipe.html +++ /dev/null @@ -1,397 +0,0 @@ - - - - - - - - Converting from rotated latitude-longitude to regular latitude-longitude — Documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
- - -
- - -
-

Converting from rotated latitude-longitude to regular latitude-longitudeΒΆ

-

In this recipe, we will be regridding from a rotated latitude-longitude source domain to a regular latitude-longitude destination domain.

-
    -
  1. Import cf-python, cf-plot and numpy:

  2. -
-
import cfplot as cfp
-import numpy as np
-
-import cf
-
-
-
    -
  1. Read the field constructs using read function:

  2. -
-
f = cf.read("~/recipes/au952a.pd20510414.pp")
-print(f)
-
-
-
[<CF Field: id%UM_m01s03i463_vn1006(time(8), grid_latitude(432), grid_longitude(444))>]
-
-
-
    -
  1. Select the field by index and print its description to show properties of all constructs:

  2. -
-
gust = f[0]
-gust.dump()
-
-
-
-----------------------------------------------------------
-Field: id%UM_m01s03i463_vn1006 (ncvar%UM_m01s03i463_vn1006)
------------------------------------------------------------
-Conventions = 'CF-1.10'
-_FillValue = -1073741824.0
-history = 'Converted from UM/PP by cf-python v3.15.0'
-lbproc = '8192'
-lbtim = '122'
-long_name = 'WIND GUST'
-runid = 'aaaaa'
-source = 'UM vn1006'
-stash_code = '3463'
-submodel = '1'
-um_stash_source = 'm01s03i463'
-
-Data(time(8), grid_latitude(432), grid_longitude(444)) = [[[5.587890625, ..., 5.1376953125]]]
-
-Cell Method: time(8): maximum
-
-Domain Axis: grid_latitude(432)
-Domain Axis: grid_longitude(444)
-Domain Axis: height(1)
-Domain Axis: time(8)
-
-Dimension coordinate: time
-    axis = 'T'
-    calendar = '360_day'
-    standard_name = 'time'
-    units = 'days since 2051-1-1'
-    Data(time(8)) = [2051-04-14 01:30:00, ..., 2051-04-14 22:30:00] 360_day
-    Bounds:calendar = '360_day'
-    Bounds:units = 'days since 2051-1-1'
-    Bounds:Data(time(8), 2) = [[2051-04-14 00:00:00, ..., 2051-04-15 00:00:00]] 360_day
-
-Dimension coordinate: height
-    axis = 'Z'
-    positive = 'up'
-    standard_name = 'height'
-    units = 'm'
-    Data(height(1)) = [-1.0] m
-
-Dimension coordinate: grid_latitude
-    axis = 'Y'
-    standard_name = 'grid_latitude'
-    units = 'degrees'
-    Data(grid_latitude(432)) = [-24.474999085068703, ..., 22.93500065803528] degrees
-    Bounds:units = 'degrees'
-    Bounds:Data(grid_latitude(432), 2) = [[-24.52999908477068, ..., 22.990000657737255]] degrees
-
-Dimension coordinate: grid_longitude
-    axis = 'X'
-    standard_name = 'grid_longitude'
-    units = 'degrees'
-    Data(grid_longitude(444)) = [-29.47499145567417, ..., 19.255008280277252] degrees
-    Bounds:units = 'degrees'
-    Bounds:Data(grid_longitude(444), 2) = [[-29.52999145537615, ..., 19.31000827997923]] degrees
-
-Auxiliary coordinate: latitude
-    standard_name = 'latitude'
-    units = 'degrees_north'
-    Data(grid_latitude(432), grid_longitude(444)) = [[20.576467692711244, ..., 66.90225185059428]] degrees_north
-    Bounds:units = 'degrees_north'
-    Bounds:Data(grid_latitude(432), grid_longitude(444), 4) = [[[20.50585365074419, ..., 66.82752183591474]]] degrees_north
-
-Auxiliary coordinate: longitude
-    standard_name = 'longitude'
-    units = 'degrees_east'
-    Data(grid_latitude(432), grid_longitude(444)) = [[-10.577446822867152, ..., 68.72895292160315]] degrees_east
-    Bounds:units = 'degrees_east'
-    Bounds:Data(grid_latitude(432), grid_longitude(444), 4) = [[[-10.602339269012642, ..., 68.7357360850507]]] degrees_east
-
-Coordinate reference: grid_mapping_name:rotated_latitude_longitude
-    Coordinate conversion:grid_mapping_name = rotated_latitude_longitude
-    Coordinate conversion:grid_north_pole_latitude = 39.25
-    Coordinate conversion:grid_north_pole_longitude = 198.0
-    Dimension Coordinate: grid_longitude
-    Dimension Coordinate: grid_latitude
-    Auxiliary Coordinate: longitude
-    Auxiliary Coordinate: latitude
-
-
-
    -
  1. Access the time coordinate of the gust field and retrieve the datetime values of the time coordinate:

  2. -
-
print(gust.coordinate("time").datetime_array)
-
-
-
[cftime.Datetime360Day(2051, 4, 14, 1, 30, 0, 0, has_year_zero=True)
- cftime.Datetime360Day(2051, 4, 14, 4, 30, 0, 0, has_year_zero=True)
- cftime.Datetime360Day(2051, 4, 14, 7, 30, 0, 0, has_year_zero=True)
- cftime.Datetime360Day(2051, 4, 14, 10, 30, 0, 0, has_year_zero=True)
- cftime.Datetime360Day(2051, 4, 14, 13, 30, 0, 0, has_year_zero=True)
- cftime.Datetime360Day(2051, 4, 14, 16, 30, 0, 0, has_year_zero=True)
- cftime.Datetime360Day(2051, 4, 14, 19, 30, 0, 0, has_year_zero=True)
- cftime.Datetime360Day(2051, 4, 14, 22, 30, 0, 0, has_year_zero=True)]
-
-
-
    -
  1. Create a new instance of the cf.dt class with a specified year, month, day, hour, minute, second and microsecond. Then store the result in the variable test:

  2. -
-
test = cf.dt(2051, 4, 14, 1, 30, 0, 0)
-print(test)
-
-
-
2051-04-14 01:30:00
-
-
-
    -
  1. Plot the wind gust by creating a subspace for the specified variable test using cfplot.con. Here cfplot.mapset is used to set the mapping parameters like setting the map resolution to 50m:

  2. -
-
cfp.mapset(resolution="50m")
-cfp.con(gust.subspace(T=test), lines=False)
-
-
-plot 6 recipe
    -
  1. To see the rotated pole data on the native grid, the above steps are repeated and projection is set to rotated in cfplot.mapset:

  2. -
-
cfp.mapset(resolution="50m", proj="rotated")
-cfp.con(gust.subspace(T=test), lines=False)
-
-
-plot 6 recipe
    -
  1. Create dimension coordinates for the destination grid with the latitude and longitude values for Europe. np.linspace generates evenly spaced values between the specified latitude and longitude range. Bounds of the target longitude and target latitude are created and spherical regridding is then performed on the gust variable by passing the target latitude and target longitude as arguments. The method also takes an argument 'linear' which specifies the type of regridding method to use. The description of the regridded_data is finally printed to show properties of all its constructs:

  2. -
- -
-----------------------------------------------------------
-Field: id%UM_m01s03i463_vn1006 (ncvar%UM_m01s03i463_vn1006)
------------------------------------------------------------
-Conventions = 'CF-1.10'
-_FillValue = -1073741824.0
-history = 'Converted from UM/PP by cf-python v3.15.0'
-lbproc = '8192'
-lbtim = '122'
-long_name = 'WIND GUST'
-runid = 'aaaaa'
-source = 'UM vn1006'
-stash_code = '3463'
-submodel = '1'
-um_stash_source = 'm01s03i463'
-
-Data(time(8), latitude(10), longitude(10)) = [[[--, ..., 6.10885110153462]]]
-
-Cell Method: time(8): maximum
-
-Domain Axis: height(1)
-Domain Axis: latitude(10)
-Domain Axis: longitude(10)
-Domain Axis: time(8)
-
-Dimension coordinate: time
-    axis = 'T'
-    calendar = '360_day'
-    standard_name = 'time'
-    units = 'days since 2051-1-1'
-    Data(time(8)) = [2051-04-14 01:30:00, ..., 2051-04-14 22:30:00] 360_day
-    Bounds:calendar = '360_day'
-    Bounds:units = 'days since 2051-1-1'
-    Bounds:Data(time(8), 2) = [[2051-04-14 00:00:00, ..., 2051-04-15 00:00:00]] 360_day
-
-Dimension coordinate: height
-    axis = 'Z'
-    positive = 'up'
-    standard_name = 'height'
-    units = 'm'
-    Data(height(1)) = [-1.0] m
-
-Dimension coordinate: latitude
-    standard_name = 'latitude'
-    units = 'degrees_north'
-    Data(latitude(10)) = [34.0, ..., 72.0] degrees_north
-    Bounds:units = 'degrees_north'
-    Bounds:Data(latitude(10), 2) = [[31.88888888888889, ..., 74.11111111111111]] degrees_north
-
-Dimension coordinate: longitude
-    standard_name = 'longitude'
-    units = 'degrees_east'
-    Data(longitude(10)) = [-25.0, ..., 45.0] degrees_east
-    Bounds:units = 'degrees_east'
-    Bounds:Data(longitude(10), 2) = [[-28.88888888888889, ..., 48.888888888888886]] degrees_east
-
-
-
    -
  1. Step 6 is similarly repeated for the regridded_data to plot the wind gust on a regular latitude-longitude domain:

  2. -
-
cfp.mapset(resolution="50m")
-cfp.con(regridded_data.subspace(T=test), lines=False)
-
-
-plot 6 recipe

Total running time of the script: ( 0 minutes 25.541 seconds)

- -

Gallery generated by Sphinx-Gallery

-
- - -
- -
-
-
-
- - - - - - - \ No newline at end of file diff --git a/docs/recipes/plot_7_recipe.html b/docs/recipes/plot_7_recipe.html deleted file mode 100644 index a52a2ea8cd..0000000000 --- a/docs/recipes/plot_7_recipe.html +++ /dev/null @@ -1,310 +0,0 @@ - - - - - - - - Plotting members of a model ensemble — Documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
- - -
- - -
-

Plotting members of a model ensembleΒΆ

-

In this recipe, we will plot the members of a model ensemble.

-
    -
  1. Import cf-python and cf-plot:

  2. -
-
import cfplot as cfp
-
-import cf
-
-
-
    -
  1. Read the field constructs using read function and store it in the variable f. The * in the filename is a wildcard character which means the function reads all files in the directory that match the specified pattern. [0:5] selects the first five elements of the resulting list:

  2. -
-
f = cf.read("~/recipes/realization/PRMSL.1941_mem*.nc")[0:5]
-print(f)
-
-
-
[<CF Field: long_name=Pressure reduced to MSL(time(2920), latitude(256), longitude(512)) Pa>,
- <CF Field: long_name=Pressure reduced to MSL(time(2920), latitude(256), longitude(512)) Pa>,
- <CF Field: long_name=Pressure reduced to MSL(time(2920), latitude(256), longitude(512)) Pa>,
- <CF Field: long_name=Pressure reduced to MSL(time(2920), latitude(256), longitude(512)) Pa>,
- <CF Field: long_name=Pressure reduced to MSL(time(2920), latitude(256), longitude(512)) Pa>]
-
-
-
    -
  1. The description of one of the fields from the list shows 'realization' as a property by which the members of the model ensemble are labelled:

  2. -
-
f[1].dump()
-
-
-
------------------------------------------------------
-Field: long_name=Pressure reduced to MSL (ncvar%PRMSL)
-------------------------------------------------------
-CDI = 'Climate Data Interface version 1.9.3 (http://mpimet.mpg.de/cdi)'
-CDO = 'Climate Data Operators version 1.9.3 (http://mpimet.mpg.de/cdo)'
-Conventions = 'CF-1.6'
-citation = '<http://onlinelibrary.wiley.com/doi/10.1002/qj.776/abstract>.\n
-            Quarterly J. Roy. Meteorol. Soc./, 137, 1-28. DOI: 10.1002/qj.776.'
-comments = 'Data is from \n NOAA-CIRES 20th Century Reanalysis version 3\n,'
-ensemble_members = 10
-experiment = '451 = SODAsi.3 pentad 8 member SSTs climatologically adjusted to
-              HadISST2.3 1981 to 2010 climatology'
-forecast_init_type = 3
-history = 'Mon Apr 15 00:59:16 2019: cdo -v -f nc4 -r
-           setpartabn,/global/homes/l/lslivins/convert_grb2_netcdf/cdo_table
-           -copy -setreftime,1800-01-01,00:00:00,3hours PRMSL.1941_004.grb
-           PRMSL.1941_mem004.nc'
-institution = 'NOAA ESRL Physical Sciences Division & CU/CIRES \n'
-long_name = 'Pressure reduced to MSL'
-observations = 'International Surface Pressure Databank version 4.7'
-original_name = 'prmsl'
-param = '1.3.0'
-platform = 'Model'
-realization = 4
-units = 'Pa'
-
-Data(time(2920), latitude(256), longitude(512)) = [[[101351.0, ..., 100562.0]]] Pa
-
-Domain Axis: latitude(256)
-Domain Axis: longitude(512)
-Domain Axis: time(2920)
-
-Dimension coordinate: time
-    axis = 'T'
-    calendar = 'proleptic_gregorian'
-    standard_name = 'time'
-    units = 'hours since 1800-1-1 00:00:00'
-    Data(time(2920)) = [1941-01-01 00:00:00, ..., 1941-12-31 21:00:00] proleptic_gregorian
-
-Dimension coordinate: latitude
-    axis = 'Y'
-    long_name = 'latitude'
-    standard_name = 'latitude'
-    units = 'degrees_north'
-    Data(latitude(256)) = [89.46282196044922, ..., -89.46282196044922] degrees_north
-
-Dimension coordinate: longitude
-    axis = 'X'
-    long_name = 'longitude'
-    standard_name = 'longitude'
-    units = 'degrees_east'
-    Data(longitude(512)) = [0.0, ..., 359.2330017089844] degrees_east
-
-
-
    -
  1. An ensemble of the members is then created by aggregating the data in f along a new 'realization' axis using the cf.aggregate function, and storing the result in the variable ensemble. 'relaxed_identities=True' allows for missing coordinate identities to be inferred. [0] selects the first element of the resulting list. id%realization now shows as an auxiliary coordinate for the ensemble:

  2. -
-
ensemble = cf.aggregate(
-    f, dimension=("realization",), relaxed_identities=True
-)[0]
-print(ensemble)
-
-
-
Field: long_name=Pressure reduced to MSL (ncvar%PRMSL)
-------------------------------------------------------
-Data            : long_name=Pressure reduced to MSL(id%realization(5), time(2920), latitude(256), longitude(512)) Pa
-Dimension coords: time(2920) = [1941-01-01 00:00:00, ..., 1941-12-31 21:00:00] proleptic_gregorian
-                : latitude(256) = [89.46282196044922, ..., -89.46282196044922] degrees_north
-                : longitude(512) = [0.0, ..., 359.2330017089844] degrees_east
-Auxiliary coords: id%realization(id%realization(5)) = [1, ..., 5]
-
-
-
    -
  1. To see the constructs for the ensemble, print the constructs attribute:

  2. -
- -
Constructs:
-{'auxiliarycoordinate0': <CF AuxiliaryCoordinate: id%realization(5) >,
- 'dimensioncoordinate0': <CF DimensionCoordinate: time(2920) hours since 1800-1-1 00:00:00 proleptic_gregorian>,
- 'dimensioncoordinate1': <CF DimensionCoordinate: latitude(256) degrees_north>,
- 'dimensioncoordinate2': <CF DimensionCoordinate: longitude(512) degrees_east>,
- 'domainaxis0': <CF DomainAxis: size(2920)>,
- 'domainaxis1': <CF DomainAxis: size(256)>,
- 'domainaxis2': <CF DomainAxis: size(512)>,
- 'domainaxis3': <CF DomainAxis: size(5)>}
-
-
-

6. Loop over the realizations in the ensemble using the range function and the domain_axis to determine the size of the realization dimension. For each realization, extract a subspace of the ensemble using the subspace method and the 'id%realization' keyword argument along a specific latitude and longitude and plot the realizations from the 4D field using cfplot.lineplot. -A moving average of the ensemble along the time axis, with a window size of 90 (i.e. an approximately 3-month moving average) is calculated using the moving_window method. The mode='nearest' parameter is used to specify how to pad the data outside of the time range. The squeeze method removes any dimensions of size 1 from the field to produce a 2D field:

-
cfp.gopen()
-
-for realization in range(1, ensemble.domain_axis("id%realization").size + 1):
-    cfp.lineplot(
-        ensemble.subspace(
-            **{"id%realization": realization}, latitude=[0], longitude=[0]
-        ).squeeze(),
-        label=f"Member {realization}",
-        linewidth=1.0,
-    )
-
-cfp.lineplot(
-    ensemble.moving_window(
-        method="mean", window_size=90, axis="T", mode="nearest"
-    )[0, :, 0, 0].squeeze(),
-    label="Ensemble mean",
-    linewidth=2.0,
-    color="black",
-    title="Model Ensemble Pressure",
-)
-
-cfp.gclose()
-
-
-Model Ensemble Pressure

Total running time of the script: ( 2 minutes 35.758 seconds)

- -

Gallery generated by Sphinx-Gallery

-
- - -
- -
-
-
-
- - - - - - - \ No newline at end of file diff --git a/docs/recipes/plot_8_recipe.html b/docs/recipes/plot_8_recipe.html deleted file mode 100644 index 2e8b750ed6..0000000000 --- a/docs/recipes/plot_8_recipe.html +++ /dev/null @@ -1,314 +0,0 @@ - - - - - - - - Plotting statistically significant temperature trends with stippling — Documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
- - -
- - - - - -
- -
-
-
-
- - - - - - - diff --git a/docs/recipes/plot_9_recipe.html b/docs/recipes/plot_9_recipe.html deleted file mode 100644 index dcf96011a8..0000000000 --- a/docs/recipes/plot_9_recipe.html +++ /dev/null @@ -1,331 +0,0 @@ - - - - - - - - Plotting a joint histogram — Documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
- - -
- - -
-

Plotting a joint histogramΒΆ

-

In this recipe, we will be creating a joint histogram of PM2.5 mass -concentration and 2-metre temperature.

-
    -
  1. Import cf-python, numpy and matplotlib.pyplot:

  2. -
-
import matplotlib.pyplot as plt
-import numpy as np
-
-import cf
-
-
-
    -
  1. Read the field constructs using read function:

  2. -
-
f = cf.read("~/recipes/levtype_sfc.nc")
-print(f)
-
-
-
[<CF Field: long_name=Total Aerosol Optical Depth at 550nm(long_name=time(6), long_name=latitude(241), long_name=longitude(480)) ~>,
- <CF Field: mass_concentration_of_pm10_ambient_aerosol_particles_in_air(long_name=time(6), long_name=latitude(241), long_name=longitude(480)) kg m**-3>,
- <CF Field: mass_concentration_of_pm2p5_ambient_aerosol_particles_in_air(long_name=time(6), long_name=latitude(241), long_name=longitude(480)) kg m**-3>,
- <CF Field: long_name=2 metre temperature(long_name=time(6), long_name=latitude(241), long_name=longitude(480)) K>]
-
-
-

3. Select the PM2.5 mass concentration and 2-metre temperature fields by -index and print the description to show properties of all constructs:

- -
---------------------------------------------------------------------------------
-Field: mass_concentration_of_pm2p5_ambient_aerosol_particles_in_air (ncvar%pm2p5)
----------------------------------------------------------------------------------
-Conventions = 'CF-1.6'
-_FillValue = -32767
-history = '2023-05-02 11:17:49 GMT by grib_to_netcdf-2.25.1: /opt/ecmwf/mars-
-           client/bin/grib_to_netcdf.bin -S param -o /cache/tmp/4e68aba0-50a9-
-           4f06-947c-9fc7444b7838-adaptor.mars.internal-1683026269.508034-
-           23606-13-tmp.nc /cache/tmp/4e68aba0-50a9-4f06-947c-9fc7444b7838-
-           adaptor.mars.internal-1683026265.2095394-23606-10-tmp.grib'
-long_name = 'Particulate matter d <= 2.5 um'
-missing_value = -32767
-standard_name = 'mass_concentration_of_pm2p5_ambient_aerosol_particles_in_air'
-units = 'kg m**-3'
-
-Data(long_name=time(6), long_name=latitude(241), long_name=longitude(480)) = [[[1.5032209791448226e-10, ..., 1.1372701346394527e-10]]] kg m**-3
-
-Domain Axis: long_name=latitude(241)
-Domain Axis: long_name=longitude(480)
-Domain Axis: long_name=time(6)
-
-Dimension coordinate: long_name=time
-    calendar = 'gregorian'
-    long_name = 'time'
-    units = 'hours since 1900-01-01 00:00:00.0'
-    Data(long_name=time(6)) = [2022-01-01 00:00:00, ..., 2022-06-01 00:00:00] gregorian
-
-Dimension coordinate: long_name=latitude
-    long_name = 'latitude'
-    units = 'degrees_north'
-    Data(long_name=latitude(241)) = [90.0, ..., -90.0] degrees_north
-
-Dimension coordinate: long_name=longitude
-    long_name = 'longitude'
-    units = 'degrees_east'
-    Data(long_name=longitude(480)) = [0.0, ..., 359.25] degrees_east
-
-
- -
------------------------------------------------
-Field: long_name=2 metre temperature (ncvar%t2m)
-------------------------------------------------
-Conventions = 'CF-1.6'
-_FillValue = -32767
-history = '2023-05-02 11:17:49 GMT by grib_to_netcdf-2.25.1: /opt/ecmwf/mars-
-           client/bin/grib_to_netcdf.bin -S param -o /cache/tmp/4e68aba0-50a9-
-           4f06-947c-9fc7444b7838-adaptor.mars.internal-1683026269.508034-
-           23606-13-tmp.nc /cache/tmp/4e68aba0-50a9-4f06-947c-9fc7444b7838-
-           adaptor.mars.internal-1683026265.2095394-23606-10-tmp.grib'
-long_name = '2 metre temperature'
-missing_value = -32767
-units = 'K'
-
-Data(long_name=time(6), long_name=latitude(241), long_name=longitude(480)) = [[[247.0076398602821, ..., 226.25710500984027]]] K
-
-Domain Axis: long_name=latitude(241)
-Domain Axis: long_name=longitude(480)
-Domain Axis: long_name=time(6)
-
-Dimension coordinate: long_name=time
-    calendar = 'gregorian'
-    long_name = 'time'
-    units = 'hours since 1900-01-01 00:00:00.0'
-    Data(long_name=time(6)) = [2022-01-01 00:00:00, ..., 2022-06-01 00:00:00] gregorian
-
-Dimension coordinate: long_name=latitude
-    long_name = 'latitude'
-    units = 'degrees_north'
-    Data(long_name=latitude(241)) = [90.0, ..., -90.0] degrees_north
-
-Dimension coordinate: long_name=longitude
-    long_name = 'longitude'
-    units = 'degrees_east'
-    Data(long_name=longitude(480)) = [0.0, ..., 359.25] degrees_east
-
-
-
    -
  1. Convert the units to degree celsius for the temperature field:

  2. -
-
temp_field.units = "degC"
-temp_field.get_property("units")
-
-
-
'degC'
-
-
-

5. Digitize the PM2.5 mass concentration and 2-metre temperature fields. -This step counts the number of values in each of the 10 equally sized bins -spanning the range of the values. The 'return_bins=True' argument makes -sure that the calculated bins are also returned:

-
pm25_indices, pm25_bins = pm25_field.digitize(10, return_bins=True)
-temp_indices, temp_bins = temp_field.digitize(10, return_bins=True)
-
-
-
    -
  1. Create a joint histogram of the digitized fields:

  2. -
- -
    -
  1. Get histogram data from the joint_histogram:

  2. -
- -
    -
  1. Calculate bin centers for PM2.5 and temperature bins:

  2. -
-
pm25_bin_centers = [(a + b) / 2 for a, b in pm25_bins]
-temp_bin_centers = [(a + b) / 2 for a, b in temp_bins]
-
-
-

9. Create grids for PM2.5 and temperature bins using numpy.meshgrid:

- -

10. Plot the joint histogram using matplotlib.pyplot.pcolormesh. Use cf.Field.unique to get -the unique data array values and show the bin boundaries as ticks on the -plot. 'style='plain' in matplotlib.axes.Axes.ticklabel_format -disables the scientific notation on the y-axis:

-
plt.pcolormesh(temp_grid, pm25_grid, histogram_data, cmap="viridis")
-plt.xlabel("2-metre Temperature (degC)")
-plt.ylabel("PM2.5 Mass Concentration (kg m**-3)")
-plt.xticks(temp_bins.unique().array, rotation=45)
-plt.yticks(pm25_bins.unique().array)
-plt.colorbar(label="Frequency")
-plt.title("Joint Histogram of PM2.5 and 2-metre Temperature", y=1.05)
-plt.ticklabel_format(style="plain")
-plt.show()
-
-
-Joint Histogram of PM2.5 and 2-metre Temperature

Total running time of the script: ( 0 minutes 4.037 seconds)

- -

Gallery generated by Sphinx-Gallery

-
- - -
- -
-
-
-
- - - - - - - \ No newline at end of file