feat: 完善云端与本地数据的读取与预处理的兼容逻辑.
This commit is contained in:
parent
017714b254
commit
5ca6574780
@ -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}."
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user