1 Star 1 Fork 0

Haixu He/波段分布变化检测

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
new.py 3.56 KB
一键复制 编辑 原始数据 按行查看 历史
Haixu He 提交于 2022-05-19 21:30 . update
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Author :hhx
@Date :2022/5/15 11:02
@Description :
"""
import os
import numpy as np
import matplotlib.pyplot as plt
import datetime
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False
def preprocess_div(data1):
data = data1.ravel()
id = np.where((data.astype('str') == 'nan'))
data = np.delete(data, id)
return data
def getIndexMean(data, idx):
cpList = ['201811', '202010', '202112']
tempp = []
temp = []
# print(data)
for i in data:
if i not in idx:
temp.append(i)
else:
tempp.append(temp)
temp = [i]
print(tempp)
def formatnum(n):
if n < 10:
return '0' + str(n)
return str(n)
def CreateVertex(date1, date2):
"""创建节点"""
VertexList = []
year1, month1 = date1
year2, month2 = date2
for year in range(year1, year2 + 1):
if year == year1:
for month in range(month1, 13):
VertexList.append('{}{}'.format(year, formatnum(month)))
elif year == year2:
for month in range(1, month2 + 1):
VertexList.append('{}{}'.format(year, formatnum(month)))
else:
for month in range(1, 13):
VertexList.append('{}{}'.format(year, formatnum(month)))
return VertexList
if __name__ == '__main__':
changjiang = [6, 10, 17, 72] # changjiang
# changjiang = [6, 33, 56, 72] # luoyang
# changjiang = [6, 22, 44, 72]
loc = 'changjiangcunchu'
start = (2016, 7)
end = (2021, 12)
VertexList = CreateVertex(start, end) # 创建节点
Veg = []
SI = []
WB = []
BLI = []
for i in range(1, 5):
path = 'result/' + loc + '_' + str(i) + '.npy'
data = np.load(path)
res = []
for j in range(0, len(changjiang) - 1):
d1 = data[changjiang[j] - 6:changjiang[j + 1] - 6]
res.append([np.mean(d1)])
if i == 1:
Veg = res
elif i == 2:
SI = res
elif i == 3:
WB = res
else:
BLI = res
print(Veg)
print(SI)
print(WB)
print(BLI)
for i in range(len(WB) - 1):
if WB[i + 1][0] - WB[i][0] >= 0:
SI[i + 1][0] += WB[i + 1][0] - WB[i][0]
WB[i + 1][0] = WB[i][0]
print(Veg)
print(SI)
print(WB)
print(BLI)
VegList = []
SIList = []
WBList = []
BLIList = []
date = [datetime.datetime.strptime(x, "%Y%m") for x in VertexList]
res = []
for j in range(0, len(changjiang) - 1):
res.extend(Veg[j] * (changjiang[j + 1] - changjiang[j]))
plt.plot(date, res, color='green', label='植被')
plt.scatter(date, res, color='green', s=5)
res = []
for j in range(0, len(changjiang) - 1):
res.extend(SI[j] * (changjiang[j + 1] - changjiang[j]))
plt.plot(date, res, color='gray', label='不透水面')
plt.scatter(date, res, color='gray', s=5)
res = []
for j in range(0, len(changjiang) - 1):
res.extend(WB[j] * (changjiang[j + 1] - changjiang[j]))
plt.plot(date, res, color='blue', label='水体')
plt.scatter(date, res, color='blue', s=5)
res = []
for j in range(0, len(changjiang) - 1):
res.extend(BLI[j] * (changjiang[j + 1] - changjiang[j]))
plt.plot(date, res, color='#DAA520', label='裸地')
plt.scatter(date, res, color='#DAA520', s=5)
plt.axhline(0, c='black', ls='--')
plt.title('长江存储')
plt.legend(fontsize=12)
plt.show()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/HaixuHe/Band-distribution-change-detection.git
git@gitee.com:HaixuHe/Band-distribution-change-detection.git
HaixuHe
Band-distribution-change-detection
波段分布变化检测
master

搜索帮助