-
Notifications
You must be signed in to change notification settings - Fork 108
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
Xarray: add indexes options and better define band names #764
base: main
Are you sure you want to change the base?
Conversation
ds = self.input | ||
band_names = self.band_names | ||
if indexes := cast_to_sequence(indexes): | ||
assert all(v > 0 for v in indexes), "Indexes value must be >= 1" |
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.
xarray won't complain when we pass data[-1]
so we need this tests
if indexes != (1,): | ||
raise ValueError( | ||
f"Invalid indexes {indexes} for array of shape {ds.shape}" | ||
) |
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.
for 2D array we still allow indexes=1
@@ -1060,7 +1060,7 @@ def _get_reader(self, asset_info: AssetInfo) -> Tuple[Type[BaseReader], Dict]: | |||
assert info["netcdf"].crs | |||
|
|||
img = stac.preview(assets=["netcdf"]) | |||
assert img.band_names == ["netcdf_value"] | |||
assert img.band_names == ["netcdf_dataset"] |
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.
band value default to the DataArray's name ✨
if not self._dims: | ||
coords_name = list(self.input.coords) | ||
if len(coords_name) > 3 and (coord := coords_name[2]): | ||
return [str(self.input.coords[coord].data)] |
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 hesitant to put something like {coord_name}={coord_value}}
🤷♂️
but we don't do this for the other band names
@@ -105,6 +110,7 @@ def __attrs_post_init__(self): | |||
for d in self.input.dims | |||
if d not in [self.input.rio.x_dim, self.input.rio.y_dim] | |||
] | |||
assert len(self._dims) in [0, 1], "Can't handle >=4D DataArray" |
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.
add a check to make sure we don't have 4D arrays
@vincentsarago I'll try to look through this in a bit more detail today but it might be worth considering another naming convention for "indexes" in this context. In |
I've used But I think we can improve the documentation 🙏 |
This PR does:
indexes
options (following Rasterio convention, starts at 1)