Re: missing data

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Sun Oct 09 2011 - 12:50:22 MDT

Xiaoyan,

You cannot overlay one map plot on another using "overlay". The base
plot needs to be a map plot, and the overlaid plot should simply be a
contour or a vector plot, for example.

So, change your "plot2" line to call "gsn_csm_contour":

  plot2 = gsn_csm_contour(wks,var2,res2) ; draw second plot

You can see some overlay examples at:

http://www.ncl.ucar.edu/Applications/overlay.shtml

--Mary

On Oct 8, 2011, at 8:24 AM, Xiaoyan Ma wrote:

> Hi Adam,
>
> Continue with my last question.
>
> Now I want to make a plot with one overlay on another. The data for
> the first plot have all values available, and second data have many
> missing values (as my earlier question). I used overplay command to
> try to put second on the first. Please see ncl script below. It
> didn't work since I got 2 plots instead one overlay plot. the error
> info is
>
> fatal:NhlAddOverlay: plot class mapPlotClass cannot be overlay plot
> member
>
> it looks like mapplot could be be overlay?
>
> could you help me to fix the problem? thanks!
>
> Xiaoyan
>
> =========================================================
> begin
>
> nlat = 46
> nlon = 72
>
> setfileoption("bin","ReadByteOrder","BigEndian")
> var = fbindirread("0.dat",0, (/46,72/), "float")
> ;=============================
> ; create lat and long coordinate variables
> ;============================
> dlat = 180./nlat
> dlon = 360./nlon
>
> var!0 = "lat"
> var&lat = ispan(-23,22,1)*dlat
> var&lat@units = "degrees_north"
>
> var!1 = "lon"
> var&lon = ispan(-36,35,1)*dlon
> var&lon@units = "degrees_east"
> ;**************************************************
> ; create plot
> ;**************************************************
> wks = gsn_open_wks("ps","overlay")
>
> gsn_define_colormap(wks,"BlAqGrYeOrReVi200") ; choose colormap
>
> res = True ; plot mods desired
> res@cnFillOn = True ; turn on color
> res@cnLinesOn = False ; no contour lines
>
> res = True ; plot mods desired
>
> res@tiMainString = "Explict Contour Levels"
> res@cnFillOn = True ; turn on color fill
> res@cnLinesOn = False ; turn of contour lines
> res@gsnSpreadColors = True ; use full range of color map
> res@gsnSpreadColorStart = 20 ; color to start
> res@gsnSpreadColorEnd = 193 ; color to end
>
> res@lbOrientation = "vertical" ; vertical label bar
>
> res@pmTickMarkDisplayMode = "Always"; use NCL default lat/lon labels
> res@gsnAddCyclic = False ; data already has cyclic point
> ; this must also be set for
> any zoom
>
> res@cnLevelSelectionMode = "ExplicitLevels" ; set explicit
> contour levels
> res@cnLevels = (/
> 1e-4,5e-4,1e-3,5e-3,0.01,0.02,0.03,0.04,0.05/)
> ;===========================
> ; plot parameters
> ;===========================
> res@gsnDraw = False ; do not draw
> res@gsnFrame = False ; do not advance
> frame
>
> plot1 = gsn_csm_contour_map_ce(wks,var,res) ; draw 1st contour
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> var2 = fbindirread("1.dat",0, (/46,72/), "float")
>
> var2!0 = "lat"
> var2&lat = ispan(-23,22,1)*dlat
> var2&lat@units = "degrees_north"
>
> var2!1 = "lon"
> var2&lon = ispan(-36,35,1)*dlon
> var2&lon@units = "degrees_east"
>
> var2@_FillValue = 0.0001 ; sets _FillValue
> to 0.0001
>
> res2 = True ; plot mods desired
> res2@cnFillOn = True ; turn on color
> res2@cnLinesOn = False ; no contour lines
>
> res2@tiMainString = "Explict Contour Levels"
> res2@cnFillOn = True ; turn on color fill
> res2@cnLinesOn = False ; turn of contour lines
> res2@gsnSpreadColors = True ; use full range of color map
> res2@gsnSpreadColorStart = 20 ; color to start
> res2@gsnSpreadColorEnd = 193 ; color to end
>
> res2@lbOrientation = "vertical" ; vertical label bar
>
> res2@pmTickMarkDisplayMode = "Always"; use NCL default lat/lon
> labels
> res2@gsnAddCyclic = False ; data already has cyclic
> point
> ; this must also be set for
> any zoom
> res2@cnLevelSelectionMode = "ExplicitLevels" ; set explicit
> contour levels
> res2@cnLevels = (/
> 1e-4,5e-4,1e-3,5e-3,0.01,0.02,0.03,0.04,0.05/)
>
> res2@cnFillMode = "RasterFill"
>
> plot2 = gsn_csm_contour_map_ce(wks,var2,res2) ; draw second plot
>
> overlay(plot1,plot2) ; now over lay plots
>
> ; the result of the overlay procedure is that the second argument is
> ; placed on top of the first. The first plot (now combined) is
> returned.
>
> ; these two step are required!
> draw(plot1) ; note we are drawing the first one!
> frame(wks)
>
> end
>
> On 10/05/11, "Xiaoyan Ma" <xiaoyan.ma@asrc.albany.edu> wrote:
>>
>> Hi Adam,
>>
>> Thanks for the quick reply. I did all except the last one. Now it
>> works.
>>
>> Thanks very much for the help.
>>
>> Xiaoyan
>>
>> On 10/05/11, Adam Phillips <asphilli@ucar.edu> wrote:
>>>
>>> Hi Xiaoyan,
>>> There might be a few problems here. Are you getting any error
>>> messages?
>>> I would guess that you are... If you are the next time you send a
>>> question to ncl-talk please include any error messages that you are
>>> getting...
>>>
>>> Does your var array have latitude/longitude coordinate variables
>>> assigned to it? From the snippet of code you sent I don't see them..
>>> You are reading in your data from a binary file, but when you do
>>> that
>>> there will not be any information associated associated with your
>>> data
>>> array that describes it. So, you need to assign that information
>>> to your
>>> var array:
>>>
>>> var!0 = "lat"
>>> var&lat = ispan(-90,90,4) ; I am guessing that your latitudes run
>>> from
>>> ; -90:90 by 4.. You may need to change
>>> this.
>>> var&lat@units = "degrees_north"
>>>
>>> var!1 = "lon"
>>> var&lon = ispan(0,355,5) ; I am guessing that your longitudes
>>> run from
>>> ; 0:355 by 6.. You may need to change
>>> this.
>>> var&lon@units = "degrees_east"
>>>
>>> By default, NCL will color fill areas denoted by the _FillValue
>>> attribute as white. So you need to make sure that var@_FillValue
>>> is set
>>> appropriately:
>>>
>>> var@_FillValue = ; set _FillValue, where data is missing, to
>>> the
>>> ; appropriate value
>>>
>>> Finally, and this might be most important, if your var array is
>>> mostly
>>> composed of missing data, you are going to want to tell NCL to
>>> Raster
>>> Fill, instead of Area Fill.. Going to Raster Fill will show each
>>> individual grid box, while Area Fill may or may not.. So, add this:
>>>
>>> res@cnFillMode = "RasterFill"
>>>
>>> to your resource list.
>>>
>>> If that advice doesn't solve your issue, please respond back to
>>> ncl-talk.. Adam
>>>
>>>
>>> On 10/05/2011 10:27 AM, Xiaoyan Ma wrote:
>>> > Hi
>>> >
>>> > I want to create a contour plot from the observational data,
>>> i.e. for a
>>> > 46*72 grid there are only ~ 100 points with observations, other
>>> points
>>> > with missing data (I set a value as 0.0001). when I use ncl as
>>> below, I
>>> > want to let those points with missing data as WHITE, but others as
>>> > color. I do so in 2 ways:
>>> >
>>> > 1) set missing data as mask
>>> > 2) set missing data as FillValue
>>> >
>>> > I do see there are values of non-0.0001 by using print, but the
>>> > contour looks all white from 1) or 2). anybody tell me what is
>>> wrong?
>>> >
>>> > thanks a lot.
>>> >
>>> > Xiaoyan
>>> >
>>> >
>>> --------------------------------------------------------------------------
>>> > var = fbindirread("1.dat",0, (/46,72/), "float")
>>> >
>>> > print(var)
>>> > ; var = mask(var,var.le.0.001,False) ; create
>>> > artificial areas of missing data
>>> >
>>> > var@_FillValue = 0.0001 ; sets
>>> _FillValue to
>>> > 0.0001
>>> >
>>> > res = True ; plot mods
>>> desired
>>> > res@cnFillOn = True ; turn on
>>> color
>>> > res@cnLinesOn = False ; no contour lines
>>> >
>>> > plot= gsn_csm_contour_map_ce(wks,var,res)
>>> >
>>> >
>>> > _______________________________________________
>>> > ncl-talk mailing list
>>> > List instructions, subscriber options, unsubscribe:
>>> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>> --
>>> ______________________________________________________________
>>> Adam Phillips asphilli@ucar.edu
>>> NCAR/Climate and Global Dynamics Division (303) 497-1726
>>> P.O. Box 3000
>>> Boulder, CO 80307-3000 http://www.cgd.ucar.edu/cas/asphilli
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sun Oct 9 12:50:30 2011

This archive was generated by hypermail 2.1.8 : Mon Oct 10 2011 - 11:43:35 MDT