Wolfram Language

Image and Signal Processing

Compare Weather in Chicago and European Capitals

Find the capital city in the EU that had the most similar temperature to Chicago over the last year. Use WarpingDistance to determine the similarity between temperature sequences.

In[1]:=
Click for copyable input
chicagoTemp = WeatherData["Chicago", "Temperature", {{2015, 7}, {2016, 6}, "Week"}, "Value"];

Get the temperature for all capital cities in the European Union.

In[2]:=
Click for copyable input
capitals = CityData /@ CountryData["EU", "CapitalCity"] // Sort
Out[2]=
In[3]:=
Click for copyable input
capitalsTemp = WeatherData[#, "Temperature", {{2015, 7}, {2016, 6}, "Week"}, "Value"] -> # & /@ capitals;

Find the capital city that has the most similar temperatures to Chicago.

In[4]:=
Click for copyable input
Nearest[capitalsTemp, chicagoTemp, DistanceFunction -> (QuantityMagnitude@WarpingDistance[##] &)]
Out[4]=

Calculate pairwise distances in a matrix.

In[5]:=
Click for copyable input
dm = DistanceMatrix[Keys@capitalsTemp, DistanceFunction -> (QuantityMagnitude@WarpingDistance[##] &)];

Show a 7×7 submatrix of the distance matrix.

In[6]:=
Click for copyable input
MatrixForm[Take[dm, 7, 7]]
Out[6]//MatrixForm=

Visualize the temperature similarity using a previously computed distance matrix.

show complete Wolfram Language input
In[7]:=
Click for copyable input
MatrixPlot[dm, FrameTicks -> {{Transpose[{Range[Length@capitals], capitals}], None}, {Transpose[{Range[Length@capitals], Rotate[#, \[Pi]/2] & /@ capitals}], None}}, Mesh -> True, ColorFunction -> "BlueGreenYellow", PlotLegends -> Placed[Automatic, Above], PlotLabel -> "Distance based on temperature", ImageSize -> Large]
Out[7]=

Related Examples

de es fr ja ko pt-br ru zh