Last active
November 30, 2021 01:24
-
-
Save Kirill888/b3dad8afdc10b37cd21af4aea8f417e3 to your computer and use it in GitHub Desktop.
Error report for stackstac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --- | |
# jupyter: | |
# jupytext: | |
# formats: ipynb,py:percent | |
# text_representation: | |
# extension: .py | |
# format_name: percent | |
# format_version: '1.3' | |
# jupytext_version: 1.13.0 | |
# kernelspec: | |
# display_name: ODC | |
# language: python | |
# name: odc | |
# --- | |
# %% | |
# %matplotlib inline | |
import json | |
import numpy as np | |
import rioxarray | |
import stackstac | |
from matplotlib import pyplot as plt | |
item = json.load(open("test-tl-stac.geojson", "rt")) | |
xx = stackstac.stack( | |
[item], dtype="float32", bounds_latlon=(-180, -90, 180, +90), xy_coords="topleft" | |
) | |
yy = stackstac.stack( | |
[item], dtype="float32", bounds_latlon=(-180, -90, 180, +90), xy_coords="center" | |
) | |
# %% [markdown] | |
# ## Check pixel data is the same | |
# | |
# We expect image data to be identical between the two modes | |
# %% | |
assert (xx.data == yy.data).all().compute() | |
# %% | |
fig, axs = plt.subplots(2, 1, figsize=(8, 7)) | |
for idx in range(2): | |
xx.isel(band=idx).isel(time=0).plot.imshow(ax=axs[idx]) | |
# %% [markdown] | |
# ## Check Coordinates | |
# | |
# Data spans whole globe in `EPSG:4326` projection with 1 degree pixels. | |
# %% | |
_, _, NY, NX = xx.shape | |
expect_x_left = np.linspace(-180, 180, NX + 1)[:-1] # -180 -> +179 | |
expect_x_center = expect_x_left + 0.5 # -179.5 -> 179.5 | |
expect_y_left = np.linspace(90, -90, NY + 1)[:-1] # +90 -> -89 | |
expect_y_center = expect_y_left - 0.5 # 89.5 -> -89.5 | |
# %% [markdown] | |
# ### Check topleft | |
# | |
# Top-left coordinates are done correctly | |
# %% | |
np.testing.assert_allclose(xx.x, expect_x_left) | |
np.testing.assert_allclose(xx.y, expect_y_left) | |
# %% [markdown] | |
# ### Check center | |
# | |
# Y coordinate is incorrectly computed when `xy_coord="center"`. As a result `rioxarray` reports incorrect transform and bounds. | |
# %% | |
(yy.rio.transform(), yy.attrs["transform"], yy.rio.bounds(), yy.attrs["spec"].bounds) | |
# %% | |
np.testing.assert_allclose(yy.x, expect_x_center) | |
# %% | |
np.testing.assert_allclose(yy.y, expect_y_center) | |
# %% [markdown] | |
# ------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment