显著性检验 相关分析 回归分析代码


```python
## 加载必要的库
import numpy as np 
import xarray as xr 
import os, cmaps

from sklearn.feature_selection import f_regression

import matplotlib.pyplot as plt 

import cartopy.crs as ccrs 
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import cartopy.io.shapereader as shpreader
from cartopy.util import add_cyclic_point

##-----------------------------------------------------------------------------------------------------------------##
## 读数据
with xr.open_dataset('/mnt/e/research/data/seasonal/DJF/2.5x2.5/sst.DJF.mean.anom.nc') as f1:
      pre = f1['sst_anom'][:-1,:,:]
      lat, lon = f1['lat'], f1['lon']
pre2d = np.array(pre).reshape(pre.shape[0],pre.shape[1]*pre.shape[2])
del pre

with xr.open_dataset('/mnt/e/research/data/seasonal/DJF/2.5x2.5/pc.DJF.sst.nc') as f2:
      pc = f2['pc'][0,:]

del f1, f2

##-----------------------------------------------------------------------------------------------------------------##
## 回归系数
A = np.vstack([pc, np.ones(len(pc))]).T
pre_reg = np.linalg.lstsq(A, pre2d)[0][0].reshape(len(lat),len(lon))

## 相关系数
pre_cor = np.corrcoef(pre2d.T,pc)[:-1,-1].reshape(len(lat),len(lon))

## 显著性检验
pre_cor_sig = f_regression(np.nan_to_num(pre2d), pc)[1].reshape(len(lat),len(lon))
area = np.where(pre_cor_sig < 0.01)

del pre2d, pc, A, pre_cor_sig

##-----------------------------------------------------------------------------------------------------------------##
## 生成地图网格
pre_reg_cyc, lon_cyc = add_cyclic_point(pre_reg, coord = lon)
pre_cor_cyc = add_cyclic_point(pre_cor)
nx, ny = np.meshgrid(lon_cyc, lat)

del pre_reg, pre_cor, lat, lon, lon_cyc

##-----------------------------------------------------------------------------------------------------------------##
## 绘图
plt.figure(figsize = (12, 10))
plt.subplots_adjust(hspace = 0.3)

ax1 = plt.subplot(211, projection = ccrs.PlateCarree(central_longitude = 180))
ax1.coastlines(lw = 0.6)
ax1.set_global()

c1 = ax1.contourf(nx, ny, pre_reg_cyc, np.arange(-1.5,1.6,0.1), cmap = cmaps.BlWhRe, transform = ccrs.PlateCarree())
plt.colorbar(c1, shrink = 1.0, pad = 0.01)

## 显著性打点
sig1 = ax1.scatter(nx[area], ny[area], marker = '.', s = 1, c = 'k', alpha = 0.6, transform = ccrs.PlateCarree())

plt.title('Reg.', fontsize = 20)

ax1.set_xticks(np.arange(0,361,30), crs = ccrs.PlateCarree())
ax1.set_yticks(np.arange(-90,90,15), crs = ccrs.PlateCarree())
ax1.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label = False))
ax1.yaxis.set_major_formatter(LatitudeFormatter())

ax1.set_extent([0,361,-40,85], crs = ccrs.PlateCarree())

##-----------------------------------------------------------------------------------------------------------------##
ax2 = plt.subplot(212, projection = ccrs.PlateCarree(central_longitude = 180))
ax2.coastlines(lw = 0.6)
ax2.set_global()

c2 = ax2.contourf(nx, ny, pre_cor_cyc, np.arange(-1.0,1.1,0.1), cmap = cmaps.BlWhRe, transform = ccrs.PlateCarree())
plt.colorbar(c2, shrink = 1.0, pad = 0.01)

## 显著性打点
sig2 = ax2.scatter(nx[area], ny[area], marker = '.', s = 1, c = 'k', alpha = 0.6, transform = ccrs.PlateCarree())

plt.title('Cor.', fontsize = 20)

ax2.set_xticks(np.arange(0,361,30), crs = ccrs.PlateCarree())
ax2.set_yticks(np.arange(-90,90,15), crs = ccrs.PlateCarree())
ax2.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label = False))
ax2.yaxis.set_major_formatter(LatitudeFormatter())

ax2.set_extent([0,361,-40,85], crs = ccrs.PlateCarree())

##-----------------------------------------------------------------------------------------------------------------##

plt.show()

##-----------------------------------------------------------------------------------------------------------------##

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 显著点的检测 Itti的A Model of Saliency-Based Visual Attention for Rapid Scene Analysis (TPAMI 1999)论文是显著性检测的鼻祖论文,检测出来的是用户关注的点。 2. 显著区域的检测 侯晓迪同学在2007年发表的一篇CVPR的论文,用很简单的方法检测了显著性区域,那之后显著性检测主要以区域检测为主:Saliency detection: A spectral residual approach (CVPR 2007),虽然之后有人诟病这篇论文有不足之处,但该想法简单,推动了显著性研究的普及。侯同学靠这一篇文章再加上投稿期间的趣事,就封神了。 3. 其他经典的显著性检测方法 在那之后陆续又有一些经典的显著性检测算法被提出:https://blog.csdn.net/touch_dream/article/details/78716507 可以看这个博文。 4. 基于深度学习的显著性检测 再之后,显著性检测领域就进入了Deep Learning时代, Deep Visual Attention Prediction TIP2018 (CODE)     https://github.com/wenguanwang/deepattention Predicting Human Eye Fixations via an LSTM-based Saliency Attentive Model (CODE)     https://github.com/marcellacornia/sam CVPR2016 Shallow and Deep Convolutional Networks for Saliency Prediction (CODE)     https://github.com/imatge-upc/saliency-2016-cvpr Saliency Detection with GAN (2017)     https://github.com/imatge-upc/saliency-salgan-2017  (CODE)     https://github.com/batsa003/salgan/ (PyTorch的版本) 5. 非自然图象的显著性检测 例如,海报的显著性检测,图表的显著性检测,地理数据的显著性检测等等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值