Skip to content

Instantly share code, notes, and snippets.

@kuchaale
Created June 25, 2021 11:07
Show Gist options
  • Save kuchaale/5e194081fb569bebb85d6f01b39a9a8d to your computer and use it in GitHub Desktop.
Save kuchaale/5e194081fb569bebb85d6f01b39a9a8d to your computer and use it in GitHub Desktop.
Split and discplament detection in ERA5
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "cabb5209",
"metadata": {},
"source": [
"# Libraries"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "0ab55978",
"metadata": {
"execution": {
"iopub.execute_input": "2021-06-25T10:58:41.216923Z",
"iopub.status.busy": "2021-06-25T10:58:41.216375Z",
"iopub.status.idle": "2021-06-25T10:59:03.228569Z",
"shell.execute_reply": "2021-06-25T10:59:03.227593Z",
"shell.execute_reply.started": "2021-06-25T10:58:41.216854Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"<xarray.core.options.set_options at 0x7f3fbde067b8>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy as np\n",
"#import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"import xarray as xr\n",
"from pathlib import Path\n",
"import pandas as pd\n",
"#from scipy.stats import gaussian_kde, percentileofscore\n",
"import scipy.ndimage as ndimage\n",
"from datetime import timedelta\n",
"xr.set_options(display_style='html')"
]
},
{
"cell_type": "markdown",
"id": "7c3e0849",
"metadata": {},
"source": [
"# Functions"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "aaa06cb1",
"metadata": {
"execution": {
"iopub.execute_input": "2021-06-25T10:59:03.230680Z",
"iopub.status.busy": "2021-06-25T10:59:03.230420Z",
"iopub.status.idle": "2021-06-25T10:59:03.242814Z",
"shell.execute_reply": "2021-06-25T10:59:03.241979Z",
"shell.execute_reply.started": "2021-06-25T10:59:03.230644Z"
}
},
"outputs": [],
"source": [
"def find_consecutive_exceedences_above_threshold(events, n_events, minDuration, t, timescale = None):\n",
" \"\"\"Find all MHW events of duration >= minDuration\n",
" Updates the mhw dictionary object.\n",
" \n",
" \"\"\"\n",
" mhw = {}\n",
" mhw['time_start'] = [] # datetime format\n",
" mhw['time_end'] = [] # datetime format\n",
" mhw['event_duration'] = []\n",
" for ev in range(1, n_events + 1): # for each event\n",
" event_duration = (events == ev).sum()\n",
" #print(event_duration)\n",
" if event_duration < minDuration: # is it longer than threshold?\n",
" continue\n",
" # extract the t where event starts and ends\n",
" #print(type(t[np.where(events == ev)]))\n",
" #print(type(t[np.where(events == ev)[0]]))\n",
" start = t[np.where(events == ev)[0][0]]\n",
" end = t[np.where(events == ev)[0][-1]]\n",
" #print(end.month)\n",
" mhw[\"time_start\"].append(start)\n",
" mhw[\"time_end\"].append(end)\n",
" mhw['event_duration'].append(event_duration)\n",
" \n",
" mhw = pd.DataFrame(mhw)\n",
" #print(mhw.empty)\n",
" # filter according to radiative timescale\n",
" if timescale is not None and not mhw.empty:\n",
" mask = mhw.time_start.diff(1) > pd.Timedelta(str(timescale)+' days')\n",
" mask[0] = True # include first event\n",
" mhw = mhw[mask]\n",
" \n",
" return mhw"
]
},
{
"cell_type": "markdown",
"id": "1274b5a1",
"metadata": {},
"source": [
"# Open data"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "4acfb37e",
"metadata": {
"execution": {
"iopub.execute_input": "2021-06-25T10:59:03.244396Z",
"iopub.status.busy": "2021-06-25T10:59:03.244146Z",
"iopub.status.idle": "2021-06-25T10:59:04.124789Z",
"shell.execute_reply": "2021-06-25T10:59:04.123778Z",
"shell.execute_reply.started": "2021-06-25T10:59:03.244364Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n",
"<defs>\n",
"<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n",
"<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n",
"<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
"<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
"</symbol>\n",
"<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n",
"<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n",
"<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
"<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
"<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
"</symbol>\n",
"</defs>\n",
"</svg>\n",
"<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
" *\n",
" */\n",
"\n",
":root {\n",
" --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
" --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
" --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
" --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
" --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
" --xr-background-color: var(--jp-layout-color0, white);\n",
" --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
" --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
"}\n",
"\n",
"html[theme=dark],\n",
"body.vscode-dark {\n",
" --xr-font-color0: rgba(255, 255, 255, 1);\n",
" --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
" --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
" --xr-border-color: #1F1F1F;\n",
" --xr-disabled-color: #515151;\n",
" --xr-background-color: #111111;\n",
" --xr-background-color-row-even: #111111;\n",
" --xr-background-color-row-odd: #313131;\n",
"}\n",
"\n",
".xr-wrap {\n",
" display: block;\n",
" min-width: 300px;\n",
" max-width: 700px;\n",
"}\n",
"\n",
".xr-text-repr-fallback {\n",
" /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
" display: none;\n",
"}\n",
"\n",
".xr-header {\n",
" padding-top: 6px;\n",
" padding-bottom: 6px;\n",
" margin-bottom: 4px;\n",
" border-bottom: solid 1px var(--xr-border-color);\n",
"}\n",
"\n",
".xr-header > div,\n",
".xr-header > ul {\n",
" display: inline;\n",
" margin-top: 0;\n",
" margin-bottom: 0;\n",
"}\n",
"\n",
".xr-obj-type,\n",
".xr-array-name {\n",
" margin-left: 2px;\n",
" margin-right: 10px;\n",
"}\n",
"\n",
".xr-obj-type {\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-sections {\n",
" padding-left: 0 !important;\n",
" display: grid;\n",
" grid-template-columns: 150px auto auto 1fr 20px 20px;\n",
"}\n",
"\n",
".xr-section-item {\n",
" display: contents;\n",
"}\n",
"\n",
".xr-section-item input {\n",
" display: none;\n",
"}\n",
"\n",
".xr-section-item input + label {\n",
" color: var(--xr-disabled-color);\n",
"}\n",
"\n",
".xr-section-item input:enabled + label {\n",
" cursor: pointer;\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-section-item input:enabled + label:hover {\n",
" color: var(--xr-font-color0);\n",
"}\n",
"\n",
".xr-section-summary {\n",
" grid-column: 1;\n",
" color: var(--xr-font-color2);\n",
" font-weight: 500;\n",
"}\n",
"\n",
".xr-section-summary > span {\n",
" display: inline-block;\n",
" padding-left: 0.5em;\n",
"}\n",
"\n",
".xr-section-summary-in:disabled + label {\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-section-summary-in + label:before {\n",
" display: inline-block;\n",
" content: '►';\n",
" font-size: 11px;\n",
" width: 15px;\n",
" text-align: center;\n",
"}\n",
"\n",
".xr-section-summary-in:disabled + label:before {\n",
" color: var(--xr-disabled-color);\n",
"}\n",
"\n",
".xr-section-summary-in:checked + label:before {\n",
" content: '▼';\n",
"}\n",
"\n",
".xr-section-summary-in:checked + label > span {\n",
" display: none;\n",
"}\n",
"\n",
".xr-section-summary,\n",
".xr-section-inline-details {\n",
" padding-top: 4px;\n",
" padding-bottom: 4px;\n",
"}\n",
"\n",
".xr-section-inline-details {\n",
" grid-column: 2 / -1;\n",
"}\n",
"\n",
".xr-section-details {\n",
" display: none;\n",
" grid-column: 1 / -1;\n",
" margin-bottom: 5px;\n",
"}\n",
"\n",
".xr-section-summary-in:checked ~ .xr-section-details {\n",
" display: contents;\n",
"}\n",
"\n",
".xr-array-wrap {\n",
" grid-column: 1 / -1;\n",
" display: grid;\n",
" grid-template-columns: 20px auto;\n",
"}\n",
"\n",
".xr-array-wrap > label {\n",
" grid-column: 1;\n",
" vertical-align: top;\n",
"}\n",
"\n",
".xr-preview {\n",
" color: var(--xr-font-color3);\n",
"}\n",
"\n",
".xr-array-preview,\n",
".xr-array-data {\n",
" padding: 0 5px !important;\n",
" grid-column: 2;\n",
"}\n",
"\n",
".xr-array-data,\n",
".xr-array-in:checked ~ .xr-array-preview {\n",
" display: none;\n",
"}\n",
"\n",
".xr-array-in:checked ~ .xr-array-data,\n",
".xr-array-preview {\n",
" display: inline-block;\n",
"}\n",
"\n",
".xr-dim-list {\n",
" display: inline-block !important;\n",
" list-style: none;\n",
" padding: 0 !important;\n",
" margin: 0;\n",
"}\n",
"\n",
".xr-dim-list li {\n",
" display: inline-block;\n",
" padding: 0;\n",
" margin: 0;\n",
"}\n",
"\n",
".xr-dim-list:before {\n",
" content: '(';\n",
"}\n",
"\n",
".xr-dim-list:after {\n",
" content: ')';\n",
"}\n",
"\n",
".xr-dim-list li:not(:last-child):after {\n",
" content: ',';\n",
" padding-right: 5px;\n",
"}\n",
"\n",
".xr-has-index {\n",
" font-weight: bold;\n",
"}\n",
"\n",
".xr-var-list,\n",
".xr-var-item {\n",
" display: contents;\n",
"}\n",
"\n",
".xr-var-item > div,\n",
".xr-var-item label,\n",
".xr-var-item > .xr-var-name span {\n",
" background-color: var(--xr-background-color-row-even);\n",
" margin-bottom: 0;\n",
"}\n",
"\n",
".xr-var-item > .xr-var-name:hover span {\n",
" padding-right: 5px;\n",
"}\n",
"\n",
".xr-var-list > li:nth-child(odd) > div,\n",
".xr-var-list > li:nth-child(odd) > label,\n",
".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
" background-color: var(--xr-background-color-row-odd);\n",
"}\n",
"\n",
".xr-var-name {\n",
" grid-column: 1;\n",
"}\n",
"\n",
".xr-var-dims {\n",
" grid-column: 2;\n",
"}\n",
"\n",
".xr-var-dtype {\n",
" grid-column: 3;\n",
" text-align: right;\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-var-preview {\n",
" grid-column: 4;\n",
"}\n",
"\n",
".xr-var-name,\n",
".xr-var-dims,\n",
".xr-var-dtype,\n",
".xr-preview,\n",
".xr-attrs dt {\n",
" white-space: nowrap;\n",
" overflow: hidden;\n",
" text-overflow: ellipsis;\n",
" padding-right: 10px;\n",
"}\n",
"\n",
".xr-var-name:hover,\n",
".xr-var-dims:hover,\n",
".xr-var-dtype:hover,\n",
".xr-attrs dt:hover {\n",
" overflow: visible;\n",
" width: auto;\n",
" z-index: 1;\n",
"}\n",
"\n",
".xr-var-attrs,\n",
".xr-var-data {\n",
" display: none;\n",
" background-color: var(--xr-background-color) !important;\n",
" padding-bottom: 5px !important;\n",
"}\n",
"\n",
".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
".xr-var-data-in:checked ~ .xr-var-data {\n",
" display: block;\n",
"}\n",
"\n",
".xr-var-data > table {\n",
" float: right;\n",
"}\n",
"\n",
".xr-var-name span,\n",
".xr-var-data,\n",
".xr-attrs {\n",
" padding-left: 25px !important;\n",
"}\n",
"\n",
".xr-attrs,\n",
".xr-var-attrs,\n",
".xr-var-data {\n",
" grid-column: 1 / -1;\n",
"}\n",
"\n",
"dl.xr-attrs {\n",
" padding: 0;\n",
" margin: 0;\n",
" display: grid;\n",
" grid-template-columns: 125px auto;\n",
"}\n",
"\n",
".xr-attrs dt,\n",
".xr-attrs dd {\n",
" padding: 0;\n",
" margin: 0;\n",
" float: left;\n",
" padding-right: 10px;\n",
" width: auto;\n",
"}\n",
"\n",
".xr-attrs dt {\n",
" font-weight: normal;\n",
" grid-column: 1;\n",
"}\n",
"\n",
".xr-attrs dt:hover span {\n",
" display: inline-block;\n",
" background: var(--xr-background-color);\n",
" padding-right: 10px;\n",
"}\n",
"\n",
".xr-attrs dd {\n",
" grid-column: 2;\n",
" white-space: pre-wrap;\n",
" word-break: break-all;\n",
"}\n",
"\n",
".xr-icon-database,\n",
".xr-icon-file-text2 {\n",
" display: inline-block;\n",
" vertical-align: middle;\n",
" width: 1em;\n",
" height: 1.5em !important;\n",
" stroke-width: 0;\n",
" stroke: currentColor;\n",
" fill: currentColor;\n",
"}\n",
"</style><pre class='xr-text-repr-fallback'>&lt;xarray.Dataset&gt;\n",
"Dimensions: (time: 7671)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2000-01-01T11:30:00 ... 2020-12-...\n",
"Data variables:\n",
" aspect_ratio (time) float64 1.464 1.491 1.493 ... 1.381 1.537 1.737\n",
" centroid_latitude (time) float64 82.62 83.48 83.71 ... 73.83 75.22 76.01</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.Dataset</div></div><ul class='xr-sections'><li class='xr-section-item'><input id='section-8bd50e86-1c9b-4cb6-a533-8833eb7c00d3' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-8bd50e86-1c9b-4cb6-a533-8833eb7c00d3' class='xr-section-summary' title='Expand/collapse section'>Dimensions:</label><div class='xr-section-inline-details'><ul class='xr-dim-list'><li><span class='xr-has-index'>time</span>: 7671</li></ul></div><div class='xr-section-details'></div></li><li class='xr-section-item'><input id='section-2429d761-4e7d-4db5-a50f-c57e21f46b56' class='xr-section-summary-in' type='checkbox' checked><label for='section-2429d761-4e7d-4db5-a50f-c57e21f46b56' 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'>time</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>datetime64[ns]</div><div class='xr-var-preview xr-preview'>2000-01-01T11:30:00 ... 2020-12-...</div><input id='attrs-e428f7cb-e954-4e50-b865-894439f79dde' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-e428f7cb-e954-4e50-b865-894439f79dde' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-0df4f6e5-257d-46ec-ac16-f0ac75dad4ef' class='xr-var-data-in' type='checkbox'><label for='data-0df4f6e5-257d-46ec-ac16-f0ac75dad4ef' 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>standard_name :</span></dt><dd>time</dd><dt><span>long_name :</span></dt><dd>time</dd><dt><span>bounds :</span></dt><dd>time_bnds</dd><dt><span>axis :</span></dt><dd>T</dd></dl></div><div class='xr-var-data'><pre>array([&#x27;2000-01-01T11:30:00.000000000&#x27;, &#x27;2000-01-02T11:30:00.000000000&#x27;,\n",
" &#x27;2000-01-03T11:30:00.000000000&#x27;, ..., &#x27;2020-12-29T11:30:00.000000000&#x27;,\n",
" &#x27;2020-12-30T11:30:00.000000000&#x27;, &#x27;2020-12-31T11:30:00.000000000&#x27;],\n",
" dtype=&#x27;datetime64[ns]&#x27;)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-70ea5cdb-12af-401c-bd25-9f5d2b8daae1' class='xr-section-summary-in' type='checkbox' checked><label for='section-70ea5cdb-12af-401c-bd25-9f5d2b8daae1' class='xr-section-summary' >Data variables: <span>(2)</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>aspect_ratio</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-ab8965d6-cd34-4e77-85ac-424a569ae403' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-ab8965d6-cd34-4e77-85ac-424a569ae403' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-fbab2572-7c24-4501-95a8-36704c5e4910' class='xr-var-data-in' type='checkbox'><label for='data-fbab2572-7c24-4501-95a8-36704c5e4910' 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'></dl></div><div class='xr-var-data'><pre>array([1.464039, 1.490872, 1.492935, ..., 1.380819, 1.536664, 1.7372 ])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>centroid_latitude</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-15926426-9ff9-4cca-9ae4-36d7e457bb15' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-15926426-9ff9-4cca-9ae4-36d7e457bb15' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-1beac03e-f040-4768-9bc7-a561ae31bbea' class='xr-var-data-in' type='checkbox'><label for='data-1beac03e-f040-4768-9bc7-a561ae31bbea' 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'></dl></div><div class='xr-var-data'><pre>array([82.624449, 83.481868, 83.707622, ..., 73.826339, 75.220947, 76.012344])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-3046671a-aaec-4c5a-97bb-0805c2684156' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-3046671a-aaec-4c5a-97bb-0805c2684156' 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.Dataset>\n",
"Dimensions: (time: 7671)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2000-01-01T11:30:00 ... 2020-12-...\n",
"Data variables:\n",
" aspect_ratio (time) float64 ...\n",
" centroid_latitude (time) float64 ..."
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"inpath = '/projekt4/hochatm/ERA5/'\n",
"ds = xr.open_adataset(f'{inpath}moment_calculation_ERA5.nc')\n",
"ds"
]
},
{
"cell_type": "markdown",
"id": "2a9a1ec5",
"metadata": {},
"source": [
"## DJF only"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "a8788151",
"metadata": {
"execution": {
"iopub.execute_input": "2021-06-25T11:01:32.849624Z",
"iopub.status.busy": "2021-06-25T11:01:32.849057Z",
"iopub.status.idle": "2021-06-25T11:01:32.890295Z",
"shell.execute_reply": "2021-06-25T11:01:32.889359Z",
"shell.execute_reply.started": "2021-06-25T11:01:32.849557Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n",
"<defs>\n",
"<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n",
"<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n",
"<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
"<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
"</symbol>\n",
"<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n",
"<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n",
"<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
"<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
"<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
"</symbol>\n",
"</defs>\n",
"</svg>\n",
"<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
" *\n",
" */\n",
"\n",
":root {\n",
" --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
" --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
" --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
" --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
" --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
" --xr-background-color: var(--jp-layout-color0, white);\n",
" --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
" --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
"}\n",
"\n",
"html[theme=dark],\n",
"body.vscode-dark {\n",
" --xr-font-color0: rgba(255, 255, 255, 1);\n",
" --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
" --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
" --xr-border-color: #1F1F1F;\n",
" --xr-disabled-color: #515151;\n",
" --xr-background-color: #111111;\n",
" --xr-background-color-row-even: #111111;\n",
" --xr-background-color-row-odd: #313131;\n",
"}\n",
"\n",
".xr-wrap {\n",
" display: block;\n",
" min-width: 300px;\n",
" max-width: 700px;\n",
"}\n",
"\n",
".xr-text-repr-fallback {\n",
" /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
" display: none;\n",
"}\n",
"\n",
".xr-header {\n",
" padding-top: 6px;\n",
" padding-bottom: 6px;\n",
" margin-bottom: 4px;\n",
" border-bottom: solid 1px var(--xr-border-color);\n",
"}\n",
"\n",
".xr-header > div,\n",
".xr-header > ul {\n",
" display: inline;\n",
" margin-top: 0;\n",
" margin-bottom: 0;\n",
"}\n",
"\n",
".xr-obj-type,\n",
".xr-array-name {\n",
" margin-left: 2px;\n",
" margin-right: 10px;\n",
"}\n",
"\n",
".xr-obj-type {\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-sections {\n",
" padding-left: 0 !important;\n",
" display: grid;\n",
" grid-template-columns: 150px auto auto 1fr 20px 20px;\n",
"}\n",
"\n",
".xr-section-item {\n",
" display: contents;\n",
"}\n",
"\n",
".xr-section-item input {\n",
" display: none;\n",
"}\n",
"\n",
".xr-section-item input + label {\n",
" color: var(--xr-disabled-color);\n",
"}\n",
"\n",
".xr-section-item input:enabled + label {\n",
" cursor: pointer;\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-section-item input:enabled + label:hover {\n",
" color: var(--xr-font-color0);\n",
"}\n",
"\n",
".xr-section-summary {\n",
" grid-column: 1;\n",
" color: var(--xr-font-color2);\n",
" font-weight: 500;\n",
"}\n",
"\n",
".xr-section-summary > span {\n",
" display: inline-block;\n",
" padding-left: 0.5em;\n",
"}\n",
"\n",
".xr-section-summary-in:disabled + label {\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-section-summary-in + label:before {\n",
" display: inline-block;\n",
" content: '►';\n",
" font-size: 11px;\n",
" width: 15px;\n",
" text-align: center;\n",
"}\n",
"\n",
".xr-section-summary-in:disabled + label:before {\n",
" color: var(--xr-disabled-color);\n",
"}\n",
"\n",
".xr-section-summary-in:checked + label:before {\n",
" content: '▼';\n",
"}\n",
"\n",
".xr-section-summary-in:checked + label > span {\n",
" display: none;\n",
"}\n",
"\n",
".xr-section-summary,\n",
".xr-section-inline-details {\n",
" padding-top: 4px;\n",
" padding-bottom: 4px;\n",
"}\n",
"\n",
".xr-section-inline-details {\n",
" grid-column: 2 / -1;\n",
"}\n",
"\n",
".xr-section-details {\n",
" display: none;\n",
" grid-column: 1 / -1;\n",
" margin-bottom: 5px;\n",
"}\n",
"\n",
".xr-section-summary-in:checked ~ .xr-section-details {\n",
" display: contents;\n",
"}\n",
"\n",
".xr-array-wrap {\n",
" grid-column: 1 / -1;\n",
" display: grid;\n",
" grid-template-columns: 20px auto;\n",
"}\n",
"\n",
".xr-array-wrap > label {\n",
" grid-column: 1;\n",
" vertical-align: top;\n",
"}\n",
"\n",
".xr-preview {\n",
" color: var(--xr-font-color3);\n",
"}\n",
"\n",
".xr-array-preview,\n",
".xr-array-data {\n",
" padding: 0 5px !important;\n",
" grid-column: 2;\n",
"}\n",
"\n",
".xr-array-data,\n",
".xr-array-in:checked ~ .xr-array-preview {\n",
" display: none;\n",
"}\n",
"\n",
".xr-array-in:checked ~ .xr-array-data,\n",
".xr-array-preview {\n",
" display: inline-block;\n",
"}\n",
"\n",
".xr-dim-list {\n",
" display: inline-block !important;\n",
" list-style: none;\n",
" padding: 0 !important;\n",
" margin: 0;\n",
"}\n",
"\n",
".xr-dim-list li {\n",
" display: inline-block;\n",
" padding: 0;\n",
" margin: 0;\n",
"}\n",
"\n",
".xr-dim-list:before {\n",
" content: '(';\n",
"}\n",
"\n",
".xr-dim-list:after {\n",
" content: ')';\n",
"}\n",
"\n",
".xr-dim-list li:not(:last-child):after {\n",
" content: ',';\n",
" padding-right: 5px;\n",
"}\n",
"\n",
".xr-has-index {\n",
" font-weight: bold;\n",
"}\n",
"\n",
".xr-var-list,\n",
".xr-var-item {\n",
" display: contents;\n",
"}\n",
"\n",
".xr-var-item > div,\n",
".xr-var-item label,\n",
".xr-var-item > .xr-var-name span {\n",
" background-color: var(--xr-background-color-row-even);\n",
" margin-bottom: 0;\n",
"}\n",
"\n",
".xr-var-item > .xr-var-name:hover span {\n",
" padding-right: 5px;\n",
"}\n",
"\n",
".xr-var-list > li:nth-child(odd) > div,\n",
".xr-var-list > li:nth-child(odd) > label,\n",
".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
" background-color: var(--xr-background-color-row-odd);\n",
"}\n",
"\n",
".xr-var-name {\n",
" grid-column: 1;\n",
"}\n",
"\n",
".xr-var-dims {\n",
" grid-column: 2;\n",
"}\n",
"\n",
".xr-var-dtype {\n",
" grid-column: 3;\n",
" text-align: right;\n",
" color: var(--xr-font-color2);\n",
"}\n",
"\n",
".xr-var-preview {\n",
" grid-column: 4;\n",
"}\n",
"\n",
".xr-var-name,\n",
".xr-var-dims,\n",
".xr-var-dtype,\n",
".xr-preview,\n",
".xr-attrs dt {\n",
" white-space: nowrap;\n",
" overflow: hidden;\n",
" text-overflow: ellipsis;\n",
" padding-right: 10px;\n",
"}\n",
"\n",
".xr-var-name:hover,\n",
".xr-var-dims:hover,\n",
".xr-var-dtype:hover,\n",
".xr-attrs dt:hover {\n",
" overflow: visible;\n",
" width: auto;\n",
" z-index: 1;\n",
"}\n",
"\n",
".xr-var-attrs,\n",
".xr-var-data {\n",
" display: none;\n",
" background-color: var(--xr-background-color) !important;\n",
" padding-bottom: 5px !important;\n",
"}\n",
"\n",
".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
".xr-var-data-in:checked ~ .xr-var-data {\n",
" display: block;\n",
"}\n",
"\n",
".xr-var-data > table {\n",
" float: right;\n",
"}\n",
"\n",
".xr-var-name span,\n",
".xr-var-data,\n",
".xr-attrs {\n",
" padding-left: 25px !important;\n",
"}\n",
"\n",
".xr-attrs,\n",
".xr-var-attrs,\n",
".xr-var-data {\n",
" grid-column: 1 / -1;\n",
"}\n",
"\n",
"dl.xr-attrs {\n",
" padding: 0;\n",
" margin: 0;\n",
" display: grid;\n",
" grid-template-columns: 125px auto;\n",
"}\n",
"\n",
".xr-attrs dt,\n",
".xr-attrs dd {\n",
" padding: 0;\n",
" margin: 0;\n",
" float: left;\n",
" padding-right: 10px;\n",
" width: auto;\n",
"}\n",
"\n",
".xr-attrs dt {\n",
" font-weight: normal;\n",
" grid-column: 1;\n",
"}\n",
"\n",
".xr-attrs dt:hover span {\n",
" display: inline-block;\n",
" background: var(--xr-background-color);\n",
" padding-right: 10px;\n",
"}\n",
"\n",
".xr-attrs dd {\n",
" grid-column: 2;\n",
" white-space: pre-wrap;\n",
" word-break: break-all;\n",
"}\n",
"\n",
".xr-icon-database,\n",
".xr-icon-file-text2 {\n",
" display: inline-block;\n",
" vertical-align: middle;\n",
" width: 1em;\n",
" height: 1.5em !important;\n",
" stroke-width: 0;\n",
" stroke: currentColor;\n",
" fill: currentColor;\n",
"}\n",
"</style><pre class='xr-text-repr-fallback'>&lt;xarray.Dataset&gt;\n",
"Dimensions: (time: 1896)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2000-01-01T11:30:00 ... 2020-12-...\n",
"Data variables:\n",
" aspect_ratio (time) float64 1.464 1.491 1.493 ... 1.381 1.537 1.737\n",
" centroid_latitude (time) float64 82.62 83.48 83.71 ... 73.83 75.22 76.01</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.Dataset</div></div><ul class='xr-sections'><li class='xr-section-item'><input id='section-a278b1f9-6730-4395-a697-3b0c050e6bbe' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-a278b1f9-6730-4395-a697-3b0c050e6bbe' class='xr-section-summary' title='Expand/collapse section'>Dimensions:</label><div class='xr-section-inline-details'><ul class='xr-dim-list'><li><span class='xr-has-index'>time</span>: 1896</li></ul></div><div class='xr-section-details'></div></li><li class='xr-section-item'><input id='section-3f44c855-7695-4986-991d-68ff6e877bff' class='xr-section-summary-in' type='checkbox' checked><label for='section-3f44c855-7695-4986-991d-68ff6e877bff' 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'>time</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>datetime64[ns]</div><div class='xr-var-preview xr-preview'>2000-01-01T11:30:00 ... 2020-12-...</div><input id='attrs-44cfcf96-2c4c-4029-8ad3-1c57c9bd69ce' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-44cfcf96-2c4c-4029-8ad3-1c57c9bd69ce' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-e8e8f73f-b0aa-40f6-ae20-9d758a49a82c' class='xr-var-data-in' type='checkbox'><label for='data-e8e8f73f-b0aa-40f6-ae20-9d758a49a82c' 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>standard_name :</span></dt><dd>time</dd><dt><span>long_name :</span></dt><dd>time</dd><dt><span>bounds :</span></dt><dd>time_bnds</dd><dt><span>axis :</span></dt><dd>T</dd></dl></div><div class='xr-var-data'><pre>array([&#x27;2000-01-01T11:30:00.000000000&#x27;, &#x27;2000-01-02T11:30:00.000000000&#x27;,\n",
" &#x27;2000-01-03T11:30:00.000000000&#x27;, ..., &#x27;2020-12-29T11:30:00.000000000&#x27;,\n",
" &#x27;2020-12-30T11:30:00.000000000&#x27;, &#x27;2020-12-31T11:30:00.000000000&#x27;],\n",
" dtype=&#x27;datetime64[ns]&#x27;)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-20b87e20-e118-4112-9e4e-82e63092aa6b' class='xr-section-summary-in' type='checkbox' checked><label for='section-20b87e20-e118-4112-9e4e-82e63092aa6b' class='xr-section-summary' >Data variables: <span>(2)</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>aspect_ratio</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>1.464 1.491 1.493 ... 1.537 1.737</div><input id='attrs-f4c658a7-7362-4c74-adab-9c0f1a43548d' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-f4c658a7-7362-4c74-adab-9c0f1a43548d' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-0c0cb23f-c525-4ae0-83e8-e593d7546273' class='xr-var-data-in' type='checkbox'><label for='data-0c0cb23f-c525-4ae0-83e8-e593d7546273' 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'></dl></div><div class='xr-var-data'><pre>array([1.464039, 1.490872, 1.492935, ..., 1.380819, 1.536664, 1.7372 ])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>centroid_latitude</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>82.62 83.48 83.71 ... 75.22 76.01</div><input id='attrs-af97ff4d-d1d5-4b95-b26e-3cb35fb74964' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-af97ff4d-d1d5-4b95-b26e-3cb35fb74964' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-f12ddc2b-b525-47d8-bf0b-71891d72b682' class='xr-var-data-in' type='checkbox'><label for='data-f12ddc2b-b525-47d8-bf0b-71891d72b682' 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'></dl></div><div class='xr-var-data'><pre>array([82.624449, 83.481868, 83.707622, ..., 73.826339, 75.220947, 76.012344])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-54028ca9-c921-4ba8-8ac9-4df669552fd7' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-54028ca9-c921-4ba8-8ac9-4df669552fd7' 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.Dataset>\n",
"Dimensions: (time: 1896)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2000-01-01T11:30:00 ... 2020-12-...\n",
"Data variables:\n",
" aspect_ratio (time) float64 1.464 1.491 1.493 ... 1.381 1.537 1.737\n",
" centroid_latitude (time) float64 82.62 83.48 83.71 ... 73.83 75.22 76.01"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mask = (ds.time.dt.month == 12) | \\\n",
" (ds.time.dt.month == 1) | (ds.time.dt.month == 2) #| (ds.time.dt.month == 3)(ds.time.dt.month == 11) |\n",
"ds_sel = ds.sel(time = mask)\n",
"ds_sel"
]
},
{
"cell_type": "markdown",
"id": "e3357075",
"metadata": {},
"source": [
"## Analysis"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "dbe24ead",
"metadata": {
"execution": {
"iopub.execute_input": "2021-06-25T11:01:34.699228Z",
"iopub.status.busy": "2021-06-25T11:01:34.698675Z",
"iopub.status.idle": "2021-06-25T11:01:34.713944Z",
"shell.execute_reply": "2021-06-25T11:01:34.713005Z",
"shell.execute_reply.started": "2021-06-25T11:01:34.699161Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"aspect ratio threshold: [2.79789406] centroid latitude threshold: [64.22916133]\n"
]
}
],
"source": [
"nc_days = 7 # number of consecutive days below or above threshold\n",
"timescale = 30 # gap between events\n",
"perc = 5/100. # percentile to estimate thresholds below\n",
"ar_threshold= ds_sel['aspect_ratio'].quantile([1-perc], dim = ['time']).values\n",
"cl_threshold= ds_sel['centroid_latitude'].quantile([perc], dim = ['time']).values\n",
"print('aspect ratio threshold: ', ar_threshold, 'centroid latitude threshold: ', cl_threshold)"
]
},
{
"cell_type": "markdown",
"id": "58e0b403",
"metadata": {},
"source": [
"### Splits"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "81d3a87a",
"metadata": {
"execution": {
"iopub.execute_input": "2021-06-25T11:01:49.515080Z",
"iopub.status.busy": "2021-06-25T11:01:49.514508Z",
"iopub.status.idle": "2021-06-25T11:01:49.612772Z",
"shell.execute_reply": "2021-06-25T11:01:49.611612Z",
"shell.execute_reply.started": "2021-06-25T11:01:49.515012Z"
}
},
"outputs": [],
"source": [
"temp = ds['aspect_ratio']\n",
"exceed_bool = temp - ar_threshold # or 2.3999 from Seviour et al\n",
"exceed_bool[exceed_bool <= 0] = False\n",
"exceed_bool[exceed_bool > 0] = True\n",
"\n",
"# Find contiguous regions of exceed_bool = True\n",
"events, n_events = ndimage.label(exceed_bool)\n",
"mhw_split = find_consecutive_exceedences_above_threshold(events, n_events, nc_days, \\\n",
" temp.time.to_index(), timescale = timescale)\n",
"\n",
"mask2drop = (mhw_split.time_start.dt.month == 1) | \\\n",
" (mhw_split.time_start.dt.month == 12) | \\\n",
" (mhw_split.time_start.dt.month == 2)\n",
"mhw_split = mhw_split[mask2drop]\n",
"\n",
"counted = mhw_split.groupby(mhw_split.time_start.dt.month).count().reindex([12,1,2])['event_duration']\n",
"#counted.name = ens\n",
"counted.index.name = 'month'\n",
"\n",
"\n",
"ed = mhw_split['event_duration']\n",
"#ave_duration_ls.append(ed.mean())\n",
"#std_duration_ls.append(ed.std())"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "f5b60db8",
"metadata": {
"execution": {
"iopub.execute_input": "2021-06-25T11:01:51.710661Z",
"iopub.status.busy": "2021-06-25T11:01:51.710112Z",
"iopub.status.idle": "2021-06-25T11:01:51.774666Z",
"shell.execute_reply": "2021-06-25T11:01:51.773526Z",
"shell.execute_reply.started": "2021-06-25T11:01:51.710595Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>time_start</th>\n",
" <th>time_end</th>\n",
" <th>event_duration</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2003-01-17 11:30:00</td>\n",
" <td>2003-01-23 11:30:00</td>\n",
" <td>7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2009-01-19 11:30:00</td>\n",
" <td>2009-01-27 11:30:00</td>\n",
" <td>9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2013-01-06 11:30:00</td>\n",
" <td>2013-01-12 11:30:00</td>\n",
" <td>7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2014-02-03 11:30:00</td>\n",
" <td>2014-02-10 11:30:00</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2019-01-08 11:30:00</td>\n",
" <td>2019-01-20 11:30:00</td>\n",
" <td>13</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" time_start time_end event_duration\n",
"0 2003-01-17 11:30:00 2003-01-23 11:30:00 7\n",
"1 2009-01-19 11:30:00 2009-01-27 11:30:00 9\n",
"2 2013-01-06 11:30:00 2013-01-12 11:30:00 7\n",
"3 2014-02-03 11:30:00 2014-02-10 11:30:00 8\n",
"4 2019-01-08 11:30:00 2019-01-20 11:30:00 13"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mhw_split.reset_index(drop = True)"
]
},
{
"cell_type": "markdown",
"id": "6da06d85",
"metadata": {},
"source": [
"### Displacements"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "0756ba2f",
"metadata": {
"execution": {
"iopub.execute_input": "2021-06-25T11:02:51.069396Z",
"iopub.status.busy": "2021-06-25T11:02:51.068806Z",
"iopub.status.idle": "2021-06-25T11:02:51.101770Z",
"shell.execute_reply": "2021-06-25T11:02:51.100951Z",
"shell.execute_reply.started": "2021-06-25T11:02:51.069327Z"
}
},
"outputs": [],
"source": [
"temp = ds['centroid_latitude']\n",
"exceed_bool = temp - cl_threshold # or 66.0000001 from Seviour et al\n",
"exceed_bool[exceed_bool >= 0] = False\n",
"exceed_bool[exceed_bool < 0] = True\n",
"\n",
"# Find contiguous regions of exceed_bool = True\n",
"events, n_events = ndimage.label(exceed_bool)\n",
"mhw_displ = find_consecutive_exceedences_above_threshold(events, n_events, nc_days, \\\n",
" temp.time.to_index(), timescale = timescale)\n",
"\n",
"mask2drop = (mhw_displ.time_start.dt.month == 1) | \\\n",
" (mhw_displ.time_start.dt.month == 12) | \\\n",
" (mhw_displ.time_start.dt.month == 2)\n",
"mhw_displ = mhw_displ[mask2drop]\n",
"\n",
"counted = mhw_displ.groupby(mhw_displ.time_start.dt.month).count().reindex([12,1,2])['event_duration']\n",
"counted.index.name = 'month'\n",
"\n",
"ed = mhw_displ['event_duration']"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "d44200ea",
"metadata": {
"execution": {
"iopub.execute_input": "2021-06-25T11:02:52.281956Z",
"iopub.status.busy": "2021-06-25T11:02:52.281399Z",
"iopub.status.idle": "2021-06-25T11:02:52.296582Z",
"shell.execute_reply": "2021-06-25T11:02:52.295606Z",
"shell.execute_reply.started": "2021-06-25T11:02:52.281890Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>time_start</th>\n",
" <th>time_end</th>\n",
" <th>event_duration</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2001-02-13 11:30:00</td>\n",
" <td>2001-02-23 11:30:00</td>\n",
" <td>11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2004-01-02 11:30:00</td>\n",
" <td>2004-01-17 11:30:00</td>\n",
" <td>16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2006-01-19 11:30:00</td>\n",
" <td>2006-02-10 11:30:00</td>\n",
" <td>23</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2009-01-28 11:30:00</td>\n",
" <td>2009-02-28 11:30:00</td>\n",
" <td>32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2013-01-13 11:30:00</td>\n",
" <td>2013-01-20 11:30:00</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>2018-02-12 11:30:00</td>\n",
" <td>2018-02-22 11:30:00</td>\n",
" <td>11</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" time_start time_end event_duration\n",
"0 2001-02-13 11:30:00 2001-02-23 11:30:00 11\n",
"1 2004-01-02 11:30:00 2004-01-17 11:30:00 16\n",
"2 2006-01-19 11:30:00 2006-02-10 11:30:00 23\n",
"3 2009-01-28 11:30:00 2009-02-28 11:30:00 32\n",
"4 2013-01-13 11:30:00 2013-01-20 11:30:00 8\n",
"5 2018-02-12 11:30:00 2018-02-22 11:30:00 11"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mhw_displ.reset_index(drop = True)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:.conda-moje] *",
"language": "python",
"name": "conda-env-.conda-moje-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment