Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

r - Extracting gridded (netcdf) climate data for an entire watershed polygon

My goal is to extract precipitation data from the Daymet database (https://daymet.ornl.gov/) for each of my 68 watershed polygons. I was able to use the ncdf4 package to download the data:

download_daymet_ncss(location = c(53.5,-116.6, 48,-98),
                     start = 1992,
                     end = 2000,
                     param = "prcp",
                     path = "./Daymet gridded data/Precip_raw")#download the data

I realize this is quite a large area and might be part of the issue.

Once the data is downloaded, the challenge begins. I've tried two approaches, the first to aggregate the data into annual values (using daymet_grid_agg from the daymetr package). But then extracting the correct areas from the raster generated is challenging (and I haven't been able to do successfully). I then tried to use the RavenR package to generate a grid overlay from a netcdf (rvn_netcdf_to_gridshp).

fn<-"prcp_daily_1992_ncss.nc"
ncfile<-nc_open(fn)
outshp<-rvn_netcdf_to_gridshp(ncfile, projID = 4326)

This fails completely - either RStudio freezes, cannont allocate 2.7 GB, or the shapefile is empty. I have tried increasing memory size, but then R is just running forever and nothing seems to happen.

Next, I tried this simple approach (as per https://www.researchgate.net/post/How-to-get-data-only-within-shapefile-boundary-from-a-netcdf-data-file-in-R-software):

shp<-st_read(file.choose())

data<-brick(file.choose()) 

crs(data) <- "+proj=lcc +lon_0=-90 +lat_1=33 +lat_2=45" 

output<-raster::mask(data, shp) 

The output brick raster is full of NAs...

I have made the downloaded netcdf quite a bit smaller, but none of these approaches seem to work... And yes, my data are gridded (unlike in this case: How to extract NetCDF data frame by region using a polygon shapefile)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...