From 2438a6b488c32509b65f495da10722f7ef34708b Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Sat, 17 Dec 2022 09:51:00 -0700 Subject: [PATCH] Comparison - SWI - Add Snow-17 outputs. Feedback from last round of reviews. --- comparison/Snobal-SWI_static.ipynb | 189 +++++++++++++++++++---------- 1 file changed, 126 insertions(+), 63 deletions(-) diff --git a/comparison/Snobal-SWI_static.ipynb b/comparison/Snobal-SWI_static.ipynb index 28fdba30..bc28ab95 100644 --- a/comparison/Snobal-SWI_static.ipynb +++ b/comparison/Snobal-SWI_static.ipynb @@ -11,6 +11,55 @@ "from common import *" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "2fdeb03f-e8c0-4262-a6c6-928385ebd1e2", + "metadata": {}, + "outputs": [], + "source": [ + "# Convert SNOBAL grid cell from meter to square feet\n", + "CELL_AREA = (50.0 * 3.28084)**2\n", + "# MM in one foot\n", + "MM_IN_FT = 304.8\n", + "# Convert to cubic feet\n", + "CELL_AREA_IN_MM = CELL_AREA / MM_IN_FT" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "79bf1112-48e2-445f-84eb-c527cbdfbada", + "metadata": {}, + "outputs": [], + "source": [ + "# Cubic feet to cubic meter\n", + "FT3_to_M3 = (MM_IN_FT/1000)**3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b2f86265-8c13-4b5f-8bb8-6e4bb26728f6", + "metadata": {}, + "outputs": [], + "source": [ + "wy2018 = dict(time=slice(\"2017-10-01\", \"2018-09-30\"))\n", + "wy2019 = dict(time=slice(\"2018-10-01\", \"2019-09-30\"))\n", + "wy2020 = dict(time=slice(\"2019-10-01\", \"2020-09-30\"))\n", + "wy2021 = dict(time=slice(\"2020-10-01\", \"2021-09-30\"))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "657177d4-54d8-499e-b7c6-1f9213629f4c", + "metadata": {}, + "outputs": [], + "source": [ + "zones = cbrfc_zones()" + ] + }, { "cell_type": "markdown", "id": "bbbf5165-787c-4078-a97d-e83b1cbe368a", @@ -38,7 +87,7 @@ { "cell_type": "code", "execution_count": null, - "id": "cef98708-11c7-4bff-a71c-c8e680fc85a2", + "id": "69101631-83b0-426c-9a39-839566358aac", "metadata": {}, "outputs": [], "source": [ @@ -57,41 +106,77 @@ " **PD_OPTIONS\n", ")\n", "\n", - "data.Discharge = data.Discharge * 60 * 60 * 24" + "data.Discharge = data.Discharge * 60 * 60 * 24 * FT3_to_M3" ] }, { "cell_type": "markdown", - "id": "bb52d74d-463a-4813-be1d-5ead2cfb66f4", + "id": "903647ff-2b1a-476b-886f-b47fd3340a9e", "metadata": {}, "source": [ - "## SNOBAL" + "Area average from iSnobal vs CSV" + ] + }, + { + "cell_type": "markdown", + "id": "64426da2-be7a-44be-afc0-10f8a862be47", + "metadata": {}, + "source": [ + "## CBRFC" ] }, { "cell_type": "code", "execution_count": null, - "id": "a9039ec9-e757-42fa-a4db-98482fe6d46c", + "id": "6db00201-bdf5-4308-9e1f-16516e74c7dd", "metadata": {}, "outputs": [], "source": [ - "client = start_cluster(5, 16)\n", - "client_ip_and_port(client)" + "PD_OPTIONS = dict(\n", + " comment='#',\n", + " parse_dates=True,\n", + " index_col=0,\n", + " names=['Date', 'SWE'],\n", + " header=0,\n", + " sep=',',\n", + " dtype={'Discharge': np.float64},\n", + ")\n", + "cbrfc_HLF = pd.read_csv(\n", + " CBRFC_DIR / 'SWI/ALEC2HLF.RAIM.MA.csv', \n", + " **PD_OPTIONS\n", + ")\n", + "cbrfc_HMF = pd.read_csv(\n", + " CBRFC_DIR / 'SWI/ALEC2HMF.RAIM.MA.csv', \n", + " **PD_OPTIONS\n", + ")\n", + "cbrfc_HUF = pd.read_csv(\n", + " CBRFC_DIR / 'SWI/ALEC2HUF.RAIM.MA.csv', \n", + " **PD_OPTIONS\n", + ")\n", + "cbrfc = cbrfc_HLF + cbrfc_HMF + cbrfc_HUF\n", + "cbrfc = cbrfc[\"2017-10-01\":\"2021-09-30\"]\n", + "cbrfc = (cbrfc.SWE * (INCH_TO_MM / 1000)) * (zones[zones != 0].size * 50**2)" + ] + }, + { + "cell_type": "markdown", + "id": "bb52d74d-463a-4813-be1d-5ead2cfb66f4", + "metadata": { + "tags": [] + }, + "source": [ + "## SNOBAL" ] }, { "cell_type": "code", "execution_count": null, - "id": "2fdeb03f-e8c0-4262-a6c6-928385ebd1e2", + "id": "a9039ec9-e757-42fa-a4db-98482fe6d46c", "metadata": {}, "outputs": [], "source": [ - "# Convert SNOBAL grid cell from meter to square feet\n", - "CELL_AREA = (50.0 * 3.28084)**2\n", - "# MM in one foot\n", - "FT_IN_MM = 304.8\n", - "# Convert to area\n", - "CELL_AREA_IN_MM = CELL_AREA / FT_IN_MM" + "client = start_cluster(8, 24)\n", + "client_ip_and_port(client)" ] }, { @@ -106,7 +191,7 @@ " data_vars=['SWI'],\n", " parallel=True,\n", ")\n", - "snobal_em.coords['mask'] = (('y', 'x'), cbrfc_zones())\n", + "snobal_em.coords['mask'] = (('y', 'x'), zones)\n", "snobal_em['time'] = snobal_em.time + np.timedelta64(2,'h')" ] }, @@ -118,7 +203,7 @@ "outputs": [], "source": [ "swi = (\n", - " snobal_em.where(snobal_em.mask != 0).SWI * CELL_AREA_IN_MM\n", + " (snobal_em.where(snobal_em.mask != 0).SWI / 1000) * 50**2\n", ").sum(['x', 'y']).compute()" ] }, @@ -132,22 +217,6 @@ "client.shutdown()" ] }, - { - "cell_type": "markdown", - "id": "e474c2ec-0647-4bac-aea6-1f8a7271841c", - "metadata": {}, - "source": [ - "### Calculate added/removed daily SWE " - ] - }, - { - "cell_type": "markdown", - "id": "c18a16bc-2735-48bb-becf-a1aba0fc2c08", - "metadata": {}, - "source": [ - "### SNOBAL " - ] - }, { "cell_type": "markdown", "id": "2be3f669-3a91-4929-bfda-df2429596a65", @@ -156,16 +225,6 @@ "### Moving 7-day average SNOBAL vs. USGS" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "de3cc2ee-b6e4-4adf-8c56-240476c73e3e", - "metadata": {}, - "outputs": [], - "source": [ - "x_axis_fmt = mdates.DateFormatter('%d-%b-%y')" - ] - }, { "cell_type": "code", "execution_count": null, @@ -173,37 +232,41 @@ "metadata": {}, "outputs": [], "source": [ - "plt.figure(dpi=300, figsize=(9,2.5))\n", + "figure = plt.figure(dpi=300, figsize=(10,3))\n", "ax = plt.gca()\n", "\n", - "swi.rolling(time=7, center=True).mean().plot(ax=ax, label='iSnobal Runoff', color='peru', alpha=0.7, lw=1)\n", - "data.rolling(7, center=True).mean().Discharge.plot(ax=ax, label='USGS Discharge', color='cadetblue', alpha=0.7, lw=1)\n", + "swi.rolling(time=7, center=True).mean().plot(ax=ax, label='HRRR-iSnobal SWI', color='peru', alpha=0.8, lw=1)\n", + "cbrfc.rolling(28, center=True).mean().plot(ax=ax, label='SNOW-17 SWI', color='olivedrab', alpha=0.8, lw=1.2, ls=(0, (5, 1)))\n", + "data.rolling(7, center=True).mean().Discharge.plot(ax=ax, label='Stream Discharge', color='cadetblue', alpha=0.8, lw=1)\n", + "\n", + "locator = mdates.AutoDateLocator(maxticks=20)\n", + "\n", + "ax.xaxis.set_major_locator(locator)\n", + "ax.xaxis.set_minor_locator(mdates.MonthLocator())\n", + "\n", + "formatter = mdates.ConciseDateFormatter(locator)\n", + "ax.xaxis.set_major_formatter(formatter)\n", "\n", - "ax.xaxis.set_major_formatter(x_axis_fmt)\n", - "ax.set_xlim(left=data.index.min(), right=data.index.max())\n", + "index = 0\n", + "for label in ax.get_xticklabels(which='major'):\n", + " label.set(rotation=0, horizontalalignment='center')\n", + " if index in [1, 5, 9, 13]:\n", + " label.set(fontstyle='italic', fontweight=600)\n", + " index += 1\n", + "\n", + "ax.set_xlim(left=data.index.min(), right=swi.time.max().values)\n", + "ax.set_ylim(bottom=-1000)\n", "ax.ticklabel_format(axis='y', useMathText=True)\n", "\n", - "plt.ylabel('7-Day Mean Output (mm)')\n", - "plt.legend();" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b2f86265-8c13-4b5f-8bb8-6e4bb26728f6", - "metadata": {}, - "outputs": [], - "source": [ - "wy2018 = dict(time=slice(\"2017-10-01\", \"2018-09-30\"))\n", - "wy2019 = dict(time=slice(\"2018-10-01\", \"2019-09-30\"))\n", - "wy2020 = dict(time=slice(\"2019-10-01\", \"2020-09-30\"))\n", - "wy2021 = dict(time=slice(\"2020-10-01\", \"2021-09-30\"))" + "plt.xlabel('')\n", + "plt.ylabel(r'Mean Volume ($\\frac{m^3}{7 \\ days}$)')\n", + "plt.legend(loc='upper center', ncol=3, bbox_to_anchor=(0.55, 1.14), frameon=False);" ] }, { "cell_type": "code", "execution_count": null, - "id": "a25a860b-cde2-42bd-b673-6cbacdb07636", + "id": "b673175f-6cd7-4eee-8853-e2c9f2455ac1", "metadata": {}, "outputs": [], "source": []