From b86886a0d7ec373061bba403d23bd403edd41381 Mon Sep 17 00:00:00 2001 From: Max Jones Date: Wed, 22 Jun 2022 22:24:06 -0400 Subject: [PATCH 1/2] Fix a few typos --- .../analysis/analyses_template.ipynb | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/cmip6_downscaling/analysis/analyses_template.ipynb b/cmip6_downscaling/analysis/analyses_template.ipynb index 7025564c..2a69a348 100644 --- a/cmip6_downscaling/analysis/analyses_template.ipynb +++ b/cmip6_downscaling/analysis/analyses_template.ipynb @@ -301,7 +301,7 @@ "metadata": {}, "outputs": [], "source": [ - "output_daily.sel(**seattle, method='nearest')[var]plot()" + "output_daily.sel(**seattle, method='nearest')[var].plot()" ] }, { @@ -312,12 +312,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()" ] }, @@ -552,10 +550,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'}" ] }, { @@ -577,7 +583,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", " )" ] @@ -599,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", " )" ] @@ -643,7 +649,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", " )" ] @@ -682,7 +688,7 @@ "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", @@ -690,7 +696,7 @@ " 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", " )" ] }, @@ -791,18 +797,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", + " )" ] }, { From 96adea5ab20402620bece2932095f8e6e5f9dacc Mon Sep 17 00:00:00 2001 From: Max Jones Date: Mon, 27 Jun 2022 15:14:27 -0400 Subject: [PATCH 2/2] Check validity of results zarr stores --- .../analysis/analyses_template.ipynb | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cmip6_downscaling/analysis/analyses_template.ipynb b/cmip6_downscaling/analysis/analyses_template.ipynb index 2a69a348..c21b6044 100644 --- a/cmip6_downscaling/analysis/analyses_template.ipynb +++ b/cmip6_downscaling/analysis/analyses_template.ipynb @@ -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", @@ -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",