mergeweathercdo-climatenco

how to add time steps to the beginning and end of a time series with cdo/nco?


Is there any command in cdo or nco (which I am not very familiar with) to add some timesteps at the beginning of a long time series? Let's say I have a long time series (1959-2021) within summer season (JJA) and I want to add from 24-30 August 2021 at the beginning of 1959 and from 1-8 June at the end of 2021. I was thinking to selec the days with cdo but then I am not sure how to do this with a cdo command (cdo mergetime I think will merge it at the end only), so I was wondering if there is any command in nco or even cdo that can do this?

Thanks in advance !!

add days at the beginning of a time series and at the end.


Solution

  • The question needs a little clarification, you mean that the 1-8 June is from 1959 and you want to post it to the end of the series? In other words you want to make the series cyclic? And what is the frequency of the data, daily? hourly? And also when you paste it to the start, you mean you want it pasted to 24-30 aug 1958, or the last days of May in 1959, in which case that will be your only May days? Please try to be specific and detailed when posting. Think of your question as a cake recipe you need to specify, we need to know the ingredients :-)

    So, guessing what you want to do, and assuming hourly data frequency... I think you could do this by selecting the steps you want, resetting the time axis and then doing mergetime (here I just paste the end to the start, duplicate for the other direction):

    cdo seldate,2021-08-24,2021-08-30 in.nc out1.nc
    cdo settaxis,1958-08-24,00:00:00,1hour out1.nc out2.nc
    cdo mergetime out2.nc in.nc merged.nc 
    

    An alternative, if you want to shift the end to 1958, same dates is to use shifttime, then the code is :

    cdo seldate,2021-08-24,2021-08-30 in.nc out1.nc
    cdo shifttime,-63years out1.nc out2.nc
    cdo mergetime out2.nc in.nc merged.nc 
    

    It seems a strange thing to do though... I'm guessing from your date range that you are playing with ERA5 reanalysis. If you want to do this because you want to apply a running mean and don't want to get a shorter output, then it is more appropriate to pad the data at the start with the first x days repeated, same thing if you want to apply an FFT.