Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
299 changes: 187 additions & 112 deletions analysis/a00_seasonal_forecast_analysis.ipynb

Large diffs are not rendered by default.

525 changes: 341 additions & 184 deletions analysis/a01_august_seasonal_forecast_results.ipynb

Large diffs are not rendered by default.

64 changes: 35 additions & 29 deletions analysis/a03_systems_comp.ipynb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{

Check failure on line 1 in analysis/a03_systems_comp.ipynb

View workflow job for this annotation

GitHub Actions / test

ruff (F821)

analysis/a03_systems_comp.ipynb:1:1: F821 Undefined name `da_land_only`
"cells": [
{
"cell_type": "code",
Expand All @@ -19,17 +19,19 @@
"metadata": {},
"outputs": [],
"source": [
"centres = {'ecmwf': ['51'], \n",
" \"meteo_france\": ['9'], \n",
" 'ukmo': ['610'], \n",
" 'dwd': ['22'], \n",
" 'cmcc': ['4'], \n",
" 'ncep': ['2'], \n",
" 'jma': ['4'], \n",
" 'eccc': ['4','5'],\n",
" 'bom': ['2']}\n",
"centres = {\n",
" \"ecmwf\": [\"51\"],\n",
" \"meteo_france\": [\"9\"],\n",
" \"ukmo\": [\"610\"],\n",
" \"dwd\": [\"22\"],\n",
" \"cmcc\": [\"4\"],\n",
" \"ncep\": [\"2\"],\n",
" \"jma\": [\"4\"],\n",
" \"eccc\": [\"4\", \"5\"],\n",
" \"bom\": [\"2\"],\n",
"}\n",
"\n",
"region_sel = 'SAS'"
"region_sel = \"SAS\""
]
},
{
Expand All @@ -50,6 +52,7 @@
" \"fcstdev\": \"monthly_standard_deviation\",\n",
"}\n",
"\n",
"\n",
"def zip_to_datatree(zip_path, extract_dir):\n",
" with zipfile.ZipFile(zip_path) as z:\n",
" names = z.namelist()\n",
Expand All @@ -64,6 +67,7 @@
"\n",
" return xr.DataTree.from_dict(tree_dict)\n",
"\n",
"\n",
"def land_only(da):\n",
" land_mask = regionmask.defined_regions.natural_earth_v5_0_0.land_110.mask(da)\n",
" da_land_only = da.where(land_mask.notnull())\n",
Expand All @@ -80,10 +84,10 @@
"trees = {}\n",
"for centre, systems in centres.items():\n",
" for system in systems:\n",
" path = f'/home/emily_zuetell/projects/poreallas/scripts//data/raw/2607_{centre}_s{system}.nc'\n",
" path = f\"/home/emily_zuetell/projects/poreallas/scripts//data/raw/2607_{centre}_s{system}.nc\"\n",
" extract_dir = path.replace(\".nc\", \"_extracted\")\n",
"\n",
" var = f'{centre}_s{system}'\n",
" var = f\"{centre}_s{system}\"\n",
" trees[var] = zip_to_datatree(path, extract_dir)"
]
},
Expand All @@ -102,9 +106,11 @@
"metadata": {},
"outputs": [],
"source": [
"#TODO switch to xesmf\n",
"# TODO switch to xesmf\n",
"def regrid_to_target(da, target):\n",
" return da.interp(latitude=target.latitude, longitude=target.longitude, method=\"linear\")\n"
" return da.interp(\n",
" latitude=target.latitude, longitude=target.longitude, method=\"linear\"\n",
" )"
]
},
{
Expand Down Expand Up @@ -148,7 +154,7 @@
"metadata": {},
"outputs": [],
"source": [
"diff = combined_anomaly.sel(centre_system = 'ecmwf_s51')-combined_anomaly"
"diff = combined_anomaly.sel(centre_system=\"ecmwf_s51\") - combined_anomaly"
]
},
{
Expand All @@ -170,9 +176,8 @@
],
"source": [
"import cartopy.crs as ccrs\n",
"import matplotlib.pyplot as plt\n",
"\n",
"p = diff.sel(forecastMonth = 2).plot(\n",
"p = diff.sel(forecastMonth=2).plot(\n",
" col=\"centre_system\",\n",
" col_wrap=3,\n",
" vmin=-3,\n",
Expand All @@ -182,7 +187,7 @@
" subplot_kws={\"projection\": ccrs.PlateCarree()},\n",
" transform=ccrs.PlateCarree(),\n",
")\n",
"p.fig.suptitle('ForecastMonth = 2')\n",
"p.fig.suptitle(\"ForecastMonth = 2\")\n",
"for ax in p.axs.flat:\n",
" ax.coastlines()"
]
Expand All @@ -202,7 +207,7 @@
"metadata": {},
"outputs": [],
"source": [
"system_std = combined_anomaly.std('centre_system')"
"system_std = combined_anomaly.std(\"centre_system\")"
]
},
{
Expand Down Expand Up @@ -293,24 +298,25 @@
"outputs": [],
"source": [
"import pandas as pd\n",
"import regionmask\n",
"\n",
"# e.g. AR6 land regions\n",
"ar6_regions = regionmask.defined_regions.ar6.land\n",
"\n",
"\n",
"def select_region(da):\n",
" mask = ar6_regions.mask(da)\n",
" region_da = da.where(mask == ar6_regions.map_keys(region_sel))\n",
" return region_da\n",
"\n",
"\n",
"records = []\n",
"for centre_system, tree in trees.items(): # e.g. key = \"ecmwf_s51\"\n",
" da = tree[\"monthly_mean\"][\"t2m\"] \n",
" da = tree[\"monthly_mean\"][\"t2m\"]\n",
" da_hc = tree[\"hindcast_climate_mean\"][\"t2m\"]\n",
" #select region\n",
" # select region\n",
" da = select_region(da)\n",
" da_hc = select_region(da_hc)\n",
" df = (da-da_hc).to_dataframe().reset_index()\n",
" df = (da - da_hc).to_dataframe().reset_index()\n",
" df[\"centre_system\"] = centre_system\n",
" records.append(df[[\"centre_system\", \"forecastMonth\", \"t2m\"]])\n",
"\n",
Expand All @@ -328,11 +334,11 @@
"for centre_system, tree in trees.items():\n",
" da = tree[\"ensemble_mean\"][\"t2m\"]\n",
" da_hc = tree[\"hindcast_climate_mean\"][\"t2m\"]\n",
" #select region\n",
" # select region\n",
" da = select_region(da)\n",
" da_hc = select_region(da_hc)\n",
"\n",
" df = (da-da_hc).to_dataframe().reset_index()\n",
" df = (da - da_hc).to_dataframe().reset_index()\n",
" df[\"centre_system\"] = centre_system\n",
" records_em.append(df[[\"centre_system\", \"forecastMonth\", \"t2m\"]])\n",
"\n",
Expand Down Expand Up @@ -360,11 +366,11 @@
")\n",
"for ax, month in zip(g.axes.flat, g.col_names):\n",
" vals = em_df.loc[em_df[\"forecastMonth\"] == month, \"t2m\"]\n",
" #q1, med, q3 = vals.quantile([0.25, 0.5, 0.75])\n",
" #ax.axvspan(q1, q3, color=\"black\", alpha=0.15, zorder=10)\n",
" # q1, med, q3 = vals.quantile([0.25, 0.5, 0.75])\n",
" # ax.axvspan(q1, q3, color=\"black\", alpha=0.15, zorder=10)\n",
" ax.axvline(vals.mean(), color=\"black\", linewidth=1.5, zorder=11)\n",
" ax.set_xlabel('t2m anomaly')\n",
"g.fig.suptitle(f'T2M Anomaly: AR6 Region = {region_sel}', y=1.02)\n",
" ax.set_xlabel(\"t2m anomaly\")\n",
"g.fig.suptitle(f\"T2M Anomaly: AR6 Region = {region_sel}\", y=1.02)\n",
"g.fig"
]
},
Expand Down
Loading