skip to Main Content

I have two netCDF files. One file elevation.nc contains just the ‘elevation’ of an area. Other file climate.nc has (‘lat’, ‘lon’,’prcp’, ‘temp’). I have used the following:

cdo merge  elevation.nc climate.nc merged.nc

The merge.nc file only has on single prcp and temp from the date that the elevation had been recorded.

How to get time varying prcp and temp in merged.nc similar to climate.nc but also with the static variable elevation?

3

Answers


  1. Chosen as BEST ANSWER

    the main issue was found to be that the elevation.nc has a single time step attribute. It is essential to remove this attribute before the merge. hence, the steps shall involve (using ncks from nco):

    ncwa -a time elevation.nc test1.nc
    ncks -O -x -v time test1.nc test2.nc #removing the time attribute
    ncks -A -v hgt test2.nc  climate.nc #appending the hgt or elevation.nc with climate.nc
    

  2. You only need to reverse the order of the input files to ensure that the multi-step file is the first input file as cdo takes the dimensions from that. So this would work:

    cdo merge climate.nc elevation.nc merged.nc
    

    If you do it in the "wrong" order (i.e. the single timestep input file first) cdo explicitly tells you in a warning that it is chopping off all the remaining steps of the time-dependent file in order to match the first input file:

    cdo    merge (Warning): Input stream 1 has 1 timestep. Stream 2 has more timesteps, skipped!
    

    Reversing the input order to have the longest input file first, everything works fine and no warning is given.

    Login or Signup to reply.
  3. This would be more concise, though you’ll have to test it to be sure it works as expected:

    ncwa -O -x -v time -a time elevation.nc test1.nc
    ncks -A -v hgt test1.nc climate.nc
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search