Run and Plot a Retrieval#
This page applies the retrieval from Create a Retrieval to local measurements, then plots the saved predictions in Python.
Run the Retrieval#
From the working project, with its environment activated:
openMWR predict my_site NN_example --date 2025-01-12
Choose a date with local HATPRO files. The command saves a daily NetCDF file
under data/sites/my_site/predictions/2025/01/. See
Run Retrieval Operational for date ranges and regular runs.
Load the predictions#
Run the following cells from the working project. The displayed figures
illustrate Munich retrievals. They are not training results for NN_example.
Rerun the cells for other models and data.
%config InlineBackend.figure_format = 'svg'
from datetime import datetime
from openMWR.predict import load_predictions
PROJECT_DIR = "."
site = "my_site"
date = datetime(2025, 1, 12)
result = load_predictions(PROJECT_DIR, site, date)
pred = result.zenith.sel(model="NN_example")
pred
Plot the results#
The SkewT object from openMWR.plot plots a profile at a selected time.
It can compare retrievals with radiosondes and other retrievals. plot_radiosonde
loads the nearest launch from the station’s cached raw data. Download the
radiosonde year for the plotted date first. See
Create a Retrieval.
from openMWR.plot import SkewT
from openMWR.site import get_config_parameter
raso_station_id = '03715'
station_alt = get_config_parameter(site, 'mwr_height', PROJECT_DIR)
noon = date.replace(hour=12)
skew = SkewT(noon, project_dir=PROJECT_DIR, station_alt=station_alt)
skew.plot_radiosonde(raso_station_id)
skew.plot_retrieval(pred, 'NN_example', color='red')
skew.finalize()
To plot data from a full day, the TimeSeriesPlot object from openMWR.plot can be used. It is a wrapper around Matplotlib.
from openMWR.plot import TimeSeriesPlot
pre_title = 'Meteorological Institute of Ludwig-Maximilians-Universität (München, Germany; 48.148 N / 11.573 E)'
data = pred.sel(height=slice(0, 10000)).transpose('time', ...)
temp = TimeSeriesPlot(date,
'Temperature - HATPRO Retrieval (NN)',
pre_title=pre_title)
ax = temp.add_axis(ylabel='Height [km]')
ax.plot_filled_contours(data.time,
data.height/1000,
data.T.values.T,
'Temperature [K]',
'RdBu_r')
rain_flag_mask = data['rain_flag'] > 0
ax.add_hatches(rain_flag_mask.time.values, rain_flag_mask.values)
temp.show()
lwp = TimeSeriesPlot(date, 'Liquid Water Path', pre_title=pre_title)
ax = lwp.add_axis(lower_ylabel=True, ylabel='[g/$m^2$]')
ax.plot(pred.time, pred.lwp, label='Hatpro Retrieval (NN)')
ax.set_best_ylim(step_of_step=10, fix_min=0)
rain_flag_mask = pred['rain_flag'] > 0
ax.add_hatches(rain_flag_mask.time.values, rain_flag_mask.values)
lwp.create_legend_with_handles()
lwp.show()
For some standard plots, like the ones above, convenience methods are available in the TimeSeriesCreator class from openMWR.plot.
from openMWR.plot import TimeSeriesCreator
temp = TimeSeriesCreator.temp(date,
data,
pre_title=pre_title,
retrieval_label='Hatpro Retrieval (NN)')
temp.show()
lwp = TimeSeriesCreator.lwp(date,
pred,
pre_title=pre_title,
retrieval_label='Hatpro Retrieval (NN)')
lwp.show()
Boundary Layer Scan Retrieval#
After training NN_BLS_example, include it when predicting:
openMWR predict my_site NN_example NN_BLS_example --date 2025-01-12
The scan result is saved in a separate daily file. Reload it to compare the zenith and scan profiles:
result = load_predictions(PROJECT_DIR, site, date)
pred_bls = result.bls.sel(model="NN_BLS_example")
skew = SkewT(noon, project_dir=PROJECT_DIR, station_alt=station_alt)
skew.plot_radiosonde(raso_station_id)
skew.plot_retrieval(pred, 'NN_example', color='red')
skew.plot_retrieval(pred_bls, 'NN_BLS_example', color='green')
skew.finalize()