Skip to content

.odc.geobox coordinate precision is not the same as DataArray coordinates #231

@saschahofmann

Description

@saschahofmann

There seems to be an issue with floating precisions when assigning the GeoBox to a xarray.DataArray related to floating point precision.

import numpy as np
import xarray as xr
import odc.geo.xr

lats = np.arange(21.95, 72.55, 0.05)
lons = np.arange(-44.55, 64.95, 0.05)
da = xr.DataArray(
    np.random.rand(lats.size, lons.size),
    coords=dict(latitude=("latitude", lats), longitude=("longitude", lons)),
)
(da.odc.geobox.coords["x"].values == da.longitude.values).sum()/da.longitude.size*100

Leads to a 0.41% agreement.

In my case, I am using a reference dataset to reproject another dataset but because of the imprecision the resulting reprojected dataset is not actually on the same grid as the reference. You can also see this when looking at the coordinates

Image

The resulting coordinate resolutions are slightly off.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions