1

I have a netCDF file FORCING.nc containing dimension "time" with values like: [ 841512., 841513., 841514., ..., 1051893., 1051894.,1051895.]. But I want to change the time stamps from the absolute value to relative values starting from 841512, say change it to [0, 1, 2,...,1051895-841512]=[0, 1, 2,...,210383]. So is there any one-line nco command to do it? Thanks a lot!

Some code example but in python (sorry I am not familiar with nco...):

import numpy as np
from netCDF4 import Dataset
file_small = Dataset('./FORCING.nc')
file_small['time'][:]

Then I can get output like:

Out[5]: 
masked_array(data=[ 841512.,  841513.,  841514., ..., 1051893., 1051894.,
                   1051895.],
             mask=False,
       fill_value=1e+20,
            dtype=float32)

What I want to do, is change the value of time from [ 841512., 841513., 841514., ..., 1051893., 1051894.,1051895.] to [0, 1, 2,...,1051895-841512]=[0, 1, 2,...,210383]. Thanks!

Xu Shan
  • 175
  • 3
  • 11

1 Answers1

2

Read the ncap2 documentation here.

ncap2 -s 'time-=841512' in.nc out.nc
Charlie Zender
  • 5,929
  • 14
  • 19
  • Thanks! but I am afraid it makes more sense (and more flexible) to use ```ncap2 -O -s 'time=time-time(0)' FORCING.nc FORCING.nc```. – Xu Shan Apr 11 '22 at 08:59