NCL Home > Documentation > Functions > WRF, Interpolation

wrf_user_interp_line

Interpolates a two-dimensional WRF-ARW field along a line.

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_interp_line (
		var2d      : numeric,  
		loc_param  : numeric,  
		opt    [1] : logical   
	)

	return_val  :  numeric

Arguments

var2d

A WRF-ARW field to be interpolated; it must have at least two dimensions, with the rightmost dimensions being latitude x longitude.

loc_param

Four values representing the start point and end point for the line (start_x, start_y, end_x, end_y), OR two values representing a single point when opt@use_pivot is set to True, representing the pivot point.

The values can be in grid coordinates or lat/lon coordinates (start_x = start_lon, start_y = start_lat, end_x = end_lon, end_y = end_lat). See the description below for more information.

opt

A logical scalar that can optionally contain attributes. See description below.

Return value

Data interpolated to a specified line on the model domain.

Description

This function interpolates two-dimensional WRF-ARW model data onto a specified line.

This function replaces wrf_user_intrp2d, which will be deprecated in NCL V6.6.0.

The interpolation can be further customized by attaching attributes to the opt argument:

  • use_pivot - set to True to indicate that loc_param and opt@angle are used. Otherwise, loc_param must be set to four values to indicate a start and end point.

    Default: False

  • angle - an angle for vertical plots - 90 represents a WE interpolation line; ignored if opt@use_pivot is either not set or is set to False.

    Default: 0.0

  • latlon - set to True if the values in loc_param are latitude and longitude values rather than grid values

    Default: False

  • file_handle - must be set to an NCL file handle (returned from addfile or addfiles) when opt@latlon is True or opt@linecoords is True; otherwise, this is ignored.

  • timeidx - the time index to use for moving nests when latlon is True. Set to 0 if the nest is not moving.

    Default: 0

  • linecoords - set to True to attach the latitude and longitude coordinates for the interpolation line as attributes "lats" and "lons" on the return variable.

    Default: False

See Also

wrf_user_interp_level, wrf_user_vert_cross

Examples

Example 1: Interpolate a 2D field to two lines: one using a west-east line and one using a north-south line.

  a = addfile("wrfout_d01_2008-09-28_06:30:00","r")

;---Calculate T2 at first time step
  t2 = wrf_user_getvar(a,"T2",0)
  printVarSummary(t2)    ; [south_north | 197] x [west_east | 206]

;---Interpolate the field to a line using a pivot point in the middle of the domain and an angle.
  dims          = dimsizes(t2)
  loc_param     = (/ dims(1)/2, dims(0)/2 /)
  opt           = True
  opt@use_pivot = True

  opt@angle     = 90.                      ; line from west to east
  t2_line_we   = wrf_user_interp_line(t2,loc_param,opt)

  opt@angle     = 0.                       ; line from south to north
  t2_line_sn   = wrf_user_interp_line(t2,loc_param,opt)

  printVarSummary(t2_line_we)     ; [line_idx | 206]
  printVarSummary(t2_line_sn)     ; [line_idx | 197]

Output:

  Variable: t2
  Type: float
  Total Size: 162328 bytes
              40582 values
  Number of Dimensions: 2
  Dimensions and sizes : [south_north | 197] x [west_east | 206]
  Coordinates: 
  Number Of Attributes: 6
  FieldType : 104
  MemoryOrder : XY 
  description : TEMP at 2 M
  units : K
  stagger :
  coordinates : XLONG XLAT
  
  Variable: t2_line_we
  Type: float
  Total Size: 824 bytes
              206 values
  Number of Dimensions: 1
  Dimensions and sizes : [line_idx | 206]
  Coordinates: 
  Number Of Attributes : 3
  units : K
  description : TEMP at 2 M
  _FillValue : 9.96921e+36
  
  
  Variable: t2_line_sn
  Type: float
  Total Size: 788 bytes
              197 values
  Number of Dimensions: 1
  Dimensions and sizes : [line_idx | 197]
  Coordinates: 
  Number Of Attributes: 3
  units : K
  description : TEMP at 2 M
  _FillValue : 9.96921e+36

Example 2: Interpolate a 2D filed to a line (read from 105 WRF output files) using start and end lat/lon values.

;---Open multiple WRF output files 
  dir       = "./"
  filenames = systemfunc("ls " + dir + "wrfout_d01_2008-09*")  ; 105 files
  a = addfiles(filenames,"r")

;---Get T2 for all time steps
  t2 = wrf_user_getvar(a, "T2",-1)   ; [Time | 105] x [south_north | 197] x [west_east | 206]

;---Start/end lat/lon line for interpolation
  start_lon = 115
  end_lon   = 130
  start_lat =  52
  end_lat   =  42

;---Options for lat/lon line
  opt             = True
  opt@latlon      = True
  opt@file_handle = a[0]   ; use first file; only valid if not a moving nest
  opt@linecoords  = True   ; returns lat/lon values on line as attributes of return value

;---Interpolate the 2D field to the lat/lon line
  t2_line  = wrf_user_interp_line(t2,(/start_lon,start_lat,end_lon,end_lat/),opt)
  printVarSummary(t2_line)   ; [Time | 105] x [south_north | 197] x [west_east | 206]

Output:

  Variable: t2
  Total Size: 17044440 bytes
              4261110 values
  Type: float
  Number of Dimensions: 3
  Dimensions and sizes : [Time | 105] x [south_north | 197] x [west_east | 206]
  Coordinates: 
  Number Of Attributes: 6
  FieldType : 104
  MemoryOrder : XY 
  description : TEMP at 2 M
  units : K
  stagger :
  coordinates : XLONG XLAT
  
  Variable: t2_line
  Type: float
  Total Size: 27720 bytes
              6930 values
  Number of Dimensions: 2
  Dimensions and sizes : [Time | 105] x [line_idx | 66]
  Coordinates: 
  Number Of Attributes : 5
  units : K
  description : TEMP at 2 M
  _FillValue : 9.96921e+36
  lats : <ARRAY of 66 elements>
  lons : <ARRAY of 66 elements>