-
Notifications
You must be signed in to change notification settings - Fork 20
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
Multiband Raster Support #107
Comments
But this is mainly for "hyper-spectral" type of data stored within a single TIFF image, and not for "RGB(A)" assets, Can you provide an example stac item from which screenshot above was generated. |
@julianblue rgb(a) sources introduce a bit of a conundrum actually, as they can be seen as either
I'm guessing your expectation for the output would be option (2)? Currently only option (1) is supported and only if |
I think the closest we get is the
A second huersitc would be to look at But I think I would prefer the |
The example I mentioned was for the true color image of a sentinel 2-l2a tile. https://stacindex.org/catalogs/earth-search#/item/43bjKKcJQfxYaT1ir3Ep6uENfjEoQrjkzhd2/NopKk2m24tJYiekqbLp72LWk57p1ZsViRLdV3HiFw13eHu73QTYZUKAB?t=2#9/-6.825703/133.001187 To extend this question, I am especially looking to load multi band COGS though odc-stac. For example, RGBNIR Planet scope data. What would a stac item need to look like to load this data via odc-stac ? |
@julianblue I had a deeper look at this and refreshed my memory
{'href': 'https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/30/S/TF/2023/3/S2A_30STF_20230322_0_L2A/TCI.tif',
'type': 'image/tiff; application=geotiff; profile=cloud-optimized',
'title': 'True color image',
'eo:bands': [{'name': 'red',
'common_name': 'red',
'description': 'Red (band 4)',
'center_wavelength': 0.665,
'full_width_half_max': 0.038},
{'name': 'green',
'common_name': 'green',
'description': 'Green (band 3)',
'center_wavelength': 0.56,
'full_width_half_max': 0.045},
{'name': 'blue',
'common_name': 'blue',
'description': 'Blue (band 2)',
'center_wavelength': 0.49,
'full_width_half_max': 0.098}],
'proj:shape': [10980, 10980],
'proj:transform': [10, 0, 199980, 0, -10, 4100040],
'roles': ['visual']} In comparison a single channel {'href': 'https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/30/S/TF/2023/3/S2A_30STF_20230322_0_L2A/B03.tif',
'type': 'image/tiff; application=geotiff; profile=cloud-optimized',
'title': 'Green (band 3) - 10m',
'eo:bands': [{'name': 'green',
'common_name': 'green',
'description': 'Green (band 3)',
'center_wavelength': 0.56,
'full_width_half_max': 0.045}],
'gsd': 10,
'proj:shape': [10980, 10980],
'proj:transform': [10, 0, 199980, 0, -10, 4100040],
'raster:bands': [{'nodata': 0,
'data_type': 'uint16',
'bits_per_sample': 15,
'spatial_resolution': 10,
'scale': 0.0001,
'offset': -0.1}],
'roles': ['data', 'reflectance']}
Problem is here: Lines 641 to 655 in 4c60523
band index gets ignored and all the bands from the same asset end up loading the first band of the image. from odc.stac import load as stac_load, __version__
from pystac import Item
from pystac.extensions.raster import RasterExtension
from odc.stac import load as stac_load
from odc.stac._mdtools import parse_item
print(f"odc.stac=={__version__}")
item = Item.from_file("https://earth-search.aws.element84.com/v1/collections/sentinel-2-l2a/items/S2A_30STF_20230322_0_L2A")
# inject raster:bands
dd = item.to_dict()
dd['assets']['visual']['raster:bands'] = [{'data_type': 'uint8'}]*3
item_patched = Item.from_dict(dd)
assert RasterExtension.ext(item.assets['visual']).bands is None
assert RasterExtension.ext(item_patched.assets['visual']).bands is not None
p = parse_item(item)
p_ = parse_item(item_patched)
print("Original")
display(p.collection.bands, p.bands)
print("\nPatched")
display(p_.collection.bands, p_.bands) Error in patched parsed data is here: ('visual', 1): RasterSource(uri='https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/30/S/TF/2023/3/S2A_30STF_20230322_0_L2A/TCI.tif',
band=1, subdataset=None, geobox=GeoBox((10980, 10980), Affine(10.0, 0.0, 199980.0,
0.0, -10.0, 4100040.0), CRS('EPSG:32630')), meta=RasterBandMetadata(data_type='uint8', nodata=None, unit='1')),
('visual', 2): RasterSource(uri='https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/30/S/TF/2023/3/S2A_30STF_20230322_0_L2A/TCI.tif',
band=1, subdataset=None, geobox=GeoBox((10980, 10980), Affine(10.0, 0.0, 199980.0,
0.0, -10.0, 4100040.0), CRS('EPSG:32630')), meta=RasterBandMetadata(data_type='uint8', nodata=None, unit='1')),
('visual', 3): RasterSource(uri='https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/30/S/TF/2023/3/S2A_30STF_20230322_0_L2A/TCI.tif',
band=1, subdataset=None, geobox=GeoBox((10980, 10980), Affine(10.0, 0.0, 199980.0,
0.0, -10.0, 4100040.0), CRS('EPSG:32630')), meta=RasterBandMetadata(data_type='uint8', nodata=None, unit='1')),
|
- Band index was always set to 1 on the parsed item - Conversion to datacube dataset also had an issue with band index: it was adding +1 to an already 1 based index.
- Band index was always set to 1 on the parsed item - Conversion to datacube dataset also had an issue with band index: it was adding +1 to an already 1 based index.
This is awesome @Kirill888 ! |
This page describes what extensions are used by https://odc-stac.readthedocs.io/en/latest/stac-best-practice.html
When extensions are not supplied, rather than inspecting all the assets to figure out things like We could potentially introduce a mode where we inspect one of the items from a collection and then assume that all of them are like that, this should at least work for |
another question. For this example: from pystac import Item
import pystac
import odc.stac
item = pystac.read_file(
"https://planetarycomputer.microsoft.com/api/stac/v1/collections/naip/items/fl_m_2608004_nw_17_060_20191215_20200113"
)
dd = item.to_dict()
dd['assets']['image']['raster:bands'] = [{'data_type': 'uint8'}]*4
item_patched = Item.from_dict(dd)
ds3 = odc.stac.load([item_patched], chunks={}, resolution=100)
ds3.data_vars which returns:
I think there needs to be some modification here ? Lines 126 to 137 in dc9f5d5
Ideally it should be image.red, image.green ... correct ? Thanks in advance. |
@julianblue in STAC the same "common_name" can be attached to multiple bands of different assets so there is potential for clashing of output bands, so we default to asset name which is guaranteed to be unique. But this approach obviously breaks down for multi-band assets. You can supply I think logic should check if asset pointed by - if idx == 1:
+ if idx == 1 and self.band_count[asset] == 1: |
@Kirill888 , is there support for loading mutliband cogs ind odc-stac ?
![Screenshot 2023-03-22 at 09 29 09](https://user-images.githubusercontent.com/21318315/226843674-377bfc96-5c37-4b73-a11b-8caeb5aacc49.png)
For example, the visual band is multi band and only loads a single band.
Thanks in advance.
The text was updated successfully, but these errors were encountered: