<div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Alex,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Thanks for providing the files and a script that I could run without any changes. :-) </div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">The issue appears to be a misunderstanding of the type of grid you are starting from (the "source" grid) and the grid you want to regrid to (the "destination" grid).</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Here are the issues:</div><div class="gmail_default" style><ul style><li style>The "SLP" variable you read off the file has coordinate arrays already attached to it, so this is a rectilinear grid. These two lines in your code are therefore unnecessary and actually wrong:</li></ul><div><div><font face="monospace, monospace"> SLP@lat2d = lat2d</font></div><div><font face="monospace, monospace"> SLP@lon2d = lon2d</font></div></div></div><div class="gmail_default" style><ul><li>You created "lat" and "lon" arrays using "fspan" and then used these as the destination grid. This is unnecessary too, because you already have the destination grid in "lat2d" and lon2d". </li></ul><div>Here are the fixes:</div><div><ul><li>Leave "SLP" untouched when you do the regridding. "ESMF_regrid" will see the lat/lon coordinate arrays associated with this SLP, and will automatically use this for the source grid.</li></ul><ul><li>Remove the generation of "lat" and "lon" as they are not needed.<br><br></li><li>Use lat2d and lon2d for DstGridLat and DstGridLon, and don't bother setting DstGridType (ESMF_regrid can figure out the type from DstGridLat and DstGridLon):</li></ul><div><div><font face="monospace, monospace"> Opt@DstGridLat = lat2d <span class="" style="white-space:pre">        </span> ; curvilinear grid </font></div><div><font face="monospace, monospace"> Opt@DstGridLon = lon2d</font></div><div><font face="monospace, monospace"><br></font></div><div><ul><li><font face="arial, helvetica, sans-serif">I don't think this "where" code is needed:</font></li></ul><div><div><font face="monospace, monospace">;---Reset 0 values to missing values. </font></div><div><font face="monospace, monospace"> SLP_regrid@_FillValue = default_fillvalue(typeof(SLP_regrid))</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> SLP_regrid = where(SLP_regrid.eq.0.0,SLP_regrid@_FillValue,\</font></div><div><font face="monospace, monospace"> SLP_regrid)</font></div></div></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><ul><li><font face="arial, helvetica, sans-serif">For the plotting section, you want to set </font><font face="monospace, monospace">res@gsnAddCyclic</font><font face="arial, helvetica, sans-serif"> to True for the original grid, because it's global and needs to have the cyclic point added. Set it to False for the regional grid.</font></li></ul></div><div><ul><li><font face="arial, helvetica, sans-serif">I recommend not doing a polar stereographic plot, because the area you are regridding to is not over the north or south pole.<br><br></font></li><li>I added a MAP_ZOOM logical variable so you could have the option of zooming in on your regional grid.</li></ul><div><font face="arial, helvetica, sans-serif">See the attached new version of your script and two sample images. One image is the full global map, and the second one is zoomed in on the regional grid you read off the ASCII file.</font></div></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">--Mary</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><br></font></div><div><br></div></div><div><br></div><ul><li><br></li></ul></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 6, 2015 at 1:43 AM, igor akkerman <span dir="ltr"><<a href="mailto:igorakkerman89@gmail.com" target="_blank">igorakkerman89@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 Mary,<div><br></div><div>Please see the files on your ftp server: </div><div><br></div><div>1) Code (regrid.ncl)</div><div>2) Original NCEP-NCAR reanalysis file (<a href="http://slp.1948.nc" target="_blank">slp.1948.nc</a>) </div><div>3) ASCII conversion file from rotated grid to geographical grid. (hirham_rot_geo_koor.dat)</div><div><br></div><div>Thanks for your help,</div><div><br></div><div>Alex</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2015-02-05 20:00 GMT+04:00 Mary Haley <span dir="ltr"><<a href="mailto:haley@ucar.edu" target="_blank">haley@ucar.edu</a>></span>:<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">Dear Igor,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">We need a little more information.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">First, it is helpful if you copy-and-paste the actual error message in your email. </div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Second, please include the output from "printVarSummary(SLP)".</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Really, though, it helps if you can provide the data files so we can run the script and see what the issue is.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Thanks,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">--Mary</div><div class="gmail_default" style="font-size:small"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Thu, Feb 5, 2015 at 2:52 AM, igor akkerman <span dir="ltr"><<a href="mailto:igorakkerman89@gmail.com" target="_blank">igorakkerman89@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><div dir="ltr"><div><font size="4">Hi,</font></div><div><font size="4"><br></font></div><div><font size="4">I need to regrid NCEP-NCAR reanalysis to a rotated regional model grid that is set up as follows:</font></div><div><br></div><div><span style="font-size:12.8000001907349px">Sketch of the rotated grid (rot.lat, rot.lon)</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">(24.5,-27.5) ------ (24.5,27.0)</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px"> | |</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px"> | |</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">(-25.0,-27.5) ------ (-25.0,27.0)</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">This is a regular grid with uniform resol. of 0.5.</span><br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">and in geograf. grid (geograf. lat, lon):</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">(53.8,-134.6) ------ (54.2,135.1)</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px"> | |</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px"> | |</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">(53.5,-44.7) ------ (53.85,44.2)</span><br style="font-size:12.8000001907349px"></div><div><br></div><div><font size="4">I also have an ascii file with rotated grid cell coordinates and equivalent geographical coordinates called 'hirham_rot_geo_koor.dat". </font></div><div><font size="4"><br></font></div><div><font size="4">I tried making a script but can't correctly assign the conversion between rotated and geographical grid coordinates. Could you please take a look at the script and suggest how to fix it?</font></div><div><font size="4"><br></font></div><div><font size="4">The error message is that SLP_regrid variable has only one coordinate instead of three.</font></div><div><br></div><div><br></div><div> WRITE_NETCDF = False </div><div> </div><div>; TEXT FILE CONVERTING ROTATED AND SPHERICAL LATS AND LONS</div><div>filename = "hirham_rot_geo_koor.dat"</div><div>coords = asciiread(filename,(/100,110,4/),"float")</div><div>lat2d = coords(:,:,0) ; reading rotated latitude from ascii file</div><div>lon2d = coords(:,:,1) ; reading rotated longitude from ascii file</div><div>printMinMax(lon2d, True)</div><div><br></div><div>;---NCEP-NCAR reanalysis</div><div> srcFileName = "<a href="http://slp.1948.nc" target="_blank">slp.1948.nc</a>"</div><div> sfile = addfile(srcFileName,"r")</div><div><br></div><div> Opt = True</div><div> Opt@SrcTitle = "NCEP-NCAR reanalysis" ; optional</div><div><br></div><div> Opt@WgtFileName = "NCEP_to_Rect.nc"</div><div><br></div><div> Opt@ForceOverwrite = True</div><div><br></div><div> SLP = sfile->slp</div><div> SLP@lat2d = lat2d </div><div> SLP@lon2d = lon2d</div><div><br></div><div>printVarSummary(SLP)</div><div> </div><div> dims = dimsizes(lat2d)</div><div> nlat = dims(0)</div><div> nlon = dims(1)</div><div><br></div><div> Opt@SrcFileName = "Rectilinear.nc" ; Name of source and</div><div> Opt@DstFileName = "WRF_SCRIP.nc" ; destination files</div><div><br></div><div>;---Create the destination lat/lon grid</div><div> printVarSummary(lat2d)</div><div> printVarSummary(lon2d)</div><div> printMinMax(lat2d, True)</div><div> printMinMax(lon2d, True)</div><div> lat = fspan( -25, 24.5,nlat)</div><div> lon = fspan( -27.5,27,nlon)</div><div> lat@units = "degrees_north"</div><div> lon@units = "degrees_east"</div><div> lat!0 = "lat"</div><div> lon!0 = "lon"</div><div> lat&lat = lat</div><div> lon&lon = lon</div><div><br></div><div> Opt@DstGridType = "rectilinear"</div><div> Opt@DstGridLat = lat</div><div> Opt@DstGridLon = lon</div><div><br></div><div> Opt@InterpMethod = "bilinear"</div><div> Opt@SrcRegional = True</div><div> Opt@DstRegional = True</div><div> Opt@Debug = True</div><div> SLP_regrid = ESMF_regrid(SLP,Opt) ; Do the regridding for TMP</div><div>;</div><div>; The source and destination grid description files and</div><div>; weight file will be the same for the next call to </div><div>; ESMF_grid, so no need to regenerate them.</div><div>;</div><div> Opt@SkipSrcGrid = True</div><div> Opt@SkipDstGrid = True</div><div> Opt@SkipWgtGen = True</div><div> </div><div>;---Reset 0 values to missing values.</div><div> SLP_regrid@_FillValue = default_fillvalue(typeof(SLP_regrid))</div><div><br></div><div> SLP_regrid = where(SLP_regrid.eq.0.0,SLP_regrid@_FillValue,\</div><div> SLP_regrid)</div><div><br></div><div> printVarSummary(SLP_regrid)</div><div><br></div><div>;----------------------------------------------------------------------</div><div>; Plotting section</div><div>;</div><div>; This section creates filled contour plots of both the original</div><div>; data and the regridded data, and panels them.</div><div>;----------------------------------------------------------------------</div><div> wks_slp = gsn_open_wks("png","interpolate_slp")</div><div><br></div><div> res = True</div><div><br></div><div> res@gsnDraw = False</div><div> res@gsnFrame = False</div><div><br></div><div> res@cnFillOn = True</div><div> res@cnLinesOn = False</div><div> res@cnLineLabelsOn = False</div><div> res@lbLabelBarOn = False</div><div> res@cnLevelSelectionMode = "ManualLevels"</div><div><br></div><div> res@gsnPolar = "NH"</div><div> res@mpMinLatF = min(lat)</div><div> res@gsnAddCyclic = False</div><div><br></div><div> nrec = 0</div><div> dims_orig = tostring(dimsizes(SLP(nrec,:,:)))</div><div><br></div><div> mnmxint_slp = nice_mnmxintvl( min(SLP), max(SLP), 18, False)</div><div><br></div><div>;---SLP</div><div> res@cnMinLevelValF = mnmxint_slp(0)</div><div> res@cnMaxLevelValF = mnmxint_slp(1)</div><div> res@cnLevelSpacingF = mnmxint_slp(2)/2. ; Create more levels</div><div> res@tiMainFontHeightF = 0.015</div><div><br></div><div>;---SLP regridded</div><div> res@tiMainString = "rectilinear grid (" + Opt@InterpMethod + " interpolation)"</div><div> slp_regrid = gsn_csm_contour_map(wks_slp,SLP_regrid(nrec,:,:),res)</div><div><br></div><div>;---SLP original</div><div> res@tiMainString = "SLP on original curvilinear grid (" + \</div><div> str_join(dims_orig," x ") + ")"</div><div><br></div><div> slp_orig = gsn_csm_contour_map(wks_slp,SLP(nrec,:,:),res) </div><div><br></div><div>;---Compare the plots in a panel</div><div> pres = True</div><div> pres@gsnMaximize = True</div><div> pres@gsnPanelLabelBar = True</div><div><br></div><div> gsn_panel(wks_slp,(/slp_orig,slp_regrid/),(/1,2/),pres)</div><div><br></div><div>;---Trim</div><div> system("convert -trim interpolate_slp.png interpolate.png")</div></div>
<br></div></div>_______________________________________________<br>
ncl-talk mailing list<br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>