Re: Bug in the wrf_user_ll_to_ij function ????????

From: wrfhelp <wrfhelp_at_nyahnyahspammersnyahnyah>
Date: Tue Jun 19 2012 - 12:25:03 MDT

Both the functions should work correctly.
The differences between the two are:
        ll_to_ij can return the ij from anywhere in the world in relation to your domain, latlon_to_ij can not do this
        ll_to_ij will return values in Fortran space, latlon_to_ij will return values in ncl space (so the arrays as NCL see them, so for this you do not have to subtract -1)

The script below will find the smallest min and max, lat/lon values, but these are not necessarily the corner points. For a Lambert projection, these may be outside the domain. If values are outside the domain, latlon_to_ij will simply return the corner values as it cannot calculate outside the domain, so it seems correct.
ll_to_ij will return the relative points, which may be outside the domain - and in this case it seems incorrect.

To get the the correct corner points you need a script that looks something like this:

opts = True

xLat_f1 = wrf_user_getvar(f1,"XLAT", 0)
xLong_f1 = wrf_user_getvar(f1,"XLONG", 0)
dims = dimsizes(xLat_f1)

;xLat_min = min(xLat_f1)
;xLat_max = max(xLat_f1)
xLat_min = xLat_f1(0,0)
xLat_max = xLat_f1(dims(0)-1,dims(1)-1)

;xLong_min = min(xLong_f1)
;xLong_max = max(xLong_f1)
xLong_min = xLong_f1(0,0)
xLong_max = xLong_f1(dims(0)-1,dims(1)-1)

; New ll_to_ij function
min_loc_ll = wrf_user_ll_to_ij(f1,xLong_min,xLat_min,opts)
max_loc_ll = wrf_user_ll_to_ij(f1,xLong_max,xLat_max,opts)

print("min. x-coord fm ll func.: "+min_loc_ll(0)+"; min. y_coord fm ll func.: "+min_loc_ll(1))
print("max. x-coord fm ll func.: "+max_loc_ll(0)+"; max. y_coord fm ll func.: "+max_loc_ll(1))

; Old latlon_to_ij function
min_loc_latlon = wrf_user_latlon_to_ij(f1,xLat_min,xLong_min)
max_loc_latlon = wrf_user_latlon_to_ij(f1,xLat_max,xLong_max)

print("min. x-coord fm latlon func.: "+min_loc_latlon(1)+"; min. y_coord fm latlon func.: "+min_loc_latlon(0))
print("max. x-coord fm latlon func.: "+max_loc_latlon(1)+"; max. y_coord fm latlon func.: "+max_loc_latlon(0))

This will return
(0) min. x-coord fm ll func.: 1; min. y_coord fm ll func.: 1
(0) max. x-coord fm ll func.: 285; max. y_coord fm ll func.: 243
(0) min. x-coord fm latlon func.: 0; min. y_coord fm latlon func.: 0
(0) max. x-coord fm latlon func.: 284; max. y_coord fm latlon func.: 242

I have a domain with 285x243 points.
        You will see ll_to_ij return Fortran relative data (so 1 to 285, for instance) and latlon_to_ij returns the ncl arrays (so 0 to 284 in this case)

Hope this helps
wrfhelp
------------------------------------------------------------------------------
http://www.mmm.ucar.edu/wrf/users/supports/wrfhelp.html

On Jun 12, 2012, at 9:55 AM, Mary Haley wrote:

> I'm fowarding this to wrfhelp@ucar.edu.
>
> --Mary
>
> On Jun 12, 2012, at 7:48 AM, BasitAli Khan wrote:
>
>> Hi all,
>>
>> I am encountering this problem of converting latlon to ij coordinates using wrf_user_ll_to_ij function. When I convert max lat and long to ij coordinates, the function give me grid y_coordinates larger than total number of grid points in y_dimension. In the same way conversion of minimum longitude results in a negative number. However, the old latlon to ij conversion function "wrf_user_latlon_to_ij" does the conversion correctly.
>>
>> I wrote the following small code to recheck this. I used both old and new functions to show the difference. There are 651 x 651 grid points in the wrfout file.
>>
>>
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
>>
>> begin
>>
>> f1 = addfile("/wrfout_d01_2006-06-02_13:00:00.nc","r")
>>
>> opts = True
>>
>> xLat_f1 = wrf_user_getvar(f1,"XLAT", 0)
>> xLong_f1 = wrf_user_getvar(f1,"XLONG", 0)
>>
>> xLat_min = min(xLat_f1)
>> xLat_max = max(xLat_f1)
>>
>> xLong_min = min(xLong_f1)
>> xLong_max = max(xLong_f1)
>>
>> ; New ll_to_ij function
>> min_loc_ll = wrf_user_ll_to_ij(f1,xLong_min,xLat_min,opts)
>> max_loc_ll = wrf_user_ll_to_ij(f1,xLong_max,xLat_max,opts)
>>
>> print("min. x-coord fm ll func.: "+min_loc_ll(0)+"; min. y_coord fm ll func.: "+min_loc_ll(1))
>> print("max. x-coord fm ll func.: "+max_loc_ll(0)+"; max. y_coord fm ll func.: "+max_loc_ll(1))
>>
>> ; Old latlon_to_ij function
>> min_loc_latlon = wrf_user_latlon_to_ij(f1,xLat_min,xLong_min)
>> max_loc_latlon = wrf_user_latlon_to_ij(f1,xLat_max,xLong_max)
>>
>>
>> print("min. x-coord fm latlon func.: "+min_loc_latlon(1)+"; min. y_coord fm latlon func.: "+min_loc_latlon(0))
>> print("max. x-coord fm latlon func.: "+max_loc_latlon(1)+"; max. y_coord fm latlon func.: "+max_loc_latlon(0))
>>
>>
>> end
>> ;;;
>>
>> Output from wrf_user_ll_to_ij
>> min. x-coord fm ll func.: -16; min. y_coord fm ll func.: 0
>> max. x-coord fm ll func.: 651; max. y_coord fm ll func.: 657
>> Output from wrf_user_latlon_to_ij
>> min. x-coord fm latlon func.: 0; min. y_coord fm latlon func.: 0
>> max. x-coord fm latlon func.: 650; max. y_coord fm latlon func.: 650
>> ;----------------------------------------------------------
>>
>>
>>
>> I am just wondering if there is some bug in this function (wrf_user_ll_to_ij).
>>
>> Cheers,
>> ----
>> Basit A. Khan, Ph.D.
>> Postdoctoral Research Fellow
>> Division of Physical Sciences & Engineering
>> Office# 3204, Level 3, Building 1,
>> King Abdullah University of Science & Technology
>> 4700 King Abdullah Blvd, Box 2753, Thuwal 23955 –6900,
>> Kingdom of Saudi Arabia.
>>
>> Office: +966(0)2 808 0276, Mobile: +966(0)5 0860 3617
>> E-mail: basitali.khan@kaust.edu.sa
>> Skype name: basit.a.khan
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Jun 19 12:25:12 2012

This archive was generated by hypermail 2.1.8 : Mon Jun 25 2012 - 09:57:23 MDT