Project

General

Profile

How to add new date and date axis

Added by Suvarna Tikle 8 months ago

Hi all,
I have added date information sucessufuly using below command.
cdo -settaxis,2015-01-01,00:00:00,1day OC_Factor_ene_Jan.nc OC_Jan_2015.nc

Finally created one file consist of parameters from Dec2014 to Jan 2016(Ex DACCIWA_OC_2015.nc). I would like to add date and datesec like CAMS emissions in parameter list. I have tried with below steps but encountered error.

cdo setreftime,2018-01-01,00:00:00 date_n_datesec_2019.nc tmp.nc

ncks -A tmp.nc DACCIWA_OC_2015.nc

ERROR:ncks: WARNING nco_cpy_var_dfn_trv() reports variable "time" output type = NC_FLOAT does not equal input type = NC_DOUBLE. This is legal yet usually ill-advised when appending variables (i.e., with -A). Writing values into slots created for a different type is begging for trouble (e.g., data corruption, truncation, gingivitis).

Can anyone please help to resolve issue?.

Thanking you.
Best regards,
Suvarna


Replies (12)

RE: How to add new date and date axis - Added by Suvarna Tikle 8 months ago

Correct command is cdo setreftime,2014-01-01,00:00:00 date_n_datesec_2019.nc tmp.nc. date_n_datesec_2019.nc consist of date from Dec2018 to Jan 2020. So I just tried to change date. Is this right way?

RE: How to add new date and date axis - Added by Ralf Mueller 8 months ago

hi Suvarna!
I think the input file is needed for further help. can you upload it? or post a download link maybe?

cheers
ra;lf

RE: How to add new date and date axis - Added by Suvarna Tikle 8 months ago

Hi Ralf,
Please find attached sample file.
I also tried with other approach of nco.
command ncap2 -s 'date=20200101' -s 'datesec=0' DC_BC_tro_2019_%.nc test.nc but no error no output.

Best regards,
Suvarna

RE: How to add new date and date axis - Added by Suvarna Tikle 8 months ago

Hi Ralf,
Afraid to ask, Did you get time to look into the error.

Suvarna

RE: How to add new date and date axis - Added by Ralf Mueller 8 months ago

hi Survarna!

sorry, I missed your message from last week.

What you want is two additional variables? or do you want to change the existing time axis?

RE: How to add new date and date axis - Added by Suvarna Tikle 8 months ago

I want additional variables date and datesec like CAMS format.

RE: How to add new date and date axis - Added by Ralf Mueller 8 months ago

Here is my best try:

  1. create a separate file with the new constants:
    ncap2 -s 'date=20200101;datesec=0' dates.nc
  2. append this to the original file:
    ncks -A dates.nc DC_BC_tro_2019__.nc

or do you want something like?

       int date(time) ;
                date:long_name = "current date (YYYYMMDD)" ;
        int datesec(time) ;
                datesec:long_name = "current seconds of current date" ;

RE: How to add new date and date axis - Added by Ralf Mueller 8 months ago

ncap2 -s 'date=int(time);date(:)=20013232;datesec=int(time);datesec(:)=0' DC_WORK.nc outfile.nc 

would do somehting like that, but keeps the attributed from the time variable...

RE: How to add new date and date axis - Added by Suvarna Tikle 8 months ago

Thanks. The third option works but it added like below-
int date(time) ;
date:axis = "T" ;
date:calendar = "gregorian" ;
date:standard_name = "time" ;
date:units = "days since 2010-01-01" ;
int datesec(time) ;
datesec:axis = "T" ;
datesec:calendar = "gregorian" ;
datesec:standard_name = "time" ;
datesec:units = "days since 2010-01-01" ;

We want to add in this format of CAMS
int date(time) ;
date:long_name = "date" ;
date:units = " " ;
date:format = "YYYYMMDD" ;
int datesec(time) ;

RE: How to add new date and date axis - Added by Ralf Mueller 8 months ago

#!/bin/bash            

set -x                 

infile=$1              

# copy original        
copy="copy_$(basename ${infile})" 
cp $1 ${copy}          

# remove previous temperoray data
[[ -f _tmp.nc ]] && rm _tmp.nc

# add placeholder for date
ncap2 -s 'date=int(time/time);datesec=int(time/time)' ${copy} _tmp.nc

# remove wrong attributes
ncatted -a ,date,d,, _tmp.nc
ncatted -a ,datesec,d,, _tmp.nc

# remove previous output
[[ -f DC_with_date.nc ]] && rm DC_with_date.nc
#                                                                                                                                                                                                                                                              
# set the values coording to the input file
cdo -aexpr,'date=cdate()*1;datesec=int(csecond()*1)' _tmp.nc DC_with_date.nc

This should do it

RE: How to add new date and date axis - Added by Ralf Mueller 8 months ago

for the right attributes for date and datesec you can use ncatted. I missed that detail

RE: How to add new date and date axis - Added by Suvarna Tikle 8 months ago

Thanks a lot. I will try.

    (1-12/12)