增加坡度计算

This commit is contained in:
2026-04-22 09:27:59 +08:00
parent 4fd1b0a203
commit d563a56358
20 changed files with 4891 additions and 344 deletions

View File

@ -177,11 +177,11 @@ def _block_windows(src, block_size=512):
def _resolve_output_envi_path(output_file):
"""Return the ENVI image path used for rasterio writes."""
if output_file.lower().endswith(".img"):
if output_file.lower().endswith(".dat"):
return output_file
if output_file.lower().endswith(".hdr"):
return output_file[:-4] + ".img"
return output_file + ".img"
return output_file[:-4] + ".dat"
return output_file + ".dat"
def _read_wavelengths_from_header(hyperspectral_file):
@ -259,7 +259,7 @@ def _get_output_filename(base_output_file: str, var_name: str) -> str:
input.hdr + brdf_unc -> input_brdf_unc.hdr
"""
base, ext = os.path.splitext(base_output_file)
if ext.lower() in ('.hdr', '.img'):
if ext.lower() in ('.hdr', '.dat'):
base = base # keep base without extension
suffix = f"_{var_name}" if var_name.lower() != "rw_brdf" else ""
return f"{base}{suffix}{ext}"
@ -486,6 +486,29 @@ def run_brdf_correction_block(
for dst in output_dsts.values():
dst.close()
# Write ENVI header files with wavelength information from input
for var_name, out_path in output_paths.items():
hdr_path = out_path[:-4] + ".hdr" if out_path.lower().endswith(".dat") else out_path + ".hdr"
# Prepare ENVI header content with wavelengths from input file
header_lines = [
"ENVI",
f"description = {{BRDF corrected result: {var_name}}}",
f"samples = {n_cols}",
f"lines = {n_rows}",
f"bands = {n_bands}",
"header offset = 0",
"file type = ENVI Standard",
"data type = 4", # float32
"interleave = bsq",
"byte order = 0", # little-endian
f"wavelength = {{{', '.join(str(v) for v in wavelengths.tolist())}}}",
"wavelength units = nm",
]
# Write header file
with open(hdr_path, 'w') as f:
f.write('\n'.join(header_lines))
print(f" Written header: {hdr_path}")
# Print performance statistics
total_blocks = blocks_processed + blocks_skipped
if total_blocks > 0:
@ -864,7 +887,7 @@ def main():
parser.add_argument("hyperspectral_file", help="Input ENVI BSQ hyperspectral file or .hdr path.")
parser.add_argument("angle_file", help="Input ENVI BIP angle file or .hdr path.")
parser.add_argument("mask_file", help="Input water mask GeoTIFF; pixels == 1 are corrected.")
parser.add_argument("output_file", help="Output path prefix. ENVI writes .hdr/.img, NetCDF writes .nc.")
parser.add_argument("output_file", help="Output path prefix. ENVI writes .hdr/.dat, NetCDF writes .nc.")
parser.add_argument("--brdf-model", default="L11", choices=["L11", "M02", "M02SeaDAS", "O25"])
parser.add_argument("--output-var", nargs='+', default=["Rw_brdf"],
help="Output variables to save (one or more). "