I am relatively new to Python, and I am having trouble plotting some data. Specifically, I am plotting wind speed data on a 2-D plot that I grabbed from the Weather Research & Forecasting (WRF) weather model. Though I'm able to generate a plot, there are noticeable gaps in plot, particularly as the model height increases. The purpose of generating these plots is to compare WRF model data to observations collected from dropsondes during a field campaign. Below is the code that I've been working with as well as the plot that was generated.

import numpy as np
from netCDF4 import Dataset
import wrf
from wrf import getvar
import glob
import pandas as pd
import matplotlib.pyplot as plt

dir = glob.glob('~/wrfout_d04_2017-05-27_20:00:00')
nf = range(0,len(dir),6)

for n in nf:
  data = Dataset(dir[n], 'r')
  windspeed = wrf.getvar(data, 'uvmet_wspd_wdir', meta = False)[0,:]
  winddir = wrf.getvar(data, 'wdir', meta = False)
  altitude = wrf.getvar(data, 'z', meta = False)
  lat = wrf.getvar(data, 'lat', meta = False)
  lon = wrf.getvar(data, 'lon', meta = False)

  for i in range(len(windspeed)):
    fig = plt.figure
    plt.plot(windspeed[i], altitude[i], color = 'blue')
    plt.xlabel('Wind speed (m/s)')
    plt.ylabel('Height (m)')
    plt.title('Wind speed and model height for\nwrfout_d04_2017-05-27_20:00:00')

enter image description here

I've tried checking to see if the WRF output file 'wrfout_d04_2017-05-27_20:00:00' contains masked data using ncdump -h wrfout_d04_2017-05-27_20:00:00, but I'm not seeing anything there. I really appreciate anyone taking the time to read this post and any recommendations would be greatly appreciated.

  • 1
    $\begingroup$ for these sort of questions it is recommended that you provide the data set somewhere otherwise how else can one try to provide a solution ? $\endgroup$ – gansub Jul 7 at 3:17
  • 1
    $\begingroup$ Hi. Yes, show us the data. I doubt that it is continuous anyway and would assume that distances get larger with increasing height. I have no idea of Python but a little bit of general programming, I'd check the documentation of those imported libraries, if the functions called do an aggregation or mean calculation (are these lines a spread that's in the data or calculated on the fly ?) scaling or anything else for the user experience. The chosen graph type also influences the display of the data. $\endgroup$ – user20217 Jul 7 at 5:29
  • 2
    $\begingroup$ The output looks reasonable: the data are written out on discrete vertical layers as @a_donda wrote. Probably the height of each layer varies spatially (the horizontal lines are slightly blurred). This might be due to pressure coordinates or terrain following coordinates. $\endgroup$ – daniel.heydebreck Jul 7 at 7:25

The answer is actually pretty easy. The WRF model lies on a grid. The vertical component of the grid is unevenly spaced, though you can manually space it. The vertical coordinate of WRF uses a sigma vertical coordinate (even though the namelist calls them eta): $$\sigma=\frac{P-P_{surface}}{P_{top}-P_{surface}}$$. So the values of sigma are specified (or just resorted to the default values). So when you get altitude levels for WRF, there is a space between the levels. You would probably find something similar if you change the y-axis to west-east or south-north.

The default vertical spacing for WRF has higher resolution near the surface, which is useful for convection and PBL modeling.

| improve this answer | |
  • 1
    $\begingroup$ This observation answered my question. Thank you so much! $\endgroup$ – mpletch1 Jul 8 at 20:30
  • $\begingroup$ You're welcome! $\endgroup$ – BarocliniCplusplus Jul 8 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.