Project

General

Profile

How to create a 'time' variable in the existing netcdf file?

Added by Sam United almost 7 years ago

I have a file(file1) with three dimensions(lon,lat,time), however, it doesn't include the 'time'variable. How can i create 'time' variable in the file1, whose 'time'variable is the same with file2. thank you.
file1:
dimensions:
lon = 144 ;
lat = 96 ;
time = 3768 ;
variables:
float BAF ;
BAF:long_name = "burnt area fraction" ;
BAF:unit = "%/d" ;
float lon(lon) ;
lon:missing_value = 1.e+36f ;
lon:units = "degrees_east" ;
lon:long_name = "coordinate longitude" ;
lon:_FillValue = 1.e+36f ;
float lat(lat) ;
lat:missing_value = 1.e+36f ;
lat:units = "degrees_north" ;
lat:long_name = "coordinate latitude" ;
lat:_FillValue = 1.e+36f ;
data:

BAF =
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

file2:
dimensions:
longitude = 192 ;
latitude = 96 ;
nv = 2 ;
time = UNLIMITED ; // (3768 currently)
variables:
double longitude(longitude) ;
longitude:standard_name = "longitude" ;
longitude:long_name = "longitude" ;
longitude:units = "degrees_east" ;
longitude:axis = "X" ;
double latitude(latitude) ;
latitude:standard_name = "latitude" ;
latitude:long_name = "latitude" ;
latitude:units = "degrees_north" ;
latitude:axis = "Y" ;
int time(time) ;
time:standard_name = "time" ;
time:long_name = "time" ;
time:units = "days since 1700-01-01 00:00:00Z" ;
time:calendar = "gregorian" ;
time:bounds = "time_bnds" ;
int time_bnds(time, nv) ;
time_bnds:units = "days since 1700-01-01 00:00:00Z" ;
time_bnds:calendar = "gregorian" ;
float cVeg(time, latitude, longitude) ;
cVeg:long_name = "Carbon in vegetation" ;
cVeg:units = "kg(C) m-2" ;
cVeg:cell_methods = "time: mean" ;
cVeg:_FillValue = 9.e+36f ;
cVeg:history = "molCtokgC*(In.veg{160}+In.veg{161}+In.veg{162})" ;


Replies (6)

RE: How to create a 'time' variable in the existing netcdf file? - Added by Karin Meier-Fleischer almost 7 years ago

Hi Sam,

how did you create that file? Your first file has a variable BAF which is neither depending on time, lat nor lon. Is it possible to upload both files or a subset?

-Karin

RE: How to create a 'time' variable in the existing netcdf file? - Added by Sam United almost 7 years ago

Hi Karin, The file is too large to upload, how can i just extract part of file?
this is the file1 variables:
float BAF ;
BAF:long_name = "burnt area fraction" ;
BAF:unit = "%/d" ;
float lon(lon) ;
lon:missing_value = 1.e+36f ;
lon:units = "degrees_east" ;
lon:long_name = "coordinate longitude" ;
lon:_FillValue = 1.e+36f ;
float lat(lat) ;
lat:missing_value = 1.e+36f ;
lat:units = "degrees_north" ;
lat:long_name = "coordinate latitude" ;
lat:_FillValue = 1.e+36f ;

RE: How to create a 'time' variable in the existing netcdf file? - Added by Karin Meier-Fleischer almost 7 years ago

IMO, there is no way to do that with CDO but you can add a time dimension with NCO's ncap2 or ncecat command-line function.
[[https://sourceforge.net/p/nco/discussion/9830/thread/cee4e1ad/]]

Good luck!
-Karin

RE: How to create a 'time' variable in the existing netcdf file? - Added by Ralf Mueller almost 7 years ago

You can do it with CDO like this

cdo -f nc -settaxis,2001-01-01,12:00:00,1day -topo t.nc 

topo creates a 0.5deg topography without any time axis. settaxis add a time axis. If BAF does not have a native grid, you should create a single-point grid - there should be some lon/lat dimension in BAF

RE: How to create a 'time' variable in the existing netcdf file? - Added by Karin Meier-Fleischer almost 7 years ago

Hi Ralf,

I didn't expect that settaxis really creates a time dimension because the settaxis description in the documentation gives the impression of 'overwriting existing time axis':

This module sets the time axis or part of the time axis. Which part of the time axis is overwritten depends on the chosen operator.

-Karin ;)

RE: How to create a 'time' variable in the existing netcdf file? - Added by Ralf Mueller almost 7 years ago

docu will be updated in the next CDO release - thx for the hint!

cheers
ralf

    (1-6/6)