Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update analyses notebook #236

Merged
merged 2 commits into from
Jun 30, 2022
Merged
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
79 changes: 54 additions & 25 deletions cmip6_downscaling/analysis/analyses_template.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
") # , plot_each_step_bcsd\n",
"from cmip6_downscaling.analysis.qaqc import make_qaqc_ds\n",
"from cmip6_downscaling.methods.common.containers import BBox\n",
"from cmip6_downscaling.methods.common.utils import validate_zarr_store\n",
"import matplotlib.pyplot as plt\n",
"import cartopy.crs as ccrs\n",
"from carbonplan import styles\n",
Expand Down Expand Up @@ -207,6 +208,27 @@
"method = parameters['method']"
]
},
{
"cell_type": "markdown",
"id": "22bfaabb",
"metadata": {},
"source": [
"# Check that final zarr stores are valid¶\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6693897a",
"metadata": {},
"outputs": [],
"source": [
"for path in stores.values():\n",
" if 'flow-outputs/results' in path:\n",
" print(path)\n",
" validate_zarr_store(path)"
]
},
{
"cell_type": "markdown",
"id": "62e1930b-e0d9-4916-b0f1-61a7151761ed",
Expand Down Expand Up @@ -301,7 +323,7 @@
"metadata": {},
"outputs": [],
"source": [
"output_daily.sel(**seattle, method='nearest')[var]plot()"
"output_daily.sel(**seattle, method='nearest')[var].plot()"
]
},
{
Expand All @@ -312,12 +334,10 @@
"outputs": [],
"source": [
"fig, axarr = plt.subplots()\n",
"output_daily.sel(**seattle, method='nearest')[var]groupby('time.month').mean().plot(\n",
"output_daily.sel(**seattle, method='nearest')[var].groupby('time.month').mean().plot(\n",
" ax=axarr, label='downscaled'\n",
")\n",
"obs.sel(**seattle, method='nearest')[var]groupby('time.month').mean().plot(\n",
" ax=axarr, label='ERA5'\n",
")\n",
"obs.sel(**seattle, method='nearest')[var].groupby('time.month').mean().plot(ax=axarr, label='ERA5')\n",
"plt.legend()"
]
},
Expand Down Expand Up @@ -552,10 +572,18 @@
" },\n",
" 'over 30c': (0, 365),\n",
" 'over 40c': (0, 50),\n",
" }\n",
" },\n",
" 'pr': {\n",
" 'general': {\n",
" 'mean': (0, 10),\n",
" 'std': (0, 5),\n",
" 'percentile1': (0, 0.1),\n",
" 'percentile99': (10, 25),\n",
" }\n",
" },\n",
"}\n",
"diff_limits = {'tasmax': {'general': 5, 'over 30c': 50, 'over 40c': 25}}\n",
"diff_method = {'tasmax': 'absolute'}"
"diff_limits = {'tasmax': {'overall': 5, 'over 30c': 50, 'over 40c': 25}, 'pr': {'overall': 50}}\n",
"diff_method = {'tasmax': 'absolute', 'pr': 'percent'}"
]
},
{
Expand All @@ -577,7 +605,7 @@
" variable=var,\n",
" metric=metric,\n",
" var_limits=var_limits[var]['general'][metric],\n",
" diff_limit=diff_limits[var]['general'],\n",
" diff_limit=diff_limits[var]['overall'],\n",
" diff_method=diff_method[var],\n",
" )"
]
Expand All @@ -599,7 +627,7 @@
" variable=var,\n",
" metric=metric,\n",
" var_limits=var_limits[var]['general'][metric],\n",
" diff_limit=diff_limits[var]['general'],\n",
" diff_limit=diff_limits[var]['overall'],\n",
" diff_method=diff_method[var],\n",
" )"
]
Expand Down Expand Up @@ -643,7 +671,7 @@
" variable=var,\n",
" metric=metric,\n",
" var_limits=var_limits[var]['general'][metric],\n",
" diff_limit=diff_limits[var]['general'],\n",
" diff_limit=diff_limits[var]['overall'],\n",
" diff_method=diff_method[var],\n",
" )"
]
Expand Down Expand Up @@ -682,15 +710,15 @@
"metadata": {},
"outputs": [],
"source": [
"### if var == \"tasmax\":\n",
"if var == \"tasmax\":\n",
" plot_values_and_difference(\n",
" days_over_30c_era5[\"tasmax\"],\n",
" days_over_30c_ds[\"tasmax\"],\n",
" cbar_kwargs={\"label\": \"Days over 30C\"},\n",
" var_limits=var_limits[var]['over 30c'],\n",
" diff_limit=diff_limits[var]['over 30c'],\n",
" variable=var,\n",
" metric='daysover30'\n",
" metric='daysover30',\n",
" )"
]
},
Expand Down Expand Up @@ -791,18 +819,19 @@
"metadata": {},
"outputs": [],
"source": [
"for metric in gcm_change_cities:\n",
" plot_values_and_difference(\n",
" gcm_change_cities[metric],\n",
" downscaled_change_cities[metric],\n",
" gcm_change_cities,\n",
" city_coords=obs_cities,\n",
" title1=\"GCM change in {}\".format(metric),\n",
" title2=\"Downscaled change in {}\".format(metric),\n",
" title3=\"Difference downscaled-GCM\",\n",
" variable=var,\n",
" metric=metric,\n",
" )"
"if change_analyses:\n",
" for metric in gcm_change_cities:\n",
" plot_values_and_difference(\n",
" gcm_change_cities[metric],\n",
" downscaled_change_cities[metric],\n",
" gcm_change_cities,\n",
" city_coords=obs_cities,\n",
" title1=\"GCM change in {}\".format(metric),\n",
" title2=\"Downscaled change in {}\".format(metric),\n",
" title3=\"Difference downscaled-GCM\",\n",
" variable=var,\n",
" metric=metric,\n",
" )"
]
},
{
Expand Down