hourly data to daily- when time steps start at 00:00 and end on 23:00 each day (how to consider another 1 hour between 23:00 to 23:59 which presents on the next day)

21 views (last 30 days)
I have one year data (3d array, name is tp) (lat*lon*time) based on hourly time steps from a netcdf file, I want to convert this hourly data to daily. the time steps of each days are:
0:00
1:00
2:00
3:00
4:00
5:00
6:00
7:00
8:00
9:00
10:00
11:00
12:00
13:00
14:00
15:00
16:00
17:00
18:00
19:00
20:00
21:00
22:00
23:00
I want to have one value for each day. as you can see time range of 23:00 to 23:59 presents in next day, so I think I should have a code that continue to one hour ahead of each day (like 25 hours)
please help me.
here is ncdisp() I want tp daily (49*41*365)
>> ncdisp(filename)
Source:
C:\Users\Behzad\Desktop\download.nc
Format:
64bit
Global Attributes:
Conventions = 'CF-1.6'
history = '2019-11-01 07:36:15 GMT by grib_to_netcdf-2.14.0: /opt/ecmwf/eccodes/bin/grib_to_netcdf -o /cache/data6/adaptor.mars.internal-1572593007.3569295-19224-27-449cad76-bcd6-4cfa-9767-8a3c1219c0bb.nc /cache/tmp/449cad76-bcd6-4cfa-9767-8a3c1219c0bb-adaptor.mars.internal-1572593007.35751-19224-4-tmp.grib'
Dimensions:
longitude = 49
latitude = 41
time = 8760
Variables:
longitude
Size: 49x1
Dimensions: longitude
Datatype: single
Attributes:
units = 'degrees_east'
long_name = 'longitude'
latitude
Size: 41x1
Dimensions: latitude
Datatype: single
Attributes:
units = 'degrees_north'
long_name = 'latitude'
time
Size: 8760x1
Dimensions: time
Datatype: int32
Attributes:
units = 'hours since 1900-01-01 00:00:00.0'
long_name = 'time'
calendar = 'gregorian'
tp
Size: 49x41x8760
Dimensions: longitude,latitude,time
Datatype: int16
Attributes:
scale_factor = 3.0792e-07
add_offset = 0.010089
_FillValue = -32767
missing_value = -32767
units = 'm'
long_name = 'Total precipitation'

Accepted Answer

Guillaume
Guillaume on 1 Nov 2019
Nothing is attached. Anyway, the simplest way to do what you want is to store your data in a timetable. Then you simply retime the timetable:
tt = timetable(???); %don't know what your data is
ttdaily = retime(tt, 'daily', 'mean'); %you haven't said what aggregation method you want to use
  7 Comments
Guillaume
Guillaume on 1 Nov 2019
All the bugs have been fixed (hopefully!). Indeed Steven's approach to constructing the datetime vector is much simpler than mine.

Sign in to comment.

More Answers (0)

Categories

Find more on Weather and Atmospheric Science in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!