[ncl-talk] Plotting over the ocean

Rick Brownrigg brownrig at ucar.edu
Thu Feb 8 16:18:50 MST 2018


(sorry -- I meant to post this to the whole group):

Hi Grace,

The dataset has no valid data over the oceans, which is why it is not
plotted. There are many NaNs in it, which the script is converting to
missing_values. If you instead set those NaNs to something that looks like
real data, you'll see that they occur precisely over the ocean

Hope that helps...
Rick


On Thu, Feb 8, 2018 at 2:00 PM, Grace Choi <gracesh27 at gmail.com> wrote:

> Hello,
>
> I have been trying to find and apply a function that allows me to plot
> over the ocean as well as the land, but I have not been able to succeed.
>
> If someone could direct me to a reference where mapping over the ocean is
> talked about, or help me with the script itself, I would really appreciate
> it.
>
> I am attaching the script and the netCDF file I am working with here for
> reference:
>
> begin
>
>
> ;************************************************************
>
> ; START user input
>
> ;************************************************************
>
>
> datadir = "./"
>
> filename = "Dalhousie_PM2.5_2011.nc"
>
>
> ; specify latitude and longitude bounds for plot:
>
> ; latitude spans -54.75 degrees to 69.75 degrees
>
> minlat = 25
>
> maxlat = 50
>
>
> ; longitude spans -179.95 to 179.95 degrees
>
> minlon = -130
>
> maxlon = -70
>
>
> title_string = "Dalhousie PM2.5 2011" ; whatever you want the title on the
> plot to be
>
>
> plot_name = "dalhousie_ocean_PM25_2011"   ; what you want the plot file
> name to be (less the extension/format)
>
> plotfiletype = "pdf" ; check NCL documentation for other plot output file
> formats
>
>                      ; options include "pdf" and "png"
>
>
> showgrid = "yes"     ; options are "yes" (plot will show grid size and
> look blocky)
>
>                      ; or "no" (plot will show smoothed-out data)
>
>
> ;************************************************************
>
> ; read in the file:
>
> ;************************************************************
>
>
> fin = addfile(datadir+filename,"r")
>
> ; now read in the variables. I found the variable names using the
> following lines:
>
> ; varnames = getfilevarnames(fin)
>
> ; print(varnames)
>
> ; then used the resulting names below:
>
> lats = fin->LAT
>
> lons = fin->LON
>
> PM25data = fin->PM25
>
>
> printVarSummary(PM25data) ; will tell us the shape of the PM2.5 array
>
> ; that tells us it's arranged (lat,lon) and has units of ug/m3
>
> ; you can comment out that line, if you want!
>
>
> ; this dataset has IEEE NaN "values," which NCL doesn't like.
>
> ;print(num(isnan_ieee(PM25data)))
>
> ; so let's replace them with something NCL can handle better:
>
> if (any(isnan_ieee(PM25data))) then
>
>    value = -999.
>
>    replace_ieeenan(PM25data,value,0)
>
>    PM25data at _FillValue = value
>
> end if
>
>
> ; this will print out the min and max of the -whole- dataset (not just the
> part you sample)
>
> ; which can be helpful for picking out contour levels (res at cnLevels,
> below)
>
> printVarSummary(PM25data)
>
> printMinMax(PM25data,True)
>
> ;**********************************************************************
>
> ; plot section
>
> ;**********************************************************************
>
> res = True
>
>
> res at tiMainString = "Dalhousie PM2.5 2011"
>
> name = plot_name
>
> print("Dalhousie PM2.5 2011 "+name)
>
> wks   = gsn_open_wks("pdf", name)
>
>
> res at cnLevelSelectionMode = "ExplicitLevels"  ; Set contour levels manually
>
> res at cnFillOn             = True                ; turn on color
>
> if (showgrid.eq."yes") then
>
>    res at cnFillMode           = "CellFill"
>
> end if
>
> res at gsnSpreadColors      = True                ; use full colormap
>
> res at cnLinesOn            = False               ; turn off contour lines
>
>
> ; specify color table you want:
>
> gsn_define_colormap(wks,"sunshine_9lev")
>
>
> ; specify which values bound color changes in the plot:
>
> res at cnLevels = (/0.1,0.25,0.5,1.,2.,3.,4.,5.,7.5,10.,12.,14.,16.,18./);
> the original
>
> ;res at cnLevels = (/0.25, 9.3, 11.0, 13.2/)
>
>
> res at gsnMaximize          = True
>
> res at gsnPaperOrientation  = "Landscape"
>
>
> res at mpLimitMode = "Corners"
>
> res at mpLeftCornerLatF = minlat
>
> res at mpLeftCornerLonF = minlon
>
> res at mpRightCornerLatF = maxlat
>
> res at mpRightCornerLonF = maxlon
>
>
> res at mpFillOn = False ; this will give you a white background
>
> res at mpOutlineOn = True                 ; Turn on map outlines
>
> res at mpOutlineBoundarySets = "GeophysicalAndUSStates"  ; Turn on US states
>
>
> res at lbBoxLinesOn = False             ; Turn off labelbar box lines
>
> res at lbLabelAutoStride = True ; so there aren't overlapping numbers
>
> res at lbTitleOn                = True     ; turn on label bar title
>
> res at lbTitleString = (PM25data at units)    ; label bar title
>
> res at pmLabelBarOrthogonalPosF = .20      ; move label bar down
>
>
> plot = gsn_csm_contour_map(wks,PM25data,res)
>
>
> end   ; end of script
>
>
>
> Sincerely,
>
> Grace
>
> _______________________________________________
> 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/20180208/fdff3553/attachment.html>


More information about the ncl-talk mailing list