{ "cells": [ { "cell_type": "markdown", "id": "48080cc2-be7e-4fa2-b34d-329041fccdd7", "metadata": {}, "source": [ "# University of Wyoming and UFS-Chem: Read Paired Data and Create Plots" ] }, { "cell_type": "markdown", "id": "1f968f42-85e9-4eab-bbe7-f53e3c54e315", "metadata": {}, "source": [ "Our first example will demonstrate the basics available in MELODIES MONET to compare the UFS-Chem model results against University of Wyoming sonde observations (https://weather.uwyo.edu/upperair/sounding.shtml) for dewpoint, relative humidity, wind speed, wind direction, potential temperature, and specific humidity.\n", "\n", "This example reads in the University of Wyoming paired data created by the previous example titled \"Example for Pairing University of Wyoming data with UFS-Chem\". This includes analysis over a day and a sampling of 2s.\n", "\n", "First, we import the melodies_monet.driver module." ] }, { "cell_type": "code", "execution_count": 1, "id": "d7240c01-7c05-49e7-bfca-01e23dc6bed6", "metadata": {}, "outputs": [], "source": [ "from melodies_monet import driver" ] }, { "cell_type": "markdown", "id": "0a8484c7-5b57-4d0b-b132-cb30338bac43", "metadata": {}, "source": [ "## Analysis driver class" ] }, { "cell_type": "markdown", "id": "24c2f889-4fde-4e13-9092-35c54c096148", "metadata": {}, "source": [ "Now, lets create an instance of the analysis driver class, melodies_monet.driver.analysis. It consists of these main parts:\n", "\n", "* model instances\n", "\n", "* observation instances\n", "\n", "* a paired instance of both" ] }, { "cell_type": "code", "execution_count": 2, "id": "45a85e85-8d36-4dd6-8001-c6cc28275746", "metadata": {}, "outputs": [], "source": [ "an = driver.analysis()" ] }, { "cell_type": "markdown", "id": "6c5b21f7-9d2d-4b32-b8e8-853f7587e733", "metadata": {}, "source": [ "Initially, most of our analysis object’s attributes are set to None, though some have meaningful defaults:" ] }, { "cell_type": "code", "execution_count": 3, "id": "84f0538c-2bc4-468d-8130-5878ef45f600", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "analysis(\n", " control='control.yaml',\n", " control_dict=None,\n", " models={},\n", " obs={},\n", " paired={},\n", " start_time=None,\n", " end_time=None,\n", " time_intervals=None,\n", " download_maps=True,\n", " output_dir=None,\n", " output_dir_save=None,\n", " output_dir_read=None,\n", " debug=False,\n", " save=None,\n", " read=None,\n", " regrid=False,\n", ")" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "an" ] }, { "cell_type": "markdown", "id": "8f39e654-28eb-42b0-ad1b-887ef241755c", "metadata": {}, "source": [ "## Control file" ] }, { "cell_type": "markdown", "id": "265ea0ea-d420-4c6f-ab87-65229adb2df5", "metadata": {}, "source": [ "We set the YAML control file and begin by reading the file." ] }, { "cell_type": "code", "execution_count": 4, "id": "cf1a865a-ead4-436a-8287-5bb8cbf4d3fe", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'analysis': {'start_time': '2023-08-01 00:00:00',\n", " 'end_time': '2023-08-02-00:00:00',\n", " 'output_dir': './output/uwy_ufschem',\n", " 'debug': True,\n", " 'read': {'paired': {'method': 'netcdf',\n", " 'filenames': {'uwy_ufschem': ['0801_12Z_72632_uwy_ufschem.nc4']}}}},\n", " 'model': {'ufschem': {'files': 'example:ufschem:2023-08-01',\n", " 'mod_type': 'ufschem',\n", " 'radius_of_influence': 100000,\n", " 'extra_calc': {'dewpoint': {'specific_hum': 'spfh',\n", " 'pres_calc': 'pressure_model'},\n", " 'rel_hum': {'specific_hum': 'spfh',\n", " 'pres_calc': 'pressure_model',\n", " 'temp_calc': 'temperature_k'},\n", " 'windspeed': {'u_comp': 'ugrd', 'v_comp': 'vgrd'},\n", " 'winddir': {'u_comp': 'ugrd', 'v_comp': 'vgrd'},\n", " 'ptemp_mod': {'pres_calc': 'pressure_model',\n", " 'temp_calc': 'temperature_k'}},\n", " 'mapping': {'uwy': {'temperature_k': 'temperature_C',\n", " 'dewpoint': 'dpt_obs',\n", " 'rel_hum': 'relh_obs',\n", " 'windspeed': 'windspeed_obs',\n", " 'winddir': 'wdir_obs',\n", " 'ptemp_mod': 'ptemp_obs'}},\n", " 'variables': {'pres_pa_mid': {'rename': 'pressure_model',\n", " 'unit_scale': 1,\n", " 'unit_scale_method': '*'}},\n", " 'projection': None,\n", " 'plot_kwargs': {'color': 'dodgerblue', 'marker': '^', 'linestyle': ':'}}},\n", " 'obs': {'uwy': {'filename': 'example:uwy-sonde:2023-08-01',\n", " 'obs_type': 'aircraft',\n", " 'time_var': 'time',\n", " 'resample': '2s',\n", " 'extra_calc': {'ptemp_obs': {'temp_calc': 'temperature_C',\n", " 'pres_calc': 'pressure_obs'}},\n", " 'variables': {'pressure_hPa': {'rename': 'pressure_obs',\n", " 'unit_scale': 100,\n", " 'unit_scale_method': '*',\n", " 'ylabel_plot': 'Pressure (Pa)',\n", " 'xlabel_plot': 'Pressure (Pa)',\n", " 'nan_value': -1},\n", " 'temperature_C': {'unit_scale': 273.15,\n", " 'unit_scale_method': '+',\n", " 'ylabel_plot': 'Temperature (K)',\n", " 'xlabel_plot': 'Temperature (K)',\n", " 'nan_value': -1},\n", " 'dew point temperature_C': {'rename': 'dpt_obs',\n", " 'unit_scale': 273.15,\n", " 'unit_scale_method': '+',\n", " 'ylabel_plot': 'Dewpoint (K)',\n", " 'xlabel_plot': 'Dewpoint (K)',\n", " 'nan_value': -1},\n", " 'relative humidity_%': {'rename': 'relh_obs',\n", " 'unit_scale': 1,\n", " 'unit_scale_method': '*',\n", " 'ylabel_plot': 'Relative Humidity (%)',\n", " 'xlabel_plot': 'Relative Humidity (%)',\n", " 'nan_value': -1},\n", " 'wind speed_m/s': {'rename': 'windspeed_obs',\n", " 'unit_scale': 1,\n", " 'unit_scale_method': '*',\n", " 'ylabel_plot': 'Windspeed (m/s)',\n", " 'xlabel_plot': 'Windspeed (m/s)',\n", " 'nan_value': -1},\n", " 'ptemp_obs': {'ylabel_plot': 'Potential Temperature (K)',\n", " 'xlabel_plot': 'Potential Temperature (K)'},\n", " 'wind direction_degree': {'rename': 'wdir_obs',\n", " 'unit_scale': 1,\n", " 'unit_scale_method': '*',\n", " 'ylabel_plot': 'Wind direction (deg)',\n", " 'xlabel_plot': 'Wind direction (deg)',\n", " 'nan_value': -1}}}},\n", " 'plots': {'plot_grp1': {'type': 'timeseries',\n", " 'fig_kwargs': {'figsize': [12, 6]},\n", " 'default_plot_kwargs': {'linewidth': 2.0, 'markersize': 5.0},\n", " 'text_kwargs': {'fontsize': 18.0},\n", " 'domain_type': ['all'],\n", " 'domain_name': ['White Lake MI (72632)'],\n", " 'data': ['uwy_ufschem'],\n", " 'data_proc': {'altitude_variable': 'pressure_obs',\n", " 'rem_obs_nan': True,\n", " 'ts_select_time': 'time',\n", " 'set_axis': False,\n", " 'altitude_yax2': {'altitude_variable': 'pressure_obs',\n", " 'altitude_ticks': 20000,\n", " 'ylabel2': 'Pressure (Pa)',\n", " 'plot_kwargs_y2': {'color': 'g'}}}},\n", " 'plot_grp2': {'type': 'vertprofile',\n", " 'fig_kwargs': {'figsize': [10, 14]},\n", " 'default_plot_kwargs': {'linewidth': 4.0, 'markersize': 10.0},\n", " 'text_kwargs': {'fontsize': 24.0},\n", " 'ylabel_vert': 'Pressure (Pa)',\n", " 'domain_type': ['all'],\n", " 'domain_name': ['White Lake MI (72632)'],\n", " 'data': ['uwy_ufschem'],\n", " 'data_proc': {'rem_obs_nan': True,\n", " 'set_axis': False,\n", " 'interquartile_style': 'shading'},\n", " 'altitude_variable': 'pressure_obs',\n", " 'vertprofile_bins': {'range': {'start': 0, 'stop': 100001, 'step': 5000}},\n", " 'vmin': 0,\n", " 'vmax': 100000,\n", " 'gridlines': True}}}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "control_fn='control_read_looped_aircraft_UWY_UFS_CHEM.yaml'\n", "an.control=control_fn\n", "an.read_control() \n", "an.control_dict " ] }, { "cell_type": "markdown", "id": "a0afea3b-d7cd-4dbd-afb0-4364ddaf08dd", "metadata": {}, "source": [ "Now, some of our analysis object’s attributes are populated:" ] }, { "cell_type": "code", "execution_count": 5, "id": "1adbb5e0-17a1-4420-978a-7c2b27bc0452", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "analysis(\n", " control='control_read_looped_aircraft_UWY_UFS_CHEM.yaml',\n", " control_dict=...,\n", " models={},\n", " obs={},\n", " paired={},\n", " start_time=Timestamp('2023-08-01 00:00:00'),\n", " end_time=Timestamp('2023-08-02 00:00:00'),\n", " time_intervals=None,\n", " download_maps=True,\n", " output_dir='./output/uwy_ufschem',\n", " output_dir_save='./output/uwy_ufschem',\n", " output_dir_read='./output/uwy_ufschem',\n", " debug=True,\n", " save=None,\n", " read={'paired': {'method': 'netcdf', 'filenames': {'uwy_ufschem': ['0801_12Z_72632_uwy_ufschem.nc4']}}},\n", " regrid=False,\n", ")" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "an" ] }, { "cell_type": "markdown", "id": "f31ca9b8-be51-4116-831a-dc8568b964ac", "metadata": {}, "source": [ "## Load the model data" ] }, { "cell_type": "markdown", "id": "bd3879b4-511a-4566-8019-96a07f52bca0", "metadata": {}, "source": [ "The driver will automatically loop through the “models” found in the model section of the YAML file and create an instance of melodies_monet.driver.model for each that includes the\n", "\n", "* label\n", "\n", "* mapping information\n", "\n", "* file names (can be expressed using a glob expression)\n", "\n", "* xarray object" ] }, { "cell_type": "code", "execution_count": 6, "id": "70b89dc7-5d11-47b6-b53f-ef1a05b2bf59", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ufschem\n", "example:ufschem:2023-08-01\n", "**** Reading UFS-AQM or UFS-Chem model output...\n", "Performing extra model calculations...\n", "Calculating modeled Dewpoint...\n", "Calculating modeled relative humidity...\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/Users/rschwantes/Documents/MONET/version1.1/Met_updates/review/MELODIES-MONET/melodies_monet/util/metcalc.py:115: UserWarning: Saturation mixing ratio is undefined for some requested pressure/temperature combinations. Total pressure must be greater than the water vapor saturation pressure for liquid water to be in equilibrium.\n", " rlh = (metpy.calc.relative_humidity_from_specific_humidity(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Calculating modeled windspeed...\n", "Calculating modeled wind direction...\n", "Calculating modeled potential temperature...\n" ] } ], "source": [ "an.open_models()" ] }, { "cell_type": "markdown", "id": "dc72de4e-8379-4dd7-bdb5-747882b800c0", "metadata": {}, "source": [ "Applying open_models() populates the models attribute." ] }, { "cell_type": "code", "execution_count": 7, "id": "49e3ca24-3457-4bc6-9b0b-f247661c64de", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'ufschem': model(\n", " model='ufschem',\n", " is_global=False,\n", " radius_of_influence=100000,\n", " mod_kwargs={'var_list': ['spfh', 'ugrd', 'vgrd', 'lat', 'lon', 'phalf', 'tmp', 'pressfc', 'dpres', 'hgtsfc', 'delz']},\n", " file_str='example:ufschem:2023-08-01',\n", " label='ufschem',\n", " obj=...,\n", " extra_calc={'dewpoint': {'specific_hum': 'spfh', 'pres_calc': 'pressure_model'}, 'rel_hum': {'specific_hum': 'spfh', 'pres_calc': 'pressure_model', 'temp_calc': 'temperature_k'}, 'windspeed': {'u_comp': 'ugrd', 'v_comp': 'vgrd'}, 'winddir': {'u_comp': 'ugrd', 'v_comp': 'vgrd'}, 'ptemp_mod': {'pres_calc': 'pressure_model', 'temp_calc': 'temperature_k'}},\n", " mapping={'uwy': {'temperature_k': 'temperature_C', 'dewpoint': 'dpt_obs', 'rel_hum': 'relh_obs', 'windspeed': 'windspeed_obs', 'winddir': 'wdir_obs', 'ptemp_mod': 'ptemp_obs'}},\n", " variable_dict={'spfh': 'None', 'pressure_model': {'rename': 'pressure_model', 'unit_scale': 1, 'unit_scale_method': '*'}, 'temperature_k': 'None', 'ugrd': 'None', 'vgrd': 'None'},\n", " label='ufschem',\n", " ...\n", " )}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "an.models" ] }, { "cell_type": "markdown", "id": "b33c2c76-296c-40da-82bd-e7c33a23c4f3", "metadata": {}, "source": [ "We can access the underlying dataset with the obj attribute." ] }, { "cell_type": "code", "execution_count": 8, "id": "c5343592-fc96-467a-9d09-c3a380b9eed0", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset> Size: 8GB\n",
"Dimensions: (time: 24, z: 64, y: 192, x: 384)\n",
"Coordinates:\n",
" latitude (y, x) float64 590kB dask.array<chunksize=(192, 384), meta=np.ndarray>\n",
" longitude (y, x) float64 590kB dask.array<chunksize=(192, 384), meta=np.ndarray>\n",
" * time (time) datetime64[ns] 192B 2023-08-01T01:00:00 ... 2023-0...\n",
"Dimensions without coordinates: z, y, x\n",
"Data variables: (12/15)\n",
" spfh (time, z, y, x) float32 453MB dask.array<chunksize=(1, 1, 192, 384), meta=np.ndarray>\n",
" ugrd (time, z, y, x) float32 453MB dask.array<chunksize=(1, 1, 192, 384), meta=np.ndarray>\n",
" vgrd (time, z, y, x) float32 453MB dask.array<chunksize=(1, 1, 192, 384), meta=np.ndarray>\n",
" temperature_k (time, z, y, x) float32 453MB dask.array<chunksize=(1, 1, 192, 384), meta=np.ndarray>\n",
" surfpres_pa (time, y, x) float32 7MB dask.array<chunksize=(1, 192, 384), meta=np.ndarray>\n",
" dp_pa (time, z, y, x) float32 453MB dask.array<chunksize=(1, 1, 192, 384), meta=np.ndarray>\n",
" ... ...\n",
" alt_msl_m_full (time, z, y, x) float32 453MB dask.array<chunksize=(1, 1, 192, 384), meta=np.ndarray>\n",
" dewpoint (time, z, y, x) float64 906MB dask.array<chunksize=(1, 1, 192, 384), meta=np.ndarray>\n",
" rel_hum (time, z, y, x) float64 906MB dask.array<chunksize=(1, 1, 192, 384), meta=np.ndarray>\n",
" windspeed (time, z, y, x) float32 453MB dask.array<chunksize=(1, 1, 192, 384), meta=np.ndarray>\n",
" winddir (time, z, y, x) float32 453MB 88.26 89.23 ... 49.98 48.84\n",
" ptemp_mod (time, z, y, x) float64 906MB dask.array<chunksize=(1, 1, 192, 384), meta=np.ndarray>\n",
"Attributes:\n",
" ak: [2.0000000e+01 6.4247000e+01 1.3779000e+02 2.2195800e+02 3....\n",
" bk: [0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 0....\n",
" grid: gaussian\n",
" grid_id: 1\n",
" hydrostatic: non-hydrostatic\n",
" im: 384\n",
" jm: 192\n",
" ncnsto: 139\n",
" source: FV3GFS\n",
" history: Tue Mar 3 14:52:03 2026: ncrcat 20230801_dynf001.nc 202308...\n",
" NCO: netCDF Operators version 5.0.7 (Homepage = http://nco.sf.ne...<xarray.Dataset> Size: 405kB\n",
"Dimensions: (time: 3619)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 29kB 2023-08-01T11:05:36 ....\n",
"Data variables: (12/13)\n",
" longitude (time) float64 29kB -83.47 -83.47 ... nan -83.13\n",
" latitude (time) float64 29kB 42.7 42.7 42.7 ... nan 41.93\n",
" pressure_obs (time) float64 29kB 9.836e+04 9.824e+04 ... 520.0\n",
" geopotential height_m (time) float64 29kB 332.0 343.0 ... nan 3.597e+04\n",
" temperature_C (time) float64 29kB 286.9 288.8 290.0 ... nan 239.6\n",
" dpt_obs (time) float64 29kB 286.0 286.7 286.1 ... nan 196.0\n",
" ... ...\n",
" relh_obs (time) float64 29kB 95.0 87.5 77.5 ... nan nan 0.0\n",
" humidity wrt ice_% (time) float64 29kB 95.0 87.5 77.5 ... nan nan 1.0\n",
" mixing ratio_g/kg (time) float64 29kB 9.58 9.98 9.62 ... nan nan 0.2\n",
" wdir_obs (time) float64 29kB 66.5 129.0 129.0 ... nan 109.0\n",
" windspeed_obs (time) float64 29kB 1.25 2.9 3.25 ... nan nan 26.9\n",
" ptemp_obs (time) float64 29kB 288.3 290.3 ... nan 1.077e+03