Wolfram Computation Meets Knowledge

Visualizing Weather Patterns in Mathematica 7

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.

Vector graphics in Mathematica 7—click to enlarge

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:

In[1]:= DateListPlot[WeatherData[#,"MeanTemperature",{{2006,1,1},{2009,1,1},"Day"}]&/@{"Cairo","Sydney"}]

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:

In[2]:= Show[Graphics[{GrayLevel[.7],CountryData["Italy","Polygon"]}],ListStreamPlot[Table[{{x,y},-Through[{Sin,Cos}[WeatherData[{y,x},"WindDirection"]\[Degree]]]},{x,6,18,3},{y,36,48,3}]]]

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:

In[3]:= outline[region_]:=Graphics[{GrayLevel[0.2],AbsoluteThickness[1.5],CountryData[region,"Polygon"]/.Polygon->Line}];

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:

In[4]:= windVelocity[x_,y_]:=-WeatherData[{y,x},"WindSpeed"]{1/Cos[y \[Degree]],1} Through[{Sin,Cos}[WeatherData[{y,x},"WindDirection"]\[Degree]]]

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

In[5]:= data=Table[{{x,y},windVelocity[x,y]},{x,113,153,4},{y,-43,-11,4}]//Flatten[#,1]&;

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

In[6]:= Show[ListVectorPlot[data,VectorColorFunction->"RustTones",AspectRatio->Automatic,VectorPoints->25,InterpolationOrder->None,VectorScale->5/100],outline["Australia"]]

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):

In[7]:= Show[ListStreamPlot[data,StreamColorFunction->"RustTones",AspectRatio->Automatic,InterpolationOrder->None,StreamPoints->{Automatic,0.5}],outline["Australia"]]

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:

In[8]:= temperatureData=Table[{{x,y},{windVelocity[x,y],WeatherData[{y,x},"Temperature"]}},{x,-20,50,5},{y,-35,35,5}]//Flatten[#,1]&//Cases[#,u_/;FreeQ[u,"NotAvailable"]]&;

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

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

In[9]:= Show[ListVectorDensityPlot[temperatureData,ColorFunction->"TemperatureMap",AspectRatio->Automatic,Mesh->20,VectorPoints->25,VectorStyle->Black,InterpolationOrder->None,MaxRecursion->1,VectorScale->5/100],outline["Africa"]]

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

Wind velocity and atmospheric pressure

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?


Join the discussion

!Please enter your comment (at least 5 characters).

!Please enter your name.

!Please enter a valid email address.


  1. Hi,
    this is a really cool blog entry!
    I understand how to adapt the ListPlot for displaying data from two stations – f.ex.:
    “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?

  2. 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.

  3. 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?