由于遥感观测总是受到云层,大气影响,总会造成植被指数骤降问题,包络滤波的就是根据植被的特性,将骤降值认为是错误值,选择最大值进行滤波
SG滤波代码参考&后来&博客
定义滤波函数
import pandas as pd
import matplotlib.pyplot as plt
#%% SG_filter
import numpy as np
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
def sgoal_filter(data,window_size,order):if window_size == None:
window_size = int(len(data)) // 10
if window_size % 2 == 0 or window_size == 0:
window_size += 1arr = []
step = int((window_size-1)/2)
for i in range(window_size):
a = []
for j in range(order):
y_val = np.power(-step + i, j)
a.append(y_val)
arr.append(a)arr = np.mat(arr)
arr = arr * (arr.T * arr).I * arr.Ta = np.array(arr[step])
a = a.reshape(window_size)data = https://www.it610.com/article/np.insert(data, 0, [data[0] for i in range(step)])
data = np.append(data, [data[-1] for i in range(step)])qlist = []
for i in range(step, data.shape[0] - step):
arra = []
for j in range(-step, step+1):
arra.append(data[i +j])
b = np.sum(np.array(arra) * a)
qlist.append(b)
return qlist
ndvi[‘MCD15A3H_006_ndvi_500m’]滤波前图片
文章图片
initial = np.array(ndvi['MCD15A3H_006_ndvi_500m'])
data_sg = sgoal_filter(ndvi['MCD15A3H_006_ndvi_500m'])
sg_1 = np.array(data_sg)
dev = initial-sg_1
stad = np.sqrt(np.mean(dev**2))
while stad > 0.08:
for i in range(len(sg_1)):
if dev[i] >0:
sg_1[i] = initial[i]
initial = sg_1
sg_1 = np.array(sgoal_filter(sg_1,3,1))
dev = initial-sg_1
stad = np.sqrt(np.mean(dev**2))
fig, axes = plt.subplots()
axes.plot(ndvi.Date, sg_1)
axes.plot(ndvi.Date, np.array(ndvi['MCD15A3H_006_Lai_500m']))
【数据处理|S-G滤波之包络滤波】结果
文章图片
推荐阅读
- 游戏|2020级C语言大作业 - 小球进框
- 算法|求数组两个值最大差-Python
- 我的Python心路历程 第九期 (9.2 通过pycharm的python Console获取配置路径)
- 我的Python心路历程 第十一期 (11.1 初探python调试总结之基础篇)
- python基础教程|Python模块(基本概念、2种导入方法(import与from...import)和使用)
- 算法|1357篇ECCV 2020论文打包下载!奖项公布(李飞飞高徒获最佳论文奖)
- 职场|自学Python6个月,找到了月薪8K的工作,多亏了这套学习方式
- python|Python可以比C++更快,你不信()
- python|力扣 leetcode 1319. 连通网络的操作次数 (python)并查集模板快速解及树的高效解