speice.io/assets/js/3cafba32.13b5f899.js

1 line
11 KiB
JavaScript
Raw Normal View History

"use strict";(self.webpackChunkspeice_io=self.webpackChunkspeice_io||[]).push([["6267"],{6376:function(e,t,n){n.r(t),n.d(t,{assets:function(){return c},contentTitle:function(){return o},default:function(){return h},frontMatter:function(){return s},metadata:function(){return a},toc:function(){return l}});var a=n(63628),i=n(85893),r=n(50065);let s={slug:"2016/01/cloudy-in-seattle",title:"Cloudy in Seattle",date:new Date("2016-01-23T12:00:00.000Z"),authors:["bspeice"],tags:[]},o=void 0,c={authorsImageUrls:[void 0]},l=[{value:"Examining other cities",id:"examining-other-cities",level:2},{value:"Conclusion",id:"conclusion",level:2}];function d(e){let t={code:"code",h2:"h2",img:"img",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.p,{children:"Building on prior analysis, is Seattle's reputation as a depressing city actually well-earned?"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-python",children:"import pickle\nimport pandas as pd\nimport numpy as np\nfrom bokeh.plotting import output_notebook, figure, show\nfrom bokeh.palettes import RdBu4 as Palette\nfrom datetime import datetime\nimport warnings\n\noutput_notebook()\n"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"BokehJS successfully loaded.\n"})}),"\n",(0,i.jsx)(t.h2,{id:"examining-other-cities",children:"Examining other cities"}),"\n",(0,i.jsx)(t.p,{children:"After taking some time to explore how the weather in North Carolina stacked up over the past years, I was interested in doing the same analysis for other cities. Growing up with family from Binghamton, NY I was always told it was very cloudy there. And Seattle has a nasty reputation for being very depressing and cloudy. All said, the cities I want to examine are:"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:"Binghamton, NY"}),"\n",(0,i.jsx)(t.li,{children:"Cary, NC"}),"\n",(0,i.jsx)(t.li,{children:"Seattle, WA"}),"\n",(0,i.jsx)(t.li,{children:"New York City, NY"}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:"I'd be interested to try this analysis worldwide at some point - comparing London and Seattle might be an interesting analysis. For now though, we'll stick with trying out the US data."}),"\n",(0,i.jsxs)(t.p,{children:["There will be plenty of charts. I want to know: ",(0,i.jsx)(t.strong,{children:"How has average cloud cover and precipitation chance changed over the years for each city mentioned?"})," This will hopefully tell us whether Seattle has actually earned its reputation for being a depressing city."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-python",children:"city_forecasts = pickle.load(open('city_forecasts.p', 'rb'))\nforecasts_df = pd.DataFrame.from_dict(city_forecasts)\n"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-python",children:"cities = ['binghamton', 'cary', 'nyc', 'seattle']\ncity_colors = {cities[i]: Palette[i] for i in range(0, 4)}\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(city, 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(forecasts_df[city][x]['currently']), dates))\n cloud_cover_samples = len(list(filter(lambda x: x is not np.NaN, cloud_cover_vals)))\n # Ignore an issue with nanmean having all NaN values. We'll discuss the data issues below.\n with warnings.catch_warnings():\n warnings.simplefilter('ignore')\n return np.nanmean(cloud_cover_vals), cloud_cover_samples\n"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-python",children:"years = range(1990, 2016)\ndef city_avg_cc(city, month):\n return [monthly_avg_cloudcover(city, y, month) for y in years]\n\nmonths = [\n ('July', 7),\n ('August', 8),\n ('