I am trying to write a netcdf file using netCDF4 in Python. For that, I am creating a time variable. I created the time data using datetime. I am getting an error when I try to convert the datetime data to netcdf formats using date2num.
dates=[datetime.datetime(1996,1,1) + relativedelta(months=mon) for mon in range(120)]
The above command gives me list of dates that look like-
[datetime.datetime(1996, 1, 1, 0, 0),
datetime.datetime(1996, 2, 1, 0, 0),
datetime.datetime(1996, 3, 1, 0, 0),
datetime.datetime(1996, 4, 1, 0, 0),
datetime.datetime(1996, 5, 1, 0, 0),
...
datetime.datetime(2005, 10, 1, 0, 0),
datetime.datetime(2005, 11, 1, 0, 0),
datetime.datetime(2005, 12, 1, 0, 0)]
I am using the following command to convert the date to netCDF4 dates:
dates_nc=nc.date2num(dates,time.units)
Here time.units is since 1991-01-01 (I am not sure how time.units works)
The nc.date2num command gives the following error:
ValueError Traceback (most recent call last)
cftime\_cftime.pyx in cftime._cftime._datesplit()
ValueError: need more than 2 values to unpack
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-154-97a05959ce3c> in <module>
----> 1 dates_nc=nc.date2num(dates,time.units)
cftime\_cftime.pyx in cftime._cftime.date2num()
cftime\_cftime.pyx in cftime._cftime._dateparse()
cftime\_cftime.pyx in cftime._cftime._datesplit()
ValueError: Incorrectly formatted CF date-time unit_string
What could be the reason for the error?