Skip to content

Commit fc335a2

Browse files
Add new recipes-source for recipe scripts & context RST only
1 parent c211313 commit fc335a2

27 files changed

Lines changed: 2588 additions & 89 deletions

recipes-docs/source/index.rst

Lines changed: 3 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,9 @@
1-
:orphan:
2-
31
**Recipes using cf**
42
====================
53

64
----
75

8-
Version |release| for version |version| of the CF conventions.
9-
10-
Click on the keywords below to filter the recipes according to their function:
11-
12-
.. raw:: html
13-
14-
<script>
15-
document.addEventListener('DOMContentLoaded', function() {
16-
showFilteredRecipes('all');
17-
18-
function showFilteredRecipes(filter) {
19-
const recipes = document.querySelectorAll('.sphx-glr-thumbcontainer');
20-
recipes.forEach(recipe => {
21-
if (filter === 'all') {
22-
recipe.style.display = 'inline-block';
23-
} else if (recipe.classList.contains(filter)) {
24-
recipe.style.display = 'inline-block';
25-
} else {
26-
recipe.style.display = 'none';
27-
}
28-
});
29-
}
30-
31-
const filterButtons = document.querySelectorAll('.filter-menu button');
32-
filterButtons.forEach(button => {
33-
button.addEventListener('click', () => {
34-
const filter = button.getAttribute('data-filter');
35-
showFilteredRecipes(filter);
36-
});
37-
});
38-
});
39-
</script>
40-
41-
.. raw:: html
42-
43-
<style>
44-
.filter-menu {
45-
margin-bottom: 20px;
46-
}
47-
</style>
48-
49-
<div class="filter-menu">
50-
<button data-filter="all">All</button>
51-
<button data-filter="aggregate">Aggregate</button>
52-
<button data-filter="collapse">Collapse</button>
53-
<button data-filter="contourmap">Contourmap</button>
54-
<button data-filter="histogram">Histogram</button>
55-
<button data-filter="lineplot">Lineplot</button>
56-
<button data-filter="maths">Mathematical Operations</button>
57-
<button data-filter="regrid">Regrid</button>
58-
<button data-filter="subspace">Subspace</button>
59-
<button data-filter="mask">Mask</button>
60-
<button data-filter="vectorplot">Vectorplot</button>
61-
<button data-filter="subplot">Subplot</button>
62-
<button data-filter="stats">Statistical Operations</button>
63-
</div>
64-
65-
.. raw:: html
66-
67-
68-
.. raw:: html
69-
70-
<div class="sphx-glr-thumbnails">
71-
72-
73-
.. raw:: html
74-
75-
</div>
76-
77-
78-
.. only:: html
79-
80-
.. container:: sphx-glr-footer sphx-glr-footer-gallery
81-
82-
.. container:: sphx-glr-download sphx-glr-download-python
83-
84-
:download:`Download all examples in Python source code: recipes_python.zip </recipes/recipes_python.zip>`
85-
86-
.. container:: sphx-glr-download sphx-glr-download-jupyter
87-
88-
:download:`Download all examples in Jupyter notebooks: recipes_jupyter.zip </recipes/recipes_jupyter.zip>`
89-
90-
91-
.. only:: html
92-
93-
.. rst-class:: sphx-glr-signature
6+
.. toctree::
7+
:maxdepth: 2
948

95-
`Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
9+
recipes-source/gallery
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
**Recipes using cf**
2+
====================
3+
4+
----
5+
6+
Version |release| for version |version| of the CF conventions.
7+
8+
Click on the keywords below to filter the recipes according to their function:
9+
10+
.. raw:: html
11+
12+
<script>
13+
document.addEventListener('DOMContentLoaded', function() {
14+
showFilteredRecipes('all');
15+
16+
function showFilteredRecipes(filter) {
17+
const recipes = document.querySelectorAll('.sphx-glr-thumbcontainer');
18+
recipes.forEach(recipe => {
19+
if (filter === 'all') {
20+
recipe.style.display = 'inline-block';
21+
} else if (recipe.classList.contains(filter)) {
22+
recipe.style.display = 'inline-block';
23+
} else {
24+
recipe.style.display = 'none';
25+
}
26+
});
27+
}
28+
29+
const filterButtons = document.querySelectorAll('.filter-menu button');
30+
filterButtons.forEach(button => {
31+
button.addEventListener('click', () => {
32+
const filter = button.getAttribute('data-filter');
33+
showFilteredRecipes(filter);
34+
});
35+
});
36+
});
37+
</script>
38+
39+
.. raw:: html
40+
41+
<style>
42+
.filter-menu {
43+
margin-bottom: 20px;
44+
}
45+
</style>
46+
47+
<div class="filter-menu">
48+
<button data-filter="all">All</button>
49+
<button data-filter="aggregate">Aggregate</button>
50+
<button data-filter="collapse">Collapse</button>
51+
<button data-filter="contourmap">Contourmap</button>
52+
<button data-filter="histogram">Histogram</button>
53+
<button data-filter="lineplot">Lineplot</button>
54+
<button data-filter="maths">Mathematical Operations</button>
55+
<button data-filter="regrid">Regrid</button>
56+
<button data-filter="subspace">Subspace</button>
57+
<button data-filter="mask">Mask</button>
58+
<button data-filter="vectorplot">Vectorplot</button>
59+
<button data-filter="subplot">Subplot</button>
60+
<button data-filter="stats">Statistical Operations</button>
61+
</div>
62+
63+
.. raw:: html
64+
81.7 KB
Loading
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
**Recipes using cf**
2+
====================
3+
4+
----
5+
6+
Version |release| for version |version| of the CF conventions.
7+
8+
Click on the keywords below to filter the recipes according to their function:
9+
10+
.. raw:: html
11+
12+
<script>
13+
document.addEventListener('DOMContentLoaded', function() {
14+
showFilteredRecipes('all');
15+
16+
function showFilteredRecipes(filter) {
17+
const recipes = document.querySelectorAll('.sphx-glr-thumbcontainer');
18+
recipes.forEach(recipe => {
19+
if (filter === 'all') {
20+
recipe.style.display = 'inline-block';
21+
} else if (recipe.classList.contains(filter)) {
22+
recipe.style.display = 'inline-block';
23+
} else {
24+
recipe.style.display = 'none';
25+
}
26+
});
27+
}
28+
29+
const filterButtons = document.querySelectorAll('.filter-menu button');
30+
filterButtons.forEach(button => {
31+
button.addEventListener('click', () => {
32+
const filter = button.getAttribute('data-filter');
33+
showFilteredRecipes(filter);
34+
});
35+
});
36+
});
37+
</script>
38+
39+
.. raw:: html
40+
41+
<style>
42+
.filter-menu {
43+
margin-bottom: 20px;
44+
}
45+
</style>
46+
47+
<div class="filter-menu">
48+
<button data-filter="all">All</button>
49+
<button data-filter="aggregate">Aggregate</button>
50+
<button data-filter="collapse">Collapse</button>
51+
<button data-filter="contourmap">Contourmap</button>
52+
<button data-filter="histogram">Histogram</button>
53+
<button data-filter="lineplot">Lineplot</button>
54+
<button data-filter="maths">Mathematical Operations</button>
55+
<button data-filter="regrid">Regrid</button>
56+
<button data-filter="subspace">Subspace</button>
57+
<button data-filter="mask">Mask</button>
58+
<button data-filter="vectorplot">Vectorplot</button>
59+
<button data-filter="subplot">Subplot</button>
60+
<button data-filter="stats">Statistical Operations</button>
61+
</div>
62+
63+
.. raw:: html
64+
65+
66+
67+
68+
.. raw:: html
69+
70+
<div class="sphx-glr-thumbnails">
71+
72+
.. thumbnail-parent-div-open
73+
74+
.. raw:: html
75+
76+
<div class="sphx-glr-thumbcontainer" tooltip="Given a file containing northerly and easterly wind components, we can calculate the magnitude and bearing of the resultant wind at each point in the region and plot them using a scatter plot on a polar grid to create a wind rose representing wind vectors in the given area.">
77+
78+
.. only:: html
79+
80+
.. image:: /recipes/images/thumb/sphx_glr_plot_22_recipe_thumb.png
81+
:alt:
82+
83+
:doc:`/recipes/plot_22_recipe`
84+
85+
.. raw:: html
86+
87+
<div class="sphx-glr-thumbnail-title">Plotting a wind rose as a scatter plot</div>
88+
</div>
89+
90+
91+
.. thumbnail-parent-div-close
92+
93+
.. raw:: html
94+
95+
</div>
96+
97+
98+
.. toctree::
99+
:hidden:
100+
101+
/recipes/plot_22_recipe
102+
103+
104+
.. only:: html
105+
106+
.. container:: sphx-glr-footer sphx-glr-footer-gallery
107+
108+
.. container:: sphx-glr-download sphx-glr-download-python
109+
110+
:download:`Download all examples in Python source code: recipes_python.zip </recipes/recipes_python.zip>`
111+
112+
.. container:: sphx-glr-download sphx-glr-download-jupyter
113+
114+
:download:`Download all examples in Jupyter notebooks: recipes_jupyter.zip </recipes/recipes_jupyter.zip>`
115+
116+
117+
.. only:: html
118+
119+
.. rst-class:: sphx-glr-signature
120+
121+
`Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cf-python recipes
2+
=================
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
7+
recipes/gallery
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""
2+
Calculating global mean temperature timeseries
3+
==============================================
4+
5+
In this recipe we will calculate and plot monthly and annual global mean temperature timeseries.
6+
"""
7+
8+
# %%
9+
# 1. Import cf-python and cf-plot:
10+
11+
import cfplot as cfp
12+
13+
import cf
14+
15+
# %%
16+
# 2. Read the field constructs:
17+
18+
f = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc")
19+
print(f)
20+
21+
# %%
22+
# 3. Select near surface temperature by index and look at its contents:
23+
24+
temp = f[1]
25+
print(temp)
26+
27+
# %%
28+
# 4. Select latitude and longitude dimensions by identities, with two different techniques:
29+
30+
lon = temp.coordinate("long_name=longitude")
31+
lat = temp.coordinate("Y")
32+
33+
# %%
34+
# 5. Print the description of near surface temperature using the dump method to show properties of all constructs:
35+
36+
temp.dump()
37+
38+
# %%
39+
# 6. Latitude and longitude dimension coordinate cell bounds are absent, which are created and set:
40+
41+
a = lat.create_bounds()
42+
lat.set_bounds(a)
43+
lat.dump()
44+
45+
# %%
46+
47+
b = lon.create_bounds()
48+
lon.set_bounds(b)
49+
lon.dump()
50+
51+
# %%
52+
53+
print(b.array)
54+
55+
# %%
56+
# 7. Time dimension coordinate cell bounds are similarly created and set for cell sizes of one calendar month:
57+
58+
time = temp.coordinate("long_name=time")
59+
c = time.create_bounds(cellsize=cf.M())
60+
time.set_bounds(c)
61+
time.dump()
62+
63+
# %%
64+
# 8. Calculate and plot the area weighted mean surface temperature for each time:
65+
66+
global_avg = temp.collapse("area: mean", weights=True)
67+
cfp.lineplot(global_avg, color="red", title="Global mean surface temperature")
68+
69+
# %%
70+
# 9. Calculate and plot the annual global mean surface temperature:
71+
72+
annual_global_avg = global_avg.collapse("T: mean", group=cf.Y())
73+
cfp.lineplot(
74+
annual_global_avg,
75+
color="red",
76+
title="Annual global mean surface temperature",
77+
)

0 commit comments

Comments
 (0)