Re: pdfx function

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Wed Oct 02 2013 - 11:42:06 MDT

Hi Cecille

You can look at the 'pdfx' driver code contained within contributed.ncl.

%> less $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl

Search for 'function pdfx(' ....include the ( in this search

It has the following

undef("pdfx")
function pdfx(x:numeric, nbin[1]:integer, opt:logical)
local nGood, nbins, xMin, xMax, mnmxint, xSpace \
      ,bin, pdf, nTot, XMIN, XMAX, nLoOut, nHiOut
begin

   if (opt .and. isatt(opt, "v510") .and. opt@v510) then
       pdf = pdfx_v510(x, nbin, opt) ; different binning
       return(pdf)
   end if

   if (nbin.le.2) then
       nbins = 25 ; default
   else
       nbins = nbin
   end if

   nGood = num(.not.ismissing(x))
   if (nGood.lt.3) then
       print("pdfx: nGood="+nGood+" : Need more non-missing points")
       pdf = new( nbins, "double", getFillValue(x))
       return( pdf )
   end if
[SNIP]

You got the following *warning* error message because all your values
were missing [_FillValue]

(0) pdfx: nGood=0 : Need more non-missing points

The code just returned an empty array with no attributes.
I could make that a fatal error and just exit from the script.

So the reason the attribute were not there is because the pdfx
function exited immediately and did not proceed. WHen you tried
to reference the attribute which was not present, NCL returned
a default _FillValue.

===
Why are you doing:

> w1 = new((/num_vert,num_horiza,num_horizb/), float, getFillValue(w))
> w1 = where(qc.ge.0.0001,w,w@_FillValue)

The 'where' will create an array of the correct size and shape.

     w1 = where(qc.ge.0.0001,w,w@_FillValue)
     printVarSummary(w1)

Punch line ... something is wrong with variable 'gc'

Use
printVarSummary(gc)
print("gc: min="+min(gc)+" max="+mac(gc))

also, maybe

   optsd = True
   optsd@PrintStat = True
   statb = stat_dispersion(gc, optsd )

prior to the 'where'

M

On 10/2/13 9:41 AM, Cecille Villanueva wrote:
> Hello ncl-talk,
>
> I am trying to make pdfs of vertical velocities at different heights within a cloud where the cloud mixing ratio exceeds 1 g/kg. I have specified the bin_spacing, the bin_boundaries and the number of bins. From my understanding the pdfx function should ignore missing values and obtain these attributes. However, when I run the script, is like those attributes are not passed when the pdfs are calculated and I get the following error,
>
> (0) pdfx: nGood=0 : Need more non-missing points
> warning:Attempt to reference attribute (bin_min) which is undefined
> (0) -2147483647
> warning:Attempt to reference attribute (bin_center) which is undefined
> (0) gsn_csm_xy: Fatal: X and Y must have the same dimensions sizes, or one must be one-dimensional and both have the same rightmost dimension.
> fatal:CheckArray:Each vector in the caXArray array must have at least 2 elements
> fatal:CoordArraysInitialize:caXArray resource is invalid
> fatal:Unable to initialize layer-Can't Create
> fatal:Unable to access object with id:-4
> fatal:PID #-4 can't be found in NhlSetValues
> fatal:PID #-4 can't be found in NhlSetValues
> fatal:Unable to access object with id:-4
> warning:Unable to add DataItem "(null)" to DataList "xyCoordData"
> fatal:CompileDataList:DataList has no valid members
> fatal:Unable to access object with id:-4
> warning:Unable to add DataItem "(null)" to DataList "xyCoordData"
> fatal:CompileDataList:DataList has no valid members
> fatal:Argument type mismatch on argument (0) of (attsetvalues_check) can not coerce
> fatal:Execute: Error occurred at or near line 10802 in file $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl
>
> fatal:Execute: Error occurred at or near line 4837 in file $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl
>
> fatal:Execute: Error occurred at or near line 188 in file WRF_pdf.ncl
>
>
> The part of the script that does the calculation is shown below.
>
>
> ;------------------------------------------------
> ; Plot each PDF
> ;------------------------------------------------
> opt = True
> delt_bin = 1
> opt@bin_spacing = delt_bin
> max_ws = 30
> min_ws= -30
> opt@bin_min = min_ws
> opt@bin_max = max_ws
> nbins = floattointeger((max_ws - min_ws)/delt_bin)
>
>
> ; nTot_bins = new( nbins, "double")
> ; nTot_bins = nTot
>
> ;print(nTot_bins)
>
> w1 = new((/num_vert,num_horiza,num_horizb/), float, getFillValue(w))
>
> w1 = where(qc.ge.0.0001,w,w@_FillValue)
> ; w1 = where(qc.ge.0.0001,w,0)
> ;print(w1)
> ap = pdfx(w1(level,:,:), nbins, opt)
> print(ap@bin_min)
>
> ;print(ap)
>
> ; ap = where(nTot_bins.ne.0.,100d0*pdf/nTot_bins,0) ; CMV - percent frequency
>
> ; nVar = 3
> ; plot = new ( nVar, "graphic")
>
> ; wks = gsn_open_wks ("pdf","w_pdf")
>
> res = True
> ; res@gsnDraw = False
> ; res@gsnFrame = False
> res@xyLineThicknessF = 2
> res@tiYAxisString = "PDF (%)"
> ; res@tiYAxisString = "PDF (Frequency)"
> res@tiMainString = timelabl(it)+", "+z_avg(level)+" km"
>
> res@gsnCenterString = "Univariate PDF: Normal"
> plot = gsn_csm_xy (wks, ap@bin_center, ap, res)
>
>
> end do
>
> Why is it that when I print the bin_min it comes as -2147483647 and not -30 as I specified above?
>
> The w variable is set to a missing value when this threshold is not met so the 0 m/s data points don't go into the pdf. I also ran the script changing contributed.ncl to make pdf = 0 when only missing values were encountered and I get the same error. Any help will be greatly appreciated. Let me know if you need the whole script and data file.
>
> Cheers,
> Cecille
>
>> ********************************************************
>> Cecille M. Villanueva Birriel
>> Ph.D. Candidate
>> Cloud Microphysics Research Group
>> Purdue University
>> Department of Earth, Atmospheric, & Planetary Sciences
>> 550 Stadium Mall Drive, West Lafayette, IN 47907-2051
>> email: cvillanu@purdue.edu
>> ********************************************************
>
>
>
>
> _______________________________________________
> 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 Wed Oct 2 11:42:15 2013

This archive was generated by hypermail 2.1.8 : Fri Oct 04 2013 - 16:45:17 MDT