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

✨ Implement PyCogReader struct with new and to_numpy methods #12

Merged
merged 4 commits into from
Mar 17, 2024

Conversation

weiji14
Copy link
Owner

@weiji14 weiji14 commented Mar 15, 2024

A (Py)CogReader class for Python that wraps around the CogReader struct!

Usage (Python):

import numpy as np
from cog3pio import CogReader

cog_url: str = (
    "https://github.com/cogeotiff/rio-tiler/raw/6.4.1/tests/fixtures/cog_nodata_nan.tif"
)
reader = CogReader(path=cog_url)

array: np.ndarray = reader.to_numpy()
assert array.shape == (1, 549, 549)  # bands, height, width

TODO:

  • Initial implementation of new (__init__) and to_numpy methods
  • Add docstrings
  • Add unit tests

TODO in the future:

  • Add type hint stubs (best to set up linter CIs first)

P.S. This is a set up for the eventual xarray backend code 😉

A (Py)CogReader class for Python that wraps around the CogReader struct! Have implemented the new (i.e. __init__) and data methods, and used them in the read_geotiff_py function. Needed to set CogReader struct visibility to pub(crate). Renamed vec_data to array_data since they contain arrays, not Vec. Also updated the regex match for one of the unit tests.
@weiji14 weiji14 added the feature New feature or request label Mar 15, 2024
@weiji14 weiji14 added this to the 0.1.0 milestone Mar 15, 2024
@weiji14 weiji14 self-assigned this Mar 15, 2024
Numpydoc style docstrings for the CogReader class and .data method. Included some example code on how to use the class and methods to read a sample GeoTIFF too.
Ensure that the `.data()` method returns a numpy.ndarray output with the correct shape and values.
Originally went with `.data()` to match https://docs.xarray.dev/en/v2024.02.0/generated/xarray.DataArray.data.html, but realized that xarray's `.data` is a property, not a method. Now going with `.to_numpy()` instead, following what's used by xarray, pandas and pyarrow.
@weiji14 weiji14 changed the title ✨ Implement PyCogReader struct with new and data methods ✨ Implement PyCogReader struct with new and to_numpy methods Mar 17, 2024
@weiji14 weiji14 marked this pull request as ready for review March 17, 2024 00:18
@weiji14 weiji14 enabled auto-merge (squash) March 17, 2024 00:18
@weiji14 weiji14 merged commit b23a973 into main Mar 17, 2024
12 checks passed
@weiji14 weiji14 deleted the class_CogReader branch March 17, 2024 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant