I am having a forcing NetCDF climatology file that has 4 dimensions, i.e. time, lat, long and lev. I am reading this file using Flexible Modelling System (FMS) from GFDL. I want to keep the time continuous, or something like a periodic boundary condition. For example, I should provide just one year monthly file, and the model should directly pick up the corresponding month from my file without exactly checking the specific year. I am performing some experiments in which some forcings are kept fixed and others changing (to provide a context why I want to do this).
2 Answers
You can use the following nco command to add modulo attribute to your time dimension
ncatted -a modulo,time,c,c," " filename.nc

- 405
- 2
- 11
-
+1, This is really neat! I presume it works fine with monthly data, but would not with daily (or finer) timesteps because of leap years, correct? – ClimateUnboxed Nov 06 '19 at 11:44
-
It should technically work with the daily data as well. In my model, I am using monthly data, but the way my model picks up values is, it does a linear interpolation to calculate daily values. So, I think it should work for daily data as well – Manmeet Singh Nov 08 '19 at 07:56
-
Sorry, still confused. My understanding was this solution makes the time axis "cyclic". If you access March 2004 and the dataset is only for 12 months for the year 2003 (modulo time axis), the code reads month 15 mod 12 = 3, i.e. March03. In your reply you refer linear interpolation of monthly data, but what I am referring to is using the modulo soln with input data which is daily time resolution,e.g.if you have daily data for 2003, and I ask for 1 March 2004, does the code read 1st March 2003, or 2nd March 2003? (because 2004 is a leap year while the source dataset only has 365 days.) – ClimateUnboxed Nov 08 '19 at 08:53
-
Hey, Yes you are right, this solution makes the time axis "cyclic", What I was just saying was that it doesnt matter whether your data is having 12 points (monthly) or 365 points (daily), that linear interpolation is automatically done by the Flexible Modelling System (FMS) which my model uses, This linear interpolation is independent of this answer, that was just a detailed explanation I was providing, sorry if that led to any confusion – Manmeet Singh Nov 10 '19 at 15:40
-
Okay, but it does mean that your input will shift by one day per four years... It means that if one uses this for climate integrations you will be "off" by approximately a month by the year 2100. – ClimateUnboxed Nov 11 '19 at 12:58
You could create a netcdf file with the same year repeated many times and the timestamp overwritten to give a "dummy" year using cdo. Let's say your example netcdf file "oneyear.nc" has the times for the year 2002, whereas your other "changing" files cover the years from 1980 to 2010 (if I understand your question, some variables will change from year to year, it is just one specific file you want to keep invariant).
Then you could create a set of year files with the dummy timestamp in this way
for offset in $(seq -22 8) ; do
cdo shifttime,${offset}years oneyear.nc year${offset}.nc
done
and you can then merge them to one file using mergetime:
cdo mergetime year*.nc mydriverfile.nc
mydriverfile.nc should now contain the same monthly data repeated for 30 years with dummy "fake" years, which then be easy to read in the same way as your other driver files.
edit: Concerning the discussion above on leap years, obviously for monthly data this is not an issue, but if you want to perform this task with daily data, then with this solution you should select a sample year that is a leapyear, or insert a dummy day for Feb 29. I also suspect that the modulo solution above suffers from the leap year issue when applied to daily input.

- 7,106
- 3
- 41
- 86