From 4589cca8922124be24213345e71c951e957913aa Mon Sep 17 00:00:00 2001 From: Antsalacia Date: Sun, 24 Nov 2024 14:09:41 +0100 Subject: [PATCH 1/2] add metadata to tiff files --- earthspy/earthspy.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/earthspy/earthspy.py b/earthspy/earthspy.py index de6581d..a8de043 100644 --- a/earthspy/earthspy.py +++ b/earthspy/earthspy.py @@ -228,8 +228,13 @@ def get_available_data(self) -> list: # and update service_url if dowload failed try: # store metadata of available scenes - self.metadata = [list(iterator) for iterator in search_iterator] - + self.metadata = {} + for iterator in search_iterator: + iterator_list = list(iterator) + if len(iterator_list) > 0: + date = iterator_list[0]["properties"]["datetime"].split("T")[0] + self.metadata[date] = iterator_list + except shb.exceptions.DownloadFailedException: # set specific base URL of deployment self.catalog_config.sh_base_url = shb.DataCollection[ @@ -250,8 +255,13 @@ def get_available_data(self) -> list: ] # store metadata of available scenes - self.metadata = [list(iterator) for iterator in search_iterator] - + self.metadata = {} + for iterator in search_iterator: + iterator_list = list(iterator) + if len(iterator_list) > 0: + date = iterator_list[0]["properties"]["datetime"].split("T")[0] + self.metadata[date] = iterator_list + # create date +-1 hour around acquisition time time_difference = timedelta(hours=1) @@ -1065,7 +1075,7 @@ def merge_rasters(self) -> None: # write mosaic with rasterio.open(date_output_filename, "w", **output_meta) as dst: dst.write(mosaic) - + dst.update_tags(**{k:self.metadata[date][0][k] for k in ["id"]}) # save file name of merged raster self.output_filenames_renamed.append(date_output_filename) From 37e44193be2d506771d64449ecae4306ada819a9 Mon Sep 17 00:00:00 2001 From: Antsalacia Date: Tue, 26 Nov 2024 11:40:28 +0100 Subject: [PATCH 2/2] add the **kwargs in variable --- earthspy/earthspy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/earthspy/earthspy.py b/earthspy/earthspy.py index a8de043..0296aba 100644 --- a/earthspy/earthspy.py +++ b/earthspy/earthspy.py @@ -1071,11 +1071,11 @@ def merge_rasters(self) -> None: "transform": output_transform, } ) - + id_dict = {k:self.metadata[date][0][k] for k in ["id"]} # write mosaic with rasterio.open(date_output_filename, "w", **output_meta) as dst: dst.write(mosaic) - dst.update_tags(**{k:self.metadata[date][0][k] for k in ["id"]}) + dst.update_tags(**id_dict) # save file name of merged raster self.output_filenames_renamed.append(date_output_filename)