{ "cells": [ { "cell_type": "markdown", "id": "3dbc19fd-54c4-467a-9b0f-07160387c37b", "metadata": {}, "source": [ "# **EVALUATING STORM'S PERFORMANCE** #\n", "\n", "#### Objectives: ####\n", "+ Evaluate the performance of STORM rainfall fields\n", "+ More recipes for awesome spatial plotting via [Xarray](https://docs.xarray.dev/en/stable/)\n", "\n", "---" ] }, { "cell_type": "markdown", "id": "4641498d-47c4-4958-aa29-04c2c26ad98a", "metadata": {}, "source": [ "Let's see how well/bad STORM captures/simulates seasonal rainfall; and how far off the current parameterization is.\n", "\n", "---" ] }, { "cell_type": "markdown", "id": "88325985-5589-46e2-99b2-d700883fdd2e", "metadata": {}, "source": [ "## ONE SIMULATED-SEASON $\\to$ CLUSTERS $\\equiv$ 1 ##" ] }, { "cell_type": "code", "execution_count": 3, "id": "cbf1fe78-f8d8-4915-ac2a-ef75facddd8e", "metadata": {}, "outputs": [], "source": [ "# loading libraries\n", "import cmaps # -> nice color-palettes\n", "import geopandas as gpd\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "import rioxarray as rio\n", "import xarray as xr\n", "from cmcrameri import cm as cmc\n", "from rasterio.enums import Resampling" ] }, { "cell_type": "markdown", "id": "6ddc8654-4be3-4380-b64c-9b51ecaa282b", "metadata": {}, "source": [ "Start by reading the output produced by STORM.\n", "\n", "STORM exports its outputs to the folder [**model_output**](../model_output).\n", "\n", "*Note: The exercise carried out here is for a (simulated) MAM season.*" ] }, { "cell_type": "code", "execution_count": 5, "id": "2ebcacdd-88b1-4fd3-aa71-d633a93a2def", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.DataArray 'year_2023' (time_001: 3515, y: 470, x: 408)>\n",
"array([[[0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" ...,\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.]],\n",
"\n",
" [[0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" ...,\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.]],\n",
"\n",
" [[0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" ...,\n",
"...\n",
" ...,\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.]],\n",
"\n",
" [[0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" ...,\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.]],\n",
"\n",
" [[0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" ...,\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.]]], dtype=float32)\n",
"Coordinates:\n",
" projection_y_coordinate (y) int32 1167500 1162500 ... -1172500 -1177500\n",
" projection_x_coordinate (x) int32 1342500 1347500 ... 3372500 3377500\n",
" * time_001 (time_001) object 2023-03-01 02:30:00 ... 10136-...\n",
" * y (y) int32 1167500 1162500 ... -1172500 -1177500\n",
" * x (x) int32 1342500 1347500 ... 3372500 3377500\n",
"Attributes:\n",
" precision: 0.002\n",
" units: mm\n",
" long_name: rainfall\n",
" grid_mapping: spatial_ref<xarray.DataArray 'k_means' (y: 470, x: 408)>\n",
"array([[nan, nan, nan, ..., nan, nan, nan],\n",
" [nan, nan, nan, ..., nan, nan, nan],\n",
" [nan, nan, nan, ..., nan, nan, nan],\n",
" ...,\n",
" [nan, nan, nan, ..., nan, nan, nan],\n",
" [nan, nan, nan, ..., nan, nan, nan],\n",
" [nan, nan, nan, ..., nan, nan, nan]], dtype=float32)\n",
"Coordinates:\n",
" projection_y_coordinate (y) int32 1167500 1162500 ... -1172500 -1177500\n",
" projection_x_coordinate (x) int32 1342500 1347500 ... 3372500 3377500\n",
" * y (y) int32 1167500 1162500 ... -1172500 -1177500\n",
" * x (x) int32 1342500 1347500 ... 3372500 3377500\n",
"Attributes:\n",
" grid_mapping: spatial_ref\n",
" long_name: k-means clusters\n",
" description: -1 indicates region out of any cluster<xarray.DataArray 'year_2023' (y: 470, x: 408)>\n",
"array([[0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" ...,\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.],\n",
" [0., 0., 0., ..., 0., 0., 0.]])\n",
"Coordinates:\n",
" projection_y_coordinate (y) int32 1167500 1162500 ... -1172500 -1177500\n",
" projection_x_coordinate (x) int32 1342500 1347500 ... 3372500 3377500\n",
" * y (y) int32 1167500 1162500 ... -1172500 -1177500\n",
" * x (x) int32 1342500 1347500 ... 3372500 3377500<xarray.DataArray 'year_2023' (y: 5, x: 5)>\n",
"array([[ 0. , 0. , 0. , 82.888, 54.052],\n",
" [ 77.368, 70.174, 72.594, 69.088, 85.746],\n",
" [106.796, 86.17 , 95.222, 91.568, 89.474],\n",
" [ 99.708, 111.044, 153.232, 109.89 , 106.454],\n",
" [120.286, 131.718, 125.342, 121.31 , 110.068]])\n",
"Coordinates:\n",
" projection_y_coordinate (y) int32 1157500 1152500 1147500 1142500 1137500\n",
" projection_x_coordinate (x) int32 2142500 2147500 2152500 2157500 2162500\n",
" * y (y) int32 1157500 1152500 1147500 1142500 1137500\n",
" * x (x) int32 2142500 2147500 2152500 2157500 2162500| \n", " | k | \n", "mean_in | \n", "mean_out | \n", "mean_xtra | \n", "mean_nc4 | \n", "
|---|---|---|---|---|---|
| 0 | \n", "0 | \n", "237.76195 | \n", "237.806487 | \n", "237.804079 | \n", "237.8040790794155 | \n", "
| \n", " | k | \n", "mean_nc4 | \n", "
|---|---|---|
| 0 | \n", "0 | \n", "585.1801125876708 | \n", "
| 1 | \n", "1 | \n", "234.3012125775295 | \n", "
| 2 | \n", "2 | \n", "123.34646416649124 | \n", "
| 3 | \n", "3 | \n", "375.2105049615562 | \n", "
| \n", " | k | \n", "mean_in | \n", "mean_out | \n", "mean_xtra | \n", "
|---|---|---|---|---|
| 0 | \n", "0 | \n", "122.20316 | \n", "123.01343482432205 | \n", "122.84915667218301 | \n", "
| 1 | \n", "1 | \n", "374.7068 | \n", "374.86894913237956 | \n", "374.7010015098805 | \n", "
| 2 | \n", "2 | \n", "582.65515 | \n", "582.956113011005 | \n", "582.7885422042028 | \n", "
| 3 | \n", "3 | \n", "234.15459 | \n", "234.3431215911475 | \n", "234.178792987438 | \n", "
| 4 | \n", "k | \n", "mean_in | \n", "mean_out | \n", "mean_xtra | \n", "
| 5 | \n", "0 | \n", "582.8078 | \n", "585.1803500996468 | \n", "584.8981125876714 | \n", "
| 6 | \n", "1 | \n", "234.23451 | \n", "234.303528511481 | \n", "234.02055815101698 | \n", "
| 7 | \n", "2 | \n", "122.230225 | \n", "123.34755948793945 | \n", "123.06533824546656 | \n", "
| 8 | \n", "3 | \n", "374.87192 | \n", "375.2136687682176 | \n", "374.93388460274764 | \n", "
| \n", " | k | \n", "mean_in | \n", "mean_out | \n", "mean_xtra | \n", "mean_nc4 | \n", "
|---|---|---|---|---|---|
| 0 | \n", "0 | \n", "582.8078 | \n", "585.1803500996468 | \n", "584.8981125876714 | \n", "585.1801125876708 | \n", "
| 1 | \n", "1 | \n", "234.23451 | \n", "234.303528511481 | \n", "234.02055815101698 | \n", "234.3012125775295 | \n", "
| 2 | \n", "2 | \n", "122.230225 | \n", "123.34755948793945 | \n", "123.06533824546656 | \n", "123.34646416649124 | \n", "
| 3 | \n", "3 | \n", "374.87192 | \n", "375.2136687682176 | \n", "374.93388460274764 | \n", "375.2105049615562 | \n", "
<xarray.Dataset>\n",
"Dimensions: (x: 408, y: 470)\n",
"Coordinates:\n",
" * x (x) float64 1.342e+06 1.348e+06 1.352e+06 ... 3.372e+06 3.378e+06\n",
" * y (y) float64 1.168e+06 1.162e+06 ... -1.172e+06 -1.178e+06\n",
" xomethin int64 0\n",
"Data variables:\n",
" rain (y, x) float32 8.853 12.19 12.01 14.22 ... 527.5 527.5 526.5 526.5\n",
" mask (y, x) uint8 1 1 1 1 1 1 1 1 1 1 1 1 1 ... 0 0 0 0 0 0 0 0 0 0 0 0