Message Boards Message Boards

[GiF] Temperatures in 80 largest cities of China in 2016 (English/Chinese)

GROUPS:

The following GIF illustrates daily temperatures in top 80 biggest cities around China. We can observe any change in temperature:

下面的GIF图片显示了大中华地区人口排名前 80 个城市每天的温度变化: enter image description here

Process the geographic data:

处理地理边界的数据:

getPolygon[entity_] :=
  Replace[
   EntityValue[
     entity,
     "Polygon"
     ] /. GeoPosition -> Identity,
   {longitude_, latitude_} :> {latitude, longitude, 0}, {-2}
   ];
neighbourings = 
  getPolygon /@ CountryData["China", "BorderingCountries"];
creatercn = 
  getPolygon /@ {Entity["Country", "China"], 
    Entity["Country", "Taiwan"], 
    Entity["City", {"HongKong", "HongKong", "HongKong"}], 
    Entity["Country", "Macau"]};

Get the population and location information for these cities.

获取这些城市的人口和地理位置信息.

largeCities = 
  Join[Flatten[
    CityData[{Large, #}] & /@ {"China", "Taiwan"}], {Entity[
     "City", {"HongKong", "HongKong", "HongKong"}], 
    Entity["Country", "Macau"]}];
cityInfo =
 EntityValue[largeCities, {"Population", "Position"}, 
  "EntityAssociation"]

I only selected the top 80 biggest cities:

选出人口最多的前 80 城市:

numCities = 80;
hugeCities = TakeLargestBy[cityInfo, #[[1]] &, numCities];

Get geographic coordinates:

获取地理坐标

hugeCityCoords = 
  Replace[Values[
    hugeCities[[All, 2, 1]]], {long_, lat_} :> {lat, long, 0}, {-2}];

customize the color legend that the temperature:

定义颜色函数图例:

colorScl = 
  Blend[{{-8, RGBColor[0.178927, 0.305394, 0.933501]}, {0, GrayLevel[
      1]}, {34, RGBColor[0.817319, 0.134127, 0.164218]}}, #] &;
clst = Subdivide[-8, 34, 12];
tempLegend =
 Graphics[{
   Table[{
     {colorScl[clst[[i]]], Rectangle[{i, 0}, {1, 0} + {i, 1}]},
     Thin, GrayLevel[0.6],
     {If[Mod[i, 2] == 0, 
       Text[Row[{NumberForm[N@clst[[i]], {\[Infinity], 1}], 
          "\[Degree]"}], {i, -1}]]},
     {If[Mod[i, 2] == 0, Line[{{i, -.2}, {i, -.6}}]]}
     }, {i, Length[clst]}]
   }, ImageSize -> 400
  ]

the time specification of the query:

定义每次查询的时间范围:

dayRange2016 =
  BlockMap[
   {Sequence @@ #, "Day"} &,
   DateRange[{2016, 1, 1}, {2016, 12, 31}, Quantity[1, "Days"]],
   2, 1
   ];

Now query temperature data (In fact, my approach is to export data in each loop):

开始查询 (对于类似这样时间较长数据检索, 我的做法其实是在每次循环的时候将数据导出到本地新建的文件当中):

LaunchKernels[8];
hugeCityTempInfo = 
  Transpose[
   Table[AirTemperatureData[Keys[hugeCities], dayRange2016[[i]], 
     Mean], {i, Length[dayRange2016]}]];

Finally, let's build a dynamic model with Manipulate:

现在让我们用 Manipulate 建立动态的模型:

Manipulate[
 With[{day = dayRange2016[[i, 1]]},
  Panel[
   Column[{
     Overlay[{
       Dynamic@
        Graphics3D[{{Opacity[0.6], china}, EdgeForm[None], 
          Specularity[White, 20],
          Table[
           With[{
             tempValue = hugeCityTempInfo[[cityIdx, i]],
             cityCoord = hugeCityCoords[[cityIdx]]
             },
            {colorScl[tempValue], 
             Cuboid[cityCoord, 
              cityCoord + .5 {1, 1, 
                 Rescale[tempValue, {-18, 42}, {0, 1}]}]}
            ],
           {cityIdx, numCities}
           ],
          {GrayLevel[0.5], neighbourings}
          },
          Axes -> False, ImageSize -> 600, BoxRatios -> {1, 1, .2}, 
         Boxed -> False, BoxStyle -> GrayLevel[0.3], 
         PlotRange -> {{50, 150}, {0, 65}, {-.1, 1.1}}, 
         Background -> GrayLevel[0], ViewAngle -> 0.22, 
         ViewCenter -> {{0.5`, 0.5`, 0.5`}, {0.36, 0.51}}],
       Graphics[{
         Inset[
          Style[DateString[#, {"Month", "/", "Day"}] &[day], 40, 
           GrayLevel[0.5]]]
         }
        ]
       }, All, 1, Alignment -> {Right, Bottom}],
     tempLegend
     }, Background -> GrayLevel[0.], Alignment -> Center],
    Background -> GrayLevel[0.], ImageSize -> 600
   ]
  ],
 {{i, 1}, 1, 365, 1}
 ]

enter image description here

In addition, I have a account in WeChat, more articles please check here( Chinese only :-( )

我在微信有相应的账号[遇见数学], 更多的文章请查看, 也请各位朋友多多指导交流.

图解高等数学: 【向量】 【内积/叉积/三重积】

地球科学课堂 【2012至2016PM2.5可视化】 【吃了冬至饭一天长一线】 【琥珀里的恐龙】 【中秋何时月最圆】 【回顾 2016 的PM2.5】

地理课堂 【2016全年降雨量数据可视化】 【难以会当的凌绝顶】 【经线与纬线】 【全球教师节探秘】 【回顾2016大地震】

信息技术课堂 【3D福字滚滚来】 【孩子们的社交网络】 【玩转3D打印模型设计】 【悼念西蒙.帕派特】 【Wolfram三维打印】

Attachments:
POSTED BY: Xiang Li
Answer
2 months ago

enter image description here - you have earned "Featured Contributor" badge, congratulations !

This is a great post and it has been selected for the curated Staff Picks group. Your profile is now distinguished by a "Featured Contributor" badge and displayed on the "Featured Contributor" board.

POSTED BY: Moderation Team
Answer
2 months ago

Group Abstract Group Abstract