diff --git a/examples/nblibrary/rof/global_discharge_gauge_compare_obs.ipynb b/examples/nblibrary/rof/global_discharge_gauge_compare_obs.ipynb index 1bdcc54..6c8d951 100644 --- a/examples/nblibrary/rof/global_discharge_gauge_compare_obs.ipynb +++ b/examples/nblibrary/rof/global_discharge_gauge_compare_obs.ipynb @@ -10,38 +10,38 @@ "tags": [] }, "source": [ - "## NB1. ROF global monthly, annual, seasonal flows analysis \n", + "## ROF global monthly, annual, seasonal flows analysis \n", "\n", - "Use \n", + "Use the following datasets\n", "\n", "1. reach-D19 gauge link ascii\n", "2. D19 flow site geopackage\n", "3. D19 discharge netCDF\n", - "4. monthly and yearly flow netCD (history file)\n", + "4. history netCD including river discharge\n", "\n", "[1. Setupt](#setup)\n", "\n", "[2. Loading data](#load_data)\n", "\n", - "- monthly history files (directory from CESM or postprocessed) from archive. \n", - "\n", - "- Reference data is monthly discharge estimates at 922 big river mouths from Dai et al. 2019 data (D19)\n", + "- Read monthly history files from archive. \n", + "- Reference data: monthly discharge estimates at 922 big river mouths from Dai et al. 2019 data (D19)\n", "\n", "[3. Large 24 river analysis](#24_large_rivers)\n", "\n", - "- Plotting time seriese (annual, seasonal cycle) and scatter plots at Large 24 selected rivers with D19 referece data\n", + "- Plotting time seriese (annual, seasonal cycle).\n", + "- if D19 referece data is available, scatter plots at Large 24 selected rivers against D19 referece data\n", "\n", "[4. Large 50 rivers analysis](#50_large_rivers)\n", "\n", - "- Annual flow summary table at large 50 selected rivers. \n", + "- Annual flow summary table at large 50 selected rivers.\n", + "- if D19 referece data is available, Scatter plot of annual flow against D19 reference data.\n", "\n", "[5. 922 rivers analysis](#922_rivers)\n", "\n", - "- summary statistics (%bias, rmse, correlation) at all 922 river sites - map and boxplots.\n", - "\n", - "[6. basin area vs annual flow](#flow_diagnoisis)\n", - "\n", - "Moved this to another notebook" + "- run only if reference flow is available\n", + "- error statistics (%bias, rmse, correlation) at all 922 river sites.\n", + "- plot error statistic on the global map\n", + "- plot boxplots including case(s) for each error metric\n" ] }, { @@ -73,6 +73,7 @@ "from dask.distributed import Client, LocalCluster\n", "\n", "import scripts.colors as colors\n", + "import scripts.metrics as metric\n", "from scripts.utility import load_yaml\n", "from scripts.utility import no_time_variable\n", "\n", @@ -194,7 +195,7 @@ "source": [ "# Spin up cluster (if running in parallel)\n", "client = None\n", - "if serial:\n", + "if not serial:\n", " cluster = LocalCluster(**lc_kwargs)\n", " client = Client(cluster)\n", "\n", @@ -213,9 +214,9 @@ "metadata": {}, "source": [ "### 2.1. Monthly/annual flow netCDFs\n", - "- month_data (xr dataset)\n", - "- year_data (xr dataset)\n", - "- seas_data (xr dataset)" + "- month_data (xr dataset) - read from archive\n", + "- year_data (xr dataset) - computed from monthly\n", + "- seas_data (xr dataset) - computed from monthly" ] }, { @@ -386,13 +387,6 @@ "dr_q_obs_seasonal = ds_q_obs_mon.groupby(\"time.month\").mean(\"time\")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", "metadata": {}, @@ -971,14 +965,14 @@ "metadata": {}, "source": [ "------\n", - "## 3. Anaysis for all 922 sites " + "## 5. Anaysis for all 922 sites " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### 3.1 Compute metris at all the sites (no plots nor tables)" + "### 5.1 Compute metris at all the sites (no plots nor tables)" ] }, { @@ -1042,9 +1036,9 @@ " )\n", "\n", " # compute %bias, correlation, RMSE\n", - " bias[ix] = np.nanmean(q_sim - q_obs) / np.nanmean(q_obs) * 100.0\n", + " bias[ix] = metric.pbias(q_sim, q_obs)\n", " corr[ix] = np.corrcoef(q_sim, q_obs)[0, 1]\n", - " rmse[ix] = np.sqrt(np.mean((q_sim - q_obs) ** 2))\n", + " rmse[ix] = metric.rmse(qsim, qobs)\n", "\n", " mon_pbias[case] = bias\n", " mon_corr[case] = corr\n", @@ -1059,7 +1053,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 4.2. Spatial metric map " + "### 5.2. Spatial metric map " ] }, { @@ -1093,8 +1087,13 @@ " }\n", "\n", " meta = {\n", - " \"bias\": {\"name\": \"%bias\", \"vmin\": -100, \"vmax\": 100, \"cm\": colors.cmap11},\n", - " \"corr\": {\"name\": \"correlation\", \"vmin\": 0.2, \"vmax\": 1, \"cm\": colors.cmap12},\n", + " \"bias\": {\n", + " \"name\": \"%bias\",\n", + " \"vmin\": -100,\n", + " \"vmax\": 100,\n", + " \"cm\": colors.cmap_RedGrayBlue,\n", + " },\n", + " \"corr\": {\"name\": \"correlation\", \"vmin\": 0.2, \"vmax\": 1, \"cm\": colors.cmap_corr},\n", " \"rmse\": {\"name\": \"RMSE\", \"vmin\": 0, \"vmax\": 1000, \"cm\": mpl.cm.turbo},\n", " }\n", "\n", @@ -1133,7 +1132,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 4.3 Boxplots of Error metrics (RMSE, %bias, and correlation coefficient)\n", + "### 5.4 Boxplots of Error metrics (RMSE, %bias, and correlation coefficient)\n", "Boxplot distribution is based on metrics sampled at 922 sites.\n", "\n", "The box extends from the Q1 to Q3 quartile values of the data, with a line at the median (Q2). \n", diff --git a/examples/nblibrary/rof/global_discharge_ocean_compare_obs.ipynb b/examples/nblibrary/rof/global_discharge_ocean_compare_obs.ipynb index d08065e..8b24be6 100644 --- a/examples/nblibrary/rof/global_discharge_ocean_compare_obs.ipynb +++ b/examples/nblibrary/rof/global_discharge_ocean_compare_obs.ipynb @@ -10,9 +10,9 @@ "tags": [] }, "source": [ - "## NB2. ROF monthly, annual, seasonal discharge at ocean outlets \n", + "## ROF monthly, annual, seasonal discharge at ocean outlets \n", "\n", - "Use \n", + "Use the following datasets\n", "\n", "1. reach-D19 gauge link ascii\n", "2. D19 flow site geopackage\n", @@ -21,20 +21,20 @@ "\n", "[1. Setupt](#setup)\n", "\n", - "[2. Loading data](#load_data)\n", "\n", - "- monthly history files (directory from CESM or postprocessed) from archive. \n", + "[2. Loading discharge data](#load_discharge_data)\n", "\n", - "- Reference data is monthly discharge estimates at 922 big river mouths from Dai et al. 2019 data (D19)\n", + "- Read monthly history files from archive. \n", + "- Reference data: monthly discharge estimates at 922 big river mouths from Dai et al. 2019 data (D19)\n", "\n", - "[3. Read river, catchment, gauge information](#read_meta)\n", + "[3. Read river, catchment, gauge information](#read_ancillary)\n", "\n", "- catchment polygon (geopackage)\n", "- gauge point (geopackage)\n", "- gauge-catchment link (csv)\n", "- outlet reach information (netCDF) including discharging ocean names\n", "\n", - "[4. Ocean discharge line plots](#922_rivers)\n", + "[4. Ocean discharge line plots](#24_large_rivers)\n", "\n", "- total seasonal flow for oceans. \n" ] @@ -197,7 +197,7 @@ "source": [ "# Spin up cluster (if running in parallel)\n", "client = None\n", - "if serial:\n", + "if not serial:\n", " cluster = LocalCluster(**lc_kwargs)\n", " client = Client(cluster)\n", "\n", @@ -208,7 +208,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## 2. Loading data " + "## 2. Loading discharge data " ] }, { @@ -331,7 +331,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## 3. Reading river, catchment, gauge infomation \n", + "## 3. Reading river, catchment, gauge infomation \n", "\n", "- catchment polygon (geopackage)\n", "- gauge point (geopackage)\n", @@ -484,7 +484,7 @@ }, "source": [ "------\n", - "## 4. plot annual cycle for global oceans \n", + "## 3. plot annual cycle for global oceans \n", "\n", "TODO: Referece flow plot should be independent from cases (network). Currently the last case plotted looks better matched with reference flow. " ]