# Re: Problem with dim_avg_n

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Thu, 8 Oct 2009 03:56:02 -0600 (MDT)

Hi Louis,

As Adam pointed out, there may be something a bit odd about the
subscripting.

I don't know what the dimension sizes of these variables are, but
doing:

t1 = t(time|0:23,lat|:,lon|:)
t1 = dim_avg_n(t(0:23,:,:),0)

shouldn't even work, (unless I'm missing something, liked you've
commented part of this code out).

This test worked for me, and produced "min/max diff = 0/0" as expected:

ntim = 48
nlat = 64
nlon = 128
time = ispan(1,ntim,1)
lat = fspan(-90,90,nlat)
lon = fspan(-180,180,nlon)

t = random_uniform(-50,50,(/ntim,nlat,nlon/))

t!0 = "time"
t!1 = "lat"
t!2 = "lon"
t&lat = lat
t&time = time
t&lon = lon

t1 = t(time|0:23,lat|:,lon|:)

tavg1 = dim_avg(t1(lat|:,lon|:,time|:))
tavg2 = dim_avg_n(t(0:23,:,:),0)

diff = tavg1-tavg2
print("min/max diff = " + min(diff) + "/" + max(diff))

--Mary

On Thu, 8 Oct 2009, louis Vonder wrote:

>
> I check carefully my NCL code.
> I will try to odify my script as you said.
>
> Perhaps the problem is in the selection of time 0:23?
>
> Thanks
>
>
> t1 =  t(time|0:23,lat|:,lon|:)
> t2= t1(lat|:,lon|:,time|0)
> t2=dim_avg(t1(lat|:,lon|:,time|:))
>
>  t1=dim_avg_n(t(0:23,:,:),0)
>
> --- En date de : Mer 7.10.09, Adam Phillips <asphilli_at_ucar.edu> a écrit :
>
> Objet: Re: [ncl-talk] Problem with dim_avg_n
> Ŕ: "louis Vonder" <appopson_at_yahoo.fr>
> Cc: "ncl forum" <ncl-talk_at_ucar.edu>
> Date: Mercredi 7 Octobre 2009, 19h10
>
> Hi Louis,
> I just ran a quick test here and everything looks fine to me. I notice in your script that for the dim_avg_n line that you are subsetting time from 0:23, but for the dim_avg line you are not. Could that explain the difference in the plots?
> Best regards,
>
> louis Vonder wrote:
>> Dear NCL users,
>>
>> Here attached two figure using the NCL functions "dim_avg_n" and "dim_avg".
>>
>> I am wondering because the produced figures look completly different !!!!
>>
>> I don't why the figure using dim_avg_n is smoothed.
>>
>> It is a bug or there is  something which is bad in my script?
>>
>>
>>
>> Louis
>>
>>
>> ;*****************************************************
>> ;*****************************************************
>> begin
>>
>>
>>
>>
>>   a     = addfile ("TotPrecc.nc", "r")
>>
>>
>> lat = a->lat
>> lon = a->lon
>> time = a->time
>> t= a->TotPrecc
>>   t1 =  t(time|0:23,lat|:,lon|:)
>> t2= t1(lat|:,lon|:,time|0)
>> t2=dim_avg(t1(lat|:,lon|:,time|:))
>> ; t1=dim_avg_n(t(0:23,:,:),0)
>>   wks  = gsn_open_wks ("ps", "wrf_dim_avg")
>>
>>
>>   res                             = True                 ; plot mods desired
>> gsn_define_colormap(wks,"gui_default")        ; choose colormap*
>>           res_at_gsnSpreadColors      = True               ; use full range of colors
>>
>>
>>   res_at_cnFillOn                    = True                 ; turn on color
>>   res_at_cnLinesOn                   = False               ; no contour lines
>>   ;res_at_gsnSpreadColors             = True                 ; use full color map
>>   res_at_lbLabelAutoStride           = True                    ; every other label
>>
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> ;;;;;;;;;;;;;;;;;;;;;;;;draw national boundery map;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> ; Map stuff                                                                        ;
>>    res_at_mpDataBaseVersion           = "Ncarg4_0"    ; use finer database             ;
>>    res_at_mpOutlineOn                 = True                                           ;
>>    res_at_mpFillOn                    = False        ; turn off gray fill              ;
>>    res_at_mpOutlineBoundarySets       = "National"   ; turn on country boundaries      ;
>>
>>    res_at_mpNationalLineColor          = "Black"     ;"Red"
>>    res_at_mpNationalLineDashPattern    = 0                 ;1 ;for dashpattern
>>    res_at_mpNationalLineThicknessF     = 1.5
>>     res_at_mpGeophysicalLineColor      = "Black"       ; color of cont. outlines        ;
>>    res_at_mpGeophysicalLineThicknessF = 1.5          ; thickness of outlines;;         ;
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>
>>
>> ; res_at_cnLevelSelectionMode        = "ManualLevels"       ; manual levels
>> ; res_at_cnMinLevelValF              = 0.
>>   ;res_at_cnMaxLevelValF              = 300.
>> ; res_at_cnLevelSpacingF             = 4.
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> res_at_cnLevelSelectionMode = "ExplicitLevels"
>>          res_at_cnLevels             = (/  .5, 1., 2.,5., 10.,15.,20. , \
>>                                         30., 50, 75, 100, 110./)
>>         ; res_at_cnFillColors         = (/"White","White","DarkOliveGreen1", \
>>                          ;                "DarkOliveGreen3","Chartreuse", \
>>                           ;               "Chartreuse3","Green","ForestGreen", \
>>                            ;              "Yellow","Orange","Red","Violet"/)
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>   res_at_pmTickMarkDisplayMode       = "Always"             ; turn on tick marks
>>
>>   res_at_tiMainString                = "with dim_avg"
>>
>>   res_at_gsnAddCyclic                = False                ; regional data
>>
>> ; The following resources are Required to plot this projection correctly
>>
>>   ;res_at_mpProjection                = "Stereographic"     ; projection
>>
>>   res_at_mpLimitMode                 = "Corners"           ; method to zoom
>>   ;res_at_mpLeftCornerLatF            = min(lat)
>>   ;res_at_mpLeftCornerLonF            = min(lon)
>>   ;res_at_mpRightCornerLatF           = max(lat)
>>   ;res_at_mpRightCornerLonF           = max(lon)
>>
>>
>>   res_at_mpLeftCornerLatF            = -1.143
>>   res_at_mpLeftCornerLonF            = -0.256
>>   res_at_mpRightCornerLatF           = 12.983
>>   res_at_mpRightCornerLonF           = 22.084
>>
>>
>>   ;res_at_mpRelativeCenterLon         = True                 ; set a center lon
>>   ;res_at_mpCenterLonF                = lon(147,172)         ; center lon
>>   ;res_at_mpRelativeCenterLat         = True                ; set a center lat
>> ; res_at_mpCenterLatF                = 90.                  ; center lat
>> ; res_at_tfDoNDCOverlay              = True                 ; do not transform data
>>
>>   plot = gsn_csm_contour_map (wks,t2,res)
>> ;plot = gsn_csm (wks,res)
>>
>>
>> end
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>>
>> ------------------------------------------------------------------------
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> -- __________________________________________________