I am trying to merge multiple NetCDFs containing 4 dimensions (lat, lon, depth, time) into one NetCDF. Each contain the same variable (sea surface temperature or 'thetao') and the same depth value and coordinates. The only differing parameter is time and values of thetao. I have some overlapping time values too. I am working with monthly data of multiple years. So far I have the following code. But it is giving me NA values in my final array. Thank you so much for the help!
nc_files<- list.files(path = "C:/Users/dell/OneDrive - UGent/Thesis/NetCDFs/sst")
#empty lists
sst_all<- list()
dates_all<- c()
#looping through each file
for (i in seq_along(nc_files)) {
#open netcdf
nc<- open.nc(nc_files[i])
var.get.nc(nc, "thetao") #to check variable exsists
#read dimensions/variables
lon<- var.get.nc(nc, "longitude")
lat<- var.get.nc(nc, "latitude")
depth<- var.get.nc(nc, "depth")
time<- var.get.nc(nc, "time")
time_units<- att.get.nc(nc, "time", "units")
date <- utcal.nc(time_units, time, "c") # Transform times to POSIXct
dates_all <- format(date, format="%Y-%m")
#read sst
sst<- var.get.nc(nc, "thetao")
sst_all[[i]] <- sst
close.nc(nc)
}
#combining all SST arrays
sst_combined <- abind::abind(sst_all, along=4)
print(head(dates_all))
I tried looping all the 3 NetCDFs but the final NetCDF seems to have no values. Ultimately, I want one NetCDF or one .CSV with data from all 3 NetCDFs. Thank you!
open.ncsuggests it is not the recentncdf4, and its predecessorncdfis archived and no longer available. There are other packages, but I'm not sure which. Questions here on SO do much better if they are fully reproducible, including sample data and clearly listing non-base packages, etc. Please add context. Thanks!