Filter löschen
Filter löschen

Accumulate rain events with determined dry period

4 Ansichten (letzte 30 Tage)
Danilo M
Danilo M am 20 Nov. 2018
Kommentiert: Danilo M am 21 Nov. 2018
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
  2 Kommentare
Andrei Bobrov
Andrei Bobrov am 20 Nov. 2018
Please attach small example your data as mat-file.
Danilo M
Danilo M am 21 Nov. 2018
Here is an small example of rain data. The rain data is on 7th row.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Andrei Bobrov
Andrei Bobrov am 21 Nov. 2018
Bearbeitet: Andrei Bobrov am 21 Nov. 2018
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 Kommentar
Danilo M
Danilo M am 21 Nov. 2018
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?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Time Series Events finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by