From time to time I ride a bike to work. Sometimes it rains outside, the weather is “not cycling,” and then a dilemma arises: wait a bit until it ends, or even drive a car. It also happens that in the morning the weather is good, and in the evening it starts to rain and I want to find a “window” in order to get home dry. It’s ridiculous a couple of times - the sun is shining in the morning, I leave, after about five minutes a steady rain begins, and after a few minutes it ends, the sun shines again, and I enter the office wet to the underwear.
Thus, we need a service with a short-term weather forecast - within a couple of hours. Most weather services offer a forecast for several days (while the quality of the forecast is so-so), but I have not seen a convenient and simple short-term forecast. Although it would seem - what could be simpler - there are precipitation maps at each moment in time, and after analyzing the history in the last couple of hours, it is possible to quite reliably calculate what will happen in the next hour or two.
Under the cut, we will do the following - programmatically load the rain maps from one of the services and see what happens in the vicinity of a certain point, saving the results to the dropbox. The simple Friday exercise will, of course, be performed in LabVIEW.
')
Initial data
First, let's see what we have. I’m geographically located in the north of Germany, so the presentation will be applicable to this country, but the general principle, of course, applies to other countries - you just need to find a suitable source of information. In Russia, the situation is a bit worse - I have not seen good detailed maps of precipitation - this, by the way, is an idea for a good startup. The first service I came across is
www.niederschlagsradar.de . There is almost everything you need in order to assess whether it will rain or not, but there is no convenient presentation of information for a specific point. The second service is
www.rain-alarm.com . It is also almost what you need - where you can specify the location, but I need not so much a warning as a small sign - I’m not only interested in when it rains, it’s also important for me to know when the rain ends to find a window in 20-30 minutes, during which I will get to work dry. In addition, in the free version there are a lot of restrictions (for example, an analysis only within 75 km, which is a lot of advertising). For the paid version of the money is not so sorry, it's just not exactly what you need.
maps.google.com can show clouds, but not precipitations, and it’s easy to get a ban for constantly polling data. There are also several Android apps that show an animated rain map, but again, the animation has to be analyzed in the head. Well, roll up your sleeves and make a simple bike. Along the way, I will show how to get a picture from the Internet in LabVIEW - the actual post is about that.
We will parasitize on the site
www.niederschlagsradar.de . I do not plan to upload the application online, but I don’t see any problems in writing the robot “for myself”. My first thought was to analyze the location and movement of precipitation in the vicinity of the point of interest, then calculate the motion vectors of the clouds and build a forecast for the next hour. However, I didn’t have to reinvent the wheel - there is already a forecast (though I lost the most interesting part of the problem). The server provides forecast images in this format, for example, for 13:00 on January 4, 2013:
www.niederschlagsradar.de/images.aspx?j=-4&file=201301041200It is easy to see that the time is in UTC.
Obtaining images from the Internet in LabVIEW
To get pictures from the Internet, we use the following simple method:

In this example, the NI site logo is loaded. If you are reading this article in Internet Explorer and you have LabVIEW version 2010 or higher, you can drag this snippet directly to the block diagram. A slightly nontrivial part is adding the string [text] to the URL. Why this is so - you can read the document
Retrieving an Unformatted Text File via FTP or HTTP Using DataSocket .
So we got the contents of the gif in the string. LabVIEW does not know how to work out of the box with gif files, so we will use
the good Samaritan MikeS81 library to convert gif into picture. I added the ability to read the contents of the line there, otherwise I would have to save the resulting image to a file, and so you can perform the conversion on the fly in memory:

URL Formation
Now we need to form a string like
www.niederschlagsradar.de/images.aspx?j=-4&file=201301041200The time here is used in increments of five minutes - 12:00, 12:05, etc. So we’ll get the current time, round it up to five minutes (then in the cycle we add 300 seconds each to get all the forecast files):

String generation is primitive:

Analysis
Now we proceed to the analysis. Analysis is, of course, loudly said, but nonetheless. The server gives us GIF images of 550x512 pixels with a transparent background. The blue component is always 255, and the red and green are reduced in rain areas. Let's say R = 100; G = 100; B = 255 is quite heavy rain. The blue color shows areas with rain:

Let's do a simple analysis: take a point with given coordinates (my city is approximately at the point with coordinates x = 302, y = 79), cut out a square from the image array (I took 13x13 pixels - that's about 10 km) and calculate the minimum. Theoretically, it is more correct to consider the average, but with a minimum I got better results (it happens that the cloud only touches the edge of the square, but at the same time there is quite heavy rain outside the window, so the minimum gives a more realistic result):

Technically, a LabVIEW RGB picture (picture) is a one-dimensional byte array, in which every three bytes are RGBRGBRGB color components, etc. Accordingly, Decimate 1D Array with three outputs will decompose us into an array of components. In order not to fool around with calculating the indices, the one-dimensional array is distilled into a two-dimensional one, and then a square piece is cut out from there.
Save
It remains only to save the report to the HTML file:

A two-dimensional array with results comes to our input. The first column is the forecast time, and the second is the result. We will save the result in% USERPROFILE% \ Dropbox (good form - do not use hard-coded paths):

That's almost all. It remains only to enclose a map of Germany under the clouds to monitor the position and size of the region of interest. For this we use MaskColor - this SubVI will create a mask through which the map will shine. The map is loaded from the same folder in which the main VI is located. Let's put it all together and run it in a loop:

Here While the cycle works every 5 minutes (a pause of 300000 ms is non-kosher, but I do not want to complicate the diagram), and for the cycle loads data in two hours (22 iterations - just as many images with the forecast are available on the server). I deliberately did not hide the logic under SubVI, so that it was clearer. On the front panel we will have this picture:

Here is such a Hamburg winter. Well, in the dropbox there will be such a file, for example, this morning (dashes indicate the absence of rain, and the plus signs - the presence and strength):

It is immediately obvious that at eight in the morning it is better not to leave the house, but to wait until half past eight.
Since I have a dropbox client both on the tablet and on the phone - I can always look before leaving the house to see if I should ride a bike or it makes sense to take a car.
Of course, the program can be hung with whistles to infinity (minimizing to tray, uploading data to ftp, adding temperature, messages to e-mail / SMS, etc.), but in this simple form this application suits me more than completely. And it goes without saying that a similar thing can be assembled in any programming language, this article is just an example - how a small applied task can be solved by means of LabVIEW.
LabVIEW 2010 Source Code