NCL script to plot filled wind speed contours and streamlines

Derrick Salmon

New member
I have searched the forums but see no similar issues, so apologies if I have missed relevant posts. I have spent 3 days attempting to plot filled wind speed contours over plotted with streamlines for a regional domain using a wrfout file and, after MANY variations, I keep failing. I can get a plot but always with a global world view.

If anyone can suggest corrections to the script, or better, has an appropriate NCL script they would be good enough to share as a template this would be greatly appreciated.

typical failure message follows, and an early script version follows that.

(0) check_for_y_lat_coord: Warning: Data either does not contain
(0) a valid latitude coordinate array or doesn't contain one at all.
(0) A valid latitude coordinate array should have a 'units'
(0) attribute equal to one of the following values:
(0) 'degrees_north' 'degrees-north' 'degree_north' 'degrees north' 'degrees_N' 'Degrees_north' 'degree_N' 'degreeN' 'degreesN' 'deg north'
(0) check_for_lon_coord: Warning: Data either does not contain
(0) a valid longitude coordinate array or doesn't contain one at all.
(0) A valid longitude coordinate array should have a 'units'
(0) attribute equal to one of the following values:
(0) 'degrees_east' 'degrees-east' 'degree_east' 'degrees east' 'degrees_E' 'Degrees_east' 'degree_E' 'degreeE' 'degreesE' 'deg east'

; Load the required WRF NCL libraries
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

begin
; Open the WRF output file
filename = "wrfout_d02_2025-02-06_06:00:00" ; Modify with actual filename
f = addfile(filename, "r")

; Read U and V wind components at a specified level (e.g., 10m or a pressure level)
U10 = wrf_user_getvar(f, "U10", -1) ; 10m U-wind component
V10 = wrf_user_getvar(f, "V10", -1) ; 10m V-wind component

U10 = U10(0, :, :)
V10 = V10(0, :, :)

; Calculate wind speed
WSPD = sqrt(U10^2 + V10^2)

; Get lat/lon from file
lat = wrf_user_getvar(f, "XLAT", -1)
lon = wrf_user_getvar(f, "XLONG", -1)

lat = lat(0,:,:)
lon = lon(0,:,:)

; print(lat)
; print(lon)

; check XLAT and XLONG variables
printVarSummary(lat)
printVarSummary(lon)

; Open a workstation (X11 for interactive display, or change to PNG/PDF)
wks = gsn_open_wks("x11", "wind_speed_streamlines")

; Set contour plot resources
res = True
res@gsnMaximize = True
res@cnFillOn = True
res@cnFillPalette = "BlAqGrYeOrRe" ; Color map for wind speed
res@cnLinesOn = False
res@lbLabelBarOn = True
res@tiMainString = "Wind Speed (m/s) and Streamlines (10m)"

; Set streamline resources
st_res = True
st_res@gsnMaximize = True
st_res@stLineColor = "black" ; Streamlines in black
st_res@stMinDistanceF = 0.02 ; Controls streamline density

; covert WSPD from 3D to 2D

WSPD2 = WSPD(0,:,:)

; Generate the contour plot
plot = gsn_csm_contour_map(wks, WSPD2, res)

; Overlay streamlines
stream = gsn_csm_streamline(wks, U10, V10, st_res)

; Overlay streamlines on the contour plot
overlay(plot, stream)

; Draw and frame the plot
draw(plot)
frame(wks)

end
 
I have searched the forums but see no similar issues, so apologies if I have missed relevant posts. I have spent 3 days attempting to plot filled wind speed contours over plotted with streamlines for a regional domain using a wrfout file and, after MANY variations, I keep failing. I can get a plot but always with a global world view.

If anyone can suggest corrections to the script, or better, has an appropriate NCL script they would be good enough to share as a template this would be greatly appreciated.

typical failure message follows, and an early script version follows that.

(0) check_for_y_lat_coord: Warning: Data either does not contain
(0) a valid latitude coordinate array or doesn't contain one at all.
(0) A valid latitude coordinate array should have a 'units'
(0) attribute equal to one of the following values:
(0) 'degrees_north' 'degrees-north' 'degree_north' 'degrees north' 'degrees_N' 'Degrees_north' 'degree_N' 'degreeN' 'degreesN' 'deg north'
(0) check_for_lon_coord: Warning: Data either does not contain
(0) a valid longitude coordinate array or doesn't contain one at all.
(0) A valid longitude coordinate array should have a 'units'
(0) attribute equal to one of the following values:
(0) 'degrees_east' 'degrees-east' 'degree_east' 'degrees east' 'degrees_E' 'Degrees_east' 'degree_E' 'degreeE' 'degreesE' 'deg east'

; Load the required WRF NCL libraries
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

begin
; Open the WRF output file
filename = "wrfout_d02_2025-02-06_06:00:00" ; Modify with actual filename
f = addfile(filename, "r")

; Read U and V wind components at a specified level (e.g., 10m or a pressure level)
U10 = wrf_user_getvar(f, "U10", -1) ; 10m U-wind component
V10 = wrf_user_getvar(f, "V10", -1) ; 10m V-wind component

U10 = U10(0, :, :)
V10 = V10(0, :, :)

; Calculate wind speed
WSPD = sqrt(U10^2 + V10^2)

; Get lat/lon from file
lat = wrf_user_getvar(f, "XLAT", -1)
lon = wrf_user_getvar(f, "XLONG", -1)

lat = lat(0,:,:)
lon = lon(0,:,:)

; print(lat)
; print(lon)

; check XLAT and XLONG variables
printVarSummary(lat)
printVarSummary(lon)

; Open a workstation (X11 for interactive display, or change to PNG/PDF)
wks = gsn_open_wks("x11", "wind_speed_streamlines")

; Set contour plot resources
res = True
res@gsnMaximize = True
res@cnFillOn = True
res@cnFillPalette = "BlAqGrYeOrRe" ; Color map for wind speed
res@cnLinesOn = False
res@lbLabelBarOn = True
res@tiMainString = "Wind Speed (m/s) and Streamlines (10m)"

; Set streamline resources
st_res = True
st_res@gsnMaximize = True
st_res@stLineColor = "black" ; Streamlines in black
st_res@stMinDistanceF = 0.02 ; Controls streamline density

; covert WSPD from 3D to 2D

WSPD2 = WSPD(0,:,:)

; Generate the contour plot
plot = gsn_csm_contour_map(wks, WSPD2, res)

; Overlay streamlines
stream = gsn_csm_streamline(wks, U10, V10, st_res)

; Overlay streamlines on the contour plot
overlay(plot, stream)

; Draw and frame the plot
draw(plot)
frame(wks)

end
if you know python i would reccomend wrf-python, it's a little easier to do it there
 
Back
Top