NCL Home > Documentation > Functions > WRF, Lat/Lon functions

wrf_user_xy_to_ll

Finds the nearest longitude, latitude locations to the specified WRF-ARW model grid indexes.

Available in version 6.6.0 and later.

Prototype

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"      ; These two libraries are automatically
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"    ; loaded from NCL V6.4.0 onward.
                                                              ; No need for user to explicitly load.

	function wrf_user_xy_to_ll (
		file_handle  : file or list,  
		x            : numeric,       
		y            : numeric,       
		opt          : logical        
	)

	return_val  :  float or double

Arguments

file_handle

Reference to a single WRF-ARW NetCDF file opened with addfile or a list of WRF-ARW NetCDF files opened with addfiles.

x
y

Arrays of x and y indexes for which longitude and latitude locations are required. These index values should be 0-based, meaning the index count starts at 0.

opt

A logical scalar containing attributes. See description below.

Return value

An array that holds the lon, lat locations to the input x, y indexes. If a single x, y location is used as input, the return value will have a dimension of 2, where the first element holds the lon location and the second element holds the lat location.

If an array of x, y values are used on input, the return value will be 2 x n, where n is the size of the input arrays.

Description

This function makes use of map projection information out of the input file (nc_file) to locate the lon/lat locations which corresponds to the input x/y locations. Note that if the x/y locations are outside your model domain, the returned lon/lat locations will represent a point outside the domain.

If opt is True, options can be attached to it as attributes. The list of possible attributes is as follows:

  • useTime - which time in the file should be used when extracting XLAT/XLONG arrays from input file. Only important to set if output is for a moving nest and all the output times are in a single wrfout file
wrf_user_xy_to_ll is part of a library of functions and procedures in WRFUserARW.ncl written to help users plot ARW WRF model data.

See Also

wrf_user_ll_to_xy

See the full list of WRF functions.

Examples

Example 1

  a   = addfile("wrfout_d01_2000-01-24_12:00:00.nc","r")
  ll = wrf_user_xy_to_ll(a, 10., 30., True)
  print("lon value is: " + ll(0))
  print("lat value is: " + ll(1))

Example 2

This example shows how using the output from wrf_user_ll_to_xy as input to wrf_user_xy_to_ll should give you close to the same values:

  a    = addfile("wrfout_d01_2000-01-24_12:00:00.nc","r")
  xlat = a->XLAT(0,:,:)
  xlon = a->XLONG(0,:,:)

  minlat =  30
  maxlat =  40
  minlon = -80
  maxlon = -70

;---Get xy indexes, and then use these to get lat/lon values back again.
  opt    = True
  loc    = wrf_user_ll_to_xy(a,(/minlon,maxlon/),(/minlat,maxlat/),opt)
  latlon = wrf_user_xy_to_ll(a,loc(0,:),loc(1,:),opt)


;---The min/max values printed should be close.
  print("----")
  print("Requested  min/max xlon = " + minlon + "/" + maxlon)
  print("Actual     min/max xlon = " + xlon(loc(1,0),loc(0,0)) + "/" + \
                                       xlon(loc(1,1),loc(0,1)))
  print("Calculated min/max xlon = " + latlon(0,0) + "/" + latlon(0,1))

  print("----")
  print("Requested  min/max xlat = " + minlat + "/" + maxlat)
  print("Actual     min/max xlat = " + xlat(loc(1,0),loc(0,0)) + "/" + \
                                       xlat(loc(1,1),loc(0,1)))
  print("Calculated min/max xlat = " + latlon(1,0) + "/" + latlon(1,1))
  print("----")

Example 3

You can retrieve xy coordinates from a list of WRF ARW NetCDF files:

  files = systemfunc("ls -1 wrfout_d01_2000*") + ".nc"
  a = addfiles(files,"r")

  ll = wrf_user_xy_to_ll(a, 10., 30., True)
  print("lon/lat values are: " + ll)

You can see some other example scripts and their resultant images at:

http://www2.mmm.ucar.edu/wrf/OnLineTutorial/Graphics/NCL/