Project

General

Profile

Incorrect dates when selecting a season

Added by Lyndon Mark Olaguera almost 4 years ago

Dear CDO-experts,

I would like to select the NDJFM season from a daily netcdf file (rain_1979-1980.nc)
Where ND is for the current year, while the JFM is for the succeding year.

I use the following commands:

cdo selmon,8,9,10,11,12 -shifttime,-3mo -selyear,1980 rain_1979-1980.nc test2.nc

when I display the date:

1979-10-01  1979-10-02  1979-10-03  1979-10-04  1979-10-05  1979-10-06  1979-10-07  1979-10-08  1979-10-09  1979-10-10  1979-10-11  1979-10-12  1979-10-13  1979-10-14  1979-10-15  1979-10-16  1979-10-17  1979-10-18  1979-10-19  1979-10-20  1979-10-21  1979-10-22  1979-10-23  1979-10-24  1979-10-25  1979-10-26  1979-10-27  1979-10-28  1979-10-29  1979-10-30  1979-10-31  1979-11-01  1979-11-02  1979-11-03  1979-11-04  1979-11-05  1979-11-06  1979-11-07  1979-11-08  1979-11-09  1979-11-10  1979-11-11  1979-11-12  1979-11-13  1979-11-14  1979-11-15  1979-11-16  1979-11-17  1979-11-18  1979-11-19  1979-11-20  1979-11-21  1979-11-22  1979-11-23  1979-11-24  1979-11-25  1979-11-26  1979-11-27  1979-11-28  1979-11-29  1979-12-01  1979-12-02  1979-12-03  1979-12-04  1979-12-05  1979-12-06  1979-12-07  1979-12-08  1979-12-09  1979-12-10  1979-12-11  1979-12-12  1979-12-13  1979-12-14  1979-12-15  1979-12-16  1979-12-17  1979-12-18  1979-12-19  1979-12-20  1979-12-21  1979-12-22  1979-12-23  1979-12-24  1979-12-25  1979-12-26  1979-12-27  1979-12-28  1979-12-29  1979-12-30  1979-12-31  

1980-08-01  1980-08-02  1980-08-03  1980-08-04  1980-08-05  1980-08-06  1980-08-07  1980-08-08  1980-08-09  1980-08-10  1980-08-11  1980-08-12  1980-08-13  1980-08-14  1980-08-15  1980-08-16  1980-08-17  1980-08-18  1980-08-19  1980-08-20  1980-08-21  1980-08-22  1980-08-23  1980-08-24  1980-08-25  1980-08-26  1980-08-27  1980-08-28  1980-08-29  1980-08-30  1980-09-01  1980-09-02  1980-09-03  1980-09-04  1980-09-05  1980-09-06  1980-09-07  1980-09-08  1980-09-09  1980-09-10  1980-09-11  1980-09-12  1980-09-13  1980-09-14  1980-09-15  1980-09-16  1980-09-17  1980-09-18  1980-09-19  1980-09-20  1980-09-21  1980-09-22  1980-09-23  1980-09-24  1980-09-25  1980-09-26  1980-09-27  1980-09-28  1980-09-29  1980-09-30  1980-10-01

Why are the dates incorrect?

This should be 1979 November to 1980 of March.

Any idea on how to do this correctly in CDO?


Replies (10)

RE: Incorrect dates when selecting a season - Added by Brendan DeTracey almost 4 years ago

You want to shift time before you select year. And you will want to shifttime the other direction afterwards.

cdo -shifttime,3mo -selmon,8,9,10,11,12 -selyear,1979 -shifttime,-3mo rain_1979-1980.nc test2.nc

Is my guess. Can't test without your data file.

RE: Incorrect dates when selecting a season - Added by Ralf Mueller almost 4 years ago

hi!

@Brendan DeTracey: perfect answer

you can create data on the fly with CDO

cdo -sinfov -settaxis,1979-01-01,12:00:00,1days -seq,1,700
cdo(1) settaxis: Process started
cdo(2) seq: Process started
   File format : GRIB
    -1 : Institut Source   T Steptype Levels Num    Points Num Dtype : Parameter name
     1 : unknown  unknown  v instant       1   1         1   1  -1   : seq           
   Grid coordinates :
     1 : lonlat                   : points=1 (1x1)
                              lon : 0 degrees_east
                              lat : 0 degrees_north
   Vertical coordinates :
     1 : surface                  : levels=1
   Time coordinate :  unlimited steps
     RefTime =  1979-01-01 12:00:00  Units = days  Calendar = proleptic_gregorian
  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss
  1979-01-01 12:00:00  1979-01-02 12:00:00  1979-01-03 12:00:00  1979-01-04 12:00:00
  1979-01-05 12:00:00  1979-01-06 12:00:00  1979-01-07 12:00:00  1979-01-08 12:00:00
  1979-01-09 12:00:00  1979-01-10 12:00:00  1979-01-11 12:00:00  1979-01-12 12:00:00
  1979-01-13 12:00:00  1979-01-14 12:00:00  1979-01-15 12:00:00  1979-01-16 12:00:00
  1979-01-17 12:00:00  1979-01-18 12:00:00  1979-01-19 12:00:00  1979-01-20 12:00:00
  1979-01-21 12:00:00  1979-01-22 12:00:00  1979-01-23 12:00:00  1979-01-24 12:00:00
  1979-01-25 12:00:00  1979-01-26 12:00:00  1979-01-27 12:00:00  1979-01-28 12:00:00
  1979-01-29 12:00:00  1979-01-30 12:00:00  1979-01-31 12:00:00  1979-02-01 12:00:00
  1979-02-02 12:00:00  1979-02-03 12:00:00  1979-02-04 12:00:00  1979-02-05 12:00:00
  1979-02-06 12:00:00  1979-02-07 12:00:00  1979-02-08 12:00:00  1979-02-09 12:00:00
  1979-02-10 12:00:00  1979-02-11 12:00:00  1979-02-12 12:00:00  1979-02-13 12:00:00
  1979-02-14 12:00:00  1979-02-15 12:00:00  1979-02-16 12:00:00  1979-02-17 12:00:00
  1979-02-18 12:00:00  1979-02-19 12:00:00  1979-02-20 12:00:00  1979-02-21 12:00:00
  1979-02-22 12:00:00  1979-02-23 12:00:00  1979-02-24 12:00:00  1979-02-25 12:00:00
  1979-02-26 12:00:00  1979-02-27 12:00:00  1979-02-28 12:00:00  1979-03-01 12:00:00
   ................................................................................
   ..................................................
  1980-10-02 12:00:00  1980-10-03 12:00:00  1980-10-04 12:00:00  1980-10-05 12:00:00
  1980-10-06 12:00:00  1980-10-07 12:00:00  1980-10-08 12:00:00  1980-10-09 12:00:00
  1980-10-10 12:00:00  1980-10-11 12:00:00  1980-10-12 12:00:00  1980-10-13 12:00:00
  1980-10-14 12:00:00  1980-10-15 12:00:00  1980-10-16 12:00:00  1980-10-17 12:00:00
  1980-10-18 12:00:00  1980-10-19 12:00:00  1980-10-20 12:00:00  1980-10-21 12:00:00
  1980-10-22 12:00:00  1980-10-23 12:00:00  1980-10-24 12:00:00  1980-10-25 12:00:00
  1980-10-26 12:00:00  1980-10-27 12:00:00  1980-10-28 12:00:00  1980-10-29 12:00:00
  1980-10-30 12:00:00  1980-10-31 12:00:00  1980-11-01 12:00:00  1980-11-02 12:00:00
  1980-11-03 12:00:00  1980-11-04 12:00:00  1980-11-05 12:00:00  1980-11-06 12:00:00
  1980-11-07 12:00:00  1980-11-08 12:00:00  1980-11-09 12:00:00  1980-11-10 12:00:00
  1980-11-11 12:00:00  1980-11-12 12:00:00  1980-11-13 12:00:00  1980-11-14 12:00:00
  1980-11-15 12:00:00  1980-11-16 12:00:00  1980-11-17 12:00:00  1980-11-18 12:00:00
  1980-11-19 12:00:00  1980-11-20 12:00:00  1980-11-21 12:00:00  1980-11-22 12:00:00
  1980-11-23 12:00:00  1980-11-24 12:00:00  1980-11-25 12:00:00  1980-11-26 12:00:00
  1980-11-27 12:00:00  1980-11-28 12:00:00  1980-11-29 12:00:00  1980-11-30 12:00:00
cdo(2) seq: 
cdo(1) settaxis: Processed 700 values from 1 variable over 700 timesteps.
cdo    sinfon: Processed 1 variable over 700 timesteps [0.01s 39MB].
Fir issues along the time axis this does the job mostly.

cheers
ralf

RE: Incorrect dates when selecting a season - Added by Lyndon Mark Olaguera almost 4 years ago

Hi Ralf,

I tried to follow Brendan's suggestion but still not getting the correct dates.
I am uploaded the smallest data set that I have in my dropbox.

I want to select the November to December of 1979 and combine it with the January to March of 1980.
I will be applying this for a netcdf file (one file) that contains all years 1979-2019.
I will be selecting the NDJFM for the 40 winters from 1979/1980 to 2018/2019.

https://www.dropbox.com/s/z59829sdnoppeae/test.nc?dl=0

Thank you for the help!

RE: Incorrect dates when selecting a season - Added by Ralf Mueller almost 4 years ago

the question is HOW did you apply this for all the years?

RE: Incorrect dates when selecting a season - Added by Ralf Mueller almost 4 years ago

ok, this is what I get with your test.nc input:

cdo -s sinfov -monmean -shifttime,3mo -selmon,8,9,10,11,12 -selyear,1979 -shifttime,-3mo test.nc
   File format : NetCDF
    -1 : Institut Source   T Steptype Levels Num    Points Num Dtype : Parameter name
     1 : unknown  unknown  v avg           1   1    100800   1  F32  : precip        
     2 : unknown  unknown  v avg           1   1    100800   1  F32  : rstn          
   Grid coordinates :
     1 : lonlat                   : points=100800 (360x280)
                        longitude : 60.125 to 149.875 by 0.25 degrees_east
                         latitude : -14.875 to 54.875 by 0.25 degrees_north
   Vertical coordinates :
     1 : surface                  : levels=1
   Time coordinate :  unlimited steps
     RefTime =  1951-01-01 00:00:00  Units = days  Calendar = standard  Bounds = true
  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss
  1979-11-15 12:00:00  1979-12-16 00:00:00  1980-01-16 00:00:00  1980-02-15 00:00:00
  1980-03-16 00:00:00
I just added monmean for better visualization of the time axis. looks good to me - isn't this want you wanted to get?

RE: Incorrect dates when selecting a season - Added by Ralf Mueller almost 4 years ago

you could upload the whole data set reduced to a single point, but that would essentially be only a replacement for -settaxis,1979-01-01,12:00:00,1days -seq,1,15000. So I think it's ok to go on testing with this instead of your upload:

for y in $(cdo -s showyear -settaxis,1979-01-01,12:00:00,1days -seq,1,15000 ); do echo $y; cdo -s -showtimestamp -monmean -shifttime,3mo -selmon,8,9,10,11,12 -selyear,${y} -shifttime,-3mo -settaxis,1979-01-01,12:00:00,1days -seq,1,15000; done 
gives this
1979
  1979-11-16T00:00:00  1979-12-16T12:00:00  1980-01-16T12:00:00  1980-02-15T12:00:00  1980-03-16T12:00:00
1980
  1980-11-16T00:00:00  1980-12-16T12:00:00  1981-01-16T12:00:00  1981-02-15T00:00:00  1981-03-16T12:00:00
1981
  1981-11-16T00:00:00  1981-12-16T12:00:00  1982-01-16T12:00:00  1982-02-15T00:00:00  1982-03-16T12:00:00
1982
  1982-11-16T00:00:00  1982-12-16T12:00:00  1983-01-16T12:00:00  1983-02-15T00:00:00  1983-03-16T12:00:00
1983
  1983-11-16T00:00:00  1983-12-16T12:00:00  1984-01-16T12:00:00  1984-02-15T12:00:00  1984-03-16T12:00:00
1984
  1984-11-16T00:00:00  1984-12-16T12:00:00  1985-01-16T12:00:00  1985-02-15T00:00:00  1985-03-16T12:00:00
1985
  1985-11-16T00:00:00  1985-12-16T12:00:00  1986-01-16T12:00:00  1986-02-15T00:00:00  1986-03-16T12:00:00
1986
  1986-11-16T00:00:00  1986-12-16T12:00:00  1987-01-16T12:00:00  1987-02-15T00:00:00  1987-03-16T12:00:00
1987
  1987-11-16T00:00:00  1987-12-16T12:00:00  1988-01-16T12:00:00  1988-02-15T12:00:00  1988-03-16T12:00:00
1988
  1988-11-16T00:00:00  1988-12-16T12:00:00  1989-01-16T12:00:00  1989-02-15T00:00:00  1989-03-16T12:00:00
1989
  1989-11-16T00:00:00  1989-12-16T12:00:00  1990-01-16T12:00:00  1990-02-15T00:00:00  1990-03-16T12:00:00
1990
  1990-11-16T00:00:00  1990-12-16T12:00:00  1991-01-16T12:00:00  1991-02-15T00:00:00  1991-03-16T12:00:00
1991
  1991-11-16T00:00:00  1991-12-16T12:00:00  1992-01-16T12:00:00  1992-02-15T12:00:00  1992-03-16T12:00:00
1992
  1992-11-16T00:00:00  1992-12-16T12:00:00  1993-01-16T12:00:00  1993-02-15T00:00:00  1993-03-16T12:00:00
.....

last year is a problem, but lets skip this for now.

RE: Incorrect dates when selecting a season - Added by Lyndon Mark Olaguera almost 4 years ago

Thanks Ralf!

Exactly what I am looking for.

Sincerely,

Lyndz

RE: Incorrect dates when selecting a season - Added by Ralf Mueller almost 4 years ago

well, the hard part was done by Brendan - so let's share thx with him

Have a good week, guys!

RE: Incorrect dates when selecting a season - Added by Lyndon Mark Olaguera almost 4 years ago

Thanks @Branden.

I'll figure it out using bash later to apply this for all years.

But before I did this manually like this:

cdo mergetime -selmon,11,12 -selyear,1979 aphro_1951-2015.nc -selmon,1,2,3 -selyear,1980 aphro_1951-2015.nc winter_NDFJM_1979-1980.nc
cdo mergetime -selmon,11,12 -selyear,1980 aphro_1951-2015.nc -selmon,1,2,3 -selyear,1981 aphro_1951-2015.nc winter_NDFJM_1980-1981.nc
cdo mergetime -selmon,11,12 -selyear,1981 aphro_1951-2015.nc -selmon,1,2,3 -selyear,1982 aphro_1951-2015.nc winter_NDFJM_1981-1982.nc
cdo mergetime -selmon,11,12 -selyear,1982 aphro_1951-2015.nc -selmon,1,2,3 -selyear,1983 aphro_1951-2015.nc winter_NDFJM_1982-1983.nc
..

Then merge at the end.

That one line command will save me space and time.

--Lyndz

RE: Incorrect dates when selecting a season - Added by Brendan DeTracey almost 4 years ago

Calling dibs on the bewildered octopus.

    (1-10/10)