Skip to content

Commit 67d253b

Browse files
Simplify code given revised proj choices in NH original recipe 16
1 parent 26e6c4e commit 67d253b

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

docs/source/recipes/plot_16_recipe.py

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,32 @@
1717

1818
# %%
1919
# 2. Read the field in:
20-
# Here I've used sample data ggap.nc (and later pressure=850),
21-
# but you could use tas_A1.nc (with time=15)
2220
PATH = "~/git-repos/cf-plot/cfplot/test/cfplot_data"
2321
f = cf.read(f"{PATH}/ggap.nc")[0]
2422

2523
# %%
26-
# 3. Create the file with subplots:
27-
# If you are changing the number of subplots ensure the number of
28-
# rows * number of columns = the number of subplots/projections
29-
# Here we are doing 6 projections so 2x3 is fine
24+
# 3. Create the file with subplots. If changing the number of subplots,
25+
# ensure the number of rows * number of columns = the number of projections.
26+
# Here we are doing 6 projections so 2 x 3 is fine:
3027
cfp.gopen(rows=2, columns=3, bottom=0.2, file="projections.png")
3128

3229
# %%
33-
# 4. List the projection types being used:
34-
# Here we are using Cylindrical/Default, North Pole Stereographic,
35-
# South Pole Stereographic, Mollweide, Cropped Lambert Conformal
36-
# and Robinson.
37-
# However you could also use other such as "rotated", "ortho" or
38-
# "merc", "ukcp", "osgb", or "EuroPP"
39-
# https://ncas-cms.github.io/cf-plot/build/user_guide.html#appendixc
40-
# TODO SB update second 'cyl' to 'lcc', replaced for now due to possible bug,
41-
# see: https://github.com/NCAS-CMS/cf-plot/issues/75
42-
projtypes = ["cyl", "npstere", "spstere", "moll", "cyl", "robin"]
30+
# 4. List the projection types to use. Here we are using
31+
# Cylindrical/Default, North Pole Stereographic, South Pole Stereographic,
32+
# Mollweide, Mercator and Robinson. However there are several other choices
33+
# possible, see:
34+
# https://ncas-cms.github.io/cf-plot/build/user_guide.html#appendixc. Our
35+
# chosen list is:
36+
projtypes = ["cyl", "npstere", "spstere", "moll", "merc", "robin"]
4337

4438
# %%
45-
# 5. We then use a for loop to cycle through all the different projection
46-
# types:
47-
# Only gpos has 1 added because it can only take 1 as its first value,
48-
# otherwise there are
49-
# errors. There are if statements for some projections (lcc, OSGB and
50-
# EuroPP) as they have
51-
# specific requirements for their contour.
52-
# However, OSGB and EuroPP will require very different data anyway.
39+
# 5. Loop through the list of projection types and plot each as a sub-plot:
5340
for i, proj in enumerate(projtypes):
41+
# gpos has 1 added to the index because it takes 1 as its first value
5442
cfp.gpos(i + 1)
55-
if proj == "lcc":
56-
cfp.mapset(proj="lcc", lonmin=-50, lonmax=50, latmin=20, latmax=85)
57-
if proj in ("OSGB", "EuroPP"):
58-
cfp.mapset(proj=proj, resolution="50m")
59-
else:
60-
cfp.mapset(proj=proj)
43+
cfp.mapset(proj=proj)
44+
45+
# For the final plot only, add a colour bar to cover all the sub-plots
6146
if i == len(projtypes) - 1:
6247
cfp.con(
6348
f.subspace(pressure=850),
@@ -66,8 +51,6 @@
6651
colorbar_position=[0.1, 0.1, 0.8, 0.02],
6752
colorbar_orientation="horizontal",
6853
)
69-
# to see the marking lines need to be True, but this can be
70-
# hard to read so if not needed use False
7154
else:
7255
cfp.con(
7356
f.subspace(pressure=850),

0 commit comments

Comments
 (0)