{ "cells": [ { "cell_type": "markdown", "id": "ca114622-27c4-46db-be66-2c489639a83f", "metadata": {}, "source": [ "# Data Exploration\n", "## Volumetric Soil Water Layer 1 (0-7 cm): \"swvl1\"\n", "### Task: \n", "1. done - Load \"swvl1\" from 1991 to 2020 (load multiple GRIB files and stored in a dictionary) \n", "2. done - Find out statistics (mean and standard deviation) for each year and for the whole period\n", "3. half-done - Save results (maps) as png files and stored to the Gallery folder\n", "4. Locate when and where the values below 0 and top 10 percent values" ] }, { "cell_type": "code", "execution_count": 1, "id": "98ab6d49-86c5-48a9-9abe-a19ca5de8826", "metadata": { "ExecuteTime": { "end_time": "2022-04-19T19:51:16.027426Z", "start_time": "2022-04-19T19:51:14.533353Z" }, "execution": { "iopub.execute_input": "2022-01-21T00:50:02.308764Z", "iopub.status.busy": "2022-01-21T00:50:02.308541Z", "iopub.status.idle": "2022-01-21T00:50:02.312282Z", "shell.execute_reply": "2022-01-21T00:50:02.311679Z", "shell.execute_reply.started": "2022-01-21T00:50:02.308747Z" }, "tags": [] }, "outputs": [ { "ename": "ModuleNotFoundError", "evalue": "No module named 'matplotlib'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m/tmp/ipykernel_1348831/2963254748.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mmetview\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mmv\u001b[0m \u001b[0;31m# https://anaconda.org/conda-forge/metview\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mmatplotlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpyplot\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mplt\u001b[0m \u001b[0;31m# https://matplotlib.org/\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mmatplotlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpyplot\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mfigure\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mtqdm\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mtrange\u001b[0m \u001b[0;31m# https://github.com/tqdm/tqdm#tqdm\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mtqdm\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mtqdm\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'matplotlib'" ] } ], "source": [ "import metview as mv # https://anaconda.org/conda-forge/metview\n", "import matplotlib.pyplot as plt # https://matplotlib.org/\n", "from matplotlib.pyplot import figure\n", "from tqdm import trange # https://github.com/tqdm/tqdm#tqdm\n", "from tqdm import tqdm\n", "import datetime\n", "import xarray as xr" ] }, { "cell_type": "markdown", "id": "57e82851-45e1-4a38-8350-7a7adb3823fc", "metadata": {}, "source": [ "#### Load GRIB files\n", "Source: https://metview.readthedocs.io/en/latest/data_types/fieldset.html" ] }, { "cell_type": "code", "execution_count": null, "id": "a0f7c1af-909b-4913-9c4a-9b7c0e90e257", "metadata": { "ExecuteTime": { "end_time": "2022-01-23T06:38:35.287601Z", "start_time": "2022-01-23T06:38:33.368220Z" }, "execution": { "iopub.execute_input": "2022-01-20T22:53:01.863457Z", "iopub.status.busy": "2022-01-20T22:53:01.863151Z", "iopub.status.idle": "2022-01-20T22:54:25.946803Z", "shell.execute_reply": "2022-01-20T22:54:25.946188Z", "shell.execute_reply.started": "2022-01-20T22:53:01.863426Z" }, "tags": [] }, "outputs": [], "source": [ "#fs = mv.Fieldset(path='*_swvl1.grib')\n", "fs = mv.Fieldset(path='1991_swvl1.grib')" ] }, { "cell_type": "code", "execution_count": null, "id": "05068119-e03e-436d-b04a-e421f60a8612", "metadata": { "ExecuteTime": { "end_time": "2022-01-23T06:38:37.451610Z", "start_time": "2022-01-23T06:38:37.448292Z" }, "execution": { "iopub.execute_input": "2022-01-21T00:48:33.289804Z", "iopub.status.busy": "2022-01-21T00:48:33.289012Z", "iopub.status.idle": "2022-01-21T00:48:33.292397Z", "shell.execute_reply": "2022-01-21T00:48:33.291805Z", "shell.execute_reply.started": "2022-01-21T00:48:33.289777Z" }, "tags": [] }, "outputs": [], "source": [ "print(fs)" ] }, { "cell_type": "code", "execution_count": null, "id": "6b72c8d3", "metadata": { "ExecuteTime": { "end_time": "2022-01-23T06:38:41.106088Z", "start_time": "2022-01-23T06:38:40.970080Z" } }, "outputs": [], "source": [ "fs[0:5].ls(extra_keys=['units'])" ] }, { "cell_type": "code", "execution_count": null, "id": "aca7d5d5", "metadata": { "ExecuteTime": { "end_time": "2022-01-23T06:38:43.991286Z", "start_time": "2022-01-23T06:38:43.927605Z" } }, "outputs": [], "source": [ "fs[-5:].ls(extra_keys=['units'])" ] }, { "cell_type": "code", "execution_count": null, "id": "0714793b", "metadata": { "ExecuteTime": { "end_time": "2022-01-23T06:38:48.856812Z", "start_time": "2022-01-23T06:38:48.846085Z" } }, "outputs": [], "source": [ "mv.datainfo(fs[0])" ] }, { "cell_type": "code", "execution_count": null, "id": "1afd8fa0", "metadata": { "ExecuteTime": { "end_time": "2022-01-23T06:38:51.606380Z", "start_time": "2022-01-23T06:38:51.575898Z" } }, "outputs": [], "source": [ "mv.base_date(fs[0:12])" ] }, { "cell_type": "markdown", "id": "b9b260db-baf5-494c-9920-a05ae5009f88", "metadata": {}, "source": [ "Test that every timestep is a map of the variable over the Maritime Continent." ] }, { "cell_type": "code", "execution_count": null, "id": "5c4aad90-e01a-4946-8344-6d0ddc20b24f", "metadata": { "ExecuteTime": { "end_time": "2022-01-23T06:25:44.605117Z", "start_time": "2022-01-23T06:25:43.977299Z" }, "tags": [] }, "outputs": [], "source": [ "my_view = mv.geoview(\n", " map_area_definition=\"CORNERS\",\n", " #map_projection=\"CYLINDRICAL\",\n", " area=[-15.00, 90.00, 15.00, 160.00]\n", ")\n", "\n", "my_coast = mv.mcoast(\n", " map_coastline_colour=\"charcoal\",\n", " map_coastline_resolution=\"medium\",\n", " map_coastline_land_shade=\"off\",\n", " map_coastline_land_shade_colour=\"beige\",\n", " map_coastline_sea_shade=\"on\",\n", " map_coastline_sea_shade_colour=\"RGB(127,205,255)\",\n", " map_grid_line_style=\"dot\",\n", " map_label_height=0.35\n", ")\n", "\n", "my_contour = mv.mcont(\n", " legend=\"on\",\n", " contour=\"off\",\n", " contour_level_count=15,\n", " contour_label=\"off\",\n", " contour_shade=\"on\",\n", " contour_shade_method=\"area_fill\",\n", " contour_shade_max_level_colour=\"blue\",\n", " contour_shade_min_level_colour=\"red\"\n", ")\n", "\n", "my_legend = mv.mlegend(\n", " legend_display_type=\"CONTINUOUS\",\n", " legend_text_font_size=0.325,\n", " legend_text_colour=\"NAVY\"\n", ")\n", "\n", "my_title = mv.mtext(\n", " text_font_size=0.7\n", ")\n", "\n", "mv.setoutput(\"jupyter\", plot_widget=False, output_width=1200)\n", "mv.plot(my_view, fs[0], my_contour, my_legend, my_coast, my_title)" ] }, { "cell_type": "code", "execution_count": null, "id": "7cd57dd6-aa1d-4171-9078-efb58cfbf51a", "metadata": { "ExecuteTime": { "end_time": "2022-01-23T06:25:48.172964Z", "start_time": "2022-01-23T06:25:47.667554Z" }, "tags": [] }, "outputs": [], "source": [ "my_title = mv.mtext(\n", " text_font_size=0.7,\n", " text_lines=[\"Volumetric soil water (0-7 cm): daily mean 1992-01-01\"],\n", ")\n", "\n", "mv.setoutput('jupyter', plot_widget=False, output_width=1200)\n", "mv.plot(my_view, mv.mean(fs[0:24]), my_contour, my_legend, my_coast, my_title)" ] }, { "cell_type": "code", "execution_count": null, "id": "506fdb70", "metadata": { "ExecuteTime": { "end_time": "2022-01-23T06:25:51.170643Z", "start_time": "2022-01-23T06:25:50.719523Z" } }, "outputs": [], "source": [ "my_contour = mv.mcont(\n", " legend=\"on\",\n", " contour=\"off\",\n", " contour_level_count=8,\n", " contour_label=\"off\",\n", " contour_shade=\"on\",\n", " contour_shade_method=\"area_fill\",\n", " contour_shade_max_level_colour=\"blue\",\n", " contour_shade_min_level_colour=\"red\"\n", ")\n", "\n", "my_title = mv.mtext(\n", " text_font_size=0.7,\n", " text_lines=[\"Volumetric soil water (0-7 cm): daily stdev 1991-01-01\"],\n", ")\n", "\n", "mv.setoutput('jupyter', plot_widget=False, output_width=1200)\n", "mv.plot(my_view, mv.stdev(fs[0:24]), my_contour, my_legend, my_coast, my_title)" ] }, { "cell_type": "code", "execution_count": null, "id": "b793d393", "metadata": { "ExecuteTime": { "end_time": "2022-01-23T06:38:59.507383Z", "start_time": "2022-01-23T06:38:59.494150Z" } }, "outputs": [], "source": [ "mv.grib_get(fs[:12], ['shortName', 'dataDate', 'dataTime', 'units'])" ] }, { "cell_type": "code", "execution_count": null, "id": "75d9aa3f", "metadata": { "ExecuteTime": { "end_time": "2022-01-23T06:44:23.555667Z", "start_time": "2022-01-23T06:44:23.551644Z" } }, "outputs": [], "source": [ "xr.set_options(keep_attrs=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "93d862d2", "metadata": { "ExecuteTime": { "end_time": "2022-01-23T06:41:07.464455Z", "start_time": "2022-01-23T06:39:43.848952Z" } }, "outputs": [], "source": [ "ds = fs.to_dataset()" ] }, { "cell_type": "code", "execution_count": null, "id": "a56f9bbe", "metadata": { "ExecuteTime": { "end_time": "2022-01-23T06:42:42.834439Z", "start_time": "2022-01-23T06:42:42.801603Z" } }, "outputs": [], "source": [ "ds" ] }, { "cell_type": "code", "execution_count": null, "id": "014fe64a", "metadata": { "ExecuteTime": { "end_time": "2022-01-23T06:43:58.471435Z", "start_time": "2022-01-23T06:43:58.466943Z" } }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "df061081", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "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.7.12" }, "toc-autonumbering": false, "toc-showcode": false, "toc-showmarkdowntxt": false, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 5 }