# Re: Problem with dim_avg_n [Solved]

From: louis Vonder <appopson_at_nyahnyahspammersnyahnyah>
Date: Thu Oct 08 2009 - 07:11:40 MDT

Hi Mary,

Using these lines

t2 = dim_avg(t(lat|:, lon|:, time|0:23))
copy_VarCoords( t(lat|:, lon|:, time|0), t2)

or

t2=dim_avg_n(t(0:23, :, :), 0)
copy_VarCoords( t(0, :, :), t2)

Give me the same result.

Louis

--- En date de : Jeu 8.10.09, Mary Haley <haley@ucar.edu> a écrit :

De: Mary Haley <haley@ucar.edu>
Objet: Re: [ncl-talk] Problem with dim_avg_n
Ŕ: "louis Vonder" <appopson@yahoo.fr>
Date: Jeudi 8 Octobre 2009, 11h56

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@ucar.edu> a écrit :
>
> Objet: Re: [ncl-talk] Problem with dim_avg_n
> Ŕ: "louis Vonder" <appopson@yahoo.fr>
> Cc: "ncl forum" <ncl-talk@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@gsnSpreadColors      = True               ; use full range of colors
>>
>>
>>   res@cnFillOn                    = True                 ; turn on color
>>   res@cnLinesOn                   = False               ; no contour lines
>>   ;res@gsnSpreadColors             = True                 ; use full color map
>>   res@lbLabelAutoStride           = True                    ; every other label
>>
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> ;;;;;;;;;;;;;;;;;;;;;;;;draw national boundery map;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> ; Map stuff                                                                        ;
>>    res@mpDataBaseVersion           = "Ncarg4_0"    ; use finer database             ;
>>    res@mpOutlineOn                 = True                                           ;
>>    res@mpFillOn                    = False        ; turn off gray fill              ;
>>    res@mpOutlineBoundarySets       = "National"   ; turn on country boundaries      ;
>>
>>    res@mpNationalLineColor          = "Black"     ;"Red"
>>    res@mpNationalLineDashPattern    = 0                 ;1 ;for dashpattern
>>    res@mpNationalLineThicknessF     = 1.5
>>     res@mpGeophysicalLineColor      = "Black"       ; color of cont. outlines        ;
>>    res@mpGeophysicalLineThicknessF = 1.5          ; thickness of outlines;;         ;
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>
>>
>> ; res@cnLevelSelectionMode        = "ManualLevels"       ; manual levels
>> ; res@cnMinLevelValF              = 0.
>>   ;res@cnMaxLevelValF              = 300.
>> ; res@cnLevelSpacingF             = 4.
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> res@cnLevelSelectionMode = "ExplicitLevels"
>>          res@cnLevels             = (/  ..5, 1., 2.,5., 10.,15.,20. , \
>>                                         30., 50, 75, 100, 110./)
>>         ; res@cnFillColors         = (/"White","White","DarkOliveGreen1", \
>>                          ;                "DarkOliveGreen3","Chartreuse", \
>>                           ;               "Chartreuse3","Green","ForestGreen", \
>>                            ;              "Yellow","Orange","Red","Violet"/)
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>   res@pmTickMarkDisplayMode       = "Always"             ; turn on tick marks
>>
>>   res@tiMainString                = "with dim_avg"
>>
>>   res@gsnAddCyclic                = False                ; regional data
>>
>> ; The following resources are Required to plot this projection correctly
>>
>>   ;res@mpProjection                = "Stereographic"     ; projection
>>
>>   res@mpLimitMode                 = "Corners"           ; method to zoom
>>   ;res@mpLeftCornerLatF            = min(lat)
>>   ;res@mpLeftCornerLonF            = min(lon)
>>   ;res@mpRightCornerLatF           = max(lat)
>>   ;res@mpRightCornerLonF           = max(lon)
>>
>>
>>   res@mpLeftCornerLatF            = -1.143
>>   res@mpLeftCornerLonF            = -0.256
>>   res@mpRightCornerLatF           = 12.983
>>   res@mpRightCornerLonF           = 22.084
>>
>>
>>   ;res@mpRelativeCenterLon         = True                 ; set a center lon
>>   ;res@mpCenterLonF                = lon(147,172)         ; center lon
>>   ;res@mpRelativeCenterLat         = True                ; set a center lat
>> ; res@mpCenterLatF                = 90.                  ; center lat
>> ; res@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
>
> -- __________________________________________________