Plotting \(\frac{\mathrm{d}p_s}{\mathrm{d}t}\) from ICON’s log file#
Load the necessary Python modules
import getpass
import re
import datetime
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
Extract \(\frac{\mathrm{d}p_s}{\mathrm{d}t}\) information from the log file:
user = getpass.getuser()
Exercise:
Specify the log file you want to use for plotting.
logfile = f"/scratch/{user[0]}/{user}/exercise_realdata/????????"
dpsdt_grep = list(filter(None, [re.findall(r"dPS/dt\| =\s*([0-9.]*).*domain 1.*",line) for line in open(logfile)]))
dpsdt = [float(item) for sublist in dpsdt_grep for item in sublist] # flat list
Extract date and time information from log file and store in temporary file
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)]))
timestamps = [item for sublist in timestamp_grep for item in sublist] # flat list
dates = [datetime.datetime.strptime(d,'%Y-%m-%d %H:%M:%S.%f') for d in timestamps] # reformat as date objects
Create the plot:
plt.figure(figsize=(12,8))
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m/%d/%Y'))
plt.gca().xaxis.set_major_locator(mdates.DayLocator())
plt.plot(dates,dpsdt)
plt.ylabel(r"$\frac{\mathrm{d}p_s}{\mathrm{d}t}\quad [Pa/s]$")
plt.show()
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.