[ncl-talk] stat_despersion

ali mughal mughalali655 at gmail.com
Wed Jun 30 21:49:31 MDT 2021


Dear All

Here is how I have modified the code according to your suggestions.
However, I am getting all values in the output of grid_stats.and when I try
plotting the tenth percentile I also have a zero value.  I will be
extremely grateful for your support.


load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
a=addfile("wrfout","r")
ta_mean_BEM=a->TA_MEAN
ta=ta_mean_BEM(24:719,0,:,:)
ta=ta-273.16
nlat1=ta(0,:,0)
mlon1=ta(0,0,:)


 nlStrt=0
 nlLast=129
 mlStrt=0
 mlLast=210
 nlat=dimsizes(nlat1)
 mlon=dimsizes(mlon1)

 grid_stats = new ((/nlat,mlon,30/), typeof(ta), getFillValue(ta))
    do nl=nlStrt,nlStrt-1
      do ml=mlStrt,mlStrt-1

         grid_stats(nl-nlStrt,ml-mlStrt,:) = stat_dispersion( ta(:,nl,ml),
opt)

      end do
   end do

tenthP=grid_stats(:,:,3)

nintythP=grid_stats(:,:,13)


type = "png"
wks = gsn_open_wks(type,"abc")
res =True
opts = res
opts at cnFillOn = True
opts at cnConstFEnableFill           = True
opts at cnConstFLabelBackgroundColor = "transparent"


pltres = True
pltres at NoTitles = True
pltres at gsnMaximize = True
pltres at FramePlot = False
pltres at PanelPlot = True
mpres = True
mpres at mpOutlineBoundarySets    ="NoBoundaries"
contour_lh = wrf_contour(a,wks,tenthP,opts)
delete(opts)

plot = wrf_map_overlays(a,wks,(/contour_lh/),pltres,mpres)
draw(plot)
frame(wks)















On Wed, Jun 30, 2021 at 10:24 PM Dave Allured - NOAA Affiliate <
dave.allured at noaa.gov> wrote:

> Also, stat_dispersion returns an array of 30 values each time, not a
> single value.  See function documentation.  So you need to add an extra
> dimension in the loop calculation, like this:
>
>     grid_stats = new ((/ nlat, mlon, 30 /), typeof(rf), getFillValue(rf))
>
>     do ...
>        do ...
>          grid_stats(nl-nlStrt,ml-mlStrt,:) = stat_dispersion( rf(:,nl,ml),
> opt)
>       end do
>     end do
>
> When the loop is complete, the 10th percentile values will be in
> grid_stats(:,:,3), which is a 2-D grid that you can plot.  The 90th
> percentile values will be in grid_stats(:,:,13).  Again, refer to the
> function documentation for the correct index values to access the desired
> statistics.
>
>
> On Wed, Jun 30, 2021 at 5:13 AM Buzan, Jonathan <jbuzan at purdue.edu> wrote:
>
>> NCL counts from 0 to n-1, not from 1 to n. So your loop vars need to
>> account for that.
>>
>> Cheers,
>> -Jonathan
>>
>> On Jun 30, 2021, at 1:10 PM, ali mughal via ncl-talk <
>> ncl-talk at mailman.ucar.edu> wrote:
>>
>> Dear community
>> Thank you very much for your helpful comments.
>> As an initial test, I was trying to obtain statistics at all grid points
>> before plotting them. I used the following code
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>> a=addfile("wrfout","r")
>> ta_mean_BEM=a->TA_MEAN
>> ta=ta_mean_BEM(24:719,0,:,:)
>> rf=ta-273.16
>> nlat1=rf(0,:,0)
>> printVarSummary(nlat)
>> mlon1=rf(0,0,:)
>> printVarSummary(mlon)
>> printVarSummary(rf)
>> opt=False
>>
>>      nlStrt=0
>>      nlLast=129
>>      mlStrt=0
>>      mlLast=210
>>      nlat=dimsizes(nlat1)
>>      mlon=dimsizes(mlon1)
>>
>>     grid_stats = new ((/nlat(0),mlon(0)/), typeof(rf), getFillValue(rf))
>>     printVarSummary(grid_stats)
>>     do nl=0,nlLast
>>       do ml=0,mlLast
>>
>>          grid_stats(nl-nlStrt,ml-mlStrt) = stat_dispersion( rf(:,nl,ml),
>> opt)
>>
>>       end do
>>    end do
>>
>>    copy_VarCoords(rf(:,nlStrt:nlLast,mlStrt:mlLast), grid_stats)
>>    grid_stats at long_name = "stat_dispersion at individual grid points"
>>    printVarSummary(grid_stats)
>>
>> But I obtain the following output from my print statements and the errors
>>
>> Variable: rf
>> Type: float
>> Total Size: 75418560 bytes
>>             18854640 values
>> Number of Dimensions: 3
>> Dimensions and sizes:   [696] x [129] x [210]
>> Coordinates:
>>
>> Variable: grid_stats
>> Type: float
>> Total Size: 108360 bytes
>>             27090 values
>> Number of Dimensions: 2
>> Dimensions and sizes:   [129] x [210]
>> Coordinates:
>> fatal:VarVarWrite: Number of dimensions on left hand side does not match
>> right hand side
>> fatal:["Execute.c":8578]:Execute: Error occurred at or near line 46 in
>> file var_Test.ncl
>>
>> fatal:Subscript out of range, error in subscript #1
>> fatal:An error occurred reading rf
>> fatal:["Execute.c":8578]:Execute: Error occurred at or near line 51 in
>> file var_Test.ncl
>>
>> Variable: grid_stats
>> Type: float
>> Total Size: 108360 bytes
>>             27090 values
>> Number of Dimensions: 2
>> Dimensions and sizes:   [129] x [210]
>> Coordinates:
>> Number Of Attributes: 1
>>   long_name :   stat_dispersion at individual grid points
>>
>>
>> On Wed, Jun 30, 2021 at 12:01 AM Dave Allured - NOAA Affiliate <
>> dave.allured at noaa.gov> wrote:
>>
>>> Ali, you do not need to make new code to find the 10th and 90th
>>> percentile values.  Just use stat_dispersion directly, and take only the
>>> output values that you need.  The function is designed to be used in this
>>> way.  There is no significant performance impact from ignoring all the
>>> other result values.
>>>
>>> You can easily make a spatial map of 10th or 90th percentile values.
>>> Just call stat_dispersion inside a double loop over X and Y dimensions.
>>>
>>>
>>> On Tue, Jun 29, 2021 at 9:23 AM Buzan, Jonathan via ncl-talk <
>>> ncl-talk at mailman.ucar.edu> wrote:
>>>
>>>> Hello,
>>>>
>>>> I’ve used that function a bunch. If you only want 10th and 90th
>>>> percentile, you’ll want to use:
>>>>
>>>> qsort
>>>> Which will sort your data within a single grid cell from lowest to
>>>> highest.
>>>>
>>>> And then grab the specific lines of code for 10th and 90th percentiles
>>>> from the stat_dispersion function in:
>>>> $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl
>>>>
>>>> If you look at the function, you’ll see that it uses qsort, then goes
>>>> step by step through calculating all the different applications.
>>>>
>>>> Cheers,
>>>> -Jonathan
>>>>
>>>> On Jun 29, 2021, at 5:14 PM, ali mughal via ncl-talk <
>>>> ncl-talk at mailman.ucar.edu> wrote:
>>>>
>>>> Dear NCL community
>>>>
>>>> In the following ncl function
>>>>
>>>>
>>>> http://www.ncl.ucar.edu/Document/Functions/Contributed/stat_dispersion.shtml
>>>>
>>>> Is it possible to use 10th and 90th percentile values only ?
>>>>
>>>> Also can these values be used to develop a spatial map?
>>>>
>>>> For example if I want to find the 10th and  90th percentile of air
>>>> temperature within the urban grid cells only.
>>>>
>>>> Can anyone share an example script or point me to any web resource will
>>>> be appreciated.
>>>>
>>>> Thanks in advance
>>>>
>>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210701/f6c1a899/attachment.html>


More information about the ncl-talk mailing list