Message Boards Message Boards

1
|
9142 Views
|
1 Reply
|
2 Total Likes
View groups...
Share
Share this post:

Search: Cities like [average weather of defined city] - with seasons. How?

Posted 8 years ago

For a while I've been looking for somewhere easy to read historic weather averages between two locations and last night it hit me, Wolframalpha! This was a success.

I would now like to be able to somehow search for the following type of query

Yearly weather averages for City X, compare city x and list other cities with similar results. The results should take into consideration northern and southern hemispheres, i.e. December in Southern Hemisphere may be average 30 Degrees C, but December in Northern might be -10, however in June you might get 30 in the northern hemisphere, and therein, December and June should be compared against eachother, not December and December. Basically, the query needs to be able to take into account the current season of the average temperature which has been recorded.

Is there a way to do this?

POSTED BY: James Edwards

Cities in the Southern Hemisphere similar to Chicago average monthly temperature, seasonally adjusted, over a ten year history:

shp = Take[Select[rankedAll, CountryData[CityData[#, "Country"], "SouthernHemisphere"] &], 10]

{Entity["City", {"Bariloche", "RioNegro", "Argentina"}], Entity["City", {"Canberra", "AustralianCapitalTerritory", "Australia"}], Entity["City", {"Tandil", "BuenosAires", "Argentina"}], Entity["City", {"Talca", "Maule", "Chile"}], Entity["City", {"ComodoroRivadavia", "Chubut", "Argentina"}], Entity["City", {"Neuquen", "Neuquen", "Argentina"}], Entity["City", {"Christchurch", "Canterbury", "NewZealand"}], Entity["City", {"Osorno", "LosLagos", "Chile"}], Entity["City", {"Valdivia", "LosRios", "Chile"}], Entity["City", {"MarDelPlata", "BuenosAires", "Argentina"}]}

GeoGraphics[{Red, PointSize[Large],
  Tooltip[Point[Reverse[CityData[#, "Coordinates"]]], 
     CityData[#, "Name"]] & /@ shp},
 GeoRange -> "World"]

WeatherData<em>TimeSeriesSH

rankedAll is the collection of all "Large" cities for each Country sorted by deviation of mean temperatures from "Chicago". The approach starts with a TimeSeries documentation example, but then I tear it apart and just go back to some of my old tricks.

cityMeanVal[city_] := cityMeanVal[city] = cityMeanVal[city, 10]
cityMeanVal[city_, yearsago_Integer] := 
 cityMeanVal[city, yearsago] = 
  Module[{year = DateValue["Year"], hist, norm, gather, smooth},
   hist = 
    WeatherData[city, 
     "MeanTemperature", {{(year - 1) - yearsago, 1, 1, 0, 0, 
       0.`}, {year, 1, 1, 0, 0, 0.`}, "Month"}];
   If[Head[hist] === WeatherData, Null,
    norm = Normal[hist];
    gather = GatherBy[norm, DateString[First[#], "Month"] &];
    smooth = {#[[-1, 1]], Mean[#[[All, 2]]]} & /@ gather;
    QuantityMagnitude[smooth[[All, 2]]]
    ]]

tempMinModel[city_][tocity_] := tempMinModel[city, tocity]
tempMinModel[city_, tocity_] := 
 Module[{meantemp0 = cityMeanVal[city], 
   meantemp = cityMeanVal[tocity]},
  If[meantemp === Null || meantemp0 === Null, Null,
   Min[Table[Total[(meantemp0 - RotateRight[meantemp, r])^2]/(12 - 1),{r, -6, 6}]
    ]]]

largeCitiesAll = 
  Join @@ (CityData[{Large, CanonicalName@#}] & /@ CountryData[]);

rankedAll = SortBy[largeCitiesAll, tempMinModel["Chicago"]];
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract