cordex.rewrite_coords#
- rewrite_coords(ds, coords='xy', bounds=False, domain_id=None, mip_era='CMIP5', method='nearest')[source]#
Rewrite coordinates in a dataset.
This function ensures that the coordinates in a dataset are consistent and can be compared to other datasets. It can reindex the dataset based on specified coordinates or domain information while trying to keep the original coordinate attributes.
- Parameters:
ds (xr.Dataset) – The dataset containing the grid to be rewritten.
coords (str, optional) – Specifies which coordinates to rewrite. Options are: - “xy”: Rewrite only the X and Y coordinates. - “lonlat”: Rewrite only the longitude and latitude coordinates. - “all”: Rewrite both X, Y, longitude, and latitude coordinates. Default is “xy”. If longitude and latitude coordinates are not present in the dataset, they will be added. Rewriting longitude and latitude coordinates is only possible if the dataset contains a grid mapping variable.
bounds (bool, optional) – If True, the function will also handle the bounds of the coordinates. If the dataset already has bounds, they will be updated while preserving attributes and shape. If not, the bounds will be assigned.
domain_id (str, optional) – The domain identifier used to obtain grid information. If not provided, the function will attempt to use the domain_id attribute from the dataset.
mip_era (str, optional) – The MIP era (e.g., “CMIP5”, “CMIP6”) used to determine coordinate attributes. Default is “CMIP5”. Only used if the dataset does not already contain coordinate attributes.
method (str, optional) – The method used for reindexing the X and Y axis. Options include “nearest”, “linear”, etc. Default is “nearest”.
- Returns:
ds (xr.Dataset) – The dataset with rewritten coordinates.