# How to find maximum value of each event present in a series ?

2 views (last 30 days)
Tapasranjan Das on 28 Jan 2020
Commented: Tapasranjan Das on 30 Jan 2020
I have a series of 30 min interval rainfall data. The data are divided in monthly basis (one month data is attached). The series is consist of various rainfall events (rainfall events are shown in picture attached herewith). Now I would like to find out a series that consist of the maximum value of each rainfall event. (A rainfall event is basically identified by Continuous non zero value). Mohammad Sami on 28 Jan 2020
Edited: Mohammad Sami on 28 Jan 2020
Another option
data.Date = fillmissing(data.Date,'previous'); % assume the data is in ascending order of time
data.Date = data.Date + days(data.Time);
data.Date.Format = 'dd-MM-yy hh:mm';
data.Event_id = cumsum(data.Intensity_cm_hr_ == 0); % create a new event if intensity goes to 0
data_summary = groupsummary(data,{'Event_id'},{'min' 'max'},{'Intensity_cm_hr_' 'Date' 'Date'});
data_summary(data_summary.max_Intensity_cm_hr_==0,:) = []; % remove 'events with 0 intensity
data_summary.Properties.VariableNames(:,5:6) = {'start_Date' 'end_Date'};

Tapasranjan Das on 30 Jan 2020
Thank you so much for introducing me with this very useful function groupsummary. It has solved many more problem of mine, but I am stuck in a position when I am trying to apply different computation method to different grouping variable. I want to include the date and at the same time I also need the sum of another grouping variable. When I try to include the method sum then the message "Unable to apply method 'sum' to data variable Date." is showing. Again in lower portion one more message is written as
Caused by:
Error using sum
Invalid data type. First argument must be numeric or logical.
I am giving you the code that I have written so far (obviously with the help of the code that you shared earlier)
clear all
clc
data.Date = fillmissing(data.Date,'previous'); % assume the data is in ascending order of time
% data.Date = data.Date + days(data.Time);
data.Date.Format = 'dd-MM-yy hh:mm';
data.Event_id = cumsum(data.Intensity_mm_hr_ == 0); % create a new event if intensity goes to 0
data.er=0.29*(1-0.72*exp(-0.05*data.Intensity_mm_hr_));
data.ervr=(data.er).*(data.Increment);
data_summary=groupsummary(data,{'Event_id'},{'sum','max'},{'ervr','Increment','Intensity_mm_hr_','Date'});
data_summary(data_summary.sum_Increment<12.7,:) = [];
data_summary.EI30_aug=data_summary.sum_ervr.*data_summary.max_Intensity_mm_hr_;
Mohammad Sami on 30 Jan 2020
data_summary=groupsummary(data,{'Event_id'},{'sum','max'},{'ervr','Increment','Intensity_mm_hr_','Date'});
You cannot apply sum to variable Date. If you need the Date variable, you can do groupsummary twice and then join the two outputs.
Tapasranjan Das on 30 Jan 2020
Thanks again... Now it works fine
data.Date = fillmissing(data.Date,'previous'); % assume the data is in ascending order of time
% data.Date = data.Date + days(data.Time);
data.Date.Format = 'dd-MM-yy hh:mm';
data.Event_id = cumsum(data.Intensity_mm_hr_ == 0); % create a new event if intensity goes to 0
data.er=0.29*(1-0.72*exp(-0.05*data.Intensity_mm_hr_));
data.ervr=(data.er).*(data.Increment);
data_summary_1=groupsummary(data,{'Event_id'},{'sum','max'},{'ervr','Increment','Intensity_mm_hr_'});
data_summary_2=groupsummary(data,{'Event_id'},{'max'},{'Date'});
data_summary= join(data_summary_1,data_summary_2);
data_summary(data_summary.sum_Increment<12.7,:) = [];
data_summary.EI30_aug=data_summary.sum_ervr.*data_summary.max_Intensity_mm_hr_;

Walter Roberson on 28 Jan 2020
Inten = T{:,5};
mask = Inten.' > 0; %row
starts = strfind([0 mask], [0 1]);
stops = strfind([mask 0], [1 0]);
event_totals = arrayfun(@(A,B) sum(Inten(A:B)), starts, stops);
[maxintens, maxpos] = max(event_totals);
max_start_time = T{starts(maxpos), 2};
max_stop_time = T{stops(maxpos), 2};
Additional work needs to be done to get the dates right, if your representative sample is correct in most date entries being blank.