x=(0:0.02:6)*1e4
y=fun([3e5,8.3,0.6],x)+rand(size(x)).*exp(-(x/2e4).^2)*20
%原图能用hist(data,n)画
%data数据n区间统计画柱状图
%要保留hist数据
%原语句要返x y值
%[y x]=hist(data,n)
%没数据所用边两句模拟xy数据
bar(x,y,1)hold on%根据xy数据画柱状图
[maxy ind]=max(y)
p=nlinfit(x,y,fun,[maxy*x(ind),log(x(ind)),1])%拟合
%p(1)~幅度关 p(2)~mu p(3)~sigma
yfit=fun(p,x)%计算拟合曲线
plot(x,yfit,'r','linewidth',2)
xmax=exp(p(2)-p(3)^2)%计算布极布处值 x=exp(mu-sigma^2)
ymax=fun(p,xmax)
plot([xmax xmax],[0 ymax],'g','linewidth',2)
xmean=exp(p(2)+p(3)^2/2)%计算期望值 x=exp(mu+sigma^2/2)
ymean=fun(p,xmean)
plot([xmean xmean],[0 ymean],'c','linewidth',2)
hold off
xlim([min(x) max(x)])
xlabel('BC浓度(ng/m^3)')
ylabel('频数')
legend('统计数据',['数态布:\mu=' num2str(p(2)) ',\sigma=' num2str(p(3))],...
['极概布位置:x=' num2str(xmax)],['期望值位置:x=' num2str(xmean)])
text(xmean+10000,ymean+10,'$ y=\frac{A}{x}e^{-\frac{(lnx-\mu)^2}{2\sigma^2}} $',...
'interpreter','latex','FontSize',18)
-
主要分析步骤:加载区域范围
加载区域范围日均温数据集ERA5
定义日均温提取分析函数
提取数据
结果可视化
二、python代码
1、分析区域
python代码如下
region_bj = '../boudary/huangtu_plateau.shp'
region = geemap.shp_to_ee(region_bj)
roi = region.geometry()
Map = geemap.Map()
Map.addLayer(ee.Image().paint(roi, 0, 2), {'palette':'darkred'}, 'plateau')
Map.centerObject(roi)
Map
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
2、定义函数、设置属性及数据分析
python代码如下:
######### 1-定义函数 #########
# 计算区域的平均温度,设置属性
def meanTempCal(image):
mt_2m = image.reduceRegion(**{
'reducer':ee.Reducer.mean(),
'geometry':roi,
'bestEffort':True
})
# 转换为摄氏度
mt_cel = ee.Number(mt_2m.get('mean_2m_air_temperature'))\
.subtract(273.15)
# 增加新的属性
return image.set({'mean_air_temp':mt_cel})
######### 2-加载数据集并进行提取分析 #########
# 获取日平均温度,进行相应时间段、区域范围筛选
era5_mt = ee.ImageCollection('ECMWF/ERA5/DAILY') \
.filterDate('2010-01-01', '2020-12-31') \
.filterBounds(roi)
mean_airTemp = era5_mt.map(meanTempCal).aggregate_array('mean_air_temp').getInfo()
dates = era5_mt.reduceColumns(ee.Reducer.toList(), ["system:index"]).get('list').getInfo()
######### 3-结果制图 #########
import matplotlib.pyplot as plt
plt.plot(dates, mean_airTemp)
plt.title('mean daily air temprature')
plt.xlabel('dates')
plt.ylabel('Temprature(℃)')
plt.show()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
结果如下:
在这里插入图片描述
三、小结
通过ERA日均数据集,利用GEE分析了10年来区域日均温度的变化,可以明显看出日均温度的周期性变化特征
下一步可进一步进行数据的分析,比如可利用R语言进行周期性、趋势性特征的统计分析,生成时间序列的变化图