通知!通知!,去我的首页转发“抽奖活动” 可以参与抽奖(一块抖音网红手表)哦。
前面文章《CSS3线性渐变、阴影、缩放实现动画下雨效果》实现了下雨的动画效果,现在我们来绘制更多天气相关的动态图标。
css3简易的天气图标动画特效
上图6种天气,我们就分开一一展示给小伙伴们,希望能给大家带来帮助。
<div class="icon sunny"> <div class="sun"> <div class="rays"></div> </div> </div>
sun标签绘制圆环,rays及其伪类绘制射线,然后添加动画,其实旋转。
body { background-color: currentColor; } .sun { width: 2.5em; height: 2.5em; margin: -1.25em; background: currentColor; border-radius: 50%; box-shadow: 0 0 0 0.375em orange; animation: spin 12s infinite linear; } .rays { position: absolute; top: -2em; left: 50%; display: block; width: 0.375em; height: 1.125em; margin-left: -0.1875em; background: yellow; border-radius: 0.25em; box-shadow: 0 5.375em yellow; } .rays:before, .rays:after { content: ''; position: absolute; top: 0em; left: 0em; display: block; width: 0.375em; height: 1.125em; transform: rotate(60deg); transform-origin: 50% 3.25em; background: yellow; border-radius: 0.25em; box-shadow: 0 5.375em yellow; } .rays:before { transform: rotate(120deg); } @keyframes spin { 100% { transform: rotate(360deg); } }
css3简易的天气图标动画特效
<div class="icon rainy"> <div class="cloud"></div> <div class="rain"></div> </div>
添加样式
body { background-color: currentColor; } .cloud { position: absolute; z-index: 1; width: 3.6875em; height: 3.6875em; margin: -1.84375em; background: currentColor; border-radius: 50%; box-shadow: -2.1875em 0.6875em 0 -0.6875em, 2.0625em 0.9375em 0 -0.9375em , 0 0 0 0.375em lightgray, -2.1875em 0.6875em 0 -0.3125em lightgray, 2.0625em 0.9375em 0 -0.5625em lightgray; }
css3简易的天气图标动画特效
这朵云是不是怪怪的,下边应该是平整的,所以添加样式。
.cloud:after { content: ''; position: absolute; bottom: 0; left: -0.5em; display: block; width: 4.5625em; height: 1em; background: currentColor; box-shadow: 0 0.4375em 0 -0.0625em lightgray; }
css3简易的天气图标动画特效
这里绘制云,和《CSS3线性渐变、阴影、缩放实现动画下雨效果》一样的,都是用box-shadow阴影来制作的。
然后我们加入雨滴
... .rain{ position: absolute; z-index: 2; top: 50%; left: 20%; width: 3.75em; height: 3.75em; margin: 0.375em 0 0 -2em; background: currentColor; } .rain:after { content: ''; position: absolute; z-index: 2; top: 50%; left: 50%; width: 1.125em; height: 1.125em; margin: -1em 0 0 -0.25em; background: #0cf; border-radius: 100% 0 60% 50% / 60% 0 100% 50%; box-shadow: 0.625em 0.875em 0 -0.125em rgba(255,255,255,0.2), -0.875em 1.125em 0 -0.125em rgba(255,255,255,0.2), -1.375em -0.125em 0 rgba(255,255,255,0.2); transform: rotate(-28deg); animation: rain 3s linear infinite; } @keyframes rain { 0% { background: #0cf; box-shadow: 0.625em 0.875em 0 -0.125em rgba(255,255,255,0.2), -0.875em 1.125em 0 -0.125em rgba(255,255,255,0.2), -1.375em -0.125em 0 #0cf; } 25% { box-shadow: 0.625em 0.875em 0 -0.125em rgba(255,255,255,0.2), -0.875em 1.125em 0 -0.125em #0cf, -1.375em -0.125em 0 rgba(255,255,255,0.2); } 50% { background: rgba(255,255,255,0.3); box-shadow: 0.625em 0.875em 0 -0.125em #0cf, -0.875em 1.125em 0 -0.125em rgba(255,255,255,0.2), -1.375em -0.125em 0 rgba(255,255,255,0.2); } 100% { box-shadow: 0.625em 0.875em 0 -0.125em rgba(255,255,255,0.2), -0.875em 1.125em 0 -0.125em rgba(255,255,255,0.2), -1.375em -0.125em 0 #0cf; } }
还有人记得《CSS3绘制一个小雨滴,见证它的成长之路》,其实很多东西都是一点点积累的过程,慢慢的拼凑,会得到不一样的东西。
css3简易的天气图标动画特效
如果你对box-shadow动画还不是很熟悉的,可以看这里《CSS3 box-shadow实现背景动画》
家好,我是杰瑞,经常更新一些有趣实用的教程,喜欢的就请关注我吧!
海南的天气实在是热得慌,杰瑞被外面燥热的空气“困”在了家里面,也不知道什么时候能下雨天气凉爽一点,好让我出去打打篮球跑跑步啥的,杰瑞也懒得去看天气预报,因为看天气预报又得打开网站、选择地址,然后再自己慢慢从页面分辨出自己想要的天气信息,对于杰瑞这样的“懒癌”患者来说这种情况是不会发生的。
所以杰瑞今天就要从技术上解决“查天气麻烦”这个问题,怎么解决呢?没错!正如标题所述,杰瑞将使用爬虫爬取杰瑞想要的天气信息。
代码部分不是很复杂,所以杰瑞这篇文章里面就主讲实现思路,各位同学跟上杰瑞的思路不要掉队哦!
首先我们的打开一个天气信息网站,然后进行一系列操作找到你所在地区的天气信息,这个展示天气信息的页面就是咱们要爬取的页面,上面有咱们需要的天气信息。
怎么对这个页面入手呢?我们先来分析一下,众所周知,像这样的页面,我们选择的地区不一样,页面显示的数据就不一样,但页面的样式是不会改变的,仅仅改变一些动态的数据而已,例如温度、风力、日期等信息,这样的页面我们称它为:“动态页面”,注意哦,动态页面并不是说这个页面的动画效果哦,而是页面中显示的数据会随着时间或其他事件的变化而变化。
那我们如何把这个页面中显示的温度、风力、日期等数据爬取下来呢?
事实上,当我们选择地区让页面显示出该地区的天气信息时,就相当于浏览器和服务器发生了以下行为:
请求过程
实际上,这就是一个浏览器向服务器发起一个请求的过程。所以,如果我们能够用python模拟这个请求过程,那么我们不就可以像浏览器那样接收天气服务器返回的天气信息了吗?
如果你这么想的话,那么恭喜你,思路完全正确!
向指定地址发起请求
我们可以使用python中的urllib库urlopen方法,该方法可以打开一个url(你可以理解为被爬取网页的网址),就像浏览器所做的那样。
运行上面这几行代码然后把soup打印出来,我们可以看到这个网页的标签信息、JavaScript代码以及我们想要的数据都显示在控制台窗口中。在这里杰瑞使用了BeautifulSoup库用于解析html数据,具体用法各位同学可以查看相关文档。
现在问题来了,我们如何从这么多的标签中查找到我们需要的天气数据呢?别急,我们先回到浏览器上,打开我们爬取的那个页面然后按一下F12打开开发者模式,以谷歌浏览器为例,我们将看到以下界面。
我们打开Elements这个选项卡,在这里可以看到这个页面的所有信息,包括标签信息、JavaScript信息、天气信息,其实Elements窗口中显示的信息和我们在控制台输出的信息是一样的,所以在Elements窗口中我们可以找到需要的天气信息。
这里小编告诉大家一个小技巧,我们用鼠标指向某一行标签时,该标签所渲染的那些元素就会在页面中“高亮”,可以借助这个特性快速找到我们要找的那行标签。
如上图,天气信息就在类名为skyid的li标签中,现在我们已经就确定了天气信息所在的标签,然后我们回到python编辑器中,我们使用BeautifulSoup中的find方法找到类名为skyid的li标签入口。
然后我们将结果打印出来,可以看到下一下信息:
是不是有点似曾相识?没错,它就是我们在浏览器中看到的那组标签:
那么接下来,各位同学应该知道怎么做了吧?find()方法我们可以这么理解,他可以返回页面中指定类名、标签中所标记的元素。所以我们可以像下面这样找到所有我们需要的数据:
到这里,我们的教程就完成啦!接下来我们看一下效果。
杰瑞爬取的是当天的天气信息,如果有同学想获取其他日期的数据也可参照上面的方法去获取。
代码运行效果
作者|编程高手杰瑞
各位同学都看到这里了,不如给杰瑞:
点赞、留言、关注
每天更新有趣实用的教程哦!
itle:Climate change now detectable from any single day of weather at global scale
标题:现在可以从全球范围内任何一天的天气中检测到气候变化
作者:Sebastian Sippel?1,2,3*, Nicolai Meinshausen 2, Erich M. Fischer1, Enik? Székelyg1, and Reto Knutti1
1 Institute for Atmospheric and Climate Science, ETH Zurich, Zurich, Switzerland.
2Seminar for Statistics, ETH Zurich, Zurich, Switzerland.
3Norwegian Institute of Bioeconomy Research, ?s, Norway.
4Swiss Data Science Center, ETH Zurich and EPFL, Lausanne, Switzerland.
E-mail: sebastian.sippel@env.ethz.ch[1]
杂志:Nature Climate Change, volume 10, pages35–41(2020)
DOI: https://doi.org/10.1038/s41558-019-0666-7[2]
原文摘要
长此以往,气候科学家传递给公众的都是“天气不是气候”的观念,气候变化也被框定为天气分布的变化缓慢地出现于这数十年里主要的气候变率中1-7。然而,现阶段考虑全球性的天气则是一个未知的领域。在这里我们基于全球观测的单日温度和水汽来检测外部驱动气候变化的“指纹”所得到的结论是:地球作为一个整体正在变暖。我们的检测方法通过统计学习和气候模型模拟来封装每日温度和湿度的空间模式与关键的气候变化指标(例如,全球年平均温度或地球的能量失衡之间)之间的关系。观测数据投影到这种关系中来检测气候变化。根据一年的数据,从2012年初和1999年以来观测到的全球记录中的任何一天都可以检测到气候变化的“指纹”。即便是忽略长期全球变暖的趋势,检测的结果也是很稳健可靠的。这是对传统气候变化检测的补充,但也为区域天气事件的交流打开了更广阔的视野,改变了气候变化的叙述方式:尽管几十年来局地的天气变化正在出现,但现在就能即时检测到全球气候变化。
Abstract
For generations, climate scientists have educated the public that ‘weather is not climate’, and climate change has been framed as the change in the distribution of weather that slowly emerges from large variability over decades1-7. However, weather when considered globally is now in uncharted territory. Here we show that on the basis of a single day of globally observed temperature and moisture, we detect the fingerprint of externally driven climate change, and conclude that Earth as a whole is warming. Our detection approach invokes statistical learning and climate model simulations to encapsulate the relationship between spatial patterns of daily temperature and humidity, and key climate change metrics such as annual global mean temperature or Earth’s energy imbalance. Observations are projected onto this relationship to detect climate change. The fingerprint of climate change is detected from any single day in the observed global record since early 2012, and since 1999 on the basis of a year of data. Detection is robust even when ignoring the long-term global warming trend. This complements traditional climate change detection, but also opens broader perspectives for the communication of regional weather events, modifying the climate change narrative: while changes in weather locally are emerging over decades, global climate change is now detected instantaneously.
数据、代码
数据[3]
All original CMIP5 data, reanalyses and observations used in this study are publicly available under the following URLs.
CMIP5 model data: https://esgf-node.llnl.gov/projects/cmip5/;
reanalysis:
ERA-Interim (https://www.ecmwf.int/en/forecasts/datasets/reanalysis-datasets/era-interim),
NCEP/NCAR Reanalysis 1 (https://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanalysis.html),
NCEP/NCAR Reanalysis 2 (https://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanalysis2.html),
Twentieth Century Reanalysis (https://www.esrl.noaa.gov/psd/data/20thC_Rean/);
observations (monthly): GISTEMP temperature dataset, version 3 (https://data.giss.nasa.gov/gistemp/),
Cowtan and Way (2014) temperature dataset, version 2 (https://www-users.york.ac.uk/~kdc3/papers/coverage2013/series.html),
Berkeley Earth Monthly Land+Ocean temperature dataset (http://berkeleyearth.org/data/), Met Office gridded land surface humidity dataset (HadISDH),
version 4.0.0.2017f (https://www.metoffice.gov.uk/hadobs/hadisdh/);
observations (daily): Berkeley Earth Daily Land temperature dataset (Experimental, http://berkeleyearth.org/data/),
NOAA Optimum Interpolation Sea Surface Temperature (OISST), AVHRR-Only (https://www.ncdc.noaa.gov/oisst).
All intermediate and derived data from these products (extracted CMIP5 fingerprints and daily/monthly time series of the test statistic (that is, obtained by projecting CMIP5 models, reanalyses and observations individually onto the fingerprints)) are available at https://data.iac.ethz.ch/Sippel_et_al_2019_DailyDetection/.
代码[4]
All computer code to reproduce the main results and all figures and Extended Data figures is available at https://data.iac.ethz.ch/Sippel_et_al_2019_DailyDetection/
图文
References
[1] sebastian.sippel@env.ethz.ch: mailto:sebastian.sippel@env.ethz.ch[2] https://doi.org/10.1038/s41558-019-0666-7: https://doi.org/10.1038/s41558-019-0666-7[3] 数据: https://www.nature.com/articles/s41558-019-0666-7#data-availability[4] 代码: https://data.iac.ethz.ch/Sippel_et_al_2019_DailyDetection/
*请认真填写需求信息,我们会在24小时内与您取得联系。