Closed BenCretois closed 1 year ago
Yes. But retrieve
assumes a range of longitudes, latitudes and times. Also, the netCDF file uses a different convention to the CF.
You can use ```r2 library(esd) seNorge.thredds <- "https://thredds.met.no/thredds/dodsC/senorge/seNorge_2018/Archive/seNorge2018_2006.nc" ncid <- nc_open(seNorge.thredds) names(ncid$var) lon <- ncvar_get(ncid,"longitude") lat <- ncvar_get(ncid,"latitude") tim <- ncvar_get(ncid,"time") image(lon) image(lat)
...
We have not managed to complete `retrieve` for reading rotated grids or UTM.
Thanks for your answer! I also found another way which might be a bit more straightforward and avoid working with zoo
objects. The solution relies on the stars
package. I am pasting it the snippet here in case it can be useful for others:
# fetch the ncdf file for a specific year
url=paste0('NETCDF:/vsicurl/https://thredds.met.no/thredds/fileServer/senorge/seNorge_2018/Archive/seNorge2018_', year,'.nc')
# Read the netcdf file from the url
netcdf_file=stars::read_stars(url, sub='rr', proxy=TRUE)
# Transform the dataset into an sf object
data_st <- data %>% st_as_sf(.,
coords = c("longitude", "latitude"),
crs=4326)
# Reproject the CRS to match the CRS of the netcdf
data_st <- st_transform(data_st, crs=st_crs(netcdf_file))
data_st$rr <- st_extract(netcdf_file, data_st, time_column="date")
I have a set of coordinates (reg1, example dataframe below) that I use to retrieve values from a netcdf file hosted on senorge:
As I understand
rr
is azoo
object containing the values for the temperate for the different dates specified.I have no experience working with
zoo
objects and I was wondering if theesd
package has a function for extracting the values contained inrr
for a specific point? That would be the equivalent ofextract
from the raster package.