NCAR / ldcpy

Statistical and visual tools for gathering metrics and comparing Earth System Model data files. A common use case is comparing data that has been lossily compressed with the original data.
https://ldcpy.readthedocs.io/
Apache License 2.0
19 stars 2 forks source link

use weighted average for means in spatial coord #261

Closed allibco closed 3 years ago

allibco commented 3 years ago

For pop, the weights are here: double TAREA(nlat, nlon) ;

For cam fv, they are here: double gw(lat) ; gw:long_name = "gauss weights" ; double hyai(ilev) ;

For CAM, FV we are just weighting the latitude:

  #weights are for lat   a_lat = np.average(data,axis=0, weights=weight)   a = np.average(a_lat)   return a

dcherian commented 3 years ago

cf_xarray can do this if the appropriate cell_measures attribute is set: e.g.: https://cf-xarray.readthedocs.io/en/latest/examples/introduction.html#Feature:-Weight-by-Cell-Measures

ds.cf.weighted("area").mean()

allibco commented 3 years ago

@dcherian Thanks for letting us know - this might make things a lot easier :)