{ "cells": [ { "cell_type": "markdown", "id": "aaf7c461-93f9-48b8-a5ac-e6fe9c57e918", "metadata": { "tags": [] }, "source": [ "# Plotting $\\frac{\\mathrm{d}p_s}{\\mathrm{d}t}$ from ICON's log file" ] }, { "cell_type": "markdown", "id": "fed5a0e6-4786-4357-b037-fbee4d29ec7c", "metadata": {}, "source": [ "Load the necessary Python modules" ] }, { "cell_type": "code", "execution_count": null, "id": "8812373c-4adb-487c-a465-2ce2a27de2e6", "metadata": {}, "outputs": [], "source": [ "import getpass\n", "import re\n", "import datetime\n", "import matplotlib.pyplot as plt\n", "import matplotlib.dates as mdates" ] }, { "cell_type": "markdown", "id": "406bf39a-a0f8-4075-8c26-50677c28f0bf", "metadata": {}, "source": [ "Extract $\\frac{\\mathrm{d}p_s}{\\mathrm{d}t}$ information from the log file:" ] }, { "cell_type": "code", "execution_count": null, "id": "12465eb9-6ba7-4b6b-bd5c-1ddb8edb533e", "metadata": {}, "outputs": [], "source": [ "user = getpass.getuser()" ] }, { "cell_type": "markdown", "id": "991adae2-d8ac-4370-8dad-c02c0c14115e", "metadata": {}, "source": [ "
\n", " Exercise: \n", " Specify the log file you want to use for plotting.\n", "
" ] }, { "cell_type": "code", "execution_count": null, "id": "6377bf6a-8df7-4b83-ac32-7de7dbf1e326", "metadata": {}, "outputs": [], "source": [ "logfile = f\"/scratch/{user[0]}/{user}/exercise_realdata/????????\"" ] }, { "cell_type": "code", "execution_count": null, "id": "16f9d3ea-576b-44bb-b756-d51305275172", "metadata": {}, "outputs": [], "source": [ "dpsdt_grep = list(filter(None, [re.findall(r\"dPS/dt\\| =\\s*([0-9.]*).*domain 1.*\",line) for line in open(logfile)]))\n", "dpsdt = [float(item) for sublist in dpsdt_grep for item in sublist] # flat list" ] }, { "cell_type": "markdown", "id": "022ee131-30e7-4325-bab2-c45d36c754df", "metadata": {}, "source": [ "Extract date and time information from log file and store in temporary file" ] }, { "cell_type": "code", "execution_count": null, "id": "73492091-ca7d-4351-96ef-9b1d52fd9699", "metadata": {}, "outputs": [], "source": [ "timestamp_grep = list(filter(None, [re.findall(r\"Time step:\\s*[\\-0-9]*.*model time: ([0-9\\-]* [0-9:.]*)\",line) for line in open(logfile)]))\n", "timestamps = [item for sublist in timestamp_grep for item in sublist] # flat list\n", "dates = [datetime.datetime.strptime(d,'%Y-%m-%d %H:%M:%S.%f') for d in timestamps] # reformat as date objects" ] }, { "cell_type": "markdown", "id": "fcf90ffb-ca70-474d-a4f1-8a36a4c94f58", "metadata": {}, "source": [ "Create the plot:" ] }, { "cell_type": "code", "execution_count": null, "id": "602a41fc-65c7-49cd-b74a-2eb342f56883", "metadata": {}, "outputs": [], "source": [ "plt.figure(figsize=(12,8))\n", "plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m/%d/%Y'))\n", "plt.gca().xaxis.set_major_locator(mdates.DayLocator())\n", "plt.plot(dates,dpsdt)\n", "plt.ylabel(r\"$\\frac{\\mathrm{d}p_s}{\\mathrm{d}t}\\quad [Pa/s]$\")\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "49e662cb-6fe1-4d97-9dc0-8e35b1a88176", "metadata": {}, "source": [ "---\n", "\n", "*Author info: Deutscher Wetterdienst (DWD) 2022 :: icon@dwd.de. For a full list of contributors, see CONTRIBUTING in the root directory. License info: see LICENSE file.*" ] } ], "metadata": { "kernelspec": { "display_name": "1 Python 3 (based on the module python3/2023.01)", "language": "python", "name": "python3_2023_01" }, "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.10.10" } }, "nbformat": 4, "nbformat_minor": 5 }