R_Language 板


LINE

[问题类型]: 程式谘询(我想用R 做某件事情,但是我不知道要怎麽用R 写出来) [软体熟悉度]: 入门(写过其他程式,只是对语法不熟悉) [问题叙述]: 继上篇发文一样想请问当出现the dims contain missing values这个错误讯息时该如何 解决??而继上篇发文的最後的推文後,我试了把两年的资料读进去去跑,但还是出现同样 的错误讯息。 因截取问题部分的程式码会跑出不同的错误讯息,且错误讯息追回源头还是需要放资料( 档案)进去,所以我就把完整的程式码贴上来了(当然不需要的部分还是有删掉),我想要 解决的问题就是能让这一完整的程式码跑完都不出错并输出结果(因为这一完整的程式码 是别人写好的一个package(Climdown,公开的))。 而需要放入的资料(档案)和其他程式码我放到下面这个google云端硬碟的共用资料夹里( 如无法进入资料夹或下载档案烦请推文告知),谢谢。 https://drive.google.com/drive/folders/1aI7SnSxJzIIkN9H9QjL8vMv3wF-WSpv5?usp= sharing 其中有一段程式码会跑需要大概半小时,先行告知。 (ps:如需要Climdown这个package的GitHub网址可在推文告知,可再贴上来)。 希望有大大愿意帮忙或是提点我可能是哪里出了问题,我在程式这块目前还是新手,所以 抱歉有时候会不太懂你们说的意思,还烦请你们解释的详细(白话)一点,真的非常谢谢你 们。 [程式范例]: # Read fine-scale grid and spatially aggregate to GCM grid rm(list=ls()) library(ncdf4) library(RNetCDF) library(doParallel) library(PCICt) source("C:\\Users\\TOM\\Desktop\\R(code)\\降尺度\\netcdf.calendar.R") config <- commandArgs(trailingOnly=TRUE) if(length(config)==0) config <- "C:\\Users\\TOM\\Desktop\\R(code)\\降尺度 \\BCSD.config.R" print(readLines(config)) source(config) mc.cores<-4 registerDoParallel(mc.cores,cores=NULL) nc.obs.file<-"C:\\Users\\TOM\\Desktop\\R(资料库)\\TRMM资料\\trmm_1998.nc" nc.obs <- nc_open(nc.obs.file) pr.nc.file<-"C:\\Users\\TOM\\Desktop\\R(资料库)\\降尺度资料 \\pr_Amon_CCSM4_historical_e1i1p1_185001-200512+rcp45_r2i1p1_200601-210012.nc" nc.gcm <- nc_open(pr.nc.file) # Read fine-scale and GCM grid dimensions obs.lon <- ncvar_get(nc.obs,"longitude") obs.lat <- ncvar_get(nc.obs,"latitude") obs.time <- ncvar_get(nc.obs,"time") n.lon <- length(obs.lon) n.lat <- length(obs.lat) obs.lats <- matrix(obs.lat, nrow=n.lon, ncol=n.lat, byrow=TRUE) obs.lons <- matrix(obs.lon, nrow=n.lon, ncol=n.lat) #obs.time <- netcdf.calendar(nc.obs) obs.time <- matrix(seq(as.Date("1998-01-01"), as.Date("1998-12-31"),1)) gcm.lon <- ncvar_get(nc.gcm, 'lon')-360 gcm.lat <- ncvar_get(nc.gcm, 'lat') gcm.lats <- matrix(gcm.lat, ncol=length(gcm.lat), nrow=length(gcm.lon), byrow=TRUE) gcm.lons <- matrix(gcm.lon, ncol=length(gcm.lat), nrow=length(gcm.lon)) gcm.lons.lats <- cbind(c(gcm.lons), c(gcm.lats)) gcm.time <- netcdf.calendar(nc.gcm) nc_close(nc.gcm) # Figure out which GCM grid boxes are associated with each fine-scale grid point # Confine search to 15 deg. x 15 deg. neighbourhood dxy <- 15 mdist <- function(x, y) apply(abs(sweep(data.matrix(y), 2, data.matrix(x), '-')), 1, sum) nn <- foreach(i = seq_along(obs.lons)) %dopar% { if((i %% 500)==0) cat(i, '') gcm.lims <- ((gcm.lons.lats[,1] >= (obs.lons[i]-dxy)) & (gcm.lons.lats[,1] <= (obs.lons[i]+dxy))) & ((gcm.lons.lats[,2] >= (obs.lats[i]-dxy)) & (gcm.lons.lats[,2] <= (obs.lats[i]+dxy))) gcm.lims <- which(gcm.lims) nn.min <- which.min(mdist(c(obs.lons[i], obs.lats[i]), gcm.lons.lats[gcm.lims,])) gcm.lims[nn.min] } nn <- unlist(nn) gridpoints <- sort(unique(nn)) cat('\n') # Spatially aggregate the fine-scale data to the GCM grid pr.aggregate <- matrix(NA, nrow=nrow(obs.time), ncol=length(gcm.lons)) i.starts <- sapply(split(seq_along(obs.time[,1]), obs.time[,1]), min) i.lengths <- sapply(split(seq_along(obs.time[,1]), obs.time[,1]), length) for(i in seq_along(i.starts)){ cat(obs.time[i.starts[i],], '\n') pr.obs <- ncvar_get(nc.obs, varid='r', start=c(1, 1, i.starts[i]), count=c(n.lon, n.lat, i.lengths[i])) dim(pr.obs) <- c(prod(dim(pr.obs)[1:2]), dim(pr.obs)[3]) pr.agg <- matrix(NA, nrow=i.lengths[i],ncol=length(gcm.lons)) all.agg <- foreach(j=1:length(gridpoints)) %dopar% { point <- gridpoints[j] cbind(apply(pr.obs[nn==point,], 2, mean, trim=0.1, na.rm=TRUE) ) } all.agg <- do.call(cbind, all.agg) pr.all.agg <- all.agg[,c(TRUE, FALSE, FALSE, FALSE)] pr.agg[,gridpoints] <- pr.all.agg pr.agg[is.nan(pr.agg)] <- NA pr.aggregate[i.starts[i]:(i.starts[i]+i.lengths[i]-1),] <- pr.agg } nc_close(nc.obs) save(gcm.lons, file=paste(output.dir, 'gcm.lons', output.suffix, '.RData', sep='')) save(gcm.lats, file=paste(output.dir, 'gcm.lats', output.suffix, '.RData', sep='')) save(gcm.time, file=paste(output.dir, 'gcm.time', output.suffix, '.RData', sep='')) save(obs.lons, file=paste(output.dir, 'obs.lons', output.suffix, '.RData', sep='')) save(obs.lats, file=paste(output.dir, 'obs.lats', output.suffix, '.RData', sep='')) save(obs.time, file=paste(output.dir, 'obs.time', output.suffix, '.RData', sep='')) save(pr.aggregate, file=paste(output.dir, 'pr.aggregate', output.suffix, '.RData', sep='')) [环境叙述]: https://imgur.com/nVXlvbb [关键字]: dim 遗失值 --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.122.136.23
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1533287357.A.49F.html







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:BuyTogether站内搜寻

TOP