roocs / clisops

Climate Simulation Operations
https://clisops.readthedocs.io/en/latest/
Other
21 stars 9 forks source link

Xarray arguments for `mean` : `skipna` and `keep_attrs` #28

Closed agstephens closed 4 years ago

agstephens commented 4 years ago

The Xarray mean method is: http://xarray.pydata.org/en/stable/generated/xarray.DataArray.mean.html

It includes two optional arguments:

Create some unit tests to help us understand the behaviour of each argument:

def test_xarray_da_mean_skipna_true():
  - create a simple 1D xarray.DataArray with 10 values of [10., 10., 10., 10., 10., nan, nan, nan, nan, nan]
  - test that the average is 2 if you use `skipna=True`

def test_xarray_da_mean_skipna_false():
  - create a simple 1D xarray.DataArray with 10 values of [10., 10., 10., 10., 10., nan, nan, nan, nan, nan]
  - test that the average is 1 if you use `skipna=False`

If the results are not as above, we need to investigate more.

def test_xarray_da_mean_keep_attrs_true():
  - read a variable from our mini-esgf-cache
  - average it with `mean` method across the time axis, with `keep_attrs=True`
  - assert the original attributes match the new attributes

def test_xarray_da_mean_keep_attrs_false():
  - read a variable from our mini-esgf-cache
  - average it with `mean` method across the time axis, with `keep_attrs=False`
  - examine the attributes of the resulting average DataArray
  - assert those values when you know them

Discuss with team whether we want to:
  1. Keep attrs
  2. Lose attrs
  3. Modify attrs (which might be: keep some then remove/edit/add others).

Keep these unit tests in our codebase anyway.