Skip to content

Commit 645e9bd

Browse files
committed
add heatmap
1 parent a38da97 commit 645e9bd

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

notebooks/wp5/xch4_lev2_growth_rates.ipynb

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,17 @@
9494
"metadata": {},
9595
"outputs": [],
9696
"source": [
97-
"def weight_dataset(ds):\n",
98-
" weights = np.abs(np.cos(np.deg2rad(ds[\"latitude\"])))\n",
99-
" return ds.weighted(weights)\n",
97+
"def weight_dataset(obj):\n",
98+
" weights = np.abs(np.cos(np.deg2rad(obj[\"latitude\"])))\n",
99+
" return obj.weighted(weights)\n",
100100
"\n",
101101
"\n",
102-
"def spatial_weighted_mean(ds, dim=None):\n",
103-
" return weight_dataset(ds).mean(dim, keep_attrs=True)\n",
102+
"def spatial_weighted_mean(obj, dim=None):\n",
103+
" return weight_dataset(obj).mean(dim, keep_attrs=True)\n",
104104
"\n",
105105
"\n",
106-
"def spatial_weighted_std(ds, dim=None):\n",
107-
" return weight_dataset(ds).std(dim, keep_attrs=True)\n",
106+
"def spatial_weighted_std(obj, dim=None):\n",
107+
" return weight_dataset(obj).std(dim, keep_attrs=True)\n",
108108
"\n",
109109
"\n",
110110
"def regrid(ds, d_lon, d_lat, lon1=180):\n",
@@ -240,7 +240,7 @@
240240
"id": "15",
241241
"metadata": {},
242242
"source": [
243-
"## Plot yearly mean growth rate"
243+
"## Heat map"
244244
]
245245
},
246246
{
@@ -249,6 +249,30 @@
249249
"id": "16",
250250
"metadata": {},
251251
"outputs": [],
252+
"source": [
253+
"with xr.set_options(keep_attrs=True):\n",
254+
" anomaly = da - spatial_weighted_mean(da)\n",
255+
"anomaly.attrs[\"long_name\"] = \"Δ\" + anomaly.long_name\n",
256+
"facet = anomaly.plot(row=\"method\", robust=True, x=\"time\", figsize=(10, 10))\n",
257+
"for ax in facet.axs.flatten():\n",
258+
" for label in ax.get_xticklabels():\n",
259+
" label.set_rotation(90)"
260+
]
261+
},
262+
{
263+
"cell_type": "markdown",
264+
"id": "17",
265+
"metadata": {},
266+
"source": [
267+
"## Plot yearly mean growth rate"
268+
]
269+
},
270+
{
271+
"cell_type": "code",
272+
"execution_count": null,
273+
"id": "18",
274+
"metadata": {},
275+
"outputs": [],
252276
"source": [
253277
"grouped = da.groupby(\"time.year\")\n",
254278
"da_mean = grouped.map(spatial_weighted_mean, dim=[\"time\", \"latitude\"])\n",

0 commit comments

Comments
 (0)