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

Update example for get_array_statistics #692

Merged
merged 1 commit into from
Apr 5, 2024

Conversation

j08lue
Copy link
Contributor

@j08lue j08lue commented Apr 5, 2024

I noticed that the example in https://cogeotiff.github.io/rio-tiler/advanced/statistics/#area-weighted-statistics was not yet updated after your changes in

This copies the latest code from the respective test into the docs page

# Data Array
# 1, 2
# 3, 4
data = np.ma.array((1, 2, 3, 4)).reshape((1, 2, 2))
# Coverage Array
# 0.5, 0
# 1, 0.25
coverage = np.array((0.5, 0, 1, 0.25)).reshape((2, 2))
stats = utils.get_array_statistics(data, coverage=coverage)
assert len(stats) == 1
assert stats[0]["min"] == 1
assert stats[0]["max"] == 4
assert (
round(stats[0]["mean"], 4) == 2.5714
) # sum of weighted array / sum of weights | 4.5 / 1.75 = 2.57
assert stats[0]["count"] == 1.75
assert stats[0]["median"] == 3 # 2 in exactextract
assert round(stats[0]["std"], 2) == 1.05

@vincentsarago vincentsarago merged commit 2a75ea9 into cogeotiff:main Apr 5, 2024
4 checks passed
@j08lue j08lue deleted the patch-1 branch April 5, 2024 13:29
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.

2 participants