English

Problem: Grid MEAN gives NODATA in some output cells

Description

The MEAN function is giving NODATA in the output cell location although some of the inputs have valid data values at that location.

Cause

If any cell location contains NODATA on any of the input grids, that location will be assigned NODATA on the output grid.

Solution or Workaround

Use the Grid IF statement inside a DOCELL block to test if each input grid's value is NODATA. If it is, skip that grid when calculating the mean at that cell location. If it is not NODATA, add the value to a running total using the += operator. Also, keep a running total of the number of valid values at that cell location. The list of grids can be accessed using an &DO &LIST directive in an AML. For example:

Code:
/* USAGE: &RUN AVE 'grid1,grid2,grid3,...'
/*
/* NOTE: Adjust the precision of scalars to mimic precision of
/* input data.
/*
/* Put the input grid list in ' ' quotes.

&args list
sum = scalar(0.00)
count = scalar(0.00)
docell
sum = scalar(0.00)
count = scalar(0.00)
&do var &list [unquote %list%]
if (^(isnull(%var%)))
begin
sum += %var%
count += 1.00
end
endif
&end
outgrid = sum / count
end
removescalar sum
removescalar count
&return


Note:
The calculation will only occur in areas where the extents of all input grids overlap.