xMIP icon indicating copy to clipboard operation
xMIP copied to clipboard

`longitude` and `latitude` dimensions lost in `rename_cmip6`

Open JoranAngevaare opened this issue 1 year ago • 0 comments

Thanks again for this fantastic tool!

The problem

In a particular dataset, the lon and lat dimentions are called latitude and longitude. The dataset is: 'ScenarioMIP.UA.MCM-UA-1-0.ssp585.r1i1p1f2.Amon.gn.none.tas'. The issue is causing the loss of longitude and latitude information in rename_cmip6. This causes issues down the road as broadcast_lonlat will interpret each of the xy indexes as corresponding lon and lat values.

The data looks like

print(ds)
Setup
<xarray.Dataset>
Dimensions:         (time: 86, bnds: 2, longitude: 96, latitude: 80)
Coordinates:
  * time            (time) object 2015-07-01 18:00:00 ... 2100-07-01 18:00:00
  * longitude       (longitude) float64 0.0 3.75 7.5 11.25 ... 348.8 352.5 356.2
  * latitude        (latitude) float64 -88.29 -86.07 -83.84 ... 86.07 88.29
Dimensions without coordinates: bnds
Data variables:
    time_bnds       (time, bnds) object dask.array<chunksize=(86, 2), meta=np.ndarray>
    longitude_bnds  (longitude, bnds) float64 dask.array<chunksize=(96, 2), meta=np.ndarray>
    latitude_bnds   (latitude, bnds) float64 dask.array<chunksize=(80, 2), meta=np.ndarray>
    tas             (time, latitude, longitude) float32 dask.array<chunksize=(86, 80, 96), meta=np.ndarray>
Attributes: (12/48)
    CDI:                    Climate Data Interface version 2.0.3 (https://mpi...
    Conventions:            CF-1.7 CMIP-6.2 
    source:                 Manabe Climate Model at U of Arizona             ...
    institution:            Department of Geosciences, University of Arizona,...
    activity_id:            ScenarioMIP
    branch_method:          standard
    ...                     ...
    variant_label:          r1i1p1f2
    variant_info:           2015 to 2100 time varying equiv CO2 and aerosol f...
    title:                  UArizona MCM-UA-1-0 ssp585              
    product:                model-output
    license:                CMIP6 model data produced by the U of Arizona is ...
    CDO:                    Climate Data Operators version 2.0.3 (https://mpi...

running this through rename_cmip6 loses the longitude and latitude dimensions. I fear this is because of the special treatment of lon and lat in rename_cmip6:

>>> print(rename_cmip6(ds))
<xarray.Dataset>
Dimensions:         (time: 86, bnds: 2, x: 96, y: 80)
Coordinates:
  * time            (time) object 2015-07-01 18:00:00 ... 2100-07-01 18:00:00
Dimensions without coordinates: bnds, x, y
Data variables:
    time_bounds     (time, bnds) object dask.array<chunksize=(86, 2), meta=np.ndarray>
    longitude_bnds  (x, bnds) float64 dask.array<chunksize=(96, 2), meta=np.ndarray>
    latitude_bnds   (y, bnds) float64 dask.array<chunksize=(80, 2), meta=np.ndarray>
    tas             (time, y, x) float32 dask.array<chunksize=(86, 80, 96), meta=np.ndarray>
Attributes: (12/48)
    CDI:                    Climate Data Interface version 2.0.3 (https://mpi...
    Conventions:            CF-1.7 CMIP-6.2 
    source:                 Manabe Climate Model at U of Arizona             ...
    institution:            Department of Geosciences, University of Arizona,...
    activity_id:            ScenarioMIP
    branch_method:          standard
    ...                     ...
    variant_label:          r1i1p1f2
    variant_info:           2015 to 2100 time varying equiv CO2 and aerosol f...
    title:                  UArizona MCM-UA-1-0 ssp585              
    product:                model-output
    license:                CMIP6 model data produced by the U of Arizona is ...
    CDO:                    Climate Data Operators version 2.0.3 (https://mpi...

Possible fix

Maybe the dimension renaming should occur earlier? For example, see this simple alteration:

>>> print(rename_cmip6(ds.rename(dict(longitude='lon', latitude='lat'))))
<xarray.Dataset>
Dimensions:         (time: 86, bnds: 2, x: 96, y: 80)
Coordinates:
  * time            (time) object 2015-07-01 18:00:00 ... 2100-07-01 18:00:00
  * x               (x) float64 0.0 3.75 7.5 11.25 ... 345.0 348.8 352.5 356.2
  * y               (y) float64 -88.29 -86.07 -83.84 ... 83.84 86.07 88.29
Dimensions without coordinates: bnds
Data variables:
    time_bounds     (time, bnds) object dask.array<chunksize=(86, 2), meta=np.ndarray>
    longitude_bnds  (x, bnds) float64 dask.array<chunksize=(96, 2), meta=np.ndarray>
    latitude_bnds   (y, bnds) float64 dask.array<chunksize=(80, 2), meta=np.ndarray>
    tas             (time, y, x) float32 dask.array<chunksize=(86, 80, 96), meta=np.ndarray>
Attributes: (12/48)
    CDI:                    Climate Data Interface version 2.0.3 (https://mpi...
    Conventions:            CF-1.7 CMIP-6.2 
    source:                 Manabe Climate Model at U of Arizona             ...
    institution:            Department of Geosciences, University of Arizona,...
    activity_id:            ScenarioMIP
    branch_method:          standard
    ...                     ...
    variant_label:          r1i1p1f2
    variant_info:           2015 to 2100 time varying equiv CO2 and aerosol f...
    title:                  UArizona MCM-UA-1-0 ssp585              
    product:                model-output
    license:                CMIP6 model data produced by the U of Arizona is ...
    CDO:                    Climate Data Operators version 2.0.3 (https://mpi...

JoranAngevaare avatar Jun 01 '23 13:06 JoranAngevaare