[ncl-talk] stat_despersion
Buzan, Jonathan
jbuzan at purdue.edu
Thu Jul 1 01:36:04 MDT 2021
Ali,
stat_dispersion produces 30 values, the space for it to be dumped into needs to have 30 spaces.
But you should separate 1 grid cell (like, ta1gridcell= ta(0,0,0)), print the values, and operate on that 1 grid cell.
Cheers,
-Jonathan
On Jul 1, 2021, at 9:33 AM, ali mughal <mughalali655 at gmail.com<mailto:mughalali655 at gmail.com>> wrote:
Thanks for the reply
shouldn't this
grid_stats(68,160,:) = stat_dispersion( ta(:,68,160), opt)
be changed to
grid_stats(68,160,3) = stat_dispersion( ta(:,68,160), opt)
to obtain the 10th Percentile ?
when I do it I get the following error
fatal:VarVarWrite: Number of dimensions on left hand side does not match right hand side
fatal:["Execute.c":8576]:Execute: Error occurred at or near line 41
On Thu, Jul 1, 2021 at 3:27 PM Muhammad Omer Mughal <m.mughal1 at graduate.curtin.edu.au<mailto:m.mughal1 at graduate.curtin.edu.au>> wrote:
Ali
This was a suggestion.
________________________________
From: Muhammad Omer Mughal <m.mughal1 at graduate.curtin.edu.au<mailto:m.mughal1 at graduate.curtin.edu.au>>
Sent: Thursday, 1 July 2021 3:22 PM
To: ali mughal <mughalali655 at gmail.com<mailto:mughalali655 at gmail.com>>; Buzan, Jonathan <jbuzan at purdue.edu<mailto:jbuzan at purdue.edu>>
Cc: Ncl-talk <ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>>
Subject: Re: [ncl-talk] stat_despersion
I used the following script . I also copied the result at the end of the script. Can it be due to the reason that the value is too small
a=addfile("BEM_April","r")
ta_mean_BEM=a->TA_MEAN
ta=ta_mean_BEM(24:719,0,:,:)
ta=ta-273.16
opt=False
nlat=dimsizes(nlat1)
mlon=dimsizes(mlon1)
grid_stats = new ((/nlat,mlon,30/), typeof(ta), getFillValue(ta))
grid_stats(68,160,:) = stat_dispersion( ta(:,68,160), opt)
printMinMax (grid_stats, False)
(0) Robust Dispersion Statistics: min=-0.552326 max=696
________________________________
From: ncl-talk <ncl-talk-bounces at mailman.ucar.edu<mailto:ncl-talk-bounces at mailman.ucar.edu>> on behalf of Buzan, Jonathan via ncl-talk <ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>>
Sent: Thursday, 1 July 2021 2:24 PM
To: ali mughal <mughalali655 at gmail.com<mailto:mughalali655 at gmail.com>>
Cc: Ncl-talk <ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>>
Subject: Re: [ncl-talk] stat_despersion
Hello,
You should try 1 grid cell first and print the values and print the stat_dispersion, and double check that you are feeding the array the correct data.
-Jonathan
On Jul 1, 2021, at 5:52 AM, ali mughal via ncl-talk <ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>> wrote:
Sorry a correction to the above email is that all values in grid_stats, tenthP and nintythP are 0.
On Thu, Jul 1, 2021 at 11:49 AM ali mughal <mughalali655 at gmail.com<mailto:mughalali655 at gmail.com>> wrote:
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<mailto: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<mailto: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<mailto: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<mailto: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<mailto: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<mailto: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
_______________________________________________
ncl-talk mailing list
ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>
List instructions, subscriber options, unsubscribe:
https://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210701/d47e80f2/attachment.html>
More information about the ncl-talk
mailing list