Re: regional average help

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Tue Mar 23 2010 - 07:42:15 MDT

Given

       double TAREA(nlat, nlon) ;
          TAREA:long_name = "area of T cells" ;
         _FillValue : 9.96921e+36

      float TLAT ( nlat, nlon )
         long_name : array of t-grid latitudes
         units : degrees_north

      float TLONG ( nlat, nlon )
         long_name : array of t-grid longitudes

       float SSH ( time, nlat, nlon )
         long_name : Sea Surface Height
         units : centimeter
         coordinates : TLONG TLAT time
=====================
untested
=====================
      tlon = f->TLONG
      tlat = f->TLAT
      tarea = f->TAREA
      ssh = f->SSH

      dims = dimsizes(ssh)
      ntim = dims(0)

      latS = -20
      latN = 20
      lonW = 120
      lomE = 180

                ; set all tarea outside desired region to _FillValue

      zarea = where((tlat.ge.latS .and. tlat.le.latN) .and. \
                              (tlon.ge.lonW .and. tlon.le.lonE) \
                                tarea, tarea@_FillValue)

                ; sum all the zarea weights [type double]

      zarea_sum = sum(zarea)

      z = new ( ntim, "double", ssh@_FillValue)

      do nt=0,ntim-1
           z(nt) = sum(ssh(nt,:,:)*zarea)/zarea_sum
      end do

      z@long_name = "weighted area average: " + ssh@long_name
      z@units = ssh@units
      z!0 = "time"
      z&time = ssh&time

      printVarSummary(z)

Good luck

Changlin Chen wrote:
> Hi,
> I have a file output from ccsm_pop model, the lat and lon is 2D and not
> a monotonically increasing or decreasing array.
> I want to calculate regional ocean average, and TAREA is a 2D weight
> array with the same size of lon and lat.
>
> $----
> f0 = addfile("pop.h.nc","r")
> SSH = f0->SSH
> TAREA = f0->TAREA
> lat2d = f0->TLAT
> lon2d = f0->TLONG
>
> wp_ave =
> wgt_areaave2(SSH(0,{-20:20},{120:180}),TAREA({-20:20},{120:180}),0)
> $----
> But it can't work, with an error:
>
> "fatal:Dimension (nlon) of (SSH) does not have an associated coordinate
> variable"
>
> How can I solve these problems? Thanks!
>
> ============================================================
> Variable: SSH
> Type: float
> Total Size: 491520 bytes
> 122880 values
> Number of Dimensions: 3
> Dimensions and sizes: [time | 1] x [nlat | 384] x [nlon | 320]
> Coordinates:
> time: [712146..712146]
> Number Of Attributes: 6
> long_name : Sea Surface Height
> units : centimeter
> coordinates : TLONG TLAT time
> cell_methods : time: mean
> _FillValue : 9.96921e+36
> missing_value : 9.96921e+36
> ===============================================================
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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 Tue Mar 23 07:42:20 2010

This archive was generated by hypermail 2.1.8 : Sat Mar 27 2010 - 07:18:15 MDT