爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 296|回复: 0

NCL 画CMIP6资料图

[复制链接]

新浪微博达人勋

发表于 2024-7-5 11:59:13 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
load "/media/lixia/WORK/Backup/present/data/map/cnmap/cnmap.ncl"

begin

;=======================================================
lon1=70
lon2=120
lat1=32
lat2=52
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   input data
indir1   = "/media/lixia/Backup/DATA/CMIP6/LS3MIP/CESM2/"
inf11     = addfile(indir1+"tas_Amon_CESM2_amip-lfmip-pdLC_r1i1p1f1_gn_197001-210012_0.5.nc","r")
tas11  =inf11->tas(120:1559,{lat1:lat2},{lon1:lon2})   

time   =inf11->time(120:1559)
lat    =inf11->lat({lat1:lat2})
lon    =inf11->lon({lon1:lon2})
ntime = dimsizes(time)
nlat = dimsizes(lat)
nlon = dimsizes(lon)

inf12     = addfile(indir1+"tas_Amon_CESM2_amip-lfmip-pdLC_r1i1p1f2_gn_197001-210012_0.5.nc","r")
tas12  =inf12->tas(120:1559,{lat1:lat2},{lon1:lon2})

;==========================
indir2   = "/media/lixia/Backup/DATA/CMIP6/LS3MIP/CMCC-ESM2/"
inf21     = addfile(indir2+"tas_Amon_CMCC-ESM2_amip-lfmip-pdLC_r1i1p1f1_gn_198001-210012_0.5.nc","r")
tas21  =inf21->tas(0:1439,{lat1:lat2},{lon1:lon2})

inf22     = addfile(indir2+"tas_Amon_CMCC-ESM2_amip-lfmip-pdLC_r1i1p1f2_gn_198001-210012_0.5.nc","r")
tas22  =inf22->tas(0:1439,{lat1:lat2},{lon1:lon2})

;============================
indir3   = "/media/lixia/Backup/DATA/CMIP6/LS3MIP/EC-Earth3/"
inf31     = addfile(indir3+"tas_Amon_EC-Earth3_amip-lfmip-pdLC_r1i1p1f1_gr_198001-210012_0.5.nc","r")
tas31  =inf31->tas(0:1439,{lat1:lat2},{lon1:lon2})

inf32     = addfile(indir3+"tas_Amon_EC-Earth3_amip-lfmip-pdLC_r1i1p1f2_gr_198001-210012_0.5.nc","r")
tas32  =inf32->tas(0:1439,{lat1:lat2},{lon1:lon2})

;============================
indir4   = "/media/lixia/Backup/DATA/CMIP6/LS3MIP/IPSL-CM6A-LR/"
inf41     = addfile(indir4+"tas_Amon_IPSL-CM6A-LR_amip-lfmip-pdLC_r1i1p1f1_gr_198001-210012_0.5.nc","r")
tas41  =inf41->tas(0:1439,{lat1:lat2},{lon1:lon2})

inf42     = addfile(indir4+"tas_Amon_IPSL-CM6A-LR_amip-lfmip-pdLC_r1i1p1f2_gr_198001-210012_0.5.nc","r")
tas42  =inf42->tas(0:1439,{lat1:lat2},{lon1:lon2})

;==============================
indir5   = "/media/lixia/Backup/DATA/CMIP6/LS3MIP/MIROC6/"
inf51     = addfile(indir5+"tas_Amon_MIROC6_amip-lfmip-pdLC_r1i1p1f1_gn_198001-210012_0.5.nc","r")
tas51  =inf51->tas(0:1439,{lat1:lat2},{lon1:lon2})

inf52     = addfile(indir5+"tas_Amon_MIROC6_amip-lfmip-pdLC_r1i1p1f2_gn_198001-210012_0.5.nc","r")
tas52  =inf52->tas(0:1439,{lat1:lat2},{lon1:lon2})

;================
indir6  = "/media/lixia/Backup/DATA/CMIP6/LS3MIP/MPI-ESM1-2-LR/"
inf61     = addfile(indir6+"tas_Amon_MPI-ESM1-2-LR_amip-lfmip-pdLC_r1i1p1f1_gn_198001-209912_0.5.nc","r")
tas61  =inf61->tas(0:1439,{lat1:lat2},{lon1:lon2})

inf62     = addfile(indir6+"tas_Amon_MPI-ESM1-2-LR_amip-lfmip-pdLC_r1i1p1f2_gn_198001-209912_0.5.nc","r")
tas62  =inf62->tas(0:1439,{lat1:lat2},{lon1:lon2})

;==================
;indir7  = "/media/lixia/Backup/DATA/CMIP6/ScenarioMIP/CESM2/"
;inf7     = addfile(indir7+"tas_Amon_CMCC-CM2-SR5_historical_r1i1p1f1_gn_185001-201412_TP.nc","r")

;================
indir8  = "/media/lixia/Backup/DATA/CMIP6/ScenarioMIP/CMCC-ESM2/"
inf81     = addfile(indir8+"tas_Amon_CMCC-ESM2_historical_r1i1p1f1_gn_185001-201412_0.5.nc","r")
tas81 =inf81->tas(1560:,{lat1:lat2},{lon1:lon2})
printVarSummary(tas81)

inf82     = addfile(indir8+"tas_Amon_CMCC-ESM2_ssp126_r1i1p1f1_gn_201501-210012_0.5.nc","r")
tas82 =inf82->tas(0:1019,{lat1:lat2},{lon1:lon2})
printVarSummary(tas82)

inf83     = addfile(indir8+"tas_Amon_CMCC-ESM2_ssp585_r1i1p1f1_gn_201501-210012_0.5.nc","r")
tas83 =inf83->tas(0:1019,{lat1:lat2},{lon1:lon2})

tas8_1 = new((/ntime,nlat,nlon/),"float",tas11@_FillValue)
tas8_1(0:419,:,:)=tas81
tas8_1(420:,:,:) =tas82

tas8_2 = new((/ntime,nlat,nlon/),"float",tas11@_FillValue)
tas8_2(0:419,:,:)=tas81
tas8_2(420:,:,:) =tas83
;================
indir9  = "/media/lixia/Backup/DATA/CMIP6/ScenarioMIP/EC-Earth3/"
inf91     = addfile(indir9+"tas_Amon_EC-Earth3_historical_r1i1p1f1_gr_185001-201412_0.5.nc","r")
tas91 =inf91->tas(1560:,{lat1:lat2},{lon1:lon2})

inf92     = addfile(indir9+"tas_Amon_EC-Earth3_ssp126_r1i1p1f1_gr_201501-210012_0.5.nc","r")
tas92 =inf92->tas(0:1019,{lat1:lat2},{lon1:lon2})

inf93     = addfile(indir9+"tas_Amon_EC-Earth3_ssp585_r1i1p1f1_gr_201501-210012_0.5.nc","r")
tas93 =inf93->tas(0:1019,{lat1:lat2},{lon1:lon2})

tas9_1 = new((/ntime,nlat,nlon/),"float",tas11@_FillValue)
tas9_1(0:419,:,:)=tas91
tas9_1(420:,:,:) =tas92

tas9_2 = new((/ntime,nlat,nlon/),"float",tas11@_FillValue)
tas9_2(0:419,:,:)=tas91
tas9_2(420:,:,:) =tas93

;================
indir10  = "/media/lixia/Backup/DATA/CMIP6/ScenarioMIP/IPSL-CM6A-LR/"
inf101     = addfile(indir10+"tas_Amon_IPSL-CM6A-LR_historical_r1i1p1f1_gr_185001-201412_0.5.nc","r")
tas101 =inf101->tas(1560:,{lat1:lat2},{lon1:lon2})

inf102     = addfile(indir10+"tas_Amon_IPSL-CM6A-LR_ssp126_r1i1p1f1_gr_201501-210012_0.5.nc","r")
tas102 =inf102->tas(0:1019,{lat1:lat2},{lon1:lon2})

inf103     = addfile(indir10+"tas_Amon_IPSL-CM6A-LR_ssp585_r1i1p1f1_gr_201501-210012_0.5.nc","r")
tas103 =inf103->tas(0:1019,{lat1:lat2},{lon1:lon2})

tas10_1 = new((/ntime,nlat,nlon/),"float",tas11@_FillValue)
tas10_1(0:419,:,:)=tas101
tas10_1(420:,:,:) =tas102

tas10_2 = new((/ntime,nlat,nlon/),"float",tas11@_FillValue)
tas10_2(0:419,:,:)=tas101
tas10_2(420:,:,:) =tas103

;==================
indir11  = "/media/lixia/Backup/DATA/CMIP6/ScenarioMIP/MIROC6/"
inf111     = addfile(indir11+"tas_Amon_MIROC6_historical_r1i1p1f1_gn_185001-201412_0.5.nc","r")
tas111 =inf111->tas(1560:,{lat1:lat2},{lon1:lon2})

inf112     = addfile(indir11+"tas_Amon_MIROC6_ssp126_r1i1p1f1_gn_201501-210012_0.5.nc","r")
tas112 =inf112->tas(0:1019,{lat1:lat2},{lon1:lon2})

inf113     = addfile(indir11+"tas_Amon_MIROC6_ssp585_r1i1p1f1_gn_201501-210012_0.5.nc","r")
tas113 =inf113->tas(0:1019,{lat1:lat2},{lon1:lon2})

tas11_1 = new((/ntime,nlat,nlon/),"float",tas11@_FillValue)
tas11_1(0:419,:,:)=tas111
tas11_1(420:,:,:) =tas112

tas11_2 = new((/ntime,nlat,nlon/),"float",tas11@_FillValue)
tas11_2(0:419,:,:)=tas111
tas11_2(420:,:,:) =tas113

;================
indir12  = "/media/lixia/Backup/DATA/CMIP6/ScenarioMIP/MPI-ESM1-2-LR/"
inf121     = addfile(indir12+"tas_Amon_MPI-ESM1-2-LR_historical_r1i1p1f1_gn_185001-201412_0.5.nc","r")
tas121 =inf121->tas(1560:,{lat1:lat2},{lon1:lon2})

inf122     = addfile(indir12+"tas_Amon_MPI-ESM1-2-LR_ssp126_r1i1p1f1_gn_201501-210012_0.5.nc","r")
tas122 =inf122->tas(0:1019,{lat1:lat2},{lon1:lon2})

inf123     = addfile(indir12+"tas_Amon_MPI-ESM1-2-LR_ssp585_r1i1p1f1_gn_201501-210012_0.5.nc","r")
tas123 =inf123->tas(0:1019,{lat1:lat2},{lon1:lon2})

tas12_1 = new((/ntime,nlat,nlon/),"float",tas11@_FillValue)
tas12_1(0:419,:,:)=tas121
tas12_1(420:,:,:) =tas122

tas12_2 = new((/ntime,nlat,nlon/),"float",tas11@_FillValue)
tas12_2(0:419,:,:)=tas121
tas12_2(420:,:,:) =tas123

;#############
data_low  = (/tas21,tas31,tas41,tas51,tas61/)-273.15
data_high = (/tas22,tas32,tas42,tas52,tas62/)-273.15
data_ssp126 = (/tas8_1,tas9_1,tas10_1,tas11_1,tas12_1/)-273.15   
data_ssp585 = (/tas8_2,tas9_2,tas10_2,tas11_2,tas12_2/)-273.15

do i=0,4
data_low(i,:,:,:)=where(.not.ismissing(tas11),data_low(i,:,:,:),tas11@_FillValue)
data_high(i,:,:,:)=where(.not.ismissing(tas11),data_high(i,:,:,:),tas11@_FillValue)
data_ssp126(i,:,:,:)=where(.not.ismissing(tas11),data_ssp126(i,:,:,:),tas11@_FillValue)
data_ssp585(i,:,:,:)=where(.not.ismissing(tas11),data_ssp585(i,:,:,:),tas11@_FillValue)
end do

;###################
data1 = data_ssp126-data_low  ;;;; low scenario
data2 = data_ssp585-data_high ;;;; high scenario

var = (/data1,data2/)
printVarSummary(var)

size = dimsizes(var)
nyear = 120
var01 = dim_avg_n_Wrap(reshape(var,(/size(0),size(1),nyear,12,size(3),size(4)/)),3)
var02 = dim_avg_n_Wrap(var01,(/3,4/))
printVarSummary(var02)


data11= dim_avg_n_Wrap(var02(0,:,:),0)
data11_max = dim_max_n_Wrap(var02(0,:,:),0)
data11_min = dim_min_n_Wrap(var02(0,:,:),0)

data22= dim_avg_n_Wrap(var02(1,:,:),0)
data22_max = dim_max_n_Wrap(var02(1,:,:),0)
data22_min = dim_min_n_Wrap(var02(1,:,:),0)


data = (/data11,data22,data11_min,data11_max,data22_min,data22_max/)
data = smth9_Wrap(data,0.5,-0.25,False)
;==============================================
plot=new(1,"graphic")
plot2=new(1,"graphic")
plot3=new(1,"graphic")
picture = "Difference_variation_tas"
type = "png"

   wks = gsn_open_wks(type,picture)

  res                    = True              
  res@gsnDraw            = False            
  res@gsnFrame           = False            

  res@vpHeightF    = 0.4               
  res@vpWidthF             = 0.7
  res@trYMaxF = 5.
  res@trYMinF = -2.0
  res@trXMaxF = 121
  res@tmXBMode   = "Explicit"
  taxis=ispan(1,120,6)
  res@tmXBValues = taxis
  res@tmXBLabels = (/"1980","1986","1992","1998","2004","2010","2016","2022","2028","2034","2040","2046","2052","2058","2064","2070","2076","2082","2088","2094"/)
  res@tmXBLabelFontHeightF = 0.01


  res@xyMonoLineColor    = False            
  res@xyLineColors       = (/"blue","red"/)
  res@xyLineThicknesses  = (/3.,3./)      
  res@xyDashPatterns  = (/0.,0./)  
  res@gsnYRefLine = 0.0
  res@gsnYRefLineDashPattern = 0
  res@gsnYRefLineColor = "black"
  res@gsnYRefLineThicknessF = 0.025

  ;res@tiYAxisString  = "~F35~J~F~C"      
  res@txFontHeightF   = 0.0195            
  time1 = ispan(1,120,1)
  plot = gsn_csm_xy (wks,time1,data(0:1,:),res)      


  delete(res@xyLineColors)
  res@gsnXYFillColors = "LightBlue"
  res@xyLineColor     = -1                          
  plot1  = gsn_csm_xy (wks,time1,data(2:3,:),res)  


  res@gsnXYFillColors = "LightPink"
  res@xyLineColor     = -1                           
  plot2  = gsn_csm_xy (wks,time1,data(4:5,:),res)
  overlay(plot,plot1)
  overlay(plot,plot2)


; Manually create and attach legend
;*****************************************************
res_text                    = True                  ; text mods desired
res_text@txFontHeightF      = 0.012                ; change text size
res_text@txJust             = "CenterLeft"          ; text justification

res_lines                   = True                  ; polyline mods desired
res_lines@gsLineDashPattern = 0.                    ; solid line
res_lines@gsLineThicknessF  = 5.                    ; line thicker
res_lines@gsLineColor       = "blue"                 ; line color
xx = (/4.,11./)
yy = (/3.5,3.5/)
dum1 = gsn_add_polyline(wks,plot,xx,yy,res_lines)              ; add polyline
dum2 = gsn_add_text(wks,plot,"ssp126",12,3.5,res_text); add text

yy = (/3.1,3.1/)
res_lines@gsLineColor       = "red"                                 ; change to blue
dum3 = gsn_add_polyline(wks,plot,xx,yy,res_lines)                ; add polyline
dum4 = gsn_add_text(wks,plot,"ssp585",12,3.1,res_text)       ; add text

  pres = True
  maximize_output(wks,pres)


end


密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表