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

expand xarray capabilities #755

Merged
merged 9 commits into from
Oct 28, 2024
Merged

Conversation

vincentsarago
Copy link
Member

@vincentsarago vincentsarago commented Oct 24, 2024

This PR does:

  • adds preview() and statistics() method to the XarrayReader
  • add output size (max_size | width, height) options for preview, part and feature methods

⚠️ Preview and Statistics methods will need to first load the full resolution data in memory and should be used with care!

cc @abarciauskas-bgse @maxrjones @hrodmn

To Do

  • update docs

@@ -118,7 +120,7 @@ def info(self) -> Info:

meta = {
"bounds": self.bounds,
"crs": CRS_to_uri(self.crs),
"crs": CRS_to_uri(self.crs) or self.crs.to_wkt(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

match what we do in io.rasterio.Reader

"attrs": {
k: (v.tolist() if isinstance(v, (numpy.ndarray, numpy.generic)) else v)
for k, v in self.input.attrs.items()
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a possible issue in titiler where pydantic wouldn't be able to serialize the attrs because pydantic do not handle well numpy arrays

height=height,
reproject_method=reproject_method,
resampling_method=resampling_method,
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feature() now use part() method (as we do in io.rasterio.Reader)

assert info
assert info.model_dump()
assert info.model_dump(mode="json")
assert info.model_dump_json()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test pydantic serialization

self.bounds[0] + xres / 2 < -180
or self.bounds[1] + yres / 2 < -90
or self.bounds[2] - xres / 2 > 180
or self.bounds[3] - yres / 2 > 90
):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @noahgolmant

closes #754

vincentsarago and others added 2 commits October 26, 2024 00:10
…756)

* check if the Y bounds are inverted and flip the image on the Y axis

* Update tests/test_io_xarray.py

Co-authored-by: Henry Rodman <[email protected]>

* Update tests/test_io_xarray.py

Co-authored-by: Henry Rodman <[email protected]>

---------

Co-authored-by: Henry Rodman <[email protected]>
@vincentsarago vincentsarago merged commit d3a552e into main Oct 28, 2024
8 checks passed
@vincentsarago vincentsarago deleted the feature/xarray-add-preview-and-stats branch October 28, 2024 11:17
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

Successfully merging this pull request may close these issues.

1 participant