2014-05-19 7 views
0

저는 R에 익숙하며 며칠 동안 R로 그리드를 그리려고하지만 실패했습니다. 내 ncdf 파일의 치수 길이가 다르기 때문에 내 지역에서 2013 년 eCMW ERA 중간에서 강수량 데이터를 받았고 플롯 그리드가 없습니다. 누군가가 나를 도울 수 있다면 정말 좋을 것입니다. Google 드라이브의ncdf 파일의 치수 길이가 다릅니다

내 .nc 데이터 : https://drive.google.com/file/d/0B0X5ssvd281gUnIyUkZHRGs1a0k/edit?usp=sharing

내가 사용하는 코드 : 나는 지오 netCDF의 파일을 처리하지 않은 도움 :

+0

없음 크로스 게시 ! http://gis.stackexchange.com/questions/97371/dimension-length-of-netcdf-file-differs – mdsumner

+0

제 의견으로는 프로그래밍 질문이므로이 질문에 답하겠습니다. – Beasterfield

답변

0

에 대한

> library(ncdf) 
> precipitation = open.ncdf("precipitation_2013.nc") 
> lonmat = get.var.ncdf(nc= precipitation,varid="longitude") 
> latmat = get.var.ncdf(nc= precipitation,varid="latitude") 
> plot(lonmat, latmat, main= "Precipitation grid 2013") 

감사합니다,하지만 때 실제로 어떤 일이 벌어지는지를 보시오.

print(precipitation) 
[1] "file ~/Downloads/precipitation_2013.nc has 3 dimensions:" 
[1] "longitude Size: 8" 
[1] "latitude Size: 5" 
[1] "time Size: 730" 
[1] "------------------------" 
[1] "file ~/Downloads/precipitation_2013.nc has 1 variables:" 
[1] "short tp[longitude,latitude,time] Longname:Total precipitation Missval:-32767" 

실제 데이터에는, latitudetime의 세 가지 치수를 갖는 short 유형의 변수가 있습니다. 차원 값은 별도의 변수로 저장되며 값을 수집하는 변수는 차원 만 참조합니다. 그것을 무엇, 당신이 실제로 당신은 실제 변수를 추출하여 데이터를 포함 할 수있는 값

> latmat 
[1] 60.0 58.5 57.0 55.5 54.0 
> lonmat 
[1] 19.5 21.0 22.5 24.0 25.5 27.0 28.5 30.0 

을 가진 경우 플롯하려는 : 그래서 질문 질문 netCDF의 또는 지리 정보 시스템의 독립적 인 긴 형식으로 가져오고 할당 치수 값을 결과 data.frame에 :

library(reshape2) 
tp.molten <- melt(get.var.ncdf(nc= precipitation,varid="tp"), varnames=c("longitude", "latitude", "time")) 
tp.molten$longitude <- lonmat[tp.molten$longitude] 
tp.molten$latitude <- lonmat[tp.molten$latitude ] 
tp.molten$time<- get.var.ncdf(nc= precipitation,varid="time")[tp.molten$time ] 

close.ncdf(precipitation) # don't forget 

head(tp.molten) 
longitude latitude time  value 
1  19.5  19.5 990564 0.002813700 
2  21.0  19.5 990564 0.004143370 
3  22.5  19.5 990564 0.006473583 
4  24.0  19.5 990564 0.008655690 
5  25.5  19.5 990564 0.007778240 
6  27.0  19.5 990564 0.005223891 

지금 당신은 예를 들어 하나 개의 평가시기하여이 데이터를 부분 집합 수와 경도 - 위도 - 그리드에이 음모

,451,515,
library(ggplot2) 
ggplot(data = tp.molten[ tp.molten$time == 992052, ], aes(x = latitude, y = longitude, fill = value)) + 
    geom_raster() 

enter image description here