Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions openeogeotrellis/load_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,14 @@ def load_stac(
# TODO: risk on overwriting/conflict
band_epsgs.setdefault(asset_band_name, set()).add(proj_epsg)

pixel_value_offset = _get_pixel_value_offset(item=itm, asset=asset)
if feature_flags.get("apply_pixel_value_scale_and_offset", True):
pixel_value_offset = _get_pixel_value_offset(item=itm, asset=asset)
else:
pixel_value_offset = (1.0, 0.0)
logger.debug(
f"FeatureBuilder.addlink {itm.id=} {asset_id=} {asset_band_names_from_metadata=} {asset_band_names=}"
)
builder = builder.addLink(get_best_url(asset), asset_id, pixel_value_offset, asset_band_names)
builder = builder.addLink(get_best_url(asset), asset_id, pixel_value_offset[0], pixel_value_offset[1], asset_band_names)

if proj_epsg:
builder = builder.withCRS(f"EPSG:{proj_epsg}")
Expand Down Expand Up @@ -1200,10 +1203,10 @@ def _get_asset_property(asset: pystac.Asset, field: str) -> Optional:
)


def _get_pixel_value_offset(*, item: pystac.Item, asset: pystac.Asset) -> float:
def _get_pixel_value_offset(*, item: pystac.Item, asset: pystac.Asset) -> (float, float):
raster_scale = asset.extra_fields.get("raster:scale", item.properties.get("raster:scale", 1.0))
raster_offset = asset.extra_fields.get("raster:offset", item.properties.get("raster:offset", 0.0))
return raster_offset / raster_scale
return raster_scale, raster_offset


def _supports_item_search(collection: pystac.Collection) -> bool:
Expand Down
18 changes: 10 additions & 8 deletions tests/test_load_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def jvm_mock():
(
["AOT_10m"],
10.0,
[(dirty_equals.IsStr(regex=".*_AOT_10m.jp2"), "AOT_10m", -1000.0, ["AOT_10m"])],
[(dirty_equals.IsStr(regex=".*_AOT_10m.jp2"), "AOT_10m", 0.0001, -0.1, ["AOT_10m"])],
),
(
["B01_60m"],
Expand All @@ -202,43 +202,45 @@ def jvm_mock():
dirty_equals.IsStr(regex=".*_B01_60m.jp2"),
"B01_60m",
# has "raster:scale": 0.0001 and "raster:offset": -0.1
-1000.0,
0.0001,
-0.1,
["B01_60m"],
)
],
),
(
["B01"],
20.0,
[(dirty_equals.IsStr(regex=".*_B01_20m.jp2"), "B01_20m", -1000.0, ["B01"])],
[(dirty_equals.IsStr(regex=".*_B01_20m.jp2"), "B01_20m", 0.0001, -0.1, ["B01"])],
),
(
["WVP_20m"],
20.0,
[(dirty_equals.IsStr(regex=".*_WVP_20m.jp2"), "WVP_20m", -1000.0, ["WVP_20m"])],
[(dirty_equals.IsStr(regex=".*_WVP_20m.jp2"), "WVP_20m", 0.0001, -0.1, ["WVP_20m"])],
),
(
["WVP_60m"],
60.0,
[(dirty_equals.IsStr(regex=".*_WVP_60m.jp2"), "WVP_60m", -1000.0, ["WVP_60m"])],
[(dirty_equals.IsStr(regex=".*_WVP_60m.jp2"), "WVP_60m", 0.0001, -0.1, ["WVP_60m"])],
),
(
["AOT_10m", "WVP_20m"],
10.0,
[
(dirty_equals.IsStr(regex=".*_AOT_10m.jp2"), "AOT_10m", -1000.0, ["AOT_10m"]),
(dirty_equals.IsStr(regex=".*_WVP_20m.jp2"), "WVP_20m", -1000.0, ["WVP_20m"]),
(dirty_equals.IsStr(regex=".*_AOT_10m.jp2"), "AOT_10m", 0.0001, -0.1, ["AOT_10m"]),
(dirty_equals.IsStr(regex=".*_WVP_20m.jp2"), "WVP_20m", 0.0001, -0.1, ["WVP_20m"]),
],
),
(
["B01_20m", "SCL_20m"],
20.0,
[
(dirty_equals.IsStr(regex=".*_B01_20m.jp2"), "B01_20m", -1000.0, ["B01_20m"]),
(dirty_equals.IsStr(regex=".*_B01_20m.jp2"), "B01_20m", 0.0001, -0.1, ["B01_20m"]),
(
dirty_equals.IsStr(regex=".*_SCL_20m.jp2"),
"SCL_20m",
# has neither "raster:scale" nor "raster:offset"
1.0,
0.0,
["SCL_20m"],
),
Expand Down