Re: create time in netcdf variable

From: Erik Noble <enoble_at_nyahnyahspammersnyahnyah>
Date: Thu, 17 Jul 2008 15:58:40 -0400

Dear Jamie.
Thank you for this explanation. Extremely helpful!

Also, please disregard my earlier question about having trouble with
multiple files. Dennis's suggestion worked.

Thank for your time.
Sincerely,
Erik

On 7/17/08 3:50 PM, "Jamie Scott" <James.D.Scott_at_noaa.gov> wrote:

> Eric,
>
> The target date is arbitrary. It could be the date of the first
> timestep or it could
> be some other reference date. If you are using the time units "hours
> since 2000-1-1 00:00:0.0"
> (that is midnight january 1 2000), and your first time step is a 6am
> jan 1, 2000, you would use the
> value 6 as your first time value -- as in 6 hours since 2000-1-1
> 00:00:0.0
>
> This is the standard way to define time for many applications.
>
> Here is an example from our data archive. Note the time variable is
> type "double". This is necessary
> when using the units "hours since" and the target date is several
> hundred years prior to the present day.
> If you aren't counting that many hours from the reference date, you
> can use float.
>
> ncdump -c /Datasets/NARR/pressure/air.199909.nc
> netcdf air.199909 {
> dimensions:
> y = 277 ;
> x = 349 ;
> level = 29 ;
> time = UNLIMITED ; // (240 currently)
> variables:
> float level(level) ;
> level:units = "millibar" ;
> level:actual_range = 1000.f, 100.f ;
> level:long_name = "Level" ;
> level:positive = "down" ;
> level:GRIB_id = 100s ;
> level:GRIB_name = "hPa" ;
> level:axis = "Z" ;
> level:coordinate_defines = "point" ;
> float lat(y, x) ;
> lat:long_name = "latitude coordinate" ;
> lat:units = "degrees_north" ;
> lat:standard_name = "latitude" ;
> lat:axis = "Y" ;
> lat:coordinate_defines = "point" ;
> float lon(y, x) ;
> lon:units = "degrees_east" ;
> lon:long_name = "longitude coordinate" ;
> lon:standard_name = "longitude" ;
> lon:axis = "X" ;
> lon:coordinate_defines = "point" ;
> double time(time) ;
> time:units = "hours since 1800-1-1 00:00:0.0" ;
> time:long_name = "time" ;
> time:actual_range = 1750224., 1750941. ;
> time:delta_t = "0000-00-00 03:00:00" ;
> time:standard_name = "time" ;
> time:axis = "T" ;
> time:coordinate_defines = "point" ;
> float x(x) ;
> x:long_name = "eastward distance from southwest
> corner of domain in projection coordinates" ;
> x:units = "m" ;
> x:standard_name = "projection_x_coordinate" ;
> float y(y) ;
> y:long_name = "northward distance from southwest
> corner of domain in projection coordinates" ;
> y:units = "m" ;
> y:standard_name = "projection_y_coordinate" ;
> short air(time, level, y, x) ;
> air:long_name = "3-hourly Air Temperature on Pressure
> Levels" ;
> air:valid_range = -32765s, -10260s ;
> air:unpacked_valid_range = 137.5f, 362.5f ;
> air:actual_range = 189.5675f, 315.3047f ;
> air:units = "degK" ;
> air:add_offset = 465.15f ;
> air:scale_factor = 0.01f ;
> air:missing_value = 32766s ;
> air:_FillValue = -32767s ;
> air:precision = 2s ;
> air:least_significant_digit = 1s ;
> air:GRIB_id = 11s ;
> air:GRIB_name = "TMP" ;
> air:var_desc = "Air temperature" ;
> air:dataset = "NARR 3-hourly" ;
> air:level_desc = "Pressure Levels" ;
> air:statistic = "Individual Obs" ;
> air:parent_stat = "Other" ;
> air:standard_name = "air_temperature" ;
> air:grid_mapping = "Lambert_Conformal" ;
> air:coordinates = "lat lon" ;
> int Lambert_Conformal ;
> Lambert_Conformal:grid_mapping_name =
> "lambert_conformal_conic" ;
> Lambert_Conformal:standard_parallel = 50., 50. ;
> Lambert_Conformal:longitude_of_central_meridian =
> -107. ;
> Lambert_Conformal:latitude_of_projection_origin = 50. ;
> Lambert_Conformal:false_easting = 5632642.22547 ;
> Lambert_Conformal:false_northing = 4612545.65137 ;
>
> // global attributes:
> :Conventions = "CF-1.0" ;
> :title = "8x Daily NARR" ;
> :history = "created 2005/07 by Hoop (netCDF2.3)" ;
> :comments = "Data is from North American Regional
> Reanalysis\n",
> "(8x/day). It consists of most variables
> interpolated to\n",
> "pressure surfaces from model (sigma)
> surfaces." ;
> :institution = "National Centers for Environmental
> Prediction" ;
> :platform = "Model" ;
> :references =
> "http://wwwt.emc.ncep.noaa.gov/mmb/rreanl/index.html
> \n",
> "http://www.cdc.noaa.gov/cdc/data.narr.html" ;
> data:
>
> level = 1000, 975, 950, 925, 900, 875, 850, 825, 800, 775, 750, 725,
> 700,
> 650, 600, 550, 500, 450, 400, 350, 300, 275, 250, 225, 200, 175,
> 150,
> 125, 100 ;
>
> time = 1750224, 1750227, 1750230, 1750233, 1750236, 1750239, 1750242,
> 1750245, 1750248, 1750251, 1750254, 1750257, 1750260, 1750263,
> 1750266,
> 1750269, 1750272, 1750275, 1750278, 1750281, 1750284, 1750287,
> 1750290,
> 1750293, 1750296, 1750299, 1750302, 1750305, 1750308, 1750311,
> 1750314,
> 1750317, 1750320, 1750323, 1750326, 1750329, 1750332, 1750335,
> 1750338,
> 1750341, 1750344, 1750347, 1750350, 1750353, 1750356, 1750359,
> 1750362,
> 1750365, 1750368, 1750371, 1750374, 1750377, 1750380, 1750383,
> 1750386,
> 1750389, 1750392, 1750395, 1750398, 1750401, 1750404, 1750407,
> 1750410,
> 1750413, 1750416, 1750419, 1750422, 1750425, 1750428, 1750431,
> 1750434,
> 1750437, 1750440, 1750443, 1750446, 1750449, 1750452, 1750455,
> 1750458,
> 1750461, 1750464, 1750467, 1750470, 1750473, 1750476, 1750479,
> 1750482,
> 1750485, 1750488, 1750491, 1750494, 1750497, 1750500, 1750503,
> 1750506,
> 1750509, 1750512, 1750515, 1750518, 1750521, 1750524, 1750527,
> 1750530,
> 1750533, 1750536, 1750539, 1750542, 1750545, 1750548, 1750551,
> 1750554,
> 1750557, 1750560, 1750563, 1750566, 1750569, 1750572, 1750575,
> 1750578,
> 1750581, 1750584, 1750587, 1750590, 1750593, 1750596, 1750599,
> 1750602,
> 1750605, 1750608, 1750611, 1750614, 1750617, 1750620, 1750623,
> 1750626,
> 1750629, 1750632, 1750635, 1750638, 1750641, 1750644, 1750647,
> 1750650,
> 1750653, 1750656, 1750659, 1750662, 1750665, 1750668, 1750671,
> 1750674,
> 1750677, 1750680, 1750683, 1750686, 1750689, 1750692, 1750695,
> 1750698,
> 1750701, 1750704, 1750707, 1750710, 1750713, 1750716, 1750719,
> 1750722,
> 1750725, 1750728, 1750731, 1750734, 1750737, 1750740, 1750743,
> 1750746,
> 1750749, 1750752, 1750755, 1750758, 1750761, 1750764, 1750767,
> 1750770,
> 1750773, 1750776, 1750779, 1750782, 1750785, 1750788, 1750791,
> 1750794,
> 1750797, 1750800, 1750803, 1750806, 1750809, 1750812, 1750815,
> 1750818,
> 1750821, 1750824, 1750827, 1750830, 1750833, 1750836, 1750839,
> 1750842,
> 1750845, 1750848, 1750851, 1750854, 1750857, 1750860, 1750863,
> 1750866,
> 1750869, 1750872, 1750875, 1750878, 1750881, 1750884, 1750887,
> 1750890,
> 1750893, 1750896, 1750899, 1750902, 1750905, 1750908, 1750911,
> 1750914,
> 1750917, 1750920, 1750923, 1750926, 1750929, 1750932, 1750935,
> 1750938,
> 1750941 ;
>
>
>
> On Jul 17, 2008, at 1:11 PM, Erik Noble wrote:
>
>> Yes. I am asking how to construct time units.
>> I'm getting mixed up in the terminology; what do people mean when
>> they say
>> target time and date? I am looking at month now, but next week I'll
>> bee
>> looking at longer timescales.
>>
>> Right now, I have had to resort to creating one netCDF file for each
>> binary
>> files with 8 time steps and then read each .nc into ncl and then use
>> addfile_getVar. This ok for a month's worth of data, but soon I will
>> have to
>> look at a decade's worth of the same data.
>> -erik
>>
>> On 7/17/08 11:24 AM, "Jamie Scott" <James.D.Scott_at_noaa.gov> wrote:
>>
>>> Are you asking how to construct the time units? I don't typically
>>> use
>>> time units in
>>> yyyymmddhh format for netcdf files. It's more common to use hours
>>> (or days) since
>>> at target time and date.
>>>
>>> On Jul 16, 2008, at 9:21 PM, Erik Noble wrote:
>>>
>>>> Dear Dennis,
>>>> This worked. Thank you. Now I am trying this with multiple files
>>>> I'm having trouble.
>>>>
>>>> How is NCL to 'know' that you want a multiple binary files with 8
>>>> time steps
>>>> in each file, say 30 days of September (at least where the first 9
>>>> days are
>>>> double digit? 01,02,03,04,...09
>>>> 200609##hh
>>>> -Erik
>>>>
>>>> On 7/16/08 2:21 PM, "Dennis Shea" <shea_at_ucar.edu> wrote:
>>>>
>>>>> As Jamie has stated and the output print statements show,
>>>>> you are overwriting the information each loop iteration.
>>>>>
>>>>> How is NCL to 'know' that you want a file with 8 time steps on it?
>>>>>
>>>>> [a]
>>>>> You could create a single netCDF file for each time and use (say)
>>>>> ncrcat
>>>>> to concatenate the files.
>>>>>
>>>>> [b]
>>>>> You can preallocate arrays and then after the loop write to the
>>>>> file once.
>>>>> Something like:
>>>>>
>>>>> ntim = 8
>>>>> nlat = 480
>>>>> mlon = 1440
>>>>>
>>>>> yyyymmdd = year*10000 + month*100 + day
>>>>> time = yyyymmdd*100 + ispan(0,21,3)
>>>>> time!0 = "time"
>>>>> time_at_units = "yyyymmddhh"
>>>>> time&time = time
>>>>> print(time)
>>>>>
>>>>> CMORPH = new ( (/ntim,nlat,mlon/), "float")
>>>>> pc_combined_MW = CMORPH
>>>>>
>>>>> fName = "./20060901_3hr-025deg_cpc+comb"
>>>>>
>>>>> do i = 0, 14,2
>>>>> pc_combined_MW(i/2,:,:) =
>>>>> fbindirread(fName,i,(/ntim,nlat,mlon/),"float")
>>>>> CMORPH(i/2,:,:) = fbindirread(fName, i+1,(/
>>>>> ntim,nlat,mlon/),"float")
>>>>> end do
>>>>>
>>>>> CMORPH!0 = "time"
>>>>> CMORPH!1 = "lat"
>>>>> CMORPH!2 = "lon"
>>>>> CMORPH&time = time
>>>>> CMORPH&lat = lat
>>>>> CMORPH&lon = lon
>>>>> CMORPH_at_long_name = "CMORPH"
>>>>> CMORPH_at_units = "mm/hr"
>>>>>
>>>>> ; same for pc_combined_MW
>>>>>
>>>>>
>>>>>
>>>>> a = addfile("sample.nc","c") ; write netCDF file
>>>>> a_at_title = "1 day of daily CMORPH precipitation data"
>>>>> a_at_source =
>>>>> "ftp://ftp.cpc.ncep.noaa.gov/precip/global_CMORPH/3-hourly_025deg"
>>>>> filedimdef(a,"time",-1,True) ; make time an UNLIMITED
>>>>>
>>>>> a->CMORPH = CMORPH
>>>>> a->COMB_MW = pc_combined_MW
>>>>> end
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Erik Noble wrote:
>>>>>> Hi.
>>>>>> You suggest eliminating the do loop, correct?
>>>>>> -Erik
>>>>>>
>>>>>> On Wed, Jul 16, 2008 at 12:20 PM, Jamie Scott <James.D.Scott_at_noaa.gov
>>>>>>> wrote:
>>>>>>
>>>>>>> Eric,
>>>>>>> I think the problem is that the 2 variables you are writing to
>>>>>>> the netcdf
>>>>>>> file
>>>>>>> only contain one time step. Even though you are looping through
>>>>>>> time
>>>>>>> and writing 8 times, I think you are just overwriting the 1st
>>>>>>> time step in
>>>>>>> the
>>>>>>> netcdf file each time.
>>>>>>> Try making the variables you write (cpc_combined_mw, cmorph and
>>>>>>> time)
>>>>>>> such that they contain all 8 time steps and write them only once.
>>>>>>>
>>>>>>> Jamie Scott
>>>>>>>
>>>>>>> NOAA/ESRL/PSD
>>>>>>>
>>>>>>> james.d.scott_at_noaa.gov
>>>>>>>
>>>>>>> On Jul 16, 2008, at 9:58 AM, ncl-talk-request_at_ucar.edu wrote:
>>>>>>>
>>>>>>> May I have some help? This is an update my earlier request for
>>>>>>> help
>>>>>>> with getting time displayed in my netcdf file. I updated my code
>>>>>>> fromearlie
>>>>>>> till getting incorrect time. When I do
>>>>>>> "ncdump -h" on the my output netcdf file, I don't get the proper
>>>>>>> time
>>>>>>> that should reflect 3-hourly intervals for 1 day.
>>>>>>> (It says time = UNLIMITED ; // (1 currently). it should be time =
>>>>>>> UNLIMITED ; // (8 currently)).
>>>>>>> I'm reading in a binary file that I'm told is composed of 16
>>>>>>> direct
>>>>>>> access binary ("big_endian") records, which are 2 variables at
>>>>>>> 3-hourly ntervals for 1 day, basically 8 pairs.
>>>>>>>
>>>>>>> I searched throughout previous posts about time coordinates
>>>>>>> before
>>>>>>> posting this question ncl-talk. Its not clear whether i need to
>>>>>>> resort
>>>>>>> to making up this variable (i.e. specifically make a variable
>>>>>>> time =
>>>>>>> year*10000 + month*100 + day...etc) or if Its something even more
>>>>>>> simple that I am overlooking.
>>>>>>>
>>>>>>> Could I have please have some advice on how to fix this? I have
>>>>>>> my
>>>>>>> screen readouts and ncl code below.
>>>>>>> -Erik
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> ncl-talk mailing list
>>>>>>> ncl-talk_at_ucar.edu
>>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> _______________________________________________
>>>>>> ncl-talk mailing list
>>>>>> ncl-talk_at_ucar.edu
>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Jul 17 2008 - 13:58:40 MDT

This archive was generated by hypermail 2.2.0 : Fri Jul 18 2008 - 08:51:52 MDT