Project

General

Profile

Fill missing timesteps with NaNs

Added by Marte Hofsteenge about 4 years ago

Hi everyone,

I am analyzing some data from a netCDF file, but I encouter a problem. The data is structured such that I have output for lat/lon and per day. However, there are some gaps in the timeseries, some days are missing. Is it possible with a cdo statement to create a new file where the timeseries has data for each day, such that the previous missing dates have NaNs?

I am very happy to hear you suggestions,

Marte


Replies (1)

RE: Fill missing timesteps with NaNs - Added by Karin Meier-Fleischer about 4 years ago

Hi Marte,

you have to add each single timestep. If you know the missing timesteps you can write a shell script to create the files (with missing values) for the single timesteps.

For example:

#!/bin/ksh

cdo -setctomiss,1e20 -addc,1e20 -mulc,0 -seltimestep,1 infile.nc 1timestep.nc

cat << EOF > missing_timesteps.txt
2000-01-03,12:00:00,1day
2000-01-06,12:00:00,1day
2000-01-08,12:00:00,1day
EOF

set -A tsteps `tr -s '\n' ' ' < missing_timesteps.txt`

nt1=$(({#tsteps[@]}-1))

for i in $(seq 0 ${nt1}); do
   cdo -O -settaxis,${tsteps[$i]} 1timestep.nc tmp_${i}.nc
done

cdo -O -mergetime infile.nc tmp_*.nc  outfile_tsteps.nc

rm -rf tmp_*.nc

-Karin

    (1-1/1)