Re: Calculating an Average for a (time, level, lat, lon) Variable

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Sun Feb 09 2014 - 16:40:27 MST

If u(time,lev,lat,lon) then

    u_avg = dim_avg_n_Wrap(u,(/0,1/))

will average all times (dimension 0) and all levels (dimension 1)
together. If you use

    printVarSummary(u_avg)

you would see that u_avg(lat,lon). There is *no* level dimension.
Hence, u_avg(9,:,:) is not appropriate.

try

    kl = 9
or
    plvl = 250

    u_avg = dim_avg_n_Wrap(u(:,kl,:,:), 0) ; 0 is the time dimension
or
    u_avg = dim_avg_n_Wrap(u(:,{plvl},:,:), 0)

    printVarSummary(u_avg) ; *** time avg at kl/plvl

Always use printVarSummary(..)

===
Good luck

On 2/9/14, 1:50 PM, Lauren Jean Vargo wrote:
> Hello,
>
> I’m working on version 6.1.2 of NCL trying to calculate a time average at a given level for all lat and lon from a variable u that is (time, plev, lat, lon) and variable v that has the same dimensions.
>
> I’ve read in the variables, and have tried calculating time averages several different ways, but none have worked (and I do not get an error message, the script appears to just keep running until I quit xQuartz). I also know that the calculation of the time average is the problem because I get the printVarSummary of u, and then nothing else happens.
>
> Here is the type of system that I am on: Darwin Lauren-Vargos-MacBook.local 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64
>
> Here is my script,
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
>
> begin
>
> a = addfile("ua_Amon_CCSM4_lgm_r1i1p1_185001-190012.nc","r")
> b = addfile("va_Amon_CCSM4_lgm_r1i1p1_185001-190012.nc","r")
>
> u = a->ua
> printVarSummary (u)
> u_avg = dim_avg_n_Wrap(u,(/0,1/))
>
> v = b->va
> printVarSummary (v)
> v_avg = dim_avg_n_Wrap(v,(/0,1/))
>
> wks = gsn_open_wks(“pdf","plt_r2")
>
> res = True
>
> plot = gsn_csm_streamline_map_ce(wks,u_avg(9,:,:),v_avg(9,:,:),res)
> ; the 9 in the (x,:,:) calculates at the 200 hPa level
> end
>
>
> This is based on example 4 from http://www.ncl.ucar.edu/Document/Functions/Contributed/dim_avg_n_Wrap.shtml
>
> I’ve also tried calculating the time average using u_avg_time = dim_avg_n_Wrap<https://www.ncl.ucar.edu/Document/Functions/Contributed/dim_avg_n_Wrap.shtml>( u, 0) based on example 3 from https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_avg_n.shtml, and I’ve tried u_avg_time = dim_avg_Wrap( u(plev:, lat|:, lon|:, time|:) ) using example 4 from https://www.ncl.ucar.edu/Document/Functions/Contributed/dim_avg_Wrap.shtml.
>
> Any help with calculating this time average is greatly appreciated,
> Thank you,
> Lauren
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sun Feb 9 16:40:36 2014

This archive was generated by hypermail 2.1.8 : Wed Feb 12 2014 - 09:35:52 MST