3

I downloaded daily TRMM 3B42 data for a few days from https://disc.gsfc.nasa.gov/datasets. The filenames are of the form 3B42_Daily.yyyymmdd.7.nc4.nc4 but the files do not contain any time dimension. Hence when I use ncecat to concatenate various files, the date information is missing in the resulting file. I want to know how to add the time information in the combined dataset.

It seems that the timestamp is a part of the global attributes. Here is the relevant part from ncdump:

$ ncdump -h ~/Downloads/3B42_Daily.19980730.7.nc4.nc4 
netcdf \3B42_Daily.19980730.7.nc4 {
dimensions:
    lon = 201 ;
    lat = 201 ;
variables:
    float lon(lon) ;
...trimmed...
// global attributes:
        :BeginDate = "1998-07-30" ;
        :BeginTime = "01:30:00.000Z" ;
        :EndDate = "1998-07-31" ;
        :EndTime = "01:29:59.999Z" ;
...trimmed...

When I tried using ncecat 3B42_Daily.199808??.7.nc4.nc4 /tmp/daily.nc4 it gives

$ ncdump -h /tmp/daily.nc
netcdf daily {
dimensions:
    record = UNLIMITED ; // (5 currently)
    lon = 201 ;
    lat = 201 ;
variables:
    float lon(lon) ;
...trimmed...
// global attributes:
        :BeginDate = "1998-08-01" ;
        :BeginTime = "01:30:00.000Z" ;
        :EndDate = "1998-08-02" ;
        :EndTime = "01:29:59.999Z" ;
...trimmed...

The time information in the global attribute of the first file is retained, which is not very useful.

When trying to use xarray in python, I face the same issue - again, I could not find how the time information that is contained in the global attribute can be used when concatenating the data.

I can think of two possible solutions, but I do not know how to achieve them.

  1. Add timestamp "by hand" using some command to each of the file first, and then use ncecat
  2. Somehow ncecat may read the global attribute and convert it into a dimension and a variable while concatenating.

From the documentation on http://nco.sourceforge.net/nco.html I could not figure out how to achieve either of these two ways. Or is there a third better way to achieve this (concatenation with relevant time information added)?

Charlie Zender
  • 5,929
  • 14
  • 19
A.Apte
  • 105
  • 5

1 Answers1

2

Since the data files do not follow CF conventions, you will likely have to manually create a time coordinate after using ncecat to concatenate the files. It only takes a few commands if the times are regular, e.g.,

ncecat -u time in*.nc out.nc
ncap2 -O -s 'time[time]={0.0,1.0,2.0,3.0,4.0}' out.nc out.nc
ncatted -a units,time,o,c,"days since 1998-08-01" out.nc
    

or use ncap2's array facilities for generic arithmetic arrays.

Charlie Zender
  • 5,929
  • 14
  • 19
  • Thanks a lot - that worked perfectly fine if I used the commands in the order `ncecat` followed by `ncap2` followed by `ncatted`. (If you change the order in the answer, it may help others.) – A.Apte Feb 10 '21 at 06:08
  • I forgot to mention that `ncap2` also needed the option `-O` for overwriting the same file. So the command I used was something like `ncap2 -O -s 'time[time]=array(5844,1,$time)' out.nc out.nc` – A.Apte Feb 10 '21 at 07:10