ClimateUnboxed
ClimateUnboxed

Reputation: 8077

Change time axis units from "years since" to "days since" in netcdf file

I have a netcdf file that someone passed me that uses "years since DATE" as the time units:

    double time(time) ;
    time:standard_name = "time" ;
    time:long_name = "time" ;
    time:calendar = "proleptic_gregorian" ;
    time:axis = "T" ;
    time:units = "years since 2000-1-1 00:00:00" ;

I want to change the units to "Days since" the same base date - Obviously the timevariable needs to be changed to be consistent. I was hoping for a solution using nco or cdo, but I am a bit stumped. (A python solution would also be okay, but in fact the reason I need to do this is that I can't actually get the file to open with xarray.)

Upvotes: 3

Views: 2362

Answers (1)

Charlie Zender
Charlie Zender

Reputation: 6322

Try NCO's udunits() function documented here:

ncap2 -O -s '@units="days since 2000-1-1 00:00:00";time=udunits(time,@units);time@units=@units' in.nc out.nc

Upvotes: 2

Related Questions