Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task: add documentation for pixel grids #95

Open
Kirill888 opened this issue Nov 24, 2022 · 0 comments
Open

Task: add documentation for pixel grids #95

Kirill888 opened this issue Nov 24, 2022 · 0 comments

Comments

@Kirill888
Copy link
Member

Problem Description

odc.stac.load output pixel grid can be confusing to users. Unexpected result often look like an error in implementation: an extra pixel column/row, but in fact it is an expected feature of the loading process and has to do with "pixel grid snapping". There is a common expectation that output will start exactly at min(x) of the input data. This is not always the case. Most commonly this manifests when loading data at reduced resolution, example #94.

Another source of confusion is to do with coordinates of the returned xarray. Coordinates are for pixel centers, not for the edge. Common mistake is to assume that image spans [img.x[0], img.x[-1]]. It does not.

  • [img.x[0], img.x[-1]], pixel centers are not pixel edges
  • [img.x[0]-res/2, img.x[-1]+res/2], better but need to know pixel size
  • ✅✅ img.odc.geobox.boundingbox.range_x, best

Worth noting that users of stackstac experience similar confusion, and there is a pinned issue gjoseph92/stackstac#152 helping users.

Pixel Grid Snapping

Just because two images have the same resolution, the same projection and overlap, does not mean that individual pixels overlap exactly with each other:

image

When requested to load two images above how the output pixel grid should look like? Should we pick pixel grid that aligns with orange or with blue image, or something else? We choose something else.

Say images above have pixel size of 100 units, orange one starts at X=130 and blue one at X=690. Image that will be produced in this case will default to starting at X=100 and so both images will be resampled into that common grid. We pick X=100 because this aligns pixel edges to integer multiples of pixel size.

A common assumption users have, is that instead, output image should start at X=130 as this is the left edge of available input data. It's a sensible assumption. Image like that can be produced by odc.stac, but requires specifying anchor= parameter, value of odc.geo.geobox.AnchorEnum.FLOATING, this turns off pixel snapping. This is not well reflected in the docs. Maybe worth adding snap=False or tight=True argument as a more obvious alias for that behaviour.

The advantage of snapping becomes apparent when combining data from different sources: just use the same resolution to load data from different sources and resulting images are guaranteed to have exactly overlapping pixels, so you can combine those arrays without needing further resampling.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant