Different results when calculating global mean of CM2.6 Data with xarray and ferret

Hello Pangeo,
I am really new to python/xarray/dask so please excuse if the solution of my problem is really obvious or my explanation is a little unclear. Every help is highly appreciated!

Goal: I want to calculate the global mean of some ocean variable (density) of the GFDL CM2.6 Model.
In order to do so I mask out the ocean area and then calculate the global mean with three different approaches (2 approaches in xarray, one in ferret) in order to check if I get the same result - spoiler alert: I don’t.

Used Data: NetCDF GFDL CM2.6 Data which is on the Pangeo Platform. I use the grid information as well as the 3D fields (salt, temperature) for the calculation of the density.

Important Gridinformation:

Information of zweighted Density (using z-weighted mean in order to account for different grid spacing in the vertical):

Calculating of global mean with xarray:
In my first step I define the ocean area, whereby I use the information saved in the grid. And calculate the total ocean area, which I need later on.
Bildschirmfoto 2022-01-28 um 15.38.52

  1. I then calculate the ocean-area-mean value as a weighted mean, whereby I define the latitude weights and then calculate a weighted mean:
    Bildschirmfoto 2022-01-28 um 15.39.38

  2. My other idea was to calculate the mean just by making the calculation „myself“: multiplying every value with the cell-area and then dividing through the total ocean area:

Sadly, both calculation result in slightly different values.

Calculating global mean with ferret
This results in a smaller number.
Bildschirmfoto 2022-01-25 um 07.39.58

Now I am not sure what the „correct“ way is and where my mistakes are. The differences seem to me too big to just arise from numeric inaccuracies. However, the variables are “just” saved with float32, so maybe numeric inaccuracies are the cause.

Can someone help me?

Thank you so much and have a great rest of the day :slight_smile:

1 Like

Thanks for posting. We will help get to the bottom of this.

This community understands well how Xarray works but not so much Ferret. Can you link to some documentation about how Ferret computes the weighted average?

Hi @rabernat thanks for the super quick reply!
I don’t really understand how ferret works (I am just starting to work with big ClimateData), but here is some documentation how ferret computes weighted averages: 3.2 EXPRESSIONS | Science Data Integration Group - Ferret Support Chapter 3, Section 2.4.6.

I hope that helps!

I’m not sure if it’s relevant but I’ve used similar weighing function based on latitude before and thought there must be some error due to Earth’s ellipsoid shape that bulges a little at the equator.

Since water density would be lower in the equatorial regions than polar regions, a weighing function that under-estimates the surface area of equatorial region (e.g. one that considers Earth as a sphere) would result in overall higher mean water density when compared to a weighing function that approximates the shape of the Earth more closely. I don’t know Ferret either but it seems like it’s specialized enough to do this in a more correct way.

Just a thought.