Re: To change the time variable attributes in merged netCDF file

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu Apr 12 2012 - 13:54:12 MDT

Something is wrong somewhere!

To my knowledge, the NCO take the units on the 1st
file and the recalculate all the time coordinates
relative to this base.

Certainly, you could rectify in NCL if this is not the case,
something like ....

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

     yyyymm = yyyymm_time(1850, 2100, "integer")
     ntim = dimsizes(yyyymm)

     year = yyyymm/100
     month = yyyymm-(year*100)
     day = conform_dims(ntim, 1, 0)
     hour = conform_dims(ntim, 0, 0)
     minit = conform_dims(ntim, 0, 0)
     sec = conform_dims(ntim, 0, 0)

     units = "days since 1850-01-01 00:00:00"
     TIME = cd_inv_calendar(year,month,day,hour,minte,sec,units, 0)
     TIME!0 = "time"
     print(TIME+" "+yyyymm)

     fio = addfile("m185001-210012.nc" , "w") ; note the "w"
     time = fio->time
     fio->time = TIME ; overwrite 'time'

On 04/12/2012 12:04 PM, Noel Aloysius wrote:
>
> Hi,
>
> I retried the 'cat' operation, just to make sure I am doing the right thing.
>
> The two files I 'cat' are m185001-200512 and m200601-210012. The time
> units are
>
> units : days since 2005-01-01 00:00:00 and
> units : days since 1850-01-01 00:00:00 respectively.
>
> I use 'ncrcat -O m185001-200512 m200601-210012 m185001-210012'
>
> Then, I use ncks to subset the 190101-210012 timeseries. The time unit
> now is,
>
> units : days since 1850-01-01 00:00:00
> time = 2400 // unlimited
>
> The time output using cd_calander within ncl is below. Time start at
> 185101 after 200512.
>
> (1257) 200510
> (1258) 200511
> (1259) 200512
> (1260) 185101
> (1261) 185102
> (1262) 185103
> (1263) 185104
>
> Any way around?
>
> Noel
>
>
>
>
> On 04/12/2012 01:02 PM, Bridget Thrasher wrote:
>> Are you sure the timestamps in the original files are correct? I would
>> worry about changing the time attribute since they may in fact be
>> correct. Does the data at i=1260 match the data in the original file
>> for time 185101?
>>
>> If you used this command "ncrcat -O m1850-2005.nc
>> <http://m1850-2005.nc/> m1850-2005.nc <http://m1850-2005.nc/>
>> m1850-2100.nc <http://m1850-2100.nc/>" to create a new file, then what
>> you did was concatenate the 1850-2005 file to itself and renamed it
>> m1850-2100.nc <http://m1850-2100.nc>, which is incorrect and would
>> possibly explain your timestamps below. Though it looks like maybe the
>> m1850-2005.nc <http://m1850-2005.nc> file actually contains data
>> starting in 1851? Check your original files and check the syntax for
>> ncrcat....
>>
>> -Bridget
>>
>>
>> On Thu, Apr 12, 2012 at 9:42 AM, Noel Aloysius
>> <noel.aloysius@gmail.com <mailto:noel.aloysius@gmail.com>> wrote:
>>
>> Hi Dennis,
>>
>> Thanks for the reply.
>>
>> I followed as per you reply. When I print the time output, after
>> 200512
>> time starts from 185101 as shown below. How can I modify the time
>> attribute to correct this.
>>
>> (1256) 200509
>> (1257) 200510
>> (1258) 200511
>> (1259) 200512
>> (1260) 185101
>> (1261) 185102
>> (1262) 185103
>> (1263) 185104
>> (1264) 185105
>>
>> Thanks,
>> Noel
>>
>> On 04/11/2012 06:57 PM, Dennis Shea wrote:
>> >
>> > Not sure why you want to change the begin time. It does not matter.
>> > It is arbitrary
>> > If the combined file created by ncrcat
>> > is m1850-2100.nc <http://m1850-2100.nc>
>> >
>> > %> ncrcat -O m1850-2005.nc <http://m1850-2005.nc> m1850-2005.nc
>> <http://m1850-2005.nc> m1850-2100.nc <http://m1850-2100.nc>
>> >
>> > then
>> >
>> > %> ncks -d time,612,, m1850-2100.nc <http://m1850-2100.nc>
>> m1901-2100.nc <http://m1901-2100.nc>
>> >
>> > I think the 612 is correct for 190101
>> >
>> >
>> > Using NCL interactively:
>> >
>> > ncl <return>
>> >
>> > f = addfile("m1901-2100.nc <http://m1901-2100.nc>", "r")
>> > time = f->time
>> > yyyymm = cd_calendar(time, -1)
>> >
>> > print(time+" "+yyyymm)
>> >
>> > You should see the 1st time as 190101
>> >
>> > On 4/11/12 4:28 PM, Noel Aloysius wrote:
>> >> Hi NCL-talk,
>> >>
>> >> I used NCO operator 'ncrcat' to merge two monthly timeseries files
>> >> ("1850-2005" + "2006-2100") and, then, created a subset for the
>> period
>> >> 1901-2100 monthly values. The resultant netCDF file has the time
>> >> attributes set to begin on 1850-01.
>> >>
>> >> To change the time attribute, I tried to create a new file and
>> transfer
>> >> all the data to that. I am able to define and create all the
>> attributes
>> >> but when I tried to write the data values (precipitiation
>> values in this
>> >> case) I get error that says
>> >>
>> >> "fatal:Variable (pr) is undefined"
>> >>
>> >> I have attached the script. I appreciate your help to resolve this
>> >> issue.
>> >>
>> >> Thanks,
>> >> Noel

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Apr 12 13:54:21 2012

This archive was generated by hypermail 2.1.8 : Fri Apr 13 2012 - 13:37:52 MDT