Skip to content

Commit 3fabd23

Browse files
Merge pull request #861 from sadielbartholomew/recipes-updates-for-build
Recipes tweaks for Sphinx Gallery build and rendering
2 parents 76e4612 + a74fe8b commit 3fabd23

File tree

7 files changed

+51
-49
lines changed

7 files changed

+51
-49
lines changed

docs/source/recipes/plot_04_recipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# %%
1414
# 2. Read the field constructs:
1515

16-
obs = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc", chunks=None)
16+
obs = cf.read("~/recipes/cru_ts4.06.1901.2021.tmp.dat.nc", dask_chunks=None)
1717
print(obs)
1818

1919
# %%

docs/source/recipes/plot_16_recipe.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@
1919
f = cf.read("~/recipes/ggap.nc")[0]
2020

2121
# %%
22-
# 3. Create the file with subplots. If changing the number of subplots,
23-
# ensure the number of rows * number of columns = the number of projections.
24-
# Here we are doing 6 projections so 2 x 3 is fine:
25-
cfp.gopen(rows=2, columns=3, bottom=0.2, file="projections.png")
26-
27-
# %%
28-
# 4. List the projection types to use. Here we are using
22+
# 3. List the projection types to use. Here we are using
2923
# Cylindrical/Default, North Pole Stereographic, South Pole Stereographic,
3024
# Mollweide, Mercator and Robinson. However there are several other choices
3125
# possible, see:
@@ -34,7 +28,11 @@
3428
projtypes = ["cyl", "npstere", "spstere", "moll", "merc", "robin"]
3529

3630
# %%
37-
# 5. Loop through the list of projection types and plot each as a sub-plot:
31+
# 4. Create the file with subplots. If changing the number of subplots,
32+
# ensure the number of rows * number of columns = the number of projections.
33+
# Here we are doing 6 projections so 2 x 3 is fine. Then loop through the
34+
# list of projection types and plot each as a sub-plot:
35+
cfp.gopen(rows=2, columns=3, bottom=0.2, file="projections.png")
3836
for i, proj in enumerate(projtypes):
3937
# gpos has 1 added to the index because it takes 1 as its first value
4038
cfp.gpos(i + 1)

docs/source/recipes/plot_17_recipe.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@
6666

6767
# %%
6868
# 5. Create the figure and give it an overall title. Ensure the
69-
# number of rows * number of columns = number of colour scales:
69+
# number of rows * number of columns = number of colour scales.
70+
# Then we loop through all the different colour maps defined and plot
71+
# as subplots, with each category in the same column, labelling each column
72+
# with the colour scale category:
7073
cfp.gopen(rows=3, columns=3, bottom=0.1, top=0.85)
7174
plt.suptitle(
7275
(
@@ -75,11 +78,6 @@
7578
),
7679
fontsize=18,
7780
)
78-
79-
# %%
80-
# 6. We loop through all the different colour maps defined and plot
81-
# as subplots, with each category in the same column, labelling each column
82-
# with the colour scale category:
8381
for i, colour_scale in enumerate(colour_scales_columns):
8482
cfp.gpos(i + 1)
8583
cfp.cscale(colour_scale)
@@ -108,5 +106,4 @@
108106
colorbar_thick=0.02,
109107
colorbar_fontsize=11,
110108
)
111-
112-
cfp.gclose(view=True)
109+
cfp.gclose()

docs/source/recipes/plot_18_recipe.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,4 @@
141141
colorbar_drawedges=False,
142142
**label_info,
143143
)
144-
145144
cfp.gclose()

docs/source/recipes/plot_19_recipe.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,17 @@
4646
}
4747

4848
# %%
49-
# 6. Create and open the plot file:
50-
cfp.gopen(
51-
rows=2, columns=1, bottom=0.1, top=0.85, file="global_avg_sst_plot.png"
52-
)
53-
54-
# %%
55-
# 7. Put maxima subplot at top since these values are higher, given
56-
# increasing x axis. Note we set limits manually with 'gset' only to
49+
# 6. Create and open the plot file. Put maxima subplot at top since these
50+
# values are higher, given increasing x axis.
51+
# Note we set limits manually with 'gset' only to
5752
# allow space so the legend doesn't overlap the data, which isn't
5853
# possible purely from positioning it anywhere within the default plot.
5954
# Otherwise cf-plot handles this for us. To plot the per-season means
6055
# of the maxima, we loop through the season query mapping and do a
6156
# "T: mean" collapse setting the season as the grouping:
57+
cfp.gopen(
58+
rows=2, columns=1, bottom=0.1, top=0.85, file="global_avg_sst_plot.png"
59+
)
6260
cfp.gpos(1)
6361
cfp.gset(xmin="1980-01-01", xmax="2022-12-01", ymin=304, ymax=312)
6462
for colour, season_query in colours_seasons_mapping.items():
@@ -78,11 +76,9 @@
7876
xlabel="",
7977
label="All months",
8078
)
81-
82-
# %%
83-
# 8. Create and add minima subplot below the maxima one. Just like for the
79+
# Create and add minima subplot below the maxima one. Just like for the
8480
# maxima case, we plot per-season means by looping through the season query
85-
# mapping and doing a "T: mean" collapse setting the season as the grouping:
81+
# mapping and doing a "T: mean" collapse setting the season as the grouping
8682
cfp.gpos(2)
8783
cfp.gset(xmin="1980-01-01", xmax="2022-12-01", ymin=269, ymax=272)
8884
for colour, season_query in colours_seasons_mapping.items():
@@ -100,9 +96,7 @@
10096
am_min,
10197
color="grey",
10298
)
103-
104-
# %%
105-
# 9. Add an overall title to the plot and close the file to save it:
99+
# Add an overall title to the plot and close the file to save it
106100
plt.suptitle(
107101
"Global mean sea surface temperature (SST) monthly\nminima and maxima "
108102
"showing seasonal means of these extrema",

docs/source/recipes/plot_20_recipe.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,22 @@
6868
div = cf.div_xy(u_2, v_2, radius="earth")
6969

7070
# %%
71-
# 8. Generate the final plot. First we configure the overall plot by
71+
# 8. First we configure the overall plot by
7272
# making the map higher resolution, to show the coastlines of the UK and
7373
# Ireland in greater detail, and changing the colourmap to better reflect
7474
# the data which can be positive or negative, i.e. has 0 as the 'middle'
75-
# value of significance, so should use a diverging colour map. Then we
76-
# plot the current vectors, noting we had to play around with the 'stride'
77-
# and 'scale' parameter values to adjust the vector spacing and size so that
78-
# the vector field is best represented and visible without over-cluttering
79-
# the plot. Finally we plot the divergence as a contour plot without any
80-
# lines showing. This compound plot is saved on one canvas using 'gopen'
81-
# and 'gclose' to wrap the two plotting calls:
75+
# value of significance, so should use a diverging colour map.
8276
cfp.mapset(resolution="10m")
8377
cfp.cscale("ncl_default")
78+
79+
# %%
80+
# 9. Now generate the final plot. Plot the current vectors, noting we had
81+
# to play around with the 'stride' and 'scale' parameter values to adjust
82+
# the vector spacing and size so that the vector field is best represented
83+
# and visible without over-cluttering the plot. Finally we plot the
84+
# divergence as a contour plot without any lines showing. This compound
85+
# plot is saved on one canvas using 'gopen' and 'gclose' to wrap the two
86+
# plotting calls:
8487
cfp.gopen(
8588
file=f"irish-sea-currents-divergence-{chosen_time.replace(' ', '-')}.png"
8689
)

release_docs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ elif [[ $1 = "dev" ]] ; then
2929
elif [[ $1 = "dev-clean" ]] ; then
3030
# For testing: creates separate dir and does not (git) commit and
3131
# also deletes an existing .doctrees subdirectory
32-
dir=$PWD/docs/dev
32+
dir=$PWD/docs/dev
3333
elif [[ $1 = "dev-scrub" ]] ; then
3434
# For testing: creates separate dir and does not (git) commit and
3535
# also completely deletes the new target directory.
@@ -38,10 +38,15 @@ elif [[ $1 = "dev-scrub" ]] ; then
3838
elif [[ $1 = "dev-recipes" ]] ; then
3939
# For testing: similar to dev, but specifically for generating recipes.
4040
dir=$PWD/docs/dev
41+
elif [[ $1 = "dev-recipes-scrub" ]] ; then
42+
# For testing: similar to dev, but specifically for generating recipes,
43+
# but cleaning any generated recipe files and gen'd dev dir first.
44+
dir=$PWD/docs/dev
45+
rm -fr $dir
4146
else
4247
set +x
4348
echo "\$1 must be one of 'dev', 'dev-clean', 'dev-scrub', 'latest', 'archive',
44-
or 'dev-recipes'"
49+
'dev-recipes' or 'dev-recipes-scrub'"
4550
exit 2
4651
fi
4752

@@ -76,6 +81,13 @@ mkdir -p $dir/_downloads
7681
# # Force recreation of recipes
7782
# rm source/recipes/*.md5
7883
#fi
84+
if [[ $1 = "dev-recipes-scrub" ]] ; then
85+
# Force recreation of recipes
86+
rm source/recipes/*.md5
87+
rm source/recipes/*.ipynb
88+
rm source/recipes/*_codeobj.pickle
89+
rm source/recipes/*_recipe.rst
90+
fi
7991

8092
export CF_DOCS_MODE=$1
8193

@@ -164,11 +176,11 @@ if [[ $1 = "latest" ]] ; then
164176
cd $dir
165177
git add \
166178
*.html \
167-
class/*.html \
168-
function/*.html \
169-
method/*.html \
170-
attribute/*.html \
171-
recipes/*.html \
179+
class/*.html \
180+
function/*.html \
181+
method/*.html \
182+
attribute/*.html \
183+
recipes/*.html \
172184
*.inv \
173185
*.js \
174186
_static \
@@ -185,4 +197,3 @@ fi
185197
set +x
186198

187199
echo PYTHONPATH=$PYTHONPATH
188-

0 commit comments

Comments
 (0)