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

.geobox property not defined for single pixel arrays #752

Closed
Kirill888 opened this issue Jun 26, 2019 · 6 comments
Closed

.geobox property not defined for single pixel arrays #752

Kirill888 opened this issue Jun 26, 2019 · 6 comments
Assignees
Labels

Comments

@Kirill888
Copy link
Member

Kirill888 commented Jun 26, 2019

Expected behaviour

xx = dc.load(.., resolution=(-10,10))
xx.nbar_red[:, :1,:1].geobox.resolution == (-10, 10)

Actual behaviour

Instead get (nan, nan)

Why

Resolution is computed from axis values, when there is only one axis value resolution can not be inferred as you need at least 2 axis values to compute "step"

res = (data[data.size - 1] - data[0]) / (data.size - 1.0)

In the code above resolution will be computed to be 0/0 which is nan.

@andrewdhicks
Copy link
Contributor

I think @uchchwhash was working on a fix for this, you should check with him

@Kirill888
Copy link
Member Author

@andrewdhicks thanks I'm aware, hence this issue, unfortunately proposed changes in this branch https://github.com/opendatacube/datacube-core/tree/virtual-product-reproject would break .geobox behaviour when decimating loaded arrays:

xx = dc.load(.., resolution=(-10,10))
xx.nbar_red[:, ::2,::2].geobox.resolution == (-20, 20)

instead it would return (-10, 10)

@Kirill888
Copy link
Member Author

Might have to be addressed as part of #519

@petewa
Copy link
Contributor

petewa commented Dec 11, 2019

I couldn't find a clean and neat way to fix this as part of Bug squash 2019.

I attempted to persist the updated resolution (non-native xarray metadata) attribute but does not seem to be propagated through the xarray native operations.

I also attempted to use with xr.set_options(keep_attrs=True): without success.

One solution I found is to override xarray's slice operator within ODC codebase to update this information but is fragile.

@petewa petewa self-assigned this Dec 11, 2019
@uchchwhash
Copy link
Member

uchchwhash commented Dec 17, 2019

Just making a note that the NetCDF CF convention prescribes:

To represent cells we add the attribute bounds to the appropriate coordinate variable(s). The value of bounds is the name of the variable that contains the vertices of the cell boundaries. We refer to this type of variable as a "boundary variable." A boundary variable will have one more dimension than its associated coordinate or auxiliary coordinate variable. The additional dimension should be the most rapidly varying one, and its size is the maximum number of cell vertices. Since a boundary variable is considered to be part of a coordinate variable’s metadata, it is not necessary to provide it with attributes such as long_name and units.

As clunky as it is, at least it is a convention. I did not like it when I first saw it, but now I am humbler.

@stale
Copy link

stale bot commented Aug 8, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

No branches or pull requests

4 participants