[ncarg-talk] NCL Contour Plotting

Mary Haley haley at ucar.edu
Thu Sep 21 17:06:05 MDT 2017


Hi Neil,

In the future, please post NCL questions to ncl-talk (
http://mailman.ucar.edu/mailman/listinfo/ncl-talk) and not ncarg-talk.
ncarg-talk is for people using old Fortran and C NCAR Graphics programs.

Thanks for providing a clean and short script and information about your
data.

The main thing that looks like a potential problem is that you have NaN as
a _FillValue, which will not work in NCL. Does your data actually contain
NaNs as well? If so, these will need to be converted to actual values as
well. NCL does not like NaNs!

Your plotting code looks correct, but it's hard to tell if the issue is
because of the NaNs, or something else.  In order to rule out NaNs as an
issue, I've modified your code a bit:

[1]

I added some code to fix the potential NaN issue.

[2]

It's always important to look at your data to make sure it looks correct.
I'm not sure how you checked your data before, but I added printMinMax and
stat_dispersion as two ways of looking at your data.

[3]

You can use a call to gsn_csm_contour_map in place of calls to gsn_csm_map,
gsn_csm_contour, overlay, draw, and frame.

[4]

To use gsn_csm_contour_map, you need to make sure the x and y arrays have
the proper units of "degrees_north" and "degrees_east". Most NetCDF files
use this type of units convention, and plotting tools others than NCL tend
to look for this information.

Please give the modified script a try and let me know if you still have
issues plotting your data.  If you continue to have issues, it would help
if you could provide the data file as well.

Thanks,

--Mary



On Thu, Sep 21, 2017 at 4:36 PM, Neil Weston - NOAA Federal <
neil.d.weston at noaa.gov> wrote:

> NCL Users,
>
> I have a netcdf file with 'z' data that ranges from 0 to 1.76. The NCL
> script below overlays contours on a map of North America.  However, I have
> noticed that data from 0.5 to 1.2 are not plotted even though measurements
> with values in that range do exist in the netcdf dataset.  I verified this
> by plotting the 'z' values in the dataset using Generic Mapping Tools (GMT)
> as well as using ncdump to look at the data.
>
> I may have overlooked something but if you have any suggestions to plot
> these values, I would sincerely appreciate them.  The short NCL script is
> below.
>
> Kind regards,
> Neil
> ----------
> ncdump header and NCL script below
>
> netcdf horizontal-high {
> dimensions:
>         x = 4601 ;
>         y = 3001 ;
> variables:
>         double x(x) ;
>                 x:long_name = "x" ;
>                 x:actual_range = -170., -55. ;
>         double y(y) ;
>                 y:long_name = "y" ;
>                 y:actual_range = 5., 80. ;
>         float z(y, x) ;
>                 z:long_name = "z" ;
>                 z:_FillValue = NaNf ;
>                 z:actual_range = 0.000674999959301203, 1.76100623607635 ;
>
> // global attributes:
>                 :Conventions = "COARDS, CF-1.5" ;
>                 :title = "" ;
>                 :history = "grdsample horizontal.nc -Ghorizontal-high.nc
> -I0.025/0.025" ;
>                 :description = "" ;
>                 :GMT_version = "5.3.2 (r17593) [64-bit]" ;
>
> ----------------
>
> begin
>
>    cdf_file = addfile("horizontal-high.nc","r")
>    ;cdf_file = addfile("vertical-high.nc","r")
>    shift = cdf_file->z(:,:)
>    lat = cdf_file->y
>    lon = cdf_file->x
>    shift at long_name = ""
>    lat at long_name = ""
>    lon at long_name = ""
>
>    wks = gsn_open_wks("x11","overlay")
>
>    ; define resources
>    mpres = True
>    mpres at gsnDraw = False
>    mpres at gsnFrame = False
>    res = mpres
>    cnres = mpres
>
>    ; contour
>    cnres at cnFillOn = True
>    cnres at cnLinesOn = False
>    cnres at cnInfoLabelOn = False
>    cnres at cnFillPalette = "MPL_jet"
>    ;cnres at cnFillPalette = "BkBlAqGrYeOrReViWh200"
>    ;cnres at cnFillPalette = "horizontal"
>    cnres at lbOrientation = "Vertical"
>    ;cnres at lbTitleString = "Horizontal Shift"
>    cnres at lbTitlePosition = "Left"
>    cnres at lbBoxLinesOn = False
>    cnres at lbTitleFontHeightF = 0.015
>    cnres at lbLabelFontHeightF = 0.01
>
>
>    cnres at sfXArray = lon
>    cnres at sfYArray = lat
>    cnres at cnLevelSelectionMode = "ManualLevels"
>    cnres at cnMinLevelValF = 0.0
>    cnres at cnMaxLevelValF = 2.0
>    cnres at cnLevelSpacingF = 0.1
>    cnres at cnLineLabelsOn = False
>
>    ; make sure contours are drawn in "predraw" phase
>    cnres at cnFillDrawOrder = "Predraw"
>
>    ; map
>    mpres at tiMainString = "Horizontal Shift (m)"
>    mpres at mpFillOn = False
>    mpres at mpMaxLatF = 80
>    mpres at mpMinLatF = 5
>    mpres at mpMinLonF = -170
>    mpres at mpMaxLonF = -55
>    mpres at mpOutlineOn = True
>    mpres at mpOutlineDrawOrder = "PostDraw"
>
>    ; create but don't draw contours, maps, vectors etc.
>    cnid = gsn_csm_contour(wks,shift,cnres)
>    mpid = gsn_csm_map(wks,mpres)
>
>    ; overlay contour, streamline and vector plots on the map plot
>    overlay(mpid,cnid)
>
>    draw(mpid)
>    frame(wks)
>
> end
> ------------------------------------------------------------
> ------------------------------------------------------------------------
> Dr. Neil D. Weston
>
> Technical Director
> OCS, National Ocean Service, NOAA
> SSMC3, Rm 7806
> 1315 East West Hwy, Silver Spring, MD 20910
>
> 301-713-2801 <(301)%20713-2801>     240-278-7194 <(240)%20278-7194>
> 301-713-4501 <(301)%20713-4501>      neil.d.weston at noaa.gov
>
> _______________________________________________
> ncarg-talk mailing list
> ncarg-talk at ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncarg-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncarg-talk/attachments/20170921/9cf5f7f7/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plot_shift.ncl
Type: application/octet-stream
Size: 1692 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncarg-talk/attachments/20170921/9cf5f7f7/attachment-0001.obj>


More information about the ncarg-talk mailing list