My question builds further upon an earlier post How to extract data from a RasterBrick? . I have multiple netCDF files with temperature data at lat, long and depth for different time periods (6 months each). I also have a data frame with lat, long and time for with I would like to extract sea surface temp data out of the netcdf files. Before I extract this data I would like to convert and merge all the netcdf files to one RaterBrick (which is easier to use). When I use a loop to 'brick' and 'merge' the files it creates a RasterLayer object with only one layer in stead of the Raster Brick that I was expecting. I have search the internet but so far I can't find the proper solution for this problem.
I'm quit new to using loops so I'm sorry in advance if I'm asking a question with a really easy answer but I could really use some advice.
Here is what I have done so far:
Create a file list of all the netcdf files.
#Open all files, creats a list of 12 files
files= list.files('copernicus/daily_temp/',pattern='*.nc', full.names=TRUE)
Try to loop over the file list to create bricks. Merge these multi layer bricks together to form one large RasterBrick with sea surface (level=1) temperature data per day.
# Loop over files to creat a RasterBrick of temp at SST
for(i in 1:length(files)) {
temp <- brick(files[i], varname="votemper",level=1)
temp.brick<-merge(temp)}
# Look what one brick is build out of
> temp
class : RasterBrick
dimensions : 375, 297, 111375, 184 (nrow, ncol, ncell, nlayers)
resolution : 0.11111, 0.06667 (x, y)
extent : -19.94444, 13.05523, 40.03333, 65.03459 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : C:\Users\PFA\Dropbox\HOM\copernicus\daily_temp\daily_temp_2003_2.nc
names : X2003.07.01, X2003.07.02, X2003.07.03, X2003.07.04, X2003.07.05, X2003.07.06, X2003.07.07, X2003.07.08, X2003.07.09, X2003.07.10, X2003.07.11, X2003.07.12, X2003.07.13, X2003.07.14, X2003.07.15, ...
Date : 2003-07-01, 2003-12-31 (min, max)
varname : votemper
level : 1
# Look at what the merged bricks are build out of
class : RasterLayer
dimensions : 375, 297, 111375 (nrow, ncol, ncell)
resolution : 0.11111, 0.06667 (x, y)
extent : -19.94444, 13.05523, 40.03333, 65.03459 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names : layer
values : 280.677, 297.669 (min, max)
nlayers(temp)
say? – Roman Luštrik