Skip to content

Commit a50e7e3

Browse files
committed
update
1 parent 80ba148 commit a50e7e3

File tree

4 files changed

+52
-71
lines changed

4 files changed

+52
-71
lines changed

stac_fastapi/pgstac/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ class Settings(ApiSettings):
174174

175175
prefix_path: str = ""
176176
use_api_hydrate: bool = False
177+
"""
178+
When USE_API_HYDRATE=TRUE, PgSTAC database will receive `NO_HYDRATE=TRUE`
179+
180+
| use_api_hydrate | nohydrate | Hydration |
181+
| --- | --- | --- |
182+
| False | False | PgSTAC |
183+
| True | True | API |
184+
185+
ref: https://stac-utils.github.io/pgstac/pgstac/#runtime-configurations
186+
"""
177187
invalid_id_chars: List[str] = DEFAULT_INVALID_ID_CHARS
178188
base_item_cache: Type[BaseItemCache] = DefaultBaseItemCache
179189

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ async def pgstac(database):
100100
# Run all the tests that use the api_client in both db hydrate and api hydrate mode
101101
@pytest.fixture(
102102
params=[
103-
# hydratation, prefix, model_validation
103+
# API hydratation, prefix, model_validation
104104
(False, "", False),
105105
(False, "/router_prefix", False),
106106
(True, "", False),

tests/data/test2_item.json

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"nodata": 0,
6565
"offset": 2.03976,
6666
"data_type": "uint8",
67-
"spatial_resolution": 60
67+
"spatial_resolution": 80
6868
}
6969
]
7070
},
@@ -83,7 +83,16 @@
8383
}
8484
],
8585
"description": "Collection 2 Level-1 Green Band Top of Atmosphere Radiance",
86-
"raster:bands": "𒍟※"
86+
"raster:bands": [
87+
{
88+
"unit": "watt/steradian/square_meter/micrometer",
89+
"scale": 0.88504,
90+
"nodata": 0,
91+
"offset": 1.51496,
92+
"data_type": "uint8",
93+
"spatial_resolution": 60
94+
}
95+
]
8796
},
8897
"nir08": {
8998
"href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-1/standard/mss/1990/018/038/LM05_L1GS_018038_19901223_20200827_02_T2/LM05_L1GS_018038_19901223_20200827_02_T2_B3.TIF",
@@ -99,7 +108,17 @@
99108
"full_width_half_max": 0.1
100109
}
101110
],
102-
"description": "Collection 2 Level-1 Near Infrared Band 0.7 Top of Atmosphere Radiance"
111+
"description": "Collection 2 Level-1 Near Infrared Band 0.7 Top of Atmosphere Radiance",
112+
"raster:bands": [
113+
{
114+
"unit": "watt/steradian/square_meter/micrometer",
115+
"scale": 0.55866,
116+
"nodata": 0,
117+
"offset": 4.34134,
118+
"data_type": "uint8",
119+
"spatial_resolution": 60
120+
}
121+
]
103122
},
104123
"nir09": {
105124
"href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-1/standard/mss/1990/018/038/LM05_L1GS_018038_19901223_20200827_02_T2/LM05_L1GS_018038_19901223_20200827_02_T2_B4.TIF",
@@ -153,7 +172,6 @@
153172
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
154173
"roles": ["cloud"],
155174
"title": "Pixel Quality Assessment Band (QA_PIXEL)",
156-
"description": "Collection 2 Level-1 Pixel Quality Assessment Band",
157175
"raster:bands": [
158176
{
159177
"unit": "bit index",

tests/resources/test_item.py

Lines changed: 19 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,90 +1750,43 @@ async def test_item_asset_change(app_client, load_test_data):
17501750
)
17511751
assert len(resp.json()["features"]) == 1
17521752
assert resp.status_code == 200
1753-
# NOTE: Hydration or Not we should get the same values as original Item
1754-
assert (
1755-
test_item["assets"]["red"]["raster:bands"]
1756-
== resp.json()["features"][0]["assets"]["red"]["raster:bands"]
1757-
)
1758-
1759-
# remove item_assets in collection
1760-
operations = [{"op": "remove", "path": "/item_assets"}]
1761-
resp = await app_client.patch(f"/collections/{collection_id}", json=operations)
1762-
assert resp.status_code == 200
1763-
1764-
# make sure item_assets is not in collection response
1765-
resp = await app_client.get(f"/collections/{collection_id}")
1766-
assert resp.status_code == 200
1767-
assert "item_assets" not in resp.json()
17681753

1769-
# NOTE: Should Fail
1770-
# For some reason we get the part not present in the Collection's item_assets but not originaly from the Item
1771-
resp = await app_client.get(
1772-
f"/collections/{collection_id}/items", params={"limit": 1}
1773-
)
1774-
assert len(resp.json()["features"]) == 1
1775-
assert resp.status_code == 200
1754+
# NOTE: API or PgSTAC Hydration we should get the same values as original Item
17761755
assert (
17771756
test_item["assets"]["red"]["raster:bands"]
17781757
== resp.json()["features"][0]["assets"]["red"]["raster:bands"]
17791758
)
17801759

1760+
# NOTE: `description` is not in the item body but in the collection's item-assets
1761+
# because it's not in the original item it won't be hydrated
1762+
assert not resp.json()["features"][0]["assets"]["qa_pixel"].get("description")
17811763

1782-
@pytest.mark.asyncio
1783-
async def test_item_asset_change_hydration(app_client, load_test_data):
1784-
"""Test hydration process."""
1785-
# Only test when Hydration is enabled
1786-
if not app_client._transport.app.state.settings.use_api_hydrate:
1787-
return
1788-
1789-
# load collection
1790-
data = load_test_data("test2_collection.json")
1791-
collection_id = data["id"]
1792-
1793-
resp = await app_client.post("/collections", json=data)
1794-
assert "item_assets" in data
1795-
assert resp.status_code == 201
1796-
assert "item_assets" in resp.json()
1797-
1798-
# load items
1799-
test_item = load_test_data("test2_item.json")
1800-
resp = await app_client.post(f"/collections/{collection_id}/items", json=test_item)
1801-
assert resp.status_code == 201
1802-
1803-
# check list of items
1804-
resp = await app_client.get(
1805-
f"/collections/{collection_id}/items", params={"limit": 1}
1806-
)
1807-
assert len(resp.json()["features"]) == 1
1808-
assert resp.status_code == 200
1809-
# The items should be the same
1810-
# When hydrated we should get the value from the collection's item_assets
1811-
assert (
1812-
resp.json()["features"][0]["assets"]["green"]["raster:bands"]
1813-
== data["item_assets"]["green"]["raster:bands"]
1814-
)
1815-
1816-
# TODO: Check if OK
1817-
# We don't have `"raster:bands"` for `nir08` asset in the original Items body
1818-
assert resp.json()["features"][0]["assets"]["nir08"]["raster:bands"]
1819-
1820-
# remove item_assets in collection
1764+
###########################################################################
1765+
# Remove item_assets in collection
18211766
operations = [{"op": "remove", "path": "/item_assets"}]
18221767
resp = await app_client.patch(f"/collections/{collection_id}", json=operations)
18231768
assert resp.status_code == 200
18241769

1825-
# make sure item_assets is not in collection response
1770+
# Make sure item_assets is not in collection response
18261771
resp = await app_client.get(f"/collections/{collection_id}")
18271772
assert resp.status_code == 200
18281773
assert "item_assets" not in resp.json()
1774+
###########################################################################
18291775

18301776
resp = await app_client.get(
18311777
f"/collections/{collection_id}/items", params={"limit": 1}
18321778
)
18331779
assert len(resp.json()["features"]) == 1
18341780
assert resp.status_code == 200
1835-
assert resp.json()["features"][0]["assets"]["green"]["raster:bands"] == "𒍟※"
18361781

1837-
# TODO: Check if OK
1838-
# We don't have `"raster:bands"` for `nir08` asset in the original Items body but for some reason we get "𒍟※"
1839-
assert resp.json()["features"][0]["assets"]["nir08"]["raster:bands"] == "𒍟※"
1782+
# NOTE: here we should only get `scale`, `offset` and `spatial_resolution`
1783+
# because the other values were stripped on ingestion (dehydration is a default in PgSTAC)
1784+
# scale and offset are no in item-asset and spatial_resolution is different, so the value in the item body is kept
1785+
assert ["scale", "offset", "spatial_resolution"] == list(
1786+
resp.json()["features"][0]["assets"]["red"]["raster:bands"][0]
1787+
)
1788+
1789+
# NOTE: `description` is not in the original item but in the collection's item-assets
1790+
# We get "𒍟※" because PgSTAC set it when ingesting (`description`is item-assets)
1791+
# because we removed item-assets, pgstac cannot hydrate this field, and thus return "𒍟※"
1792+
assert resp.json()["features"][0]["assets"]["qa_pixel"]["description"] == "𒍟※"

0 commit comments

Comments
 (0)