<div dir="ltr">Hi Mary,<div><br></div><div>Thanks for taking the time to explain the differences. </div><div><br></div><div>I'm trying to follow this example script: <a href="https://www.ncl.ucar.edu/Applications/Templates/ESMF_WRF_to_rect.ncl" target="_blank">https://www.ncl.ucar.edu/Applications/Templates/ESMF_WRF_to_rect.ncl</a>. This is where I got fspan from, not that I knew why I was using it. It's a bit frustrating that in this script, nlat and nlon aren't actually declared, and except for suggestions on what to change, the script is rather sparsely commented, leaving me to guess what to input.</div><div><br></div><div>Moving wrf_user_intrp3d up ahead of the grid conversion, and with switching back to the 1D nlat and mlon in fspan, has gotten that portion to complete successfully, so I'll call that success.</div><div><br></div><div>Next problem: I'm getting an out of bounds error when I call grad_latlon_cfd that doesn't make sense, since I'm feeding it that [281,353] grid as the first arg and 281 and 353 as the second and third args, respectively, but it says something about an error on lon (the third arg).</div><div><br></div><div>Thanks,</div><div>Ryan</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 26, 2016 at 10:15 PM, Mary Haley <span dir="ltr"><<a href="mailto:haley@ucar.edu" target="_blank">haley@ucar.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-size:small">Ryan,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">When you use ESMF_regrid, it's not required that the dimensions of the source and destination grids match.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">There are three types of grids you might encounter in regridding:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">1) rectilinear</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">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:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace">Variable: ts</font></div><div class="gmail_default"><font face="monospace, monospace">Type: float</font></div><div class="gmail_default"><font face="monospace, monospace">Total Size: 414056448 bytes</font></div><div class="gmail_default"><font face="monospace, monospace"> 103514112 values</font></div><div class="gmail_default"><font face="monospace, monospace">Number of Dimensions: 3</font></div><div class="gmail_default"><font face="monospace, monospace">Dimensions and sizes:<span style="white-space:pre-wrap">        </span>[time | 1872] x [lat | 192] x [lon | 288]</font></div><div class="gmail_default"><font face="monospace, monospace">Coordinates: </font></div><div class="gmail_default"><font face="monospace, monospace"> time: [15.5..56924.5]</font></div><div class="gmail_default"><font face="monospace, monospace"> lat: [ -90.. 90]</font></div><div class="gmail_default"><font face="monospace, monospace"> lon: [ 0..358.75]</font></div><div class="gmail_default"><br></div><div class="gmail_default">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.</div><div class="gmail_default"><br></div><div class="gmail_default">2) curvilinear</div><div class="gmail_default"><br></div><div class="gmail_default">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.<br></div><div class="gmail_default"><br></div><div class="gmail_default">3) unstructured</div><div class="gmail_default"><br></div><div class="gmail_default">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.</div><div class="gmail_default"><br></div><div class="gmail_default">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. </div><div class="gmail_default"><br></div><div class="gmail_default">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:</div><div class="gmail_default"><br></div><div class="gmail_default"><span class=""><div style="font-size:12.8px"><div><font face="monospace, monospace">(0)<span style="white-space:pre-wrap">        </span>write_grid_description: source lat dims = (281,353)</font></div><div><font face="monospace, monospace">(0)<span style="white-space:pre-wrap">        </span>write_grid_description: source lon dims = (281,353)</font></div><div><font face="monospace, monospace">(0)<span style="white-space:pre-wrap">        </span>write_grid_description: source grid type is 'curvilinear'</font></div></div><div style="font-size:12.8px"><font face="monospace, monospace">(...)</font></div></span><div><span class=""><div style="font-size:12.8px"><font face="monospace, monospace">(0)<span style="white-space:pre-wrap">        </span>write_grid_description: destination lat dims = (281)</font></div><div style="font-size:12.8px"><font face="monospace, monospace">(0)<span style="white-space:pre-wrap">        </span>write_grid_description: destination lon dims = (353)</font></div><div style="font-size:12.8px"><font face="monospace, monospace">(0)<span style="white-space:pre-wrap">        </span>write_grid_description: destination grid type is 'rectilinear'</font></div><div style="font-size:12.8px"><font face="monospace, monospace"><br></font></div></span><div style="font-size:12.8px"><font face="arial, helvetica, sans-serif">I believe this script is based on the same one used by ESMF_regrid_5.ncl at:</font></div><div style="font-size:12.8px"><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><span style="font-size:12.8px"><a href="http://www.ncl.ucar.edu/Applications/ESMF.shtml#ex5" target="_blank">http://www.ncl.ucar.edu/Applications/ESMF.shtml#ex5</a></span><br></font></div><div><span style="font-size:12.8px"><font face="arial, helvetica, sans-serif"><br></font></span></div></div></div><div class="gmail_default">As a side, I'm not sure why you are doing this:</div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><span class=""><div class="gmail_default"><font face="monospace, monospace"> dst_lat = fspan(lat_south,lat_north,src_lat)</font></div><div class="gmail_default"><font face="monospace, monospace"> dst_lon = fspan(lon_west,lon_east,src_lon)</font></div><div class="gmail_default"><br></div></span><div class="gmail_default">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:</div><div class="gmail_default"><br></div><div class="gmail_default"><font face="monospace, monospace"> x = fspan(1,5,4) ; 1, 2.3333, 3.666667, 5</font></div>
<p>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.</p><p>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?</p><p><br></p><p>--Mary</p><p><br></p></div></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Tue, Apr 26, 2016 at 3:10 PM, Ryan Connelly <span dir="ltr"><<a href="mailto:rconne01@gmail.com" target="_blank">rconne01@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Follow-up: I had my lat and lon arrays switched. Fixed that. But the error still persists.<div><br></div><div>It seems to be a Catch 22. Right now, I have</div><div><br></div><div><div><font face="monospace, monospace"> 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</font></div><div><font face="monospace, monospace"> lon_west = locSW(0)</font></div><div><font face="monospace, monospace"> lat_south = locSW(1)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">; Use any variable that spans the entire grid to get maxima of i,j</font></div><div><font face="monospace, monospace">; which will then be used to get lat, lon of upper right (NE) corner</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> grid_size = dimsizes(tc) ; z is 0th index, lat 1st, lon 2nd</font></div><div><font face="monospace, monospace"> jMax = grid_size(1)</font></div><div><font face="monospace, monospace"> iMax = grid_size(2)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> 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</font></div><div><font face="monospace, monospace"> lon_east = locNE(0)</font></div><div><font face="monospace, monospace"> lat_north = locNE(1)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> n = dimsizes(lat)</font></div><div><font face="monospace, monospace"> m = dimsizes(lon)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> nlat = n(0)</font></div><div><font face="monospace, monospace"> mlon = m(1)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> dst_lat = fspan(lat_south,lat_north,nlat)</font></div><div><font face="monospace, monospace"> dst_lon = fspan(lon_west,lon_east,mlon)</font></div></div><div><br></div><div>which means that element (2) of fspan has 1 dimension. Therefore, in the output, I see:</div><div><br></div><div><div><font face="monospace, monospace">(0)<span style="white-space:pre-wrap">        </span>write_grid_description: source lat dims = (281,353)</font></div><div><font face="monospace, monospace">(0)<span style="white-space:pre-wrap">        </span>write_grid_description: source lon dims = (281,353)</font></div><div><font face="monospace, monospace">(0)<span style="white-space:pre-wrap">        </span>write_grid_description: source grid type is 'curvilinear'</font></div></div><div><font face="monospace, monospace">(...)</font></div><div><div><font face="monospace, monospace">(0)<span style="white-space:pre-wrap">        </span>write_grid_description: destination lat dims = (281)</font></div><div><font face="monospace, monospace">(0)<span style="white-space:pre-wrap">        </span>write_grid_description: destination lon dims = (353)</font></div><div><font face="monospace, monospace">(0)<span style="white-space:pre-wrap">        </span>write_grid_description: destination grid type is 'rectilinear'</font></div></div><div><br></div><div>which seems like it should not be. Shouldn't I want(need) the dimensions of the source and destination grid to match?</div><div><br></div><div>So then, in fspan, I switch nlat to src_lat and mlon to src_lon, making that element two-dimensional instead of one-dimensional: </div><div><br></div><div><div><font face="monospace, monospace"> dst_lat = fspan(lat_south,lat_north,src_lat)</font></div><div><font face="monospace, monospace"> dst_lon = fspan(lon_west,lon_east,src_lon)</font></div></div><div><br></div><div>Yet when I run with that change, I get:<font face="monospace, monospace"> fatal:Number of dimensions in parameter (2) of (fspan) is (2), (1) dimensions were expected </font></div><div><font face="monospace, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">How can NCL simultaneously be expecting a one- and two-dimension array? I'm very confused here.</font></div><span><font color="#888888"><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Ryan</font></div></font></span></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 26, 2016 at 2:16 PM, Ryan Connelly <span dir="ltr"><<a href="mailto:rconne01@gmail.com" target="_blank">rconne01@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I'm using ESMF_WRF_to_rect.ncl to regrid (<a href="https://www.ncl.ucar.edu/Applications/Templates/ESMF_WRF_to_rect.ncl" target="_blank">https://www.ncl.ucar.edu/Applications/Templates/ESMF_WRF_to_rect.ncl</a>). Regridding completes fine, but then when i try to interpolate the regridded variable to an isobaric plane using wrf_user_intrp3d I get:</div><div><br></div><div><font face="monospace, monospace">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.</font></div><div><br></div><div>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?</div><div><br></div><div>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:</div><div><br></div><div><font face="monospace, monospace">(...)</font></div><div><font face="monospace, monospace">tc_rect = ESMF_regrid(tc,Opt) ; Do the regridding</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">; Interpolate to isobaric planes</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> pressure = 850.</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> newdim = (dimsizes(tc_rect))</font></div><div><font face="monospace, monospace"> print(newdim)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> tc_rect_plane = new((/newdim(0),newdim(1),newdim(2)/),typeof(tc_rect))</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> tc_rect_plane = wrf_user_intrp3d(tc_rect,p,"h",pressure,0.,False)</font></div><div><font face="monospace, monospace">(...)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">I'm out of ideas here.</font></div><span><font color="#888888"><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Ryan<br clear="all"></font><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><font size="1">Ryan Connelly</font></div><div dir="ltr"><div dir="ltr" style="font-size:12.8px"><font color="#000000"><font size="1">M.S. Student in Atmospheric Sciences, </font><span style="font-size:x-small">Stony Brook University</span><br></font></div><div dir="ltr" style="font-size:12.8px"><div><font color="#000000"><font size="1">B.S. in Meteorology with Minors in Mathematics and GIS, </font><span style="font-size:x-small">Valparaiso University</span></font></div></div><div><a href="mailto:rconne01@gmail.com" style="font-size:x-small" target="_blank">rconne01@gmail.com</a><br></div><div><font size="1"><a href="mailto:ryan.connelly@stonybrook.edu" target="_blank">ryan.connelly@stonybrook.edu</a></font></div></div></div></div></div></div></div></div></div></div>
</div></font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><font size="1">Ryan Connelly</font></div><div dir="ltr"><div dir="ltr" style="font-size:12.8000001907349px"><font color="#000000"><font size="1">M.S. Student in Atmospheric Sciences, </font><span style="font-size:x-small">Stony Brook University</span><br></font></div><div dir="ltr" style="font-size:12.8000001907349px"><div><font color="#000000"><font size="1">B.S. in Meteorology with Minors in Mathematics and GIS, </font><span style="font-size:x-small">Valparaiso University</span></font></div></div><div><a href="mailto:rconne01@gmail.com" style="font-size:x-small" target="_blank">rconne01@gmail.com</a><br></div><div><font size="1"><a href="mailto:ryan.connelly@stonybrook.edu" target="_blank">ryan.connelly@stonybrook.edu</a></font></div></div></div></div></div></div></div></div></div></div>
</div>
</div></div><br></div></div>_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><font size="1">Ryan Connelly</font></div><div dir="ltr"><div dir="ltr" style="font-size:12.8000001907349px"><font color="#000000"><font size="1">M.S. Student in Atmospheric Sciences, </font><span style="font-size:x-small">Stony Brook University</span><br></font></div><div dir="ltr" style="font-size:12.8000001907349px"><div><font color="#000000"><font size="1">B.S. in Meteorology with Minors in Mathematics and GIS, </font><span style="font-size:x-small">Valparaiso University</span></font></div></div><div><a href="mailto:rconne01@gmail.com" style="font-size:x-small" target="_blank">rconne01@gmail.com</a><br></div><div><font size="1"><a href="mailto:ryan.connelly@stonybrook.edu" target="_blank">ryan.connelly@stonybrook.edu</a></font></div></div></div></div></div></div></div></div></div></div>
</div>