geotiff: apply TIFF Orientation tag on HTTP COG full reads (#1717)#1724
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a backend-parity bug in the GeoTIFF reader where full HTTP COG reads (_read_cog_http) returned the decoded pixel buffer without applying the TIFF Orientation tag (274), causing different pixel order (and potentially different geospatial transform interpretation) compared to local reads.
Changes:
- Apply the Orientation tag handling to the HTTP full-read path so HTTP and local reads return consistent arrays and
GeoInfo. - Factor shared orientation +
GeoInfo.transformupdate logic into a new_apply_orientation_with_geo(...)helper. - Add a new HTTP parity test suite covering orientations 1–8 and ensuring windowed HTTP reads still reject non-default orientation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
xrspatial/geotiff/_reader.py |
Adds a shared orientation+georef helper and uses it in both local and HTTP read paths. |
xrspatial/geotiff/tests/test_http_orientation_1717.py |
New regression tests to ensure HTTP full reads match local reads for all orientation values and preserve the windowed-read rejection behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+99
to
+120
| arr_local, geo_local = read_to_array(str(path)) | ||
|
|
||
| httpd, port = _serve(payload) | ||
| try: | ||
| url = f'http://127.0.0.1:{port}/orient_{orientation}.tif' | ||
| arr_http, geo_http = _read_cog_http(url) | ||
| finally: | ||
| httpd.shutdown() | ||
| httpd.server_close() | ||
|
|
||
| assert arr_http.shape == arr_local.shape, ( | ||
| f"orientation={orientation}: HTTP shape {arr_http.shape} != " | ||
| f"local shape {arr_local.shape}" | ||
| ) | ||
| np.testing.assert_array_equal( | ||
| arr_http, arr_local, | ||
| err_msg=f"orientation={orientation}: HTTP pixels differ from local", | ||
| ) | ||
| assert geo_http.transform == geo_local.transform, ( | ||
| f"orientation={orientation}: transform mismatch " | ||
| f"http={geo_http.transform} local={geo_local.transform}" | ||
| ) |
The HTTP path in `_read_cog_http` returned the raw decoded buffer for full reads, skipping the `_apply_orientation` remap that the local path runs in `read_to_array`. Opening the same file locally vs over HTTP produced different pixel orders and transforms for any Orientation tag value other than 1. Extract the orientation + geo_info update into `_apply_orientation_with_geo` and call it from both paths. The existing rejection of windowed reads against non-default orientation is kept unchanged on both paths. Tests cover orientations 1-8 via local + HTTP round-trip against the same in-memory loopback server used by `test_cog_http_concurrent.py`, plus a regression check that windowed HTTP reads still raise on non-default orientation.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_read_cog_http's full-read branch returned the raw decoded buffer without running_apply_orientation, so the same file came back with a different pixel order over HTTP than locally. This pulls the orientation + geo_info update into a helper that both paths call.Repro
Fix
New
_apply_orientation_with_geo(arr, geo_info, orientation)in_reader.py;read_to_arrayand_read_cog_httpboth call it. The windowed-read + non-default-orientation rejection is unchanged on both paths.Tests
xrspatial/geotiff/tests/test_http_orientation_1717.pycovers orientations 1-8 via the same in-memory loopback server pattern astest_cog_http_concurrent.py. Full local vs HTTP reads match (array and transform), windowed HTTP reads against non-default orientation still raiseValueError.16 new tests pass.
test_cog_http_concurrent.py,test_orientation.py,test_orientation_gpu.py, and the othertest_http_*suites still pass.Closes #1717