egagli / easysnowdata

package to easily get data relevant to snow
Other
9 stars 3 forks source link

HLS coastal aerosol band error #6

Open etboudreau opened 2 months ago

etboudreau commented 2 months ago

Environment Information

Description

I was trying to load the Harmonized Landsat Sentinel-2 v2.0 and got an error about no coastal aerosol band existing.

What I Did

Cell ran:
hls = easysnowdata.remote_sensing.HLS(
    bbox_input=basin_gdf, start_date="2022-07-01", end_date="2022-07-31"
)
Error:
ValueError: No such band/alias: coastal aerosol

Traceback:
   1335 else:
   1336     load_params_landsat["resolution"] = 30
-> 1338 L30_ds = odc.stac.load(**load_params_landsat)
   1340 load_params_sentinel = {
   1341     "items": self.search_sentinel.item_collection(),
   1342     "bbox": self.bbox_gdf.total_bounds,
   (...)
   1347     "stac_cfg": get_stac_cfg(sensor="HLSS30.v2.0"),
   1348 }
   1349 if self.bands:
...
    141     band, idx = parts
    142     return (band, int(idx))
--> 144 raise ValueError(f"No such band/alias: {band}")
egagli commented 1 month ago

Looks like it's related to https://forum.earthdata.nasa.gov/viewtopic.php?t=5917! I was able to get rid of that error by modifying "HLSS30.v2.0" -> "HLSS30_2.0" and "HLSL30.v2.0" -> "HLSL30_2.0" in a couple of places, but now I'm running into an issue like the other person on the forum post where the metadata isn't accessible! My current issue....

hls = easysnowdata.remote_sensing.HLS(
    bbox_input=bbox_gdf, start_date="2022-07-01", end_date="2022-07-31"
)

Data searched. Access the returned seach with the .search_landsat or .search_sentinel attribute.
Data retrieved. Access with the .data attribute. Data CRS: WGS 84 / UTM zone 10N.
Nodata values removed from the data. In doing so, all bands converted to float32. To turn this behavior off, set remove_nodata=False.
Data scaled to reflectance. Access with the .data attribute. To turn this behavior off, set scale_data=False.

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[113], line 1
----> 1 hls = easysnowdata.remote_sensing.HLS(
      2     bbox_input=bbox_gdf, start_date="2022-07-01", end_date="2022-07-31"
      3 )

File ~/repos/easysnowdata/easysnowdata/remote_sensing.py:1898, in HLS.__init__(self, bbox_input, start_date, end_date, bands, resolution, crs, remove_nodata, scale_data, add_metadata, add_platform, groupby)
   1896     self.scale_data_inplace()
   1897 if self.add_metadata:
-> 1898     self.get_combined_metadata()
   1899 if self.add_platform:
   1900     self.add_platform_inplace()

File ~/repos/easysnowdata/easysnowdata/remote_sensing.py:2141, in HLS.get_combined_metadata(self)
   2140 def get_combined_metadata(self):
-> 2141     L30_metadata = self.get_metadata(self.search_landsat.item_collection())
   2142     S30_metadata = self.get_metadata(self.search_sentinel.item_collection())
   2143     combined_metadata_gdf = (
   2144         pd.concat([L30_metadata, S30_metadata])
   2145         .sort_values("datetime")
   2146         .reset_index(drop=True)
   2147     )

File ~/repos/easysnowdata/easysnowdata/remote_sensing.py:2109, in HLS.get_metadata(self, item_collection)
   2107 series_list = []
   2108 for item in item_collection:
-> 2109     url = item.assets["metadata"].href
   2110     series = HLS_xml_url_to_metadata_df(url)
   2111     series_list.append(series)

KeyError: 'metadata'

Will update once I hear something!

egagli commented 1 month ago

Sounds like this will be fixed in the next release of CMR STAC as per https://forum.earthdata.nasa.gov/viewtopic.php?t=5917&sid=b4b06789ded40a458da294708f21e7d5&start=10

We'll see how long that takes! For now you can pass in add_metadata=False, add_platform=False, and it should work!