|
1 | 1 | """
|
2 |
| -Recipe 1: Calculating and Plotting Seasonal Mean Pressure at Mean Sea Level |
| 2 | +Calculate and plotting per-season trends in global sea surface extrema |
| 3 | +====================================================================== |
3 | 4 |
|
4 |
| -Objective: Calculate and plot the seasonal mean pressure at mean sea level |
5 |
| -from ensemble simulation data for 1941. |
| 5 | +In this recipe we find the area-based extrema of global sea surface |
| 6 | +temperature per month and, because it is very difficult to |
| 7 | +interpret for trends when in a monthly form, we calculate and plot |
| 8 | +on top of this the mean across each season for both the minima and the |
| 9 | +maxima. |
6 | 10 | """
|
7 | 11 |
|
| 12 | +# %% |
| 13 | +# 1. Import cf-python, cf-plot and other required packages: |
8 | 14 | import cfplot as cfp
|
9 | 15 | import matplotlib.pyplot as plt
|
10 | 16 |
|
11 | 17 | import cf
|
12 | 18 |
|
13 |
| -# 1. Load the dataset |
| 19 | +# %% |
| 20 | +# 2. Read the dataset in extract the SST Field from the FieldList: |
14 | 21 | f = cf.read("~/recipes_break/ERA5_monthly_averaged_SST.nc")
|
15 |
| -sst = f[0] # Select the SST variable |
| 22 | +sst = f[0] |
16 | 23 |
|
17 |
| -# Collapse data by area mean (average over spatial dimensions) |
18 |
| -am_max = sst.collapse("area: maximum") # equivalent to "X Y: mean" |
19 |
| -am_min = sst.collapse("area: minimum") |
| 24 | +# %% |
| 25 | +# 3. Collapse data by area extrema (average over spatial dimensions): |
| 26 | +am_max = sst.collapse("area: maximum") # equivalent to "X Y: maximum" |
| 27 | +am_min = sst.collapse("area: minimum") # equivalent to "X Y: minimum" |
20 | 28 |
|
21 |
| -# Reduce all timeseries down to just 1980+ since there are some data |
22 |
| -# quality issues before 1970 |
| 29 | +# %% |
| 30 | +# 4. Reduce all timeseries down to just 1980+ since there are some data |
| 31 | +# quality issues before 1970 and also this window is about perfect size |
| 32 | +# for viewing the trends without the line plot becoming too cluttered: |
23 | 33 | am_max = am_max.subspace(T=cf.ge(cf.dt("1980-01-01")))
|
24 | 34 | am_min = am_min.subspace(T=cf.ge(cf.dt("1980-01-01")))
|
25 | 35 |
|
26 |
| -# TODO COMMENT |
| 36 | +# %% |
| 37 | +# 5. Create a mapping which provides the queries we need to collapse on |
| 38 | +# the four seasons, along with our description of them, as a value, with |
| 39 | +# the key of the string encoding the colour we want to plot these |
| 40 | +# trendlines in. This structure will be iterated over to make our plot: |
27 | 41 | colours_seasons_map = {
|
28 | 42 | "red": (cf.mam(), "Mean across MAM: March, April and May"),
|
29 | 43 | "blue": (cf.jja(), "Mean across JJA: June, July and August"),
|
30 | 44 | "green": (cf.son(), "Mean across SON: September, October and November"),
|
31 | 45 | "purple": (cf.djf(), "Mean across DJF: December, January and February"),
|
32 | 46 | }
|
33 | 47 |
|
| 48 | +# %% |
| 49 | +# 6. Create and open the plot file: |
34 | 50 | cfp.gopen(
|
35 | 51 | rows=2, columns=1, bottom=0.1, top=0.85, file="global_avg_sst_plot.png"
|
36 | 52 | )
|
37 | 53 |
|
38 |
| -# Put maxima subplot at top since these values are higher, given |
39 |
| -# increasing x axis |
| 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 |
| 57 | +# allow space so the legend doesn't overlap the data, which isn't |
| 58 | +# possible purely from positioning it anywhere within the default plot. |
| 59 | +# Otherwise cf-plot handles this for us. To plot the per-season means |
| 60 | +# of the maxima, we loop through the season query mapping and do a |
| 61 | +# "T: mean" collapse setting the season as the grouping: |
40 | 62 | cfp.gpos(1)
|
41 |
| -plt.suptitle( |
42 |
| - "Global Average Sea Surface Temperature monthly minima\nand maxima " |
43 |
| - "including seasonal means of these extrema", |
44 |
| - fontsize=18, |
45 |
| -) |
46 |
| -# Set limits manually only to allow space so the legend doesn't overlap the |
47 |
| -# data, which isn't possible purely from positioning it anywhere |
48 | 63 | cfp.gset(xmin="1980-01-01", xmax="2022-12-01", ymin=304, ymax=312)
|
49 | 64 | for colour, season_query in colours_seasons_map.items():
|
50 | 65 | query_on_season, season_description = season_query
|
|
64 | 79 | label="All months",
|
65 | 80 | )
|
66 | 81 |
|
67 |
| -# Minima subplot below the maxima one |
| 82 | +# %% |
| 83 | +# 8. Create and add minima subplot below the maxima one. Just like for the |
| 84 | +# 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: |
68 | 86 | cfp.gpos(2)
|
69 | 87 | cfp.gset(xmin="1980-01-01", xmax="2022-12-01", ymin=269, ymax=272)
|
70 | 88 | for colour, season_query in colours_seasons_map.items():
|
|
83 | 101 | color="grey",
|
84 | 102 | )
|
85 | 103 |
|
| 104 | +# %% |
| 105 | +# 9. Add an overall title to the plot and close the file to save it: |
| 106 | +plt.suptitle( |
| 107 | + "Global Average Sea Surface Temperature monthly minima\nand maxima " |
| 108 | + "including seasonal means of these extrema", |
| 109 | + fontsize=18, |
| 110 | +) |
86 | 111 | cfp.gclose()
|
0 commit comments