From 0d3f6e212c6d8f083dadeb5f3c0e043327695d75 Mon Sep 17 00:00:00 2001 From: xhong Date: Sun, 12 Jan 2025 02:51:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=97=B6=E7=9A=84=E5=BC=82=E5=B8=B8=E5=A4=84?= =?UTF-8?q?=E7=90=86.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HLS_SuPER/HLS_PER.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/HLS_SuPER/HLS_PER.py b/HLS_SuPER/HLS_PER.py index feb02ab..bde9684 100644 --- a/HLS_SuPER/HLS_PER.py +++ b/HLS_SuPER/HLS_PER.py @@ -55,6 +55,9 @@ def open_hls( da_org = rxr.open_rasterio(url, chunks=chunk_size, mask_and_scale=False).squeeze( "band", drop=True ) + # (Add) 若未获取到数据, 则返回 None + if da_org is None: + return None # (Add) 复制源数据进行后续操作, 以便最后复制源数据属性信息 da = da_org.copy() @@ -215,13 +218,24 @@ def process_granule( if not os.path.isfile(output_file): # Open Asset da = open_hls(url, roi, clip, scale, chunk_size) + # (Add) 若返回的da为None, 则表示该url对应的文件不存在/无法访问, 再次尝试无果后将会跳过 + if da is None: + logging.warning( + f"Asset {url} not found in {output_dir}. Try again." + ) + # 再次尝试下载 + da = open_hls(url, roi, clip, scale, chunk_size) + if da is None: + logging.warning(f"Asset {url} still not found. Skipping.") + continue # Apply Quality Mask if Desired if quality_filter: da = da.where(~qa_mask) # Write Output - if "FMASK" in output_name: + if "FMASK" in output_name and not quality_filter: + # (Add) 若 quality_filter=False, 则需要将质量层文件另外保存 da.rio.to_raster(raster_path=output_file, driver="COG") else: # (Add) 固定输出为 float32 类型, 否则会默认 float64 类型