[ncl-talk] wrf_user_intrp3d with rectilinear grid, dimension mismatch

Mary Haley haley at ucar.edu
Tue Apr 26 20:15:57 MDT 2016


Ryan,

When you use ESMF_regrid, it's not required that the dimensions of the
source and destination grids match.

There are three types of grids you might encounter in regridding:

1) rectilinear

You have a 2D data array dimensioned nlat x nlon, and the latitudes are
represented by a 1D array of size nlat, and the longitudes are represented
by a 1D array of size nlon. These are often known as coordinate arrays, and
you can identify them right away in NCL because when you do a
"printVarSummary" on a variable, you will see something like:

Variable: ts
Type: float
Total Size: 414056448 bytes
            103514112 values
Number of Dimensions: 3
Dimensions and sizes: [time | 1872] x [lat | 192] x [lon | 288]
Coordinates:
            time: [15.5..56924.5]
            lat: [ -90..  90]
            lon: [   0..358.75]

Note that under the "Coordinates" section it actually gives you the list of
coordinate arrays associated with your variable "ts", which tells you that
you have a rectilinear grid.

2) curvilinear

You have a 2D data array dimensioned nlat x nlon, and the latitudes AND
longitudes are represented by 2D arrays of size nlat x nlon. The WRF data
you read in is a curvilinear grid, because XLAT and XLONG are both 2D
arrays of the same dimensionality.

3) unstructured

Here you don't have a "gridded" data array, but rather a structure like a
triangular mesh or a hexagonal grid. I'm not going to go into this one
since this is not what you are dealing with here.

In practice, your source and destination grids can be any of these types,
and hence the dimensions do not have to match.  The idea behind regridding
is that you are trying to get your data that is on some particular grid
("source" grid), onto a *different* grid ("destination" grid), so that you
can perhaps you can do array calculations on the regridded data with some
other variable on the same destination grid.

In your case, your source grid (the WRF grid) is a curvilinear grid, and
the script you are using is regridding it to a rectilinear grid, so it's
correct that you are getting this:

(0) write_grid_description: source lat dims = (281,353)
(0) write_grid_description: source lon dims = (281,353)
(0) write_grid_description: source grid type is 'curvilinear'
(...)
(0) write_grid_description: destination lat dims = (281)
(0) write_grid_description: destination lon dims = (353)
(0) write_grid_description: destination grid type is 'rectilinear'

I believe this script is based on the same one used by ESMF_regrid_5.ncl at:

http://www.ncl.ucar.edu/Applications/ESMF.shtml#ex5

As a side, I'm not sure why you are doing this:

    dst_lat = fspan(lat_south,lat_north,src_lat)
    dst_lon = fspan(lon_west,lon_east,src_lon)

The "fspan" function is a very basic function where you give it a start
value, an end value, and the number of equally-spaced values you want to
span between those two values. For example:

  x = fspan(1,5,4)    ; 1, 2.3333, 3.666667, 5

You are trying to give "fspan" an array of latitudes and longitudes for the
third argument which makes no sense and simply won't work.

Backing up a bit here, why are you trying to regrid your WRF "tc" variable
before you call wrf_user_intrp3d?  Couldn't you simply subscript tc using
the lat/lon indexes you calculated, and pass this to wrf_user_intrp3d?


--Mary



On Tue, Apr 26, 2016 at 3:10 PM, Ryan Connelly <rconne01 at gmail.com> wrote:

> Follow-up: I had my lat and lon arrays switched.  Fixed that.  But the
> error still persists.
>
> It seems to be a Catch 22.  Right now, I have
>
>     locSW = wrf_user_ij_to_ll(a,1.,1.,True)     ; SW corner of domain for
> lat and lon minima. Func is fortran-based so 1 not 0
>     lon_west = locSW(0)
>     lat_south = locSW(1)
>
> ; Use any variable that spans the entire grid to get maxima of i,j
> ; which will then be used to get lat, lon of upper right (NE) corner
>
>     grid_size = dimsizes(tc)                    ; z is 0th index, lat 1st,
> lon 2nd
>     jMax = grid_size(1)
>     iMax = grid_size(2)
>
>     locNE = wrf_user_ij_to_ll(a,iMax,jMax,True)     ; NE corner of domain
> for lat and lon maxima. Func is fortran-based so max not max-1
>     lon_east = locNE(0)
>     lat_north = locNE(1)
>
>     n = dimsizes(lat)
>     m = dimsizes(lon)
>
>     nlat = n(0)
>     mlon = m(1)
>
>     dst_lat = fspan(lat_south,lat_north,nlat)
>     dst_lon = fspan(lon_west,lon_east,mlon)
>
> which means that element (2) of fspan has 1 dimension.  Therefore, in the
> output, I see:
>
> (0) write_grid_description: source lat dims = (281,353)
> (0) write_grid_description: source lon dims = (281,353)
> (0) write_grid_description: source grid type is 'curvilinear'
> (...)
> (0) write_grid_description: destination lat dims = (281)
> (0) write_grid_description: destination lon dims = (353)
> (0) write_grid_description: destination grid type is 'rectilinear'
>
> which seems like it should not be.  Shouldn't I want(need) the dimensions
> of the source and destination grid to match?
>
> So then, in fspan, I switch nlat to src_lat and mlon to src_lon, making
> that element two-dimensional instead of one-dimensional:
>
>     dst_lat = fspan(lat_south,lat_north,src_lat)
>     dst_lon = fspan(lon_west,lon_east,src_lon)
>
> Yet when I run with that change, I get: fatal:Number of dimensions in
> parameter (2) of (fspan) is (2), (1) dimensions were expected
>
> How can NCL simultaneously be expecting a one- and two-dimension array?
> I'm very confused here.
>
> Ryan
>
> On Tue, Apr 26, 2016 at 2:16 PM, Ryan Connelly <rconne01 at gmail.com> wrote:
>
>> Hi,
>>
>> I'm using ESMF_WRF_to_rect.ncl to regrid (
>> https://www.ncl.ucar.edu/Applications/Templates/ESMF_WRF_to_rect.ncl).
>> Regridding completes fine, but then when i try to interpolate the regridded
>> variable to an isobaric plane using wrf_user_intrp3d I get:
>>
>> fatal:Dimension size mismatch, dimension (1) of left hand side reference
>> does not have the same size as the right hand side reference after
>> subscripting.
>>
>> This is a pretty literal error message and one that I've fixed before,
>> but this time it has me stumped.  I haven't even declared the variable on
>> the left hand side until this particular line (and I've double checked that
>> by issuing a printVarSummary and having it throw a variable undefined
>> error) so how can the dimension sizes not match if this is a blank new
>> variable?
>>
>> I then decided to be extra super literal and declare a new array with the
>> right dimensions before calling wrf_user_intrp3d, but the error persists:
>>
>> (...)
>> tc_rect = ESMF_regrid(tc,Opt)     ; Do the regridding
>>
>>
>> ; Interpolate to isobaric planes
>>
>>       pressure = 850.
>>
>>       newdim = (dimsizes(tc_rect))
>>       print(newdim)
>>
>>       tc_rect_plane =
>> new((/newdim(0),newdim(1),newdim(2)/),typeof(tc_rect))
>>
>>       tc_rect_plane = wrf_user_intrp3d(tc_rect,p,"h",pressure,0.,False)
>> (...)
>>
>> I'm out of ideas here.
>>
>> Ryan
>>
>> --
>> Ryan Connelly
>> M.S. Student in Atmospheric Sciences, Stony Brook University
>> B.S. in Meteorology with Minors in Mathematics and GIS, Valparaiso
>> University
>> rconne01 at gmail.com
>> ryan.connelly at stonybrook.edu
>>
>
>
>
> --
> Ryan Connelly
> M.S. Student in Atmospheric Sciences, Stony Brook University
> B.S. in Meteorology with Minors in Mathematics and GIS, Valparaiso
> University
> rconne01 at gmail.com
> ryan.connelly at stonybrook.edu
>
> _______________________________________________
> 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/20160426/3a076bd0/attachment.html 


More information about the ncl-talk mailing list