## Visualizing Weather Patterns in *Mathematica* 7

January 13, 2009

Ulises Cervantes-Pimentel, Senior Kernel Developer

Andrew Moylan, Technical Communication & Strategy

Weather visualizations are very interesting—there are television channels that thrive by showing nothing else. Online, there are several sources for specific maps of current weather conditions. Generally these are produced and maintained by government agencies or other large organizations. But with *Mathematica* 7, you can easily produce completely customizable weather visualizations on your own computer.

As usual, this is made possible by *Mathematica*‘s tight integration of several areas of functionality. Two new features that enable this particular application are powerful new vector visualization functions and built-in weather data.

Vector visualization has been present in *Mathematica* since Version 2. In *Mathematica* 7 it has been dramatically improved, adding modern techniques in vector data visualization and new algorithms developed at Wolfram Research. Traditional arrow-based vector plots, new methods based on automatic streamline placement, support for vector glyphs, and high-resolution images produced using line integral convolutions are all now supported.

Meanwhile, the new `WeatherData` function provides access to data from all public weather stations worldwide. Real-time and historical data on temperature, pressure, wind speed, and many other variables is immediately available for mathematical analysis and visualization.

Here is the position of every station, marked with its most recently reported wind velocity:

Comparing the daily mean temperatures in Cairo, Egypt and Sydney, Australia for the last three years is this easy:

Let’s see how to combine these features to produce our own weather maps. Here’s how to make a `ListStreamPlot` of the current wind direction across Italy:

Not bad for a single input! We used the `CountryData` function, which was introduced in *Mathematica* 6, to obtain a polygonal representation of Italy.

Now let’s build up some more detailed visualizations, step by step. Here’s a function that gives a polygonal outline of a country or region:

Stream plots of wind direction like the one we produced above can be a little deceptive, because they don’t convey any information about wind speed. We can use `WeatherData` to include wind speed information:

Here’s a tabulation of wind velocity vectors as a function of latitude and longitude:

These are all the ingredients we need to produce a customized `ListVectorPlot`:

Using our wind speed data we can revisit `ListStreamPlot`. A stream plot is a good option when the positioning of the underlying data points on a rectangular grid might be distracting in a `ListVectorPlot`. In the following stream plot, we color stream lines according to the local wind speed (brighter colors indicate higher speeds):

A lot is going on behind the scenes in `ListStreamPlot`. Note the way stream lines are automatically positioned to have uniform density across the plot.

Let’s further customize our weather visualization. Here’s a tabulation of wind velocity and temperature over Africa:

(The last line filters out weather stations that are currently offline.)

The new function `ListVectorDensityPlot` visualizes vector data together with an accompanying scalar field:

A slight variation on the above code (download the source notebook) produces this pressure/wind map of the United States:

These interesting and informative visualizations of real-time weather conditions require just a few lines of code. Where to from here? We could combine any of the above visualizations with `Dynamic` to produce a constantly up-to-date weather map. We could produce an animation of historical weather conditions using `ListAnimate`. We could produce weather visualizations for any country or the whole world, taking advantage of the new integrated geodesy system to visualize in Mercator or any other cartographic projection. The possibilities are limitless. What will your weather map do?

## 3 Comments

Hi,

this is a really cool blog entry!

I understand how to adapt the ListPlot for displaying data from two stations – f.ex.:

DateListPlot[

WeatherData[#,

"MeanTemperature", {{2006, 1, 1}, {2009, 1, 1},

"Day"}] & /@ {“ETSE”, “ETSL”}]

However, how would I pick the measurements at those two stations at the same date?

Cheers,

Claus

Hi there,

It would be an *enormous* help if you would update this blog entry to include the essential step of filtering for missing data. I spent a lot of time getting nowhere, then finally thought to download your notebook. To anyone trying to follow along, I hope you read as far as this comment. Download the notebook, because the blog post alone won’t work.

Well, it is a good improvement. However, the modeling for forecasting in this field is not developed in Mathematica, I see FORTRAN everywhere, and not Mathematica. Do you think it will be possible, in future, to use Mathematica for meteo?