diff --git a/CHANGELOG.md b/CHANGELOG.md index 4629aa76..6be051cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.0.3] - 2023-12-15 + +### Added + +- Only query assets directly avaible in the search items (better performance). + ## [0.0.2] - 2023-12-15 ### Fixed - Missing json due to pypi installation. -- Multisensors datacube now support `stackstac` +- Multisensors datacube now support `stackstac`. ## [0.0.1] - 2023-12-15 diff --git a/earthdaily/earthdatastore/__init__.py b/earthdaily/earthdatastore/__init__.py index 60504601..7211ef93 100644 --- a/earthdaily/earthdatastore/__init__.py +++ b/earthdaily/earthdatastore/__init__.py @@ -509,11 +509,14 @@ def datacube( raise ValueError( f"Specified mask '{mask_with}' is not available. Currently available masks provider are : {mask._available_masks}" ) - + elif assets is not None: + mask_with = mask._native_mask_def_mapping.get(collections[0], None) + assets.append(mask_with) if mask_with == "ag_cloud_mask": search_kwargs = self._update_search_kwargs_for_ag_cloud_mask( search_kwargs, collections[0] ) + if intersects is not None: intersects = cube_utils.GeometryManager(intersects).to_geopandas() items = self.search( @@ -559,18 +562,7 @@ def datacube( if mask_with: if clear_cover and mask_statistics is False: mask_statistics = True - warnings.warn( - "Forcing mask_statistics in order to filter by clear coverage.", - category=Warning, - ) - if mask_with == "native": - mask_with = mask._native_mask_def_mapping.get(collections[0], None) - if mask_with is None: - raise ValueError( - f"Sorry, there's no native mask available for {collections[0]}. Only these collections have native cloudmask : {list(mask._native_mask_mapping.keys())}." - ) mask_kwargs = dict(mask_statistics=mask_statistics) - if mask_with == "ag_cloud_mask": acm_items = self.ag_cloud_mask_items(items) acm_datacube = datacube( @@ -622,7 +614,23 @@ def datacube( xr_datacube = mask.filter_clear_cover(xr_datacube, clear_cover) return xr_datacube - + + def _update_search_for_assets(self, assets): + fields = { + "include": [ + "id", + "type", + "collection", + "stac_version", + "stac_extensions", + "collection", + "geometry", + "bbox", + "properties" + ]} + fields['include'].extend([f'assets.{asset}' for asset in assets]) + return fields + def search( self, collections: str | list, @@ -631,6 +639,7 @@ def search( post_query=None, prefer_alternate=None, add_default_scale_factor=False, + assets=None, **kwargs, ): """ @@ -734,6 +743,8 @@ def search( } """ + if assets is not None: + kwargs['fields'] = self._update_search_for_assets(assets) if isinstance(collections, str): collections = [collections] if bbox is None and intersects is not None: diff --git a/earthdaily/earthdatastore/cube_utils/asset_mapper/asset_mapper_config.json b/earthdaily/earthdatastore/cube_utils/asset_mapper/asset_mapper_config.json index 0e526833..76125445 100644 --- a/earthdaily/earthdatastore/cube_utils/asset_mapper/asset_mapper_config.json +++ b/earthdaily/earthdatastore/cube_utils/asset_mapper/asset_mapper_config.json @@ -17,6 +17,7 @@ "rededge78": "rededge3", "watervapor": "wvp", "native-cloud-mask": "scl", + "native": "scl", "aot": "aot", "visual": "visual", "aot-jp2": "aot-jp2", @@ -52,6 +53,7 @@ "swir16": "swir16", "swir22": "swir22", "native-cloud-mask": "qa_pixel", + "native": "qa_pixel", "SAA": "SAA", "SZA": "SZA", "VAA": "VAA", @@ -72,6 +74,7 @@ "lwir": "lwir11", "lwir11": "lwir11", "native-cloud-mask": "qa_pixel", + "native": "qa_pixel", "qa": "qa", "SAA": "SAA", "SZA": "SZA", @@ -111,6 +114,7 @@ "rededge74": "image_file_SRE_B09", "rededge78": "image_file_SRE_B10", "native-cloud-mask": "detailed_cloud_mask", + "native": "detailed_cloud_mask", "mask": "mask", "license": "license", "stac_json": "stac_json", diff --git a/examples/compare_scale_s2.py b/examples/compare_scale_s2.py index 0d805255..72da1da5 100644 --- a/examples/compare_scale_s2.py +++ b/examples/compare_scale_s2.py @@ -45,15 +45,12 @@ def get_cube(rescale=True): # ---------------------------------------------------- pivot_cube = get_cube(rescale=False) * 0.0001 -plt.show() #####################################################################da######### # Plots cube with SCL with at least 50% of clear data # ---------------------------------------------------- - pivot_cube.to_array(dim="band").plot.imshow(vmin=0, vmax=0.33, col="time", col_wrap=3) - plt.show() #####################################################################da#########