Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Extracting values for specific lat long from netcdf

$
0
0

I'm trying to read into R a netCDF file. The netcdf chirps-v2.0.1981.days_p05.nc is downloaded from here:

ftp://ftp.chg.ucsb.edu/pub/org/chg/products/CHIRPS-2.0/global_daily/netcdf/p05/

This netCDF file describes daily rainfall globally as a function of longitude, latitude and has size of 1.1 GB

I also have a set of lon lat

dat <- structure(list(locatioID = paste0('ID', 1:16), lon = c(73.73, 86, 73.45, 86.41, 85.36, 81.95, 82.57, 75.66, 82.03, 
                          81.73, 85.66, 85.31, 81.03, 81.70, 87.03, 73.38), 
                        lat = c(24.59, 20.08, 22.61, 23.33, 23.99, 19.09, 18.85, 15.25, 26.78, 
                          16.63, 25.98, 23.28, 24.5, 21.23, 25.08, 21.11)), 
                  row.names = c(1L, 3L, 5L, 8L, 11L, 14L, 17L, 18L, 19L, 21L, 
                              23L, 26L, 29L, 32L, 33L, 35L), class = "data.frame")

library(ncdf4)  
library(raster)
temp <- nc_open("chirps-v2.0.1981.days_p05.nc")

precip = list()
precip$x = ncvar_get(temp, "longitude")
precip$y = ncvar_get(temp, "latitude")
precip$z = ncvar_get(temp, "precip", start=c(1, 1, 1), count=c(-1, -1, 1))
precip.r = raster(precip)
plot(precip.r)

I have two questions:

  • Can anyone explain to me what does start and count argument does? ?ncvar_get does not give me an intuitive feeling. If I want to create a raster of Julian day 252, which argument do I need to change?

  • How do I extract the daily rainfall values for all the 365 days for every lat lon in datsuch that I have a matrix/dataframe of 16 * 365 days


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>