数据处理|S-G滤波之包络滤波

由于遥感观测总是受到云层,大气影响,总会造成植被指数骤降问题,包络滤波的就是根据植被的特性,将骤降值认为是错误值,选择最大值进行滤波
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’]滤波前图片
数据处理|S-G滤波之包络滤波
文章图片

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滤波之包络滤波】结果
数据处理|S-G滤波之包络滤波
文章图片

    推荐阅读