<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 &quot;source&quot; grid) and the grid you want to regrid to (the &quot;destination&quot; 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 &quot;SLP&quot; 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 &quot;lat&quot; and &quot;lon&quot; arrays using &quot;fspan&quot; and then used these as the destination grid.  This is unnecessary too, because you already have the destination grid in &quot;lat2d&quot; and lon2d&quot;.  </li></ul><div>Here are the fixes:</div><div><ul><li>Leave &quot;SLP&quot; untouched when you do the regridding. &quot;ESMF_regrid&quot; 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 &quot;lat&quot; and &quot;lon&quot; as they are not needed.<br><br></li><li>Use lat2d and lon2d for DstGridLat and DstGridLon, and don&#39;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&#39;t think this &quot;where&quot; 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&#39;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">&lt;<a href="mailto:igorakkerman89@gmail.com" target="_blank">igorakkerman89@gmail.com</a>&gt;</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">&lt;<a href="mailto:haley@ucar.edu" target="_blank">haley@ucar.edu</a>&gt;</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 &quot;printVarSummary(SLP)&quot;.</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">&lt;<a href="mailto:igorakkerman89@gmail.com" target="_blank">igorakkerman89@gmail.com</a>&gt;</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 &#39;hirham_rot_geo_koor.dat&quot;. </font></div><div><font size="4"><br></font></div><div><font size="4">I tried making a script but can&#39;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 = &quot;hirham_rot_geo_koor.dat&quot;</div><div>coords = asciiread(filename,(/100,110,4/),&quot;float&quot;)</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 = &quot;<a href="http://slp.1948.nc" target="_blank">slp.1948.nc</a>&quot;</div><div>    sfile = addfile(srcFileName,&quot;r&quot;)</div><div><br></div><div>    Opt                = True</div><div>    Opt@SrcTitle       = &quot;NCEP-NCAR reanalysis&quot;   ; optional</div><div><br></div><div>    Opt@WgtFileName    = &quot;NCEP_to_Rect.nc&quot;</div><div><br></div><div>    Opt@ForceOverwrite = True</div><div><br></div><div>    SLP = sfile-&gt;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     = &quot;Rectilinear.nc&quot;      ; Name of source and</div><div>    Opt@DstFileName     = &quot;WRF_SCRIP.nc&quot;    ; 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 = &quot;degrees_north&quot;</div><div>    lon@units = &quot;degrees_east&quot;</div><div>    lat!0     = &quot;lat&quot;</div><div>    lon!0     = &quot;lon&quot;</div><div>    lat&amp;lat   = lat</div><div>    lon&amp;lon   = lon</div><div><br></div><div>    Opt@DstGridType          = &quot;rectilinear&quot;</div><div>    Opt@DstGridLat           = lat</div><div>    Opt@DstGridLon           = lon</div><div><br></div><div>    Opt@InterpMethod         = &quot;bilinear&quot;</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(&quot;png&quot;,&quot;interpolate_slp&quot;)</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  = &quot;ManualLevels&quot;</div><div><br></div><div>    res@gsnPolar              = &quot;NH&quot;</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  = &quot;rectilinear grid (&quot; + Opt@InterpMethod + &quot; interpolation)&quot;</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 = &quot;SLP on original curvilinear grid (&quot; +  \</div><div>                        str_join(dims_orig,&quot; x &quot;) + &quot;)&quot;</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(&quot;convert -trim interpolate_slp.png interpolate.png&quot;)</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>