-
Notifications
You must be signed in to change notification settings - Fork 41
made load_stac nicer to mismatch in band names #755
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
made load_stac nicer to mismatch in band names #755
Conversation
there is one test |
…make-bands-metadata-flexible
tests/rest/test_connection.py
Outdated
cube = con120.load_stac(str(stac_path), bands=["B01", "B02"]) | ||
assert cube.metadata.band_names == ["B01", "B02"] | ||
assert ( | ||
"The specified bands ['B01', 'B02'] are not a subset of the bands [] found in the STAC metadata (unknown bands: ['B01', 'B02']). Using specified bands as is." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... not a subset of the bands [] ...
hmm I'm a bit confused here: if there is no band dimension, doesn't the add_dimension()
above at least define a band with name None
? How can the list of bands be empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
openeo-python-client/openeo/metadata.py
Lines 619 to 624 in 4d350c4
def get_band_metadata(eo_bands_location: dict) -> List[Band]: | |
# TODO: return None iso empty list when no metadata? | |
return [ | |
Band(name=band["name"], common_name=band.get("common_name"), wavelength_um=band.get("center_wavelength")) | |
for band in eo_bands_location.get("eo:bands", []) | |
] |
openeo-python-client/openeo/metadata.py
Line 676 in 4d350c4
band_dimension = BandDimension(name="bands", bands=bands) |
So I guess there isn't a case where the metadata has no bands dimension. I'll remove
openeo-python-client/openeo/rest/datacube.py
Lines 447 to 452 in 4d350c4
if not metadata.has_band_dimension(): | |
metadata = metadata.add_dimension( | |
name="bands", | |
type="bands", | |
label=None, | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I guess there isn't a case where the metadata has no bands dimension
not yet, but that will be possible in the future with #743
While chewing on this PR, I decided to finetune this PR with 83ef8eb so feel free to inverse-review :) |
@@ -423,6 +423,25 @@ def add_dimension(self, name: str, label: Union[str, float], type: Optional[str] | |||
dim = Dimension(type=type or "other", name=name) | |||
return self._clone_and_update(dimensions=self._dimensions + [dim]) | |||
|
|||
def ensure_band_dimension( | |||
self, *, name: Optional[str] = None, bands: List[Union[Band, str]], warning: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really a fan of having a function in metadata that takes a warning as an argument just to log it. Logging could happen outside of this function imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I was hesitant about that,
but forcing the caller to think of a warning message is to make clear that this function should only be used exceptionally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in that case I would rename it to replace_band_dimension
or even set_band_dimension
as ensure sound like running some checks.
Still not a big fan of the warning argument, but if we keep I'd at least make it optional.
I'm quickly working on a commit that also retains the existing bands so we don't lose fields like wavelength_um
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a note to the documentation to better explain this design
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that for cases like this where there is doubt about the API that is added, simply making it somehow 'private' or 'internal' API can help to be future proof.
…ps://github.com/Open-EO/openeo-python-client into issue752-load-stac-make-bands-metadata-flexible
expanded the |
I'm curious why that is necessary? When you get into the Is this to support a particular use case? |
I figured we could keep as much data as possible, but indeed not for a specific use case. |
reverted my last commit as indeed it complicates things for a cause we will not encounter |
…make-bands-metadata-flexible
merged in 5e77f00 (FYI: I did a rebase first to eliminate the commit-revert pair and to get a cleaner history) |
Note: warning message could be made clearer but out of inspiration