【R语言】处理CMIP6数据

R语言处理CMIP6数据(个人笔记)

总结了近期我的CMIP6模型数据处理方法,函数可以实现对指定空间范围,指定年份内的CMIP6变量数据的裁剪和合并,并重采样为统一的分辨率。
同时,某些模型每年只有365天,没有设置闰年,会对这部分模型闰年的12.31日进行插值补全(因为数据并不是缺了2.29日)。

全部代码如下,有注释

#-----------------------------------------------------------------------------------
#1.Determine watershed number and basin shapefile and the observed data---------------------
rm(list = ls())
memory.limit(400000)
setwd('./cmip6/')
library(rgdal)
library(sf)
library(raster)
library(ncdf4)
library(abind)
library(stringr)
library(lubridate)
library(fields)
library(terra)
# 中国轮廓,用于裁剪
china_shp <-st_read("./chinaout.shp")
#2. CMIP6 data processing and tailoring-----------------------------------------------
#crop function------------------------------------------------------------------------------
# function 1------------------- 用于判断是否闰年的函数
leap<-function(x){
   
  if(x%%4==0){
   
    if(((x%%100==0)&(x%%400==0))|(x%%100!=0))
      return(TRUE) else
        return(FALSE)
  } else
    return(FALSE)
}

# #function2------------- 用于裁剪,合并,并且重采样的函数
crop_year_re <- function(end,s_china,dates,k,ncdata,dateend,dateyear){
   
  if (end ==dateend){
   
    a_2 <-crop(ncdata,s_china) 
    crs(a_2) <- '+proj=longlat +datum=WGS84 +no_defs'
    cc <-  resample( a_2, s_china , method = "bilinear") 
    a <- as.data.frame(cc,xy=TRUE,na.rm=FALSE)
  } else {
   
    a_2 <- crop(ncdata,s_china) 
    crs
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值