[ncl-talk] How to plot t-test figure?

Adam Phillips asphilli at ucar.edu
Thu Oct 22 15:51:25 MDT 2015


Hi Steven,
Starting with the error message:
"fatal:Number of dimensions in parameter (2) of (wrf_contour) is (1), (2)
dimensions were expected

fatal:["Execute.c":8578]:Execute: Error occurred at or near line 56 in file
t-test2.ncl  "

The error message is saying you are passing in a 1-dimensional array, while
wrf_contour expects a 2-dimensional array. You can see this by issuing a
printVarSummary(aveX) command.

Backing up in your script, this is happening because you are using the avg
and variance functions which will each return a single value.

I believe you want to use the dim_avg_N_Wrap and dim_variance_n_Wrap
functions, but you need to pass in the hourly values and not the mean
values as you are doing now.

I believe the following code will accomplish what you are trying to do. It
is untested, so make sure you understand what it is doing and check the
results:


load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"

begin
   a = addfile("./JAN2010/01-05/wrfout_d02_2010-01-01_00:00:00","r")
   b = addfile("./JAN2010/01-05/wrfout_d02_2010-01-02_00:00:00","r")

  wks = gsn_open_wks("x11","plt_geo2_6")
        gsn_define_colormap(wks,"BlAqGrYeOrReVi200")            ; Create a
plot workstation

  opts = True                                      ; Set some Basic Plot
options
  opts at MainTitle = "GEOGRID FIELDS"
  opts at InitTime = False                            ; Do not plot time or
footers
  opts at Footer = False

;;;;;;;;;;;;;;;;;;;;;daily mean temperature at 01 January;;;;;;;;;;;;;;

temp1 = a->T2
aveX = dim_avg_n_Wrap(temp1,0)  ; average over the 0th dim
varX = dim_variance_n_Wrap(temp1,0) ; compute variance

printVarSummary(temp1)
printVarSummary(aveX)
printVarSummary(varX)

temp2 = b->T2
aveY = dim_avg_n_Wrap(temp2,0)  ; average over the 0th dim
varY = dim_variance_n_Wrap(temp2,0) ; compute variance

alphat = 100.*(1. - ttest(aveX,varX,24, aveY,varY,24, True, False))
aveX = where(alphat.lt.95.,aveX at _FillValue, aveX)
;--------------------------------
These last two lines are straight from your original script. I would
strongly suggest you review the documentation for ttest:
https://www.ncl.ucar.edu/Document/Functions/Built-in/ttest.shtml
as I do not believe you should be setting your 2nd to last option to True.

And you should also review the documentation for dim_avg_n_Wrap and
dim_variance_n_Wrap if you have not used them before:
https://www.ncl.ucar.edu/Document/Functions/Contributed/dim_avg_n_Wrap.shtml
https://www.ncl.ucar.edu/Document/Functions/Contributed/dim_variance_n_Wrap.shtml

If the above does not help, or if you have any further questions, please
respond to the ncl-talk email list and not to me personally.
Adam



















On Wed, Oct 21, 2015 at 8:32 PM, Steven Kong <kongksk at gmail.com> wrote:

> Hi all,
>
> I try to plot t-test figure, with significant change >95% between
> 01-January and 02-Janaury. But i found an error as shown below
>
> "fatal:Number of dimensions in parameter (2) of (wrf_contour) is (1), (2)
> dimensions were
> expected
>
> fatal:["Execute.c":8578]:Execute: Error occurred at or near line 56 in
> file t-test2.ncl  "
>
> Can anyone help me on this? Your assistance is highly appreciated.
> Thank you.
>
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
>
> begin
>    a = addfile("./JAN2010/01-05/wrfout_d02_2010-01-01_00:00:00","r")
>    b = addfile("./JAN2010/01-05/wrfout_d02_2010-01-02_00:00:00","r")
>
>   wks = gsn_open_wks("x11","plt_geo2_6")
>         gsn_define_colormap(wks,"BlAqGrYeOrReVi200")            ; Create a
> plot workstation
>
>   opts = True                                      ; Set some Basic Plot
> options
>   opts at MainTitle = "GEOGRID FIELDS"
>   opts at InitTime = False                            ; Do not plot time or
> footers
>   opts at Footer = False
>
> ;;;;;;;;;;;;;;;;;;;;;daily mean temperature at 01 January;;;;;;;;;;;;;;
>
> temp1=a->T2(0,:,:)
> temp1=0
>   do i = 0,23
>     temp1 = temp1 + a->T2(i,:,:)
>   end do
>
>   mean1 = temp1/24
>
> ;;;;;;;;;;;;;;;;;;;;;daily mean temperature at 02 January;;;;;;;;;;;;;;
>
> temp2=b->T2(0,:,:)
> temp2=0
>   do i = 0,23
>     temp2 = temp2 + b->T2(i,:,:)
>   end do
>
>   mean2 = temp2/24
>
> ;------------------T-Test: Area with 95% significant
> difference----------------------------------------------
>
> aveX = avg(mean1)
> varX = variance(mean1)
>
> aveY = avg(mean2)
> varY = variance(mean2)
>
> alphat = 100.*(1. - ttest(aveX,varX,24, aveY,varY,24, True, False))
> aveX = where(alphat.lt.95.,aveX at _FillValue, aveX)
>
>   res = opts                                       ; Use basic options for
> this field
>   res at cnFillOn = True                              ; Create a color fill
> plot
> ;  res at ContourParameters = (/ -50., 50., 5. /)    ; Set the levels
>
>   contour = wrf_contour(a,wks,aveX,res)
>
>   pltres = True                                    ; Set plot options
>   mpres = True                                     ; Set map options
>   mpres at mpGeophysicalLineColor      = "Black"      ; Overwrite basic map
> settings
>   mpres at mpGridLineColor             = "Black"
>   mpres at mpLimbLineColor             = "Black"
>   mpres at mpNationalLineColor         = "Black"
>   mpres at mpPerimLineColor            = "Black"
>   mpres at mpUSStateLineColor          = "Black"
>   plot = wrf_map_overlays(a,wks,(/contour/),pltres,mpres) ; Plot field
> over map background
>
> end
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>


-- 
Adam Phillips
Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
www.cgd.ucar.edu/staff/asphilli/   303-497-1726

<http://www.cgd.ucar.edu/staff/asphilli>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151022/276eab67/attachment.html 


More information about the ncl-talk mailing list