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()
../_images/0f073967c1c1db8aab7ce91b84f35d722fa081ae0accbf3a89b54773387a913e.svg

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()
../_images/de263a1b92b54f8eda72f22e8a114809921c80de8c24a335bba31d073855592e.svg
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()
../_images/e2733a8f3f3ede5d11ec1e6cf3536b82c9a9beae1be476545b212b22f1d873d8.svg

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()
../_images/4b96dcd014432bbb0a334410940ec2f30782091e7ff6f9d9ca74e89b4b83aa90.svg ../_images/91fdad86e51fd8604ae58eb3826c1232caf1929bb66321d3c440d6a07c9d84c5.svg

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()
../_images/903525883d7642a459b9ec7446de1e496d0e48138cf254832a0539bd1a7568e2.svg