speice.io/assets/js/92079dc1.37202129.js

1 line
16 KiB
JavaScript
Raw Permalink Normal View History

"use strict";(self.webpackChunkspeice_io=self.webpackChunkspeice_io||[]).push([["9366"],{23244:function(e,t,n){n.r(t),n.d(t,{assets:function(){return l},contentTitle:function(){return i},default:function(){return d},frontMatter:function(){return s},metadata:function(){return a},toc:function(){return c}});var a=n(37133),r=n(85893),o=n(50065);let s={slug:"2016/01/complaining-about-the-weather",title:"Complaining about the weather",date:new Date("2016-01-01T12:00:00.000Z"),authors:["bspeice"],tags:[]},i="Tracking Precipitation Chances",l={authorsImageUrls:[void 0]},c=[];function h(e){let t={a:"a",code:"code",h1:"h1",img:"img",p:"p",pre:"pre",...(0,o.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.p,{children:"Figuring out whether people should be complaining about the recent weather in North Carolina."}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-python",children:"from bokeh.plotting import figure, output_notebook, show\nfrom bokeh.palettes import PuBuGn9 as Palette\nimport pandas as pd\nimport numpy as np\nfrom datetime import datetime\nimport pickle\n\noutput_notebook()\n"})}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{children:"BokehJS successfully loaded.\n"})}),"\n",(0,r.jsx)(t.p,{children:"I'm originally from North Carolina, and I've been hearing a lot of people talking about how often it's been raining recently. They're excited for any day that has sun."}),"\n",(0,r.jsx)(t.p,{children:"So I got a bit curious: Has North Carolina over the past few months actually had more cloudy and rainy days recently than in previous years? This shouldn't be a particularly challenging task, but I'm interested to know if people's perceptions actually reflect reality."}),"\n",(0,r.jsxs)(t.p,{children:["The data we'll use comes from ",(0,r.jsx)(t.a,{href:"https://forecast.io",children:"forecast.io"}),", since they can give us a cloud cover percentage. I've gone ahead and retrieved the data to a pickle file, and included the ",(0,r.jsx)(t.a,{href:"#Generating-the-Forecast-file",children:"code that was used to generate it"}),'. First up: What was the average cloud cover in North Carolina during August - November, and how many days were cloudy? We\'re going to assume that a "cloudy" day is defined as any day in which the cloud cover is above 50%.']}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-python",children:"city_forecasts = pickle.load(open('city_forecasts.p', 'rb'))\nforecast_df = pd.DataFrame.from_dict(city_forecasts)\n"})}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-python",children:"cary_forecast = forecast_df['cary']\nyears = range(1990, 2016)\nmonths = range(7, 12)\nmonths_str = ['July', 'August', 'September', 'October', 'November']\n\ndef safe_cover(frame):\n if frame and 'cloudCover' in frame:\n return frame['cloudCover']\n else:\n return np.NaN\n\ndef monthly_avg_cloudcover(year, month):\n dates = pd.DatetimeIndex(start=datetime(year, month, 1, 12),\n end=datetime(year, month + 1, 1, 12),\n freq='D', closed='left')\n cloud_cover_vals = list(map(lambda x: safe_cover(cary_forecast[x]['currently']), dates))\n cloud_cover_samples = len(list(filter(lambda x: x is not np.NaN, cloud_cover_vals)))\n return np.nanmean(cloud_cover_vals), cloud_cover_samples\n\n\nmonthly_cover_vals = [[monthly_avg_cloudcover(y, m)[0] for y in years] for m in months]\n\nf = figure(title='Monthly Average Cloud Cover',\n x_range=(1990, 2015),\n x_axis_label='Year')\nfor x in range(0, len(months)):\n f.line(years, monthly_cover_vals[x], legend=months_str[x], color=Palette[x])\nshow(f)\n"})}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.img,{alt:"Monthly average cloud cover chart",src:n(33754).Z+"",width:"600",height:"600"})}),"\n",(0,r.jsx)(t.p,{children:"As we can see from the chart above, on the whole the monthly average cloud cover has been generally trending down over time. The average cloud cover is also lower than it was last year - it seems