一波谱2.5nm 采样
# -*- coding: utf-8 -*-
import numpy as np
import numpy as np
from scipy.integrate import simps
import numpy as np
# 定义各波段波长数组
b = np.arange(450, 520+ 2.5, 2.5) # 蓝光波段
g = np.arange(520, 600+ 2.5, 2.5) # 绿光波段
r = np.arange(630, 690+ 2.5, 2.5) # 红光波段
nir = np.arange(760, 890+ 2.5, 2.5) # 近红外波段
redge = np.arange(700, 750+ 2.5, 2.5) # 红边波段
# 写入文本文件
# 为每个波段创建单独的文件
band_files = [
("blue_band.txt", b, "Blue Band (450-520nm, %d channels)"),
("green_band.txt", g, "Green Band (520-600nm, %d channels)"),
("red_band.txt", r, "Red Band (630-690nm, %d channels)"),
("nir_band.txt", nir, "NIR Band (760-890nm, %d channels)"),
("rededge_band.txt", redge, "Red Edge Band (700-750nm, %d channels)")
]
for filename, band_data, header_template in band_files:
with open(filename, "w") as f:
# 写入文件头
f.write("HJ-2B Satellite Spectral Band\n")
f.write("=" * 50 + "\n\n")
# 写入波段信息
f.write(header_template % len(band_data) + "\n")
# 写入波长数据(每个值单独一行)
f.write("\n".join(["%.1f" % x for x in band_data]))
print "各波段数据已分别保存到以下文件:"
print ", ".join([f[0] for f in band_files])
print "波段数据已保存到 spectral_bands.txt 文件"
print("波段数据已保存到 spectral_bands.txt 文件")