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

Use data_type and nodata from raster extension if present #91

Open
TomAugspurger opened this issue Nov 27, 2021 · 3 comments
Open

Use data_type and nodata from raster extension if present #91

TomAugspurger opened this issue Nov 27, 2021 · 3 comments

Comments

@TomAugspurger
Copy link
Contributor

Currently the default dtype is float64 and the default fill_value is np.nan.

The raster extension defines fields for specifying the dtype (data_type) and fill value (no_data). It might be a good idea to change the default to using values from raster:band, falling back to float64 / np.nan if the raster extension isn't present.

@gjoseph92
Copy link
Owner

Thanks for opening the issue to track this; there's some more info in #63 (comment) too. Definitely excited about the raster extension! @TomAugspurger think you'd have any time to work on this?

@TomAugspurger
Copy link
Contributor Author

Thanks for the link to #63.

We're going to standardize our use of the raster extension in our STAC API over the couple months. Once that work is started I'll be happy to work on this. I just wanted to make sure there was agreement with the API change (to use information from raster:bands) before starting on that.

@gjoseph92
Copy link
Owner

Awesome, happy to hear raster:bands is going to get some traction!

Note that in doing this, we'll probably want to add some special-handling logic for raster:bands, similar to how the subfields of eo:bands get pulled out into top-level coordinates (I could also see making this more generic to any dict-ish fields in flattened_metadata_by_asset):

eo_by_asset = []
for meta in flattened_metadata_by_asset:
# NOTE: we look for `eo:bands` in each Asset's metadata, not as an Item-level list.
# This only became available in STAC 1.0.0-beta.1, so we'll fail on older collections.
# See https://github.com/radiantearth/stac-spec/tree/master/extensions/eo#item-fields
eo = meta.pop("eo:bands", {})
if isinstance(eo, list):
eo = eo[0] if len(eo) == 1 else {}
# ^ `eo:bands` should be a list when present, but >1 item means it's probably a multi-band asset,
# which we can't currently handle, so we ignore it. we don't error here, because
# as long as you don't actually _use_ that asset, everything will be fine. we could
# warn, but that would probably just get annoying.
eo_by_asset.append(eo)
try:
meta["polarization"] = meta.pop("sar:polarizations")
except KeyError:
pass
coords.update(
accumulate_metadata.metadata_to_coords(
flattened_metadata_by_asset,
"band",
skip_fields={"href"},
# skip_fields={"href", "title", "description", "type", "roles"},
)
)
if any(eo_by_asset):
coords.update(
accumulate_metadata.metadata_to_coords(
eo_by_asset,
"band",
fields=["common_name", "center_wavelength", "full_width_half_max"],
)
)

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

No branches or pull requests

2 participants