handle list of attr_name in apply/get raster data#303
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #303 +/- ##
==========================================
+ Coverage 76.34% 78.08% +1.73%
==========================================
Files 10 10
Lines 909 940 +31
Branches 133 144 +11
==========================================
+ Hits 694 734 +40
+ Misses 179 169 -10
- Partials 36 37 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
EwoutH
left a comment
There was a problem hiding this comment.
Didn’t review the code, but I think the API is sensibel
|
Thanks! |
This PR improves
RasterLayer’s band handling by allowing multiple raster bands to be mapped to cell attribute names.It extends
RasterLayer.apply_raster()/RasterLayer.get_raster()/RasterLayer.from_file()/RasterLayer.to_file()to support multi-band rasters while keeping existing single-band usage unchanged.Motivation
Mesa-Geo currently assumes raster values map to a single attribute name, which is limiting when reading multi-band datasets (e.g., RGB, multispectral, multiple variables). Users need to manually split bands and call
apply_raster()repeatedly.This PR provides a more convenient way to name and retrieve multi-band rasters.
Changes
Updated API behavior
RasterLayer.apply_raster(data, attr_name=...)Single-band (
data.shape == (1, H, W)):attr_name: strbehaves as before (creates one attribute).attr_name: Noneauto-generates an attribute name (existing behavior).Multi-band (
data.shape == (B, H, W)):attr_name: list[str]assigns one attribute name per band (length must equalB).attr_name: struses it as a base name and creates per-band attributes (e.g.,elevation_1,elevation_2, ...).attr_name: Noneauto-generates band names.RasterLayer.get_raster(attr_name=...)attr_name: strreturns a single band as(1, H, W)(as before).attr_name: list[str]returns selected bands stacked as(B, H, W)in the provided name order.attr_name: Nonereturns all stored raster attributes stacked as(B, H, W).RasterLayer.from_file(..., attr_name=...)andRasterLayer.to_file(..., attr_name=...)from_file()andto_file()now supports the sameattr_nameoptions asapply_raster()for multi-band rasters.Validation
ValueErrorwhenattr_nameis a list but its length does not match the number of bands indata.Backward compatibility
attr_name: str | Nonecontinue to work unchanged.