Accumulate rain events with determined dry period

1 次查看(过去 30 天)
I have a rain time series with 15 minutes between data:
yyyy mm dd hh mm ss rain
2010 1 1 0 0 0 0.2
2010 1 1 0 15 0 0.4
2010 1 1 0 30 0 0
[...]
And I need to accumulate every rain value restarting the sum every time the station had at least 24 hours without rain, getting a matrix with start and end dates of each rain event and the accumulated rain during the period:
start_rain end_rain accumulated_rain
2010-1-1-0:0:0 2010-1-4-0:0:0 12
2010-1-7-0:0:0 2010-1-13-0:0:0 23
The date format above is only for exampe, could be in datenum
Any suggestions about how can I do this on MatLab?
Tks

回答(1 个)

Andrei Bobrov
Andrei Bobrov 2018-11-21
编辑:Andrei Bobrov 2018-11-21
load('ex_rain.mat')
TT = timetable('RowTimes',datetime(example(:,1:6)),example(:,7),'v',{'rain'});
TT1 = retime(TT,'daily','sum');
p = TT1.rain~=0;
p1 = [0;p;0];
Time_interv = TT1.Time([strfind(p1(:)',[0 1]);strfind(p1(:)',[1 0])-1]');
ii = cumsum(diff(p1)==1);
ii = ii(1:end-1).*p + 1;
rain_int = accumarray(ii,TT1.rain);
rain_int = rain_int(2:end);
Rain_out = table(Time_interv,rain_int);
same variant but without timetable
[Date0,~,i0] = unique(example(:,1:3),'rows');
rain_daily = table(datetime(Date0),accumarray(i0,example(:,7)),'v',{'Date','rain'});
p = rain_daily.rain~=0;
p1 = [0;p;0];
Time_interv = rain_daily.Date([strfind(p1(:)',[0 1]);strfind(p1(:)',[1 0])-1]');
ii = cumsum(diff(p1)==1);
ii = ii(1:end-1).*p + 1;
rain_interv = accumarray(ii,rain_daily.rain);
rain_interv = rain_interv(2:end);
Rain_out = table(Time_interv,rain_interv);
  1 个评论
Danilo M
Danilo M 2018-11-21
Thanks Andrei! I could run the code without timetable and did exactly what I need.
I just have two doubts about the code. There's a way to put the hour on Time_interval table? Because I need to calculate rain intensity (mm/hour), so I need to know the exactly interval.
And if I want to change the dry period interval, like 36 or 48 hours without rain, what line I can make it?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Time Series Events 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by