Skip to content

Commit

Permalink
Modified code comments to say percent bias
Browse files Browse the repository at this point in the history
  • Loading branch information
Steph-Chong committed Sep 6, 2024
1 parent c11e9c4 commit 20ca208
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions tutorials/Additive_and_multiplicative_bias.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -38,7 +38,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -58,18 +58,18 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x111a03590>]"
"[<matplotlib.lines.Line2D at 0x158e0f980>]"
]
},
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -104,16 +104,16 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x111aa68a0>]"
"[<matplotlib.lines.Line2D at 0x15b3dda30>]"
]
},
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -149,7 +149,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -520,14 +520,14 @@
" fill: currentColor;\n",
"}\n",
"</style><pre class='xr-text-repr-fallback'>&lt;xarray.DataArray &#x27;multiplicative bias&#x27; ()&gt; Size: 8B\n",
"array(inf)</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'multiplicative bias'</div></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-fa0514ac-30d3-4869-b3a4-89a58207588c' class='xr-array-in' type='checkbox' checked><label for='section-fa0514ac-30d3-4869-b3a4-89a58207588c' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>inf</span></div><div class='xr-array-data'><pre>array(inf)</pre></div></div></li><li class='xr-section-item'><input id='section-57365353-19f0-4f7a-a90d-f0fde6391096' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-57365353-19f0-4f7a-a90d-f0fde6391096' class='xr-section-summary' title='Expand/collapse section'>Coordinates: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'></ul></div></li><li class='xr-section-item'><input id='section-3952de49-b26a-4304-a25a-a62b32da1ca9' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-3952de49-b26a-4304-a25a-a62b32da1ca9' class='xr-section-summary' title='Expand/collapse section'>Indexes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'></ul></div></li><li class='xr-section-item'><input id='section-b5c3371b-0cae-495d-b766-5861e7901ef4' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-b5c3371b-0cae-495d-b766-5861e7901ef4' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>"
"array(inf)</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'multiplicative bias'</div></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-7b566680-37cf-4298-be97-170883fcdcd4' class='xr-array-in' type='checkbox' checked><label for='section-7b566680-37cf-4298-be97-170883fcdcd4' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>inf</span></div><div class='xr-array-data'><pre>array(inf)</pre></div></div></li><li class='xr-section-item'><input id='section-07d52eea-6d09-46a5-a8cd-5cdec8ed66a4' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-07d52eea-6d09-46a5-a8cd-5cdec8ed66a4' class='xr-section-summary' title='Expand/collapse section'>Coordinates: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'></ul></div></li><li class='xr-section-item'><input id='section-2f9fdf2d-035d-4f30-b844-b13a84e39b8d' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-2f9fdf2d-035d-4f30-b844-b13a84e39b8d' class='xr-section-summary' title='Expand/collapse section'>Indexes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'></ul></div></li><li class='xr-section-item'><input id='section-22dbf941-ad98-494a-aea2-98e64ceb8e91' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-22dbf941-ad98-494a-aea2-98e64ceb8e91' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>"
],
"text/plain": [
"<xarray.DataArray 'multiplicative bias' ()> Size: 8B\n",
"array(inf)"
]
},
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -538,7 +538,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -911,8 +911,8 @@
"</style><pre class='xr-text-repr-fallback'>&lt;xarray.DataArray &#x27;multiplicative bias&#x27; (lat: 1536)&gt; Size: 6kB\n",
"array([nan, nan, nan, ..., nan, nan, nan], dtype=float32)\n",
"Coordinates:\n",
" * lat (lat) float64 12kB 89.94 89.82 89.71 89.59 ... -89.71 -89.82 -89.94</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'multiplicative bias'</div><ul class='xr-dim-list'><li><span class='xr-has-index'>lat</span>: 1536</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-35e7949e-5d5d-4ef4-a6ce-60acd52180f9' class='xr-array-in' type='checkbox' checked><label for='section-35e7949e-5d5d-4ef4-a6ce-60acd52180f9' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>nan nan nan nan nan nan nan nan ... nan nan nan nan nan nan nan nan</span></div><div class='xr-array-data'><pre>array([nan, nan, nan, ..., nan, nan, nan], dtype=float32)</pre></div></div></li><li class='xr-section-item'><input id='section-94f0cc78-009b-4fec-bd05-f015be00ca88' class='xr-section-summary-in' type='checkbox' checked><label for='section-94f0cc78-009b-4fec-bd05-f015be00ca88' class='xr-section-summary' >Coordinates: <span>(1)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>lat</span></div><div class='xr-var-dims'>(lat)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>89.94 89.82 89.71 ... -89.82 -89.94</div><input id='attrs-132c641d-4dcc-497e-8633-80941cc46746' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-132c641d-4dcc-497e-8633-80941cc46746' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-643b6e81-b598-4821-b786-926a325842e4' class='xr-var-data-in' type='checkbox'><label for='data-643b6e81-b598-4821-b786-926a325842e4' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>latitudes</dd><dt><span>type :</span></dt><dd>uniform</dd><dt><span>units :</span></dt><dd>degrees_north</dd><dt><span>valid_min :</span></dt><dd>-90.0</dd><dt><span>valid_max :</span></dt><dd>90.0</dd><dt><span>axis :</span></dt><dd>Y</dd></dl></div><div class='xr-var-data'><pre>array([ 89.941406, 89.824219, 89.707031, ..., -89.707031, -89.824219,\n",
" -89.941406])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-9578ead0-70c3-4780-b752-91de3a20d274' class='xr-section-summary-in' type='checkbox' ><label for='section-9578ead0-70c3-4780-b752-91de3a20d274' class='xr-section-summary' >Indexes: <span>(1)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-index-name'><div>lat</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-9f77adde-0757-4eb7-bb1a-d51c0dc7e210' class='xr-index-data-in' type='checkbox'/><label for='index-9f77adde-0757-4eb7-bb1a-d51c0dc7e210' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([ 89.941406, 89.82421850032573, 89.70703100065145,\n",
" * lat (lat) float64 12kB 89.94 89.82 89.71 89.59 ... -89.71 -89.82 -89.94</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'multiplicative bias'</div><ul class='xr-dim-list'><li><span class='xr-has-index'>lat</span>: 1536</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-ff0bd592-c4bd-4e6a-80a5-1c583869b9e4' class='xr-array-in' type='checkbox' checked><label for='section-ff0bd592-c4bd-4e6a-80a5-1c583869b9e4' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>nan nan nan nan nan nan nan nan ... nan nan nan nan nan nan nan nan</span></div><div class='xr-array-data'><pre>array([nan, nan, nan, ..., nan, nan, nan], dtype=float32)</pre></div></div></li><li class='xr-section-item'><input id='section-39bea9fb-b46f-400f-a473-133b68a44644' class='xr-section-summary-in' type='checkbox' checked><label for='section-39bea9fb-b46f-400f-a473-133b68a44644' class='xr-section-summary' >Coordinates: <span>(1)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>lat</span></div><div class='xr-var-dims'>(lat)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>89.94 89.82 89.71 ... -89.82 -89.94</div><input id='attrs-aad91337-085f-4ec2-b5c8-4ee91c483917' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-aad91337-085f-4ec2-b5c8-4ee91c483917' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-47495cde-441f-4d70-b438-8856c4d6bd7b' class='xr-var-data-in' type='checkbox'><label for='data-47495cde-441f-4d70-b438-8856c4d6bd7b' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>latitudes</dd><dt><span>type :</span></dt><dd>uniform</dd><dt><span>units :</span></dt><dd>degrees_north</dd><dt><span>valid_min :</span></dt><dd>-90.0</dd><dt><span>valid_max :</span></dt><dd>90.0</dd><dt><span>axis :</span></dt><dd>Y</dd></dl></div><div class='xr-var-data'><pre>array([ 89.941406, 89.824219, 89.707031, ..., -89.707031, -89.824219,\n",
" -89.941406])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-2af71584-0fc7-43e3-89c8-037a13407513' class='xr-section-summary-in' type='checkbox' ><label for='section-2af71584-0fc7-43e3-89c8-037a13407513' class='xr-section-summary' >Indexes: <span>(1)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-index-name'><div>lat</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-24c87971-fd89-4450-bebb-13dd43f357c2' class='xr-index-data-in' type='checkbox'/><label for='index-24c87971-fd89-4450-bebb-13dd43f357c2' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Index([ 89.941406, 89.82421850032573, 89.70703100065145,\n",
" 89.58984350097718, 89.47265600130291, 89.35546850162864,\n",
" 89.23828100195436, 89.12109350228009, 89.00390600260582,\n",
" 88.88671850293154,\n",
Expand All @@ -921,7 +921,7 @@
" -89.23828100196343, -89.35546850163769, -89.47265600131195,\n",
" -89.58984350098623, -89.70703100066052, -89.82421850033478,\n",
" -89.94140600000904],\n",
" dtype=&#x27;float64&#x27;, name=&#x27;lat&#x27;, length=1536))</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-98323512-e8f8-47e6-98ea-e10ce6876297' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-98323512-e8f8-47e6-98ea-e10ce6876297' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>"
" dtype=&#x27;float64&#x27;, name=&#x27;lat&#x27;, length=1536))</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-21a234d6-2bee-4673-9857-681aba0dd521' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-21a234d6-2bee-4673-9857-681aba0dd521' class='xr-section-summary' title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>"
],
"text/plain": [
"<xarray.DataArray 'multiplicative bias' (lat: 1536)> Size: 6kB\n",
Expand All @@ -930,7 +930,7 @@
" * lat (lat) float64 12kB 89.94 89.82 89.71 89.59 ... -89.71 -89.82 -89.94"
]
},
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -950,7 +950,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand All @@ -968,16 +968,16 @@
"import matplotlib.pyplot as plt\n",
"fcst_flow = fcst.temp_scrn\n",
"obs_flow = obs.temp_scrn\n",
"# Calculate additive bias precentage and preserve the \"lat\" dimension\n",
"# Calculate percent bias and preserve the \"lat\" dimension\n",
"bias = pbias(fcst_flow, obs_flow, preserve_dims=\"lat\")\n",
"bias.name = \"percent bias (%)\"\n",
"# Generate second dataset with large flow values\n",
"fcst_flow_large=fcst_flow + 1000\n",
"obs_flow_large = obs_flow + 1000\n",
"# Calculate additive bias precentage for large flow values and preserve the \"lat\" dimension\n",
"# Calculate percent bias for large flow values and preserve the \"lat\" dimension\n",
"bias_large_flow = pbias(fcst_flow_large, obs_flow_large, preserve_dims=\"lat\")\n",
"bias_large_flow.name = \"percent bias (%)\"\n",
"# Compare the additive bias precentage for small and large flow values\n",
"# Compare the percent bias for small and large flow values\n",
"bias.plot(label='pbias_small_streamflow')\n",
"bias_large_flow.plot(label='pbias_large_streamflow')\n",
"plt.legend()\n",
Expand Down

0 comments on commit 20ca208

Please sign in to comment.