Hi!


Is it intended behaviour that attributes are not preserved when calling the function geo.spatial_average()? A snippet of my code:



print(data_nuts) 
print(data_nuts.attrs)

data_nuts_mean = ct.geo.spatial_average(data_nuts)

print(data_nuts_mean)
print(data_nuts_mean.attrs)


This gives me the following output:


<xarray.DataArray 'index' (time: 6, lat: 366, lon: 591, nuts_level0: 37)>
dask.array<xarray-index, shape=(6, 366, 591, 37), dtype=float32, chunksize=(6, 366, 591, 37), chunktype=numpy.ndarray>
Coordinates:
    height       float64 ...
  * lat          (lat) float64 34.6 34.7 34.8 34.9 35.0 ... 70.8 70.9 71.0 71.1
  * lon          (lon) float64 -24.1 -24.0 -23.9 -23.8 ... 34.6 34.7 34.8 34.9
  * time         (time) datetime64[ns] 2018-01-01 2019-01-01 ... 2023-01-01
  * nuts_level0  (nuts_level0) object 'ES' 'FI' 'IS' 'FR' ... 'MT' 'NL' 'NO'
Attributes:
    units:        1
    long_name:    Index
    Conventions:  CF-1.6
    source:       SIS-URBAN
    institution:  ECMWF
    comment:      General index variable for flag/index type data

{'Conventions': 'CF-1.6', 'comment': 'General index variable for flag/index type data', 'institution': 'ECMWF', 'long_name': 'Index', 'source': 'SIS-URBAN', 'units': '1'}

<xarray.DataArray 'data' (time: 6, nuts_level0: 37)>
dask.array<xarray-data, shape=(6, 37), dtype=float64, chunksize=(6, 37), chunktype=numpy.ndarray>
Coordinates:
height float64 ...
* time (time) datetime64[ns] 2018-01-01 2019-01-01 ... 2023-01-01
* nuts_level0 (nuts_level0) object 'ES' 'FI' 'IS' 'FR' ... 'MT' 'NL' 'NO'

{}


This gave me no joy later in my script where I was trying to plot some data, as the attribute 'units' had disappeared, and I had to figure out where this had happened - it was in this step.


Thanks

Rutger



2 Comments

  1. Dear Rutger,

    This bug has been fixed last week. However, It will only be available in the Toolbox at the next release on the 3rd of June.

    In the meanwhile you can add the attributes using the ct.cdm.update_attributes tool.

    Sorry for the inconvenience of the bug.

    Regards.

    Vivien

  2. Hi Vivien


    Great, thanks! Good to know this will be fixed soon.


    Cheers

    Rutger