Resample multiple overlapping datetime to 1-minute (and 15-minutes) resolution?

2 vues (au cours des 30 derniers jours)
Alex
Alex le 21 Août 2019
Modifié(e) : Alex le 23 Août 2019
Coming back again on resampling datetime....
Situation is I have many water pumps which are filled up in different time-frames. I have this table with multiple overlapping time and the total volume of individual pumps. Each row is basically a different water pump.
Column 1 (Start time), Column 2 (End time), Column 3 (Volume)
I want to sample the data to minute resolution (also 15 mins resolution) with the specified volume.
Example:
Pump1: 00:04:34 06:33:34 56
Pump2: 00:10:09 09:50:01 93
What I want it
00:04:00 56
00:05:00 56
....
00:10:00 56+93
00:11:00 56+93
....
06:34:00 93
As you can see, it sums up when there is overlapping time. Or else it is the only volume.
I have attached the actual table as well.
Thanks!
  7 commentaires
Alex
Alex le 21 Août 2019
Yes, it is part of the big table. As you can see, End Time of some pumps are same day and for some it is the next day (i.e., 2nd january).
Adam Danz
Adam Danz le 21 Août 2019
Modifié(e) : Adam Danz le 21 Août 2019
I think I understand now. After you've interpolated the time stamps to minute resolution and replicated the volumne values, (as was demonstrated here), you get a timetable with two columns. Can you just apply the cumulative sum to the "vol" column? I haven't looked too closely as to why that wouldn't work.
[Update]
I think Steven's approach below is the way to go.

Connectez-vous pour commenter.

Réponse acceptée

Steven Lord
Steven Lord le 21 Août 2019
Let's start off with two simple timetable arrays, one per pump.
pump1 = timetable(datetime(["01-Jan-2018 00:14:09"; "01-Jan-2018 11:22:13"]), ...
[2.87; 2.87], 'VariableNames', {'Volume_pump1'})
pump2 = timetable(datetime(["01-Jan-2018 00:16:40"; "01-Jan-2018 14:15:10"]), ...
[4.709; 4.709], 'VariableNames', {'Volume_pump2'})
synchronize the two timetable arrays to a new one whose Times are regularly spaced (every 15 minutes), spanning the union of the Times for the two smaller timetable arrays. I'm using linear interpolation and no extrapolation, so the pump is only 'on' during the range spanned by the Times in its smaller timetable array from above.
P = synchronize(pump1, pump2, 'regular', 'linear', ...
'TimeStep', minutes(15), ...
'EndValues', 0)
Note that because I told synchronize to give regular spacing and the Times from pump1 and pump2 aren't multiples of 15 minutes, they're not included. You could construct a NEWTIMES vector (combine the Times together and use bounds to determine the earliest and latest times) and pass that into synchronize if you need those exact times to be included.
To get the total volume:
P2 = timetable(P.Time, sum(P.Variables, 2), 'VariableNames', {'totalVolume'})
  3 commentaires
Steven Lord
Steven Lord le 21 Août 2019
If you have multiple pump cycles, you'd probably want to add a row to each of the individual timetable arrays with Volume_pumpN equal to 0 at the start and end of each time the pump is turned off. Otherwise synchronize would think it's on continuously from the first time it turns on to the last time it turns off.
You could probably store all this data in one timetable with multiple variables from the start and use retime instead of synchronize but I don't have example code for that. It should be fairly similar.
Alex
Alex le 23 Août 2019
Modifié(e) : Alex le 23 Août 2019
Thanks Steven for the clarification. However, I have a minor issue. Now, I run a loop for the 'synchronization' function. But, I am unable to run it for the whole dataset.
Seems I am missing out something in the loop, i.e., adding up the columns. Any pointers?
In the below script: pump_data is the cell array with different pump timetables.
pump1 = pump_data{1,1}(:,1);
pump1.vol(:)=0;
pump_fuel = [];
for f1 = 1:numel(pump_data)
pump_fuel = synchronize(pump_data{1,f1+1}(:,1),pump1,'regular', 'linear','TimeStep', minutes(15),'EndValues', 0);
end

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Timetables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by