Calculate daily rainfall from continuously increasing value

2 views (last 30 days)
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
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.

Sign in to comment.

Answers (3)

Adam Danz
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
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
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.

Sign in to comment.


Christoffer Veng
Christoffer Veng on 21 Aug 2018
Edited: Christoffer Veng on 21 Aug 2018
Well my technical English seems to be running short here. Every time the bucket tips, my device outputs a new number of millimeters. Meaning it's either increasing when it rains or being constant when it doesn't. I have no mat code yet but my upload code is
String postStr = apiKey;
postStr +="&field1=";
postStr += String((float)t);
postStr +="&field2=";
postStr += String((int)h);
postStr +="&field3=";
postStr += String((int)lysStyrke);
postStr +="&field4=";
postStr += String((float)millimeter,1);
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
I suppose ThingSpeak somehow timestamps my data as they flow in. As it's running stable, I made the results public at this link.
I think, what I want is pretty simple. At a minute past midnight I'd like to do a calculation and I suppose calculating a total daily increment could be done in a couple of ways. A) Highest value previous date minus lowest value previous date..... OR B) Latest value previous date minus first value previous date.

Gibier Serge
Gibier Serge on 22 Sep 2023
Bonjour,
Je suis interréssé par ce code. Pouvez-vous fournir le code complet.
Merci.
Serge

Communities

More Answers in the  ThingSpeak Community

Categories

Find more on ThingSpeak in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!