-
Notifications
You must be signed in to change notification settings - Fork 44
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
Changes from all commits
2c04f73
66ea570
1446f44
56e0731
4d350c4
5d9b6d4
83ef8eb
c344264
1868c22
371eee5
9c5a6d5
df7f662
494b44a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,6 +218,16 @@ def rename_labels(self, target, source) -> Dimension: | |
def rename(self, name) -> Dimension: | ||
return BandDimension(name=name, bands=self.bands) | ||
|
||
def contains_band(self, band: Union[int, str]) -> bool: | ||
""" | ||
Check if the given band name or index is present in the dimension. | ||
""" | ||
try: | ||
self.band_index(band) | ||
return True | ||
except ValueError: | ||
return False | ||
|
||
|
||
class GeometryDimension(Dimension): | ||
# TODO: how to model/store labels of geometry dimension? | ||
|
@@ -411,6 +421,31 @@ 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. yeah I was hesitant about that, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in that case I would rename it to 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 commentThe 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 commentThe 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. |
||
) -> CubeMetadata: | ||
""" | ||
Create new CubeMetadata object, ensuring a band dimension with given bands. | ||
This will override any existing band dimension, and is intended for | ||
special cases where pragmatism necessitates to ignore the original metadata. | ||
For example, to overrule badly/incomplete detected band names from STAC metadata. | ||
|
||
.. note:: | ||
It is required to specify a warning message as this method is only intended | ||
to be used as temporary stop-gap solution for use cases that are possibly not future-proof. | ||
Enforcing a warning should make that clear and avoid that users unknowingly depend on | ||
metadata handling behavior that is not guaranteed to be stable. | ||
""" | ||
_log.warning(warning or "ensure_band_dimension: overriding band dimension metadata with user-defined bands.") | ||
if name is None: | ||
# Preserve original band dimension name if possible | ||
name = self.band_dimension.name if self.has_band_dimension() else "bands" | ||
bands = [b if isinstance(b, Band) else Band(name=b) for b in bands] | ||
band_dimension = BandDimension(name=name, bands=bands) | ||
return self._clone_and_update( | ||
dimensions=[d for d in self._dimensions if not isinstance(d, BandDimension)] + [band_dimension] | ||
) | ||
|
||
def drop_dimension(self, name: str = None) -> CubeMetadata: | ||
"""Create new CubeMetadata object without dropped dimension with given name""" | ||
dimension_names = self.dimension_names() | ||
|
@@ -654,13 +689,13 @@ def is_band_asset(asset: pystac.Asset) -> bool: | |
raise ValueError(stac_object) | ||
|
||
# At least assume there are spatial dimensions | ||
# TODO: are there conditions in which we even should not assume the presence of spatial dimensions? | ||
# TODO #743: are there conditions in which we even should not assume the presence of spatial dimensions? | ||
dimensions = [ | ||
SpatialDimension(name="x", extent=[None, None]), | ||
SpatialDimension(name="y", extent=[None, None]), | ||
] | ||
|
||
# TODO: conditionally include band dimension when there was actual indication of band metadata? | ||
# TODO #743: conditionally include band dimension when there was actual indication of band metadata? | ||
band_dimension = BandDimension(name="bands", bands=bands) | ||
dimensions.append(band_dimension) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.