Re: Could I reset the irregular time coordinate of this netcdf file?

From: Dave Allured - NOAA Affiliate <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Mon Jan 20 2014 - 18:56:35 MST

Lin,

1. Please always CC the user list on replies. We are not private
consultants. ;-)

2. Thank you for noticing that this time coordinate is irregular. I need
to say the following, for others who might see this.

Notice that the units on the GISS-E2-H time variable is "months since".
 "Months" is very problematical as a base unit for time, for several
reasons. A month is not a fixed length unit of measurement. The
interpretation of "months since" is not standardized. And different
calendar software treats or mistreats "months since" in different,
inconsistent, and sometimes illogical ways. See "Caveats" in the
documentation for ut_calendar.

3. If you only want to read this GISS-E2-H file correctly with NCL, then
you might get acceptable results by using cd_calendar instead of
ut_calendar:

Variable: times
Type: double
  calendar : 365_day
  units : months since 1850-01-16 00:00:00

yymmdd = cd_calendar (times, -2)
print (yymmdd)

(744) 19120101
(745) 19120201
(746) 19120301
(747) 19120401
(748) 19120501
(749) 19120601
(750) 19120701
(751) 19120801
(752) 19120901
(753) 19121001
(754) 19121101
(755) 19121201
(756) 19130101
(757) 19130201
etc.

4. YES, you could copy the time coordinates from a different CMIP5 output
file. However, I think it is safer to generate your own coordinates with
software such as the calendar function in CDO utilities:

https://code.zmaw.de/projects/cdo/

5. You can also generate well behaved time coordinates with NCL. Here the
original "months since" is changed to "days since":

  year1 = 1850
  ntimes = 1872
  units = "days since 1850-01-16 00:00:00"
  opt = 0
  opt@calendar = "365_day"

  ymd = new ((/ ntimes, 6 /), integer, "No_FillValue")
  j = ispan (0, ntimes-1, 1)
  ymd(:,0) = year1 + (j / 12) ; years
  ymd(:,1) = 1 + (j % 12) ; months
  ymd(:,2) = 16 ; days
  ymd(:,3:5) = 0 ; HH:MM:SS

  times = cd_inv_calendar (ymd(:,0), ymd(:,1), ymd(:,2), \
             ymd(:,3), ymd(:,4), ymd(:,5), units, opt)
  printVarSummary (times)

  yymmdd = cd_calendar (times, -2)
  print (yymmdd)

--------------------------------------
Variable: times
Type: double
Dimensions and sizes: [1872]
Number Of Attributes: 2
  calendar : 365_day
  units : days since 1850-01-16 00:00:00

Variable: yymmdd
Type: integer
Dimensions and sizes: [1872]
Number Of Attributes: 1
  calendar : 365_day
...
(744) 19120116
(745) 19120216
(746) 19120316
(747) 19120416
(748) 19120516
(749) 19120616
(750) 19120716
(751) 19120816
(752) 19120916
(753) 19121016
(754) 19121116
(755) 19121216
(756) 19130116
(757) 19130216
...
(1869) 20051016
(1870) 20051116
(1871) 20051216

6. You can use the above NCL time coordinates "times" inside your program,
keeping the original data file intact. You can also write them back to the
original file, replacing the original time coordinates. The new
coordinates must be of the same dimension length, and the same data type
"double":

  f = addfile ("file.nc", "w") ; open for read/write
  times!0 = "time" ; setup for legal time coordinates
  times&time = times
  f->time = times

--Dave

On Fri, Jan 17, 2014 at 7:53 PM, gmail <leo.aries.g@gmail.com> wrote:

> Hi, Dave
>
> Please see as below.
>
> (0) psl_Amon_GISS-E2-H_historical_r1i1p1_185001-200512.nc
>
> Variable: time (subsection)
> Type: double
> Total Size: 128 bytes
> 16 values
> Number of Dimensions: 1
> Dimensions and sizes: [time | 16]
> Coordinates:
> time: [ 744.. 759]
> Number Of Attributes: 2
> calendar : 365_day
> units : months since 1850-01-16 00:00:00
> (0) 744
> (1) 745
> (2) 746
> (3) 747
> (4) 748
> (5) 749
> (6) 750
> (7) 751
> (8) 752
> (9) 753
> (10) 754
> (11) 755
> (12) 756
> (13) 757
> (14) 758
> (15) 759
>
> And what for the other nc file is also attached as below:
>
> (0) psl_Amon_GFDL-CM3_historical_r1i1p1_186001-200512.nc
>
> Variable: time (subsection)
> Type: double
> Total Size: 128 bytes
> 16 values
> Number of Dimensions: 1
> Dimensions and sizes: [time | 16]
> Coordinates:
> time: [22645.5..23100]
> Number Of Attributes: 8
> axis : T
> standard_name : time
> bounds : time_bnds
> calendar : noleap
> calendar_type : noleap
> cartesian_axis : T
> units : days since 1860-01-01 00:00:00
> long_name : time
> (0) 22645.5
> (1) 22675
> (2) 22704.5
> (3) 22735
> (4) 22765.5
> (5) 22796
> (6) 22826.5
> (7) 22857.5
> (8) 22888
> (9) 22918.5
> (10) 22949
> (11) 22979.5
> (12) 23010.5
> (13) 23040
> (14) 23069.5
> (15) 23100
>
> Thanks!
>
>
> Lin
>
>
> 在 2014-1-18,上午3:14,Dave Allured - NOAA Affiliate <dave.allured@noaa.gov>
> 写道:
>
> Mistake. I meant to say, please show print (time(744:759)).
>
> --Dave
>
> On Fri, Jan 17, 2014 at 12:12 PM, Dave Allured - NOAA Affiliate <
> dave.allured@noaa.gov> wrote:
>
>> Lin,
>>
>> For GISS-E2-H, please show printVarSummary (time).
>>
>> --Dave
>> (Always include user list in replies.)
>>
>>
>> On Fri, Jan 17, 2014 at 7:55 AM, gmail <leo.aries.g@gmail.com> wrote:
>>
>>> Hi, all
>>>
>>> I am reading multiple nc files from CMIP5 using the following
>>> code.
>>>
>>>
>>> ; **************************
>>> data_path = "/..../Data/CMIP5/"
>>> model_name =
>>> (/"bcc-csm1-1","BNU-ESM","CanESM2","CCSM4","CNRM-CM5","CSIRO-Mk3-6-0","FGOALS-g2","GFDL-CM3","GFDL-ESM2M","GISS-E2-H",\
>>>
>>> "GISS_E2-R","HadGEM2-ES","IPSL-CM5A-LR","MIROC-ESM","MIROC-ESM-CHEM","MRI-CGCM3","NorESM1-M"/)
>>> simulation = "historical"
>>> varname = "psl"
>>> vn = 3
>>>
>>> ntStrt = 188001
>>> ntLast = 200412
>>> x = new((/dimsizes(model_name),2004-1880+1/),"float")
>>> ; ************************
>>>
>>> do i = 0,dimsizes(model_name)-1
>>> print( " " + model_name(i) )
>>> all_files = systemfunc("ls /..../Data/CMIP5/" + model_name(i) + "/" +
>>> simulation + "/")
>>>
>>> do j = 0,dimsizes(all_files)-1
>>> fcha = stringtochar(all_files(j))
>>> fvar = charactertostring(fcha(0:vn-1))
>>> if(fvar.eq.varname) then
>>> data_filename = all_files(j)
>>> print(" " + data_filename)
>>> end if
>>> delete(fvar)
>>> delete(fcha)
>>> end do
>>>
>>> fi = addfile(data_path + model_name(i) + "/" + simulation + "/" +
>>> data_filename, "r")
>>> delete(data_filename)
>>> time = fi->time
>>> *yymm = ut_calendar(time,-1)*
>>> ;print(yymmdd(0:dimsizes(time)-1:12))
>>> *yymmdd = ut_calendar(time,-2)*
>>> print(yymmdd(11:dimsizes(time)-1:12))
>>> nt1 = ind(yymm.eq.ntStrt)
>>> nt2 = ind(yymm.eq.ntLast)
>>> print(" " + nt1 + " " + nt2 + " " + dimsizes(time))
>>> data = fi->$varname$(nt1:nt2,:,:)
>>> delete(time)
>>> delete(yymmdd)
>>> delete(yymm)
>>>
>>> end do
>>>
>>> ; **********************
>>>
>>>
>>> However, something wrong occurs when reading the "GISS-E2-H" output
>>> data, Here below is part of what I got using "print(yymmdd)"
>>>
>>> *(744) 19120131*
>>> *(745) 19120302*
>>> (746) 19120401
>>> (747) 19120502
>>> (748) 19120601
>>> (749) 19120702
>>> (750) 19120801
>>> (751) 19120901
>>> (*752) 19121001*
>>> *(753) 19121031*
>>> *(754) 19121201*
>>> *(755) 19121231*
>>> (756) 19130131
>>> (757) 19130302
>>> (758) 19130402
>>> (759) 19130502
>>> (760) 19130602
>>> (761) 19130702
>>> (762) 19130801
>>> (763) 19130901
>>> (764) 19131001
>>> (765) 19131101
>>> (766) 19131201
>>> *(767) 19140101*
>>> *(768) 19140131*
>>> (769) 19140302
>>> (770) 19140402
>>> (771) 19140502
>>> (772) 19140602
>>> (773) 19140702
>>> (774) 19140802
>>> (775) 19140901
>>> (776) 19141001
>>> (777) 19141101
>>> (778) 19141201
>>> *(779) 19150101*
>>> *(780) 19150131*
>>> (781) 19150303
>>> (782) 19150402
>>> (783) 19150503
>>> (784) 19150602
>>> (785) 19150702
>>> (786) 19150802
>>> (787) 19150901
>>> (788) 19151002
>>> (789) 19151101
>>> (790) 19151202
>>> *(791) 19160101*
>>> *(792) 19160131*
>>> (793) 19160303
>>> (794) 19160402
>>> (795) 19160503
>>> (796) 19160602
>>> (797) 19160703
>>> (798) 19160802
>>> (799) 19160902
>>> (800) 19161002
>>> (801) 19161101
>>> (802) 19161202
>>>
>>> …….
>>>
>>> (1869) 20051123
>>> (1870) 20051223
>>> *(1871) 20060123 ; It should be noticed that this value of the time
>>> dimension make me scripts listed above meet errors*
>>>
>>> *It seems that the time coordinate of the nc files is irregular. (*By
>>> the way, the package of the "panoply" can recognize the correct monthly
>>> value of the time coordinate and
>>> the last month is 200512, however, the last month is 200601 when using
>>> NCL ).
>>> * Could I reset them as the time coordinate of the other CMIP5 output
>>> data? For example.*
>>>
>>>
>>> (0) psl_Amon_GFDL-CM3_historical_r1i1p1_186001-200512.nc
>>> Variable: yymmdd
>>> Type: integer
>>> Total Size: 7008 bytes
>>> 1752 values
>>> Number of Dimensions: 1
>>> Dimensions and sizes: [1752]
>>> Coordinates:
>>> Number Of Attributes: 1
>>> calendar : noleap
>>> (0) 18600116
>>> (1) 18600215
>>> (2) 18600316
>>> (3) 18600416
>>> (4) 18600516
>>> (5) 18600616
>>> (6) 18600716
>>> (7) 18600816
>>> (8) 18600916
>>> (9) 18601016
>>> (10) 18601116
>>> (11) 18601216
>>> (12) 18610116
>>> (13) 18610215
>>> (14) 18610316
>>> (15) 18610416
>>> (16) 18610516
>>> (17) 18610616
>>> (18) 18610716
>>> (19) 18610816
>>> (20) 18610916
>>> (21) 18611016
>>> (22) 18611116
>>> (23) 18611216
>>>
>>> …..
>>>
>>> (1740) 20050116
>>> (1741) 20050215
>>> (1742) 20050316
>>> (1743) 20050416
>>> (1744) 20050516
>>> (1745) 20050616
>>> (1746) 20050716
>>> (1747) 20050816
>>> (1748) 20050916
>>> (1749) 20051016
>>> (1750) 20051116
>>> *(1751) 20051216*
>>>
>>> Thanks!
>>>
>>>
>>>
>>> Lin
>>>
>>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Jan 20 18:56:54 2014

This archive was generated by hypermail 2.1.8 : Tue Jan 21 2014 - 15:57:30 MST