Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I moved to another city and the weather sucks.

Sometimes I feel like getting sad and so I go to wolfram|alpha and check for example

${}$

enter image description here

http://www.wolframalpha.com/input/?i=weather+in+Rome+vs.+London

${}$

Today I feel like getting depressed.

Consequently I wonder if there is a way to import all the data into Mathematica and write a function

TemperatureComparison[{city1,city2},{date1,date2}]

which should evaluate to

$$ \frac{ \int_{\text{date 1}}^{\text{date 2}} \left(T_{\text{city 2}}(t)-T_{\text{city 1}}(t)\right) \text dt } { t_{\text{date 2}}-t_{\text{date 1}} },$$

$T_{\text{city X}}(t)$ being the temperature in $\text{city X}$ at time $t$.

share|improve this question
1  
You've seen WeatherData[]? –  J. M. Oct 12 '12 at 8:23
    
You can get the data out of Wolfram|Alpha pretty easily. Take a look at this article for an example: support.wolfram.com/kb/7357 The data here is financial, but the process is the same. –  Searke Oct 12 '12 at 14:41
add comment

1 Answer

up vote 4 down vote accepted

As suggested by @J.M. you don't need WolframAlpha. One way is to define :

temperatureComparison[{city1_, city2_}, {date1_, date2_}] := 
 Module[{data1, data2, int1, int2},
  data1 = {AbsoluteTime[#[[1]]], #[[2]]} & /@  WeatherData[city1, "MeanTemperature", {date1, date2, "Day"}] ;
  data2 = {AbsoluteTime[#[[1]]], #[[2]]} & /@ WeatherData[city2, "MeanTemperature", {date1, date2, "Day"}] ;
  int1 = Interpolation[data1];
  int2 = Interpolation[data2];
  {#, NIntegrate[
   int1[t] - int2[t], {t, AbsoluteTime[date1], 
    AbsoluteTime[#]}]/(AbsoluteTime[#] - AbsoluteTime[date1])} & /@    
     NestList[DatePlus[#, 1] &, DatePlus[date1, 1], Round@DateDifference[date1, date2] - 1]

]

which you can use as :

output = temperatureComparison[{"Rome", {"London", "GreaterLondon",  
     "UnitedKingdom"}}, {{2012, 1, 1}, Date[]}]

 DateListPlot[output]

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.