[ncl-talk] Inconsistency in dimension averaging using dim_avg_n

Tabish Ansari tabishumaransari at gmail.com
Wed Aug 21 07:30:36 MDT 2024


Hello,

I've got a 3D variable called "monthlypm25NCP". It has 12 timesteps and 41
lat x 41 lon values.

Here's the variable summary:
Variable: monthlypm25NCP
Type: float
Total Size: 80688 bytes
            20172 values
Number of Dimensions: 3
Dimensions and sizes:   [12] x [41] x [41]
Coordinates:
Number Of Attributes: 1
  _FillValue :  9.96921e+36


Since this is a derived variable from another 3-hourly variable, the
coordinate arrays are not retained. (I could have copied them over but I
didn't in this instance.)

Now, I want to average this 3D variable over the lat-lon grid to reduce it
to a 1D variable containing only 12 values (one for each month).

I tried using the dim_avg_n in two different ways to achieve this:

*1. In 2-steps: *
monthlypm25NCPsum1= dim_avg_n(monthlypm25NCP, 2)
monthlypm25NCPsum = dim_avg_n(monthlypm25NCPsum1, 1)
print(monthlypm25NCPsum+"")

Result:
(0)     167.83
(1)     150.403
(2)     124.87
(3)     102.86
(4)     90.6969
(5)     80.4786
(6)     75.9811
(7)     71.1969
(8)     93.9213
(9)     117.72
(10)    136.6
(11)    139.528

*2. In a single step:*
monthlypm25NCPsum = dim_avg_n(monthlypm25NCP, (/1,2/))
print(monthlypm25NCPsum+"")

Result:
(0)     155.3
(1)     140.645
(2)     116.423
(3)     96.4202
(4)     84.4638
(5)     76.3392
(6)     72.5972
(7)     67.5716
(8)     88.2773
(9)     110.789
(10)    129.426
(11)    131.247

I was expecting the results to be identical but strangely they're not, as
you can see above.

Can you please explain what's causing the difference here?

Is it possible that in the second case, the dim_avg_n function is
recognizing the lat-lon grid and using a weighted averaging based on actual
grid area? But how can it recognize that when I have not included the
coordinate arrays?

Ultimately, I do want to perform a weighted averaging over the lat-lon grid
and have obtained a separate matrix that contains gridcell area (I used the
cdo tool to obtain it). Should I do a sparse matrix multiplication with the
gridcell area before performing the grid averaging in NCL or does the
dim_avg_n function take care of the grid area itself?

Thanks

Tabish


--------------------------------------------------------------------------------------
Dr Tabish Ansari
Research Associate
Air Quality Modelling Group
Research Institute for Sustainability (RIFS) - Helmholtz Centre Potsdam
Potsdam, Germany
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20240821/915e997f/attachment.htm>


More information about the ncl-talk mailing list