From 5ca65747801f3c22acdd6911bf3b1eeb56a8da85 Mon Sep 17 00:00:00 2001 From: xhong Date: Sun, 12 Jan 2025 00:38:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E4=BA=91=E7=AB=AF?= =?UTF-8?q?=E4=B8=8E=E6=9C=AC=E5=9C=B0=E6=95=B0=E6=8D=AE=E7=9A=84=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E4=B8=8E=E9=A2=84=E5=A4=84=E7=90=86=E7=9A=84=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E9=80=BB=E8=BE=91.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HLS_SuPER/HLS_PER.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/HLS_SuPER/HLS_PER.py b/HLS_SuPER/HLS_PER.py index 5eed2a6..feb02ab 100644 --- a/HLS_SuPER/HLS_PER.py +++ b/HLS_SuPER/HLS_PER.py @@ -61,7 +61,11 @@ def open_hls( # (Add) 读取波段名称 split_asset = url.split("/")[-1].split(".") asset_name = split_asset[1] - band_name = split_asset[-2] + band_name = split_asset[-2] if split_asset[-2] != "subset" else split_asset[-3] + # 判断是否为 Fmask 波段 + is_fmask = True if (band_name in ["Fmask", "FMASK"]) else False + # 判断是否为 L30 独有的热红外波段 + is_tir = True if (band_name in ["B10", "B11", "TIR1", "TIR2"]) and (asset_name == "L30") else False # Reproject ROI and Clip if ROI is provided and clip is True if roi is not None and clip: @@ -70,15 +74,14 @@ def open_hls( # (Add) 即使大部分影像已经被缩放且填补了缺失值, 但可能仍然有些影像需要进行手动在本地GIS软件中进行缩放和填补缺失值 # Apply Scale Factor if desired for non-quality layer - if band_name != "Fmask": + if not is_fmask: if scale: # Mask Fill Values da = xr.where(da == -9999, np.nan, da) # Scale Data # (Add) 除质量层, 以及 L30 的两个热红外波段外, 其他光谱波段缩放因子均为 0.0001 # (Add) L30 的两个热红外波段缩放因子为 0.01 - # NOTE: 需要注意的是热红外此时未被改名 - if (band_name == "B10" or band_name == "B11") and (asset_name == "L30"): + if is_tir: da = da * 0.01 else: da = da * 0.0001 @@ -96,12 +99,12 @@ def open_hls( # Add Scale Factor to Attributes Manually - This will overwrite/add if the data is missing. # (Add) 若要手动缩放, 则需要手动添加缩放因子 else: - if (band_name == "B10" or band_name == "B11") and (asset_name == "L30"): + if is_tir: da.attrs["scale_factor"] = 0.01 else: da.attrs["scale_factor"] = 0.0001 - # 销毁源数据 - del da_org + # 清除源数据 + da_org = None return da @@ -186,12 +189,13 @@ def process_granule( quality_output_name = create_output_name(quality_url, band_dict) quality_output_file = f"{output_dir}/{quality_output_name}" # Check if quality asset is already processed - # Open Quality Layer - qa_da = open_hls(quality_url, roi, clip, scale, chunk_size) if not os.path.isfile(quality_output_file): + # Open Quality Layer + qa_da = open_hls(quality_url, roi, clip, scale, chunk_size) # Write Output qa_da.rio.to_raster(raster_path=quality_output_file, driver="COG") else: + qa_da = open_hls(quality_output_file, roi, clip, scale, chunk_size) logging.info( f"Existing quality file {quality_output_name} found in {output_dir}." )