Calculate daily rainfall from continuously increasing value
2 views (last 30 days)
Show older comments
So I've made a small weather thingy that reports various data to ThingSpeak. How will I go about making a Matlab Analysis that finds daily rainfall at midnight? The counter and hence the data is an ever growing variable (mm)... I'm in all aspects of the word new to this Matlab thing but I did search for answers before asking this question. Examples or links to existing working code would be much appreciated.
Kind regards, Chris
3 Comments
Adam Danz
on 21 Aug 2018
(I'm still learning about rain thingys) So, you have a tip-count per day and I assume it tips after reaching a somewhat precise, measurable volume. I saw the charts you shared on the web page but what I'd really like to see is a portion of your raw data. I still don't understand if your data is recorded every x minutes or if it's only recorded when the container tips.
Answers (3)
Adam Danz
on 20 Aug 2018
Edited: Adam Danz
on 20 Aug 2018
I assume you're sampling rainfall (mm) at some temporal interval and storing the rainfall and the timestamp in separate vectors or in a matrix. If your rainfall data are monotonic (ie, the rain never evaporates or leaks from the 'weather thingy' but keeps accumulating, then you could just choose a daily time such as midnight to mark the beginning of a new day and subtract the difference between days at midnight.
Example; sampling every hour
timestamp = [0 1 2 3 4 5 6 7 8 9 10 ... 22 23 0 1 2 3 ...]; %hours
rainfall = [0 0 0 1 1 1 2 2 2 2 3 ... 5 5 5 6 6 7 ...]; %mm
midnightIdx = timestamp == 0;
rainPerDay = diff(rainfall(midnightIdx));
However, if your rainfall data are not monotonic (your device leaks, evaporation), you'll need to differentiate, diff(), the entire rainfall vector which will give you the change every hour (or whatever your sample rate is) and then you'll need to add up all of the positive changes only per day, ignoring any loss in rainwater.
3 Comments
Adam Danz
on 20 Aug 2018
I see, thanks. I was conceptualizing the data as " an ever growing variable (mm)" from the question. If the data are merely number of dumps, this answer won't work. I'll wait for clarification before removing the answer, though.
dpb
on 20 Aug 2018
The value returned is in mm (or in depending on user preference) but how it's physically measured is by "tips". Now, whether OP is in the data stream where there's just a sequential trail of times and volumes at those times or whether the instrument reports a running total is dependent on its firmware; the original question implies that may be so; it's not clear to me whether it's actually a running total that's being returned or just that each time he gets new data that's more that has been accumulated but the actual data is the new accumulation.
Gibier Serge
on 22 Sep 2023
Bonjour,
Je suis interréssé par ce code. Pouvez-vous fournir le code complet.
Merci.
Serge
0 Comments
Communities
More Answers in the ThingSpeak Community
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!