[ncl-talk] Dealing with 2D lat and lon outputs of WRF

Dennis Shea shea at ucar.edu
Fri Oct 4 16:26:04 MDT 2019


As noted by Rick, the *grad_latlon_cfd*
<http://www.ncl.ucar.edu/Document/Functions/Contributed/grad_latlon_cfd.shtml>
 requires a rectilinear grid.
One-dimensional lat/lon arrays. This is clear in both the text and
the function prototyping

	function *grad_latlon_cfd*
<http://www.ncl.ucar.edu/Document/Functions/Contributed/grad_latlon_cfd.shtml>
(
		z          : numeric,  ; float, double, integer only
		*lat    [*]* : numeric,
		*lon    [*]* : numeric,
		cyclic [1] : logical,
		opt    [1] : logical
	)

===============================================================
   a      = *addfile*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/addfile.shtml>
(""wrfout_d04_2005-07-29_12:06:00","r")
   ctt    = *wrf_user_getvar*
<http://www.ncl.ucar.edu/Document/Functions/WRF_arw/wrf_user_getvar.shtml>(a,"ctt",-1)

   *printVarSummary*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/printVarSummary.shtml>(ctt)
  ; Examine variable
   opt_sd = True
   opt_sd at PrintStat = True
   stat_ctt = *stat_dispersion*
<http://www.ncl.ucar.edu/Document/Functions/Contributed/stat_dispersion.shtml>(ctt,
opt_sd )  ; look at distribution

   lat2d  = *wrf_user_getvar*(a,"XLAT",0)
   lon2d  = *wrf_user_getvar*(a,"XLONG",0)

   dim2d  = *dimsizes*(lat2d)
   nlat   = dim2d(0)     ; arbitrary; here (roughly same resolution as WRF)
   mlon   = dim2d(1)
                         ; generate rectilinear coordinate variables
   lat    = *fspan*( *min*(lat2d), *max*(lat2d) ,nlat)
   lon    = *fspan*( *min*(lon2d), *max*(lon2d) ,mlon)
   lat!0 = "lat"
   lon!0 = "lon"
   lat at units = "degrees_north"
   lon at units = "degrees_east"

; Bilinear interpolation to rectilinear ['regular'] grid

   cttgrd = *rcm2rgrid_Wrap*(lat2d,lon2d,ctt,lat,lon,0)
   *printVarSummary*(cttgrd)
   print("-----")

; Zonal and Meridional gradients

   cttLatLon    = *grad_latlon_cfd*
<http://www.ncl.ucar.edu/Document/Functions/Contributed/grad_latlon_cfd.shtml>
(cttgrd, lat, lon, False, False)

; Extract variables from the list variable
   ctt_grad_lat = gradLatLon[0]    ; Gradients in latitudinal
[meridional] direction
   ctt_grad_lon = gradLatLon[1]    ; Gradients in longitudinal [zonal] direction

   *printVarSummary*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/printVarSummary.shtml>(ctt_grad_lat)
  ; Examine variable
   stat_ctt_lat = *stat_dispersion*
<http://www.ncl.ucar.edu/Document/Functions/Contributed/stat_dispersion.shtml>(ctt_grad_lat,
opt_sd )  ; look at distribution
   print("-----")

   *printVarSummary*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/printVarSummary.shtml>(ctt_grad_lon)
   stat_ctt_lon = *stat_dispersion*
<http://www.ncl.ucar.edu/Document/Functions/Contributed/stat_dispersion.shtml>(ctt_grad_lon,
opt_sd )  ; look at distribution
   print("-----")

; Interpolate gradients back to WRF grid

  ctt_grad_lat_wrf  = *rgrid2rcm_Wrap*
<http://www.ncl.ucar.edu/Document/Functions/Contributed/rgrid2rcm_Wrap.shtml>
(lat, lon, ctt_grad_lat, lat2d, lon2d, 0)
  ctt_grad_lon_wrf  = *rgrid2rcm_Wrap*
<http://www.ncl.ucar.edu/Document/Functions/Contributed/rgrid2rcm_Wrap.shtml>
(lat, lon, ctt_grad_lon, lat2d, lon2d, 0)
  *printVarSummary*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/printVarSummary.shtml>(ctt_grad_lat_wrf)
  *printVarSummary*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/printVarSummary.shtml>(ctt_grad_lon_wrf)

===

There are multiple example of this methodology using ESMF_regrid
*http://www.ncl.ucar.edu/Applications/ESMF.shtml *
<http://www.ncl.ucar.edu/Applications/ESMF.shtml>

Examples: 29, 30, 37 [others there also]

Please examine carefully.


On Fri, Oct 4, 2019 at 9:59 PM Rick Brownrigg via ncl-talk <
ncl-talk at ucar.edu> wrote:

> Hi,
>
> I am not expert at this, but based upon the docs for the
> function_latlon_cfd, it looks like it requires a rectilinear grid, which
> would imply you'll need to regrid your curvilinear WRF grid. NCL has
> numerous functions for doing this (I can't advise which one you should use):
>
>    http://ncl.ucar.edu/Applications/regrid.shtml
>
> I also note in the second warning you provided, its complaining about 3
> dimensions in parameter 1 (i.e., the lat variable) -- Is there a time
> dimension on that variable as well as X/Y?
>
> Hope that helps...
> Rick
>
>
> On Fri, Oct 4, 2019 at 1:25 PM Prashanth Bhalachandran via ncl-talk <
> ncl-talk at ucar.edu> wrote:
>
>> Dear NCL'ers,
>> I have a question on dealing with the 2D lat and long variables from WRF
>> output. For example, in my code below, I am having trouble using the lat
>> long information to either use them as coordinate variables or to be used
>> as inputs to the horizontal gradient function. What is the best way to
>> create or extract 1D lat and long information so that I can use them here?
>>
>> Thank you,
>> Prashanth
>>
>> begin
>>
>>
>> a = addfile("wrfout_d04_2005-07-29_12:06:00","r")
>>
>>
>> ctt = wrf_user_getvar(a,"ctt",-1) ; Cloud top temperatures in degree
>> Celsius
>>
>> lat = wrf_user_getvar(a,"XLAT",-1)
>>
>> lon = wrf_user_getvar(a,"XLONG",-1)
>>
>>
>> ;Original Dimensions and sizes: [Time | 10] x [south_north | 480] x
>> [west_east | 480]
>>
>>
>> ; Take the horizontal gradient
>>
>>   cttLatLon  = grad_latlon_cfd (ctt, lat, lon, False, False)
>>
>>
>>   ctt_grad_lat  = gradLatLon[0]    ; Extract Individual gradients in
>> latitudinal direction
>>
>>   ctt_grad_lon  = gradLatLon[1]    ; Gradient in longitudinal directional
>>
>>
>>   delete(cttLatLon)
>>
>>
>>    if(all(ismissing(ctt_grad_lat))) then
>>
>>     print("ctt_grad_lat contains all missing values, cannot continue.")
>>
>>     return
>>
>>   end if
>>
>>
>>     if(all(ismissing(ctt_grad_lon))) then
>>
>>     print("ctt_grad_lon contains all missing values, cannot continue.")
>>
>>     return
>>
>>   end if
>> end
>>
>>
>> Output:
>>
>> I can't prescribe lat and lon as coordinate variables since they are 2D.
>>
>> $ ncl -n -Q cloud_top.ncl
>>
>> fatal:Coordinate variables must have one dimension only
>>
>> fatal:No coordinate variable exists for dimension (lat) in variable (ctt)
>>
>> fatal:["Execute.c":8637]:Execute: Error occurred at or near line 12 in
>> file cloud_top.ncl
>>
>>
>> or use them as inputs to the gradient function:
>>
>> $ ncl -n -Q cloud_top.ncl
>>
>> fatal:Number of dimensions in parameter (1) of (grad_latlon_cfd) is (3),
>> (1) dimensions were expected
>>
>> fatal:["Execute.c":8637]:Execute: Error occurred at or near line 12 in
>> file cloud_top.ncl
>>
>>
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20191004/a15683f5/attachment.html>


More information about the ncl-talk mailing list