Skip to content

[Bug]: Data is loading with lon/lat transposed #230

@alexgleith

Description

@alexgleith

Bug Summary

I'm running the below code to load an xarray, and if I don't transpose lat/lon, then the array is flipped along a diagonal axis.

Am I doing something wrong to cause the data to be flipped?

Steps to Reproduce

import ee
import xarray as xr
import odc.geo.xr  # noqa: F401

# Authenticate and initialize
# ee.Authenticate()
ee.Initialize(opt_url="https://earthengine-highvolume.googleapis.com")

dataset = "ACA/reef_habitat/v2_0"
ic = ee.ImageCollection(ee.Image(dataset))

# Region of interest. Eventually, we need to do all of -180 to 180 and -32 to 32
left = 142.0
bottom = -10.0
right = 144.0
top = -8.0

# Close to full resolution
res = 0.00005
transform = [res, 0, left, 0, -res, top]

ds = xr.open_dataset(
    ic,
    engine='ee',
    geometry=[left, bottom, right, top],
    projection=ee.Projection(
        crs="epsg:4326", transform=transform
    ),
    chunks={"time": 1, "lon": 10000, "lat": 10000},
).squeeze().drop_vars("time")

# Load into memory and clean up
reef_mask = ds.reef_mask.astype("uint8").compute()
reef_mask = reef_mask.transpose("lat", "lon")  # Why is it transposed?!
reef_mask.odc.nodata = 0

reef_mask.odc.write_cog("test.tif", overwrite=True)

Current Behavior

Data is flipped

Expected Behavior

Data comes out in the right orientation

Relevant log output

Xee Version

0.0.20

Contact Details

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions