From a40d972938031cf853c304d50651aa68bada512f Mon Sep 17 00:00:00 2001 From: konstntokas Date: Fri, 21 Jun 2024 16:49:14 +0200 Subject: [PATCH] backup --- xcube_stac/href_parse.py | 6 +++--- xcube_stac/opener.py | 2 +- xcube_stac/store.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/xcube_stac/href_parse.py b/xcube_stac/href_parse.py index 9feb488..4d80a6b 100644 --- a/xcube_stac/href_parse.py +++ b/xcube_stac/href_parse.py @@ -100,7 +100,7 @@ def _decode_href(href: str) -> Tuple[str, str, str, dict]: if root is None: protocol, remain = href.split("://") root = remain.split("/")[0] - fs_path = remain.replace(root + "/", "") + fs_path = remain.replace(f"{root}/", "") storage_options = {} return protocol, root, fs_path, storage_options @@ -163,12 +163,12 @@ def _decode_aws_s3_href(href: str): elif re.search(r"^https://.{3,63}\.s3-.{9,14}\.amazonaws\.com/", href) is not None: tmp = href[8:].split("/") region_name = tmp[0].split(".s3-")[-1][:-14] - root = tmp[0].replace(".s3-" + region_name + ".amazonaws.com", "") + root = tmp[0].replace(f".s3-{region_name}.amazonaws.com", "") fs_path = "/".join(tmp[1:]) elif re.search(r"^https://.{3,63}\.s3\..{9,14}\.amazonaws\.com/", href) is not None: tmp = href[8:].split("/") region_name = tmp[0].split(".s3.")[-1][:-14] - root = tmp[0].replace(".s3." + region_name + ".amazonaws.com", "") + root = tmp[0].replace(f".s3.{region_name}.amazonaws.com", "") fs_path = "/".join(tmp[1:]) if root is not None: diff --git a/xcube_stac/opener.py b/xcube_stac/opener.py index 42f4b8f..ec38c85 100644 --- a/xcube_stac/opener.py +++ b/xcube_stac/opener.py @@ -78,7 +78,7 @@ def open_data( stac_schema = self.get_open_data_params_schema() stac_schema.validate_instance(open_params) tile_size = open_params.get("tile_size", (512, 512)) - fs_path = "https://" + self._root + "/" + data_id + "#mode=bytes" + fs_path = f"https://{self._root}/{data_id}#mode=bytes" return xr.open_dataset(fs_path, chunks={}) diff --git a/xcube_stac/store.py b/xcube_stac/store.py index 53af680..dc9cc8d 100644 --- a/xcube_stac/store.py +++ b/xcube_stac/store.py @@ -312,11 +312,11 @@ def _access_item(self, data_id: str) -> Union[pystac.Item, str]: Raises: DataStoreError: Error, if the item json cannot be accessed. """ - response = requests.request(method="GET", url=self._url_mod + data_id) + response = requests.request(method="GET", url=f"{self._url_mod}{data_id}") if response.status_code == 200: return pystac.Item.from_dict( json.loads(response.text), - href=self._url + data_id, + href=f"{self._url_mod}{data_id}", root=self._catalog, preserve_dict=False, ) @@ -381,7 +381,7 @@ def _build_dataset( if len(ds_asset) == 1: key = asset.extra_fields["id"] else: - key = asset.extra_fields["id"] + "_" + varname + key = f"{asset.extra_fields['id']}_varname" ds[key] = da return ds