datenetcdfcdo-climate

CDO - Resample netcdf files from monthly to daily timesteps


I have a netcdf file that has monthly global data from 1991 to 2000 (10 years).

Using CDO, how can I modify the netcdf from monthly to daily timesteps by repeating the monthly values each day of each month?

for eaxample,

convert from 
Month 1, value = 0.25

to 
Day 1, value = 0.25
Day 2, value = 0.25
Day 3, value = 0.25
....
Day 31, value = 0.25

convert from 
Month 2, value = 0.87

to 
Day 1, value = 0.87
Day 2, value = 0.87
Day 3, value = 0.87
....
Day 28, value = 0.87

Thanks

############## Update

my monthly netcdf has the monthly values not on the first day of each month, but in sparse order. e.g. on the 15th, 7th, 9th, etc.. however one value for each month.


Solution

  • I could not find a solution with CDO but I solved the issue with R, as follows:

    library(dplyr)
    library(ncdf4)
    library(reshape2)
    
    ## Read ncfile
    ncpath="~/my/path/"
    ncname="my_monthly_ncfile" 
    ncfname=paste(ncpath, ncname, ".nc", sep="")
    ncin=nc_open(ncfname)
    var=ncvar_get(ncin, "nc_var")
    
    ## melt ncfile
    var=melt(var)
    var=var[complete.cases(var), ] ## remove any NA
    
    ## split ncfile by gridpoint (lat and lon) into a list
    var=split(var, list(var$lat, var$lon))
    var=var[lapply(var,nrow)>0] ## remove any empty list element 
    
    ## create new list and replicate, for each gridpoint, each monthly value n=30 times
    var_rep=list()
    for (i in 1:length(var)) {
      var_rep[[i]]=data.frame(value=rep(var[[i]]$value, each=30))
    }