Skip to content

Commit

Permalink
FIX: Fix the area bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrover1 committed Apr 16, 2024
1 parent b069915 commit 53e3d43
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions notebooks/enso-globus-flow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -793,12 +793,21 @@
"- All functions/libraries/packages need to be imported and defined within the function to execute\n",
"- The output from the function needs to serializable (ex. xarray.Dataset, numpy.array)\n",
"\n",
"Using these constraints, we setup the following function, with the key parameter being which model (`source_id`) to compare. Two examples here include The National Center for Atmospheric Research (NCAR) Model CESM2 and the Model for Interdisciplinary Research on Climate (MIROC) Model MIROC6."
"Using these constraints, we setup the following function, with the key parameter being which model (`source_id`) to compare. Two examples here include The National Center for Atmospheric Research (NCAR) Model CESM2 and the Model for Interdisciplinary Research on Climate (MIROC) Model MIROC6. Valid responses for this exercise include:\n",
"- `ACCESS-ESM1-5`\n",
"- `EC-Earth3-CC`\n",
"- `MPI-ESM1-2-LR`\n",
"- `CanESM5`\n",
"- `MIROC6`\n",
"- `EC-Earth3`\n",
"- `CESM2`\n",
"- `EC-Earth3-Veg`\n",
"- `NorCPM1`"
]
},
{
"cell_type": "code",
"execution_count": 62,
"execution_count": 102,
"id": "2b74d939-f87d-4a44-9e4a-6643b7d04fe7",
"metadata": {
"tags": []
Expand Down Expand Up @@ -850,7 +859,7 @@
" # Determine the non-time dimensions and average using these\n",
" non_time_dims = set(tos_nino34_anom.dims)\n",
" non_time_dims.remove(ds.tos.cf[\"T\"].name)\n",
" weighted_average = tos_nino34_anom.weighted(ds[\"areacello\"]).mean(dim=list(non_time_dims))\n",
" weighted_average = tos_nino34_anom.weighted(ds[\"areacello\"].fillna(0)).mean(dim=list(non_time_dims))\n",
"\n",
" # Calculate the rolling average\n",
" rolling_average = weighted_average.rolling(time=5, center=True).mean()\n",
Expand Down Expand Up @@ -920,7 +929,7 @@
},
{
"cell_type": "code",
"execution_count": 63,
"execution_count": 106,
"id": "fe8d9e8b-e38d-41a5-b5f6-df9916d69f83",
"metadata": {
"tags": []
Expand All @@ -942,7 +951,7 @@
},
{
"cell_type": "code",
"execution_count": 64,
"execution_count": 107,
"id": "0aa43e9e-6840-4b46-9a0c-ceeef8ca7e1e",
"metadata": {
"tags": []
Expand All @@ -954,7 +963,7 @@
"Executor<ep_id:6836803d-9831-4dc5-b159-eb658250e4bc; tg_id:None; bs:128>"
]
},
"execution_count": 64,
"execution_count": 107,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -977,7 +986,7 @@
},
{
"cell_type": "code",
"execution_count": 65,
"execution_count": 108,
"id": "664c9fd2-8822-4e34-9c2b-8558c489e487",
"metadata": {
"tags": []
Expand Down Expand Up @@ -1633,7 +1642,7 @@
},
{
"cell_type": "code",
"execution_count": 78,
"execution_count": 113,
"id": "aa5d4f65-a8ef-4ed0-bd6e-f49efb4f23ab",
"metadata": {
"tags": []
Expand Down Expand Up @@ -1690,7 +1699,7 @@
" # Determine the non-time dimensions and average using these\n",
" non_time_dims = set(tos_nino34_anom.dims)\n",
" non_time_dims.remove(ds.tos.cf[\"T\"].name)\n",
" weighted_average = tos_nino34_anom.weighted(ds[\"areacello\"]).mean(dim=list(non_time_dims))\n",
" weighted_average = tos_nino34_anom.weighted(ds[\"areacello\"].fillna(0)).mean(dim=list(non_time_dims))\n",
"\n",
" # Calculate the rolling average\n",
" rolling_average = weighted_average.rolling(time=5, center=True).mean()\n",
Expand Down Expand Up @@ -1749,7 +1758,7 @@
},
{
"cell_type": "code",
"execution_count": 79,
"execution_count": 114,
"id": "6ef8039b-b894-42b3-af19-dff99a6cff11",
"metadata": {
"tags": []
Expand Down Expand Up @@ -2274,12 +2283,12 @@
"data": {
"application/vnd.holoviews_exec.v0+json": "",
"text/html": [
"<div id='p1836'>\n",
" <div id=\"fe6515f8-8014-4d88-afcc-81e4c449e883\" data-root-id=\"p1836\" style=\"display: contents;\"></div>\n",
"<div id='p1979'>\n",
" <div id=\"be859ba0-9d7f-40bd-a0df-2b301c8b2fa9\" data-root-id=\"p1979\" style=\"display: contents;\"></div>\n",
"</div>\n",
"<script type=\"application/javascript\">(function(root) {\n",
" var docs_json = {\"e6f58b87-1cec-4b66-85d0-bb42c1391cc7\":{\"version\":\"3.4.0\",\"title\":\"Bokeh Application\",\"roots\":[{\"type\":\"object\",\"name\":\"panel.models.browser.BrowserInfo\",\"id\":\"p1836\"},{\"type\":\"object\",\"name\":\"panel.models.comm_manager.CommManager\",\"id\":\"p1837\",\"attributes\":{\"plot_id\":\"p1836\",\"comm_id\":\"33d87db6d87140b6af1a469c5b21753c\",\"client_comm_id\":\"f1f5dae1078b496c9a89fcf68f80185f\"}}],\"defs\":[{\"type\":\"model\",\"name\":\"ReactiveHTML1\"},{\"type\":\"model\",\"name\":\"FlexBox1\",\"properties\":[{\"name\":\"align_content\",\"kind\":\"Any\",\"default\":\"flex-start\"},{\"name\":\"align_items\",\"kind\":\"Any\",\"default\":\"flex-start\"},{\"name\":\"flex_direction\",\"kind\":\"Any\",\"default\":\"row\"},{\"name\":\"flex_wrap\",\"kind\":\"Any\",\"default\":\"wrap\"},{\"name\":\"gap\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"justify_content\",\"kind\":\"Any\",\"default\":\"flex-start\"}]},{\"type\":\"model\",\"name\":\"FloatPanel1\",\"properties\":[{\"name\":\"config\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"contained\",\"kind\":\"Any\",\"default\":true},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"right-top\"},{\"name\":\"offsetx\",\"kind\":\"Any\",\"default\":null},{\"name\":\"offsety\",\"kind\":\"Any\",\"default\":null},{\"name\":\"theme\",\"kind\":\"Any\",\"default\":\"primary\"},{\"name\":\"status\",\"kind\":\"Any\",\"default\":\"normalized\"}]},{\"type\":\"model\",\"name\":\"GridStack1\",\"properties\":[{\"name\":\"mode\",\"kind\":\"Any\",\"default\":\"warn\"},{\"name\":\"ncols\",\"kind\":\"Any\",\"default\":null},{\"name\":\"nrows\",\"kind\":\"Any\",\"default\":null},{\"name\":\"allow_resize\",\"kind\":\"Any\",\"default\":true},{\"name\":\"allow_drag\",\"kind\":\"Any\",\"default\":true},{\"name\":\"state\",\"kind\":\"Any\",\"default\":[]}]},{\"type\":\"model\",\"name\":\"drag1\",\"properties\":[{\"name\":\"slider_width\",\"kind\":\"Any\",\"default\":5},{\"name\":\"slider_color\",\"kind\":\"Any\",\"default\":\"black\"},{\"name\":\"value\",\"kind\":\"Any\",\"default\":50}]},{\"type\":\"model\",\"name\":\"click1\",\"properties\":[{\"name\":\"terminal_output\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"debug_name\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"clears\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"FastWrapper1\",\"properties\":[{\"name\":\"object\",\"kind\":\"Any\",\"default\":null},{\"name\":\"style\",\"kind\":\"Any\",\"default\":null}]},{\"type\":\"model\",\"name\":\"NotificationAreaBase1\",\"properties\":[{\"name\":\"js_events\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"bottom-right\"},{\"name\":\"_clear\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"NotificationArea1\",\"properties\":[{\"name\":\"js_events\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"notifications\",\"kind\":\"Any\",\"default\":[]},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"bottom-right\"},{\"name\":\"_clear\",\"kind\":\"Any\",\"default\":0},{\"name\":\"types\",\"kind\":\"Any\",\"default\":[{\"type\":\"map\",\"entries\":[[\"type\",\"warning\"],[\"background\",\"#ffc107\"],[\"icon\",{\"type\":\"map\",\"entries\":[[\"className\",\"fas fa-exclamation-triangle\"],[\"tagName\",\"i\"],[\"color\",\"white\"]]}]]},{\"type\":\"map\",\"entries\":[[\"type\",\"info\"],[\"background\",\"#007bff\"],[\"icon\",{\"type\":\"map\",\"entries\":[[\"className\",\"fas fa-info-circle\"],[\"tagName\",\"i\"],[\"color\",\"white\"]]}]]}]}]},{\"type\":\"model\",\"name\":\"Notification\",\"properties\":[{\"name\":\"background\",\"kind\":\"Any\",\"default\":null},{\"name\":\"duration\",\"kind\":\"Any\",\"default\":3000},{\"name\":\"icon\",\"kind\":\"Any\",\"default\":null},{\"name\":\"message\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"notification_type\",\"kind\":\"Any\",\"default\":null},{\"name\":\"_destroyed\",\"kind\":\"Any\",\"default\":false}]},{\"type\":\"model\",\"name\":\"TemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"BootstrapTemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"TemplateEditor1\",\"properties\":[{\"name\":\"layout\",\"kind\":\"Any\",\"default\":[]}]},{\"type\":\"model\",\"name\":\"MaterialTemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"copy_to_clipboard1\",\"properties\":[{\"name\":\"fill\",\"kind\":\"Any\",\"default\":\"none\"},{\"name\":\"value\",\"kind\":\"Any\",\"default\":null}]}]}};\n",
" var render_items = [{\"docid\":\"e6f58b87-1cec-4b66-85d0-bb42c1391cc7\",\"roots\":{\"p1836\":\"fe6515f8-8014-4d88-afcc-81e4c449e883\"},\"root_ids\":[\"p1836\"]}];\n",
" var docs_json = {\"9d2ee785-689a-4014-a60b-915e7453a507\":{\"version\":\"3.4.0\",\"title\":\"Bokeh Application\",\"roots\":[{\"type\":\"object\",\"name\":\"panel.models.browser.BrowserInfo\",\"id\":\"p1979\"},{\"type\":\"object\",\"name\":\"panel.models.comm_manager.CommManager\",\"id\":\"p1980\",\"attributes\":{\"plot_id\":\"p1979\",\"comm_id\":\"ebc72233b8264369b0b56b683015592e\",\"client_comm_id\":\"4e0274c8bfb74f78917b76ed1ad0836e\"}}],\"defs\":[{\"type\":\"model\",\"name\":\"ReactiveHTML1\"},{\"type\":\"model\",\"name\":\"FlexBox1\",\"properties\":[{\"name\":\"align_content\",\"kind\":\"Any\",\"default\":\"flex-start\"},{\"name\":\"align_items\",\"kind\":\"Any\",\"default\":\"flex-start\"},{\"name\":\"flex_direction\",\"kind\":\"Any\",\"default\":\"row\"},{\"name\":\"flex_wrap\",\"kind\":\"Any\",\"default\":\"wrap\"},{\"name\":\"gap\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"justify_content\",\"kind\":\"Any\",\"default\":\"flex-start\"}]},{\"type\":\"model\",\"name\":\"FloatPanel1\",\"properties\":[{\"name\":\"config\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"contained\",\"kind\":\"Any\",\"default\":true},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"right-top\"},{\"name\":\"offsetx\",\"kind\":\"Any\",\"default\":null},{\"name\":\"offsety\",\"kind\":\"Any\",\"default\":null},{\"name\":\"theme\",\"kind\":\"Any\",\"default\":\"primary\"},{\"name\":\"status\",\"kind\":\"Any\",\"default\":\"normalized\"}]},{\"type\":\"model\",\"name\":\"GridStack1\",\"properties\":[{\"name\":\"mode\",\"kind\":\"Any\",\"default\":\"warn\"},{\"name\":\"ncols\",\"kind\":\"Any\",\"default\":null},{\"name\":\"nrows\",\"kind\":\"Any\",\"default\":null},{\"name\":\"allow_resize\",\"kind\":\"Any\",\"default\":true},{\"name\":\"allow_drag\",\"kind\":\"Any\",\"default\":true},{\"name\":\"state\",\"kind\":\"Any\",\"default\":[]}]},{\"type\":\"model\",\"name\":\"drag1\",\"properties\":[{\"name\":\"slider_width\",\"kind\":\"Any\",\"default\":5},{\"name\":\"slider_color\",\"kind\":\"Any\",\"default\":\"black\"},{\"name\":\"value\",\"kind\":\"Any\",\"default\":50}]},{\"type\":\"model\",\"name\":\"click1\",\"properties\":[{\"name\":\"terminal_output\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"debug_name\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"clears\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"FastWrapper1\",\"properties\":[{\"name\":\"object\",\"kind\":\"Any\",\"default\":null},{\"name\":\"style\",\"kind\":\"Any\",\"default\":null}]},{\"type\":\"model\",\"name\":\"NotificationAreaBase1\",\"properties\":[{\"name\":\"js_events\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"bottom-right\"},{\"name\":\"_clear\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"NotificationArea1\",\"properties\":[{\"name\":\"js_events\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"notifications\",\"kind\":\"Any\",\"default\":[]},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"bottom-right\"},{\"name\":\"_clear\",\"kind\":\"Any\",\"default\":0},{\"name\":\"types\",\"kind\":\"Any\",\"default\":[{\"type\":\"map\",\"entries\":[[\"type\",\"warning\"],[\"background\",\"#ffc107\"],[\"icon\",{\"type\":\"map\",\"entries\":[[\"className\",\"fas fa-exclamation-triangle\"],[\"tagName\",\"i\"],[\"color\",\"white\"]]}]]},{\"type\":\"map\",\"entries\":[[\"type\",\"info\"],[\"background\",\"#007bff\"],[\"icon\",{\"type\":\"map\",\"entries\":[[\"className\",\"fas fa-info-circle\"],[\"tagName\",\"i\"],[\"color\",\"white\"]]}]]}]}]},{\"type\":\"model\",\"name\":\"Notification\",\"properties\":[{\"name\":\"background\",\"kind\":\"Any\",\"default\":null},{\"name\":\"duration\",\"kind\":\"Any\",\"default\":3000},{\"name\":\"icon\",\"kind\":\"Any\",\"default\":null},{\"name\":\"message\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"notification_type\",\"kind\":\"Any\",\"default\":null},{\"name\":\"_destroyed\",\"kind\":\"Any\",\"default\":false}]},{\"type\":\"model\",\"name\":\"TemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"BootstrapTemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"TemplateEditor1\",\"properties\":[{\"name\":\"layout\",\"kind\":\"Any\",\"default\":[]}]},{\"type\":\"model\",\"name\":\"MaterialTemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"copy_to_clipboard1\",\"properties\":[{\"name\":\"fill\",\"kind\":\"Any\",\"default\":\"none\"},{\"name\":\"value\",\"kind\":\"Any\",\"default\":null}]}]}};\n",
" var render_items = [{\"docid\":\"9d2ee785-689a-4014-a60b-915e7453a507\",\"roots\":{\"p1979\":\"be859ba0-9d7f-40bd-a0df-2b301c8b2fa9\"},\"root_ids\":[\"p1979\"]}];\n",
" var docs = Object.values(docs_json)\n",
" if (!docs) {\n",
" return\n",
Expand Down Expand Up @@ -2343,7 +2352,7 @@
},
"metadata": {
"application/vnd.holoviews_exec.v0+json": {
"id": "p1836"
"id": "p1979"
}
},
"output_type": "display_data"
Expand Down Expand Up @@ -2441,7 +2450,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "73de2ceb9d6b4480b29924ea7f94ad51",
"model_id": "a31915135dd14b1787f49af48acc797d",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -2455,7 +2464,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7fe0241785be4c628b07c327911ccea5",
"model_id": "b21d8a25f63744f88189f2e22d71ab1f",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -2469,7 +2478,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b8859781fbba49009d320fd80fc8cf2a",
"model_id": "7b166961d6d24486bef89a97b40b39cd",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -2486,13 +2495,13 @@
"'/Users/mgrover/git_repos/esgf-cookbook/notebooks/plot.html'"
]
},
"execution_count": 79,
"execution_count": 114,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sample = run_plot_enso(source_id=\"CESM2\", return_path=True)\n",
"sample = run_plot_enso(source_id=\"MPI-ESM1-2-LR\", return_path=True)\n",
"sample"
]
},
Expand Down

0 comments on commit 53e3d43

Please sign in to comment.