[ncl-talk] stat_despersion

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Wed Jun 30 08:24:13 MDT 2021


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/20210630/900702b9/attachment.html>


More information about the ncl-talk mailing list