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

ENH: support exactextract as a method in zonal_stats #68

Merged
merged 18 commits into from
Jul 2, 2024

Conversation

masawdah
Copy link
Contributor

This is an initial implementation for exactextract.

exactextract expects the statistical input to be an object of a Python class named 'operation' defined within the package. It utilizes a built-in method to construct these objects if the input is a string or callable. However, this built-in method does not support all callables (such as np.mean, ...), and strings like 'quantile' should follow this pattern: 'quantile(q=0.33)'. I've added a check function for the statistical input to use when the method is exactextract, but I'm unsure if this is the best option or if it should simply be added to the documentation.

@martinfleis
Copy link
Member

Thanks for this! Regarding the stats, I think it is fine to document the differences when using exactextract. Later we can try to parse it ourselves but I am fine with proper documentation for now.

@martinfleis
Copy link
Member

Can you include tests and that documentation?

@masawdah
Copy link
Contributor Author

Can you include tests and that documentation?

Yes l'll take care of that

@masawdah
Copy link
Contributor Author

I've just added a test for exactextract. Since exactextract performs statistics based on pixel fractions, the results differ from those of rasterization and iteration. I've maintained the same test functions and data, but added an if-statement specifically for the exactextract method. This introduces only one condition and does not significantly increase the code's complexity.

To avoid complexity, we could create a separate test function for exactextract and use different data. However, I believe this isn't necessary given that we're only adding one condition.

The docs will follow soon :)

it was a typo. I used same values

Co-authored-by: Martin Fleischmann <[email protected]>
@martinfleis
Copy link
Member

I am fine with how the way you did tests, keep it.

@martinfleis martinfleis changed the title exactextract ENH: support exactextract as a method in zonal_stats Jun 27, 2024
@martinfleis martinfleis linked an issue Jun 27, 2024 that may be closed by this pull request
@masawdah
Copy link
Contributor Author

Now it should be ready :)

@martinfleis
Copy link
Member

I pushed my suggestions directly now.

I am wondering - I know that exactextract only supports DataArray but shall we make an effort and return a Dataset if the input is a Dataset? As shown in the notebook, we now return DataArray, which is inconsistent with the other methods. Can we try to convert it so the input type matches the output type?

@masawdah
Copy link
Contributor Author

I pushed my suggestions directly now.

I am wondering - I know that exactextract only supports DataArray but shall we make an effort and return a Dataset if the input is a Dataset? As shown in the notebook, we now return DataArray, which is inconsistent with the other methods. Can we try to convert it so the input type matches the output type?

Yes it is better to match the types. I'll add a part to handle it

@masawdah
Copy link
Contributor Author

I reengineered the code to match the input/output types and modified the pytests accordingly.

@martinfleis
Copy link
Member

This is great! One final request, can we pass through attributes as we do with rasterio-based zonal_stats? At that point I think we get the parity and I'd be happy to merge.

Thanks a ton for working on this!

Copy link
Member

@martinfleis martinfleis left a comment

Choose a reason for hiding this comment

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

Thanks! Now we just need a proper release of exactextract 😅

@martinfleis martinfleis merged commit 6167014 into xarray-contrib:main Jul 2, 2024
9 checks passed
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.

add zonal_stats based on exactextract
2 participants