mirror of
https://github.com/bspeice/speice.io
synced 2024-12-22 16:48:10 -05:00
1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
"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 ('September', 9),\n ('October', 10),\n ('November', 11)\n]\n\nfor month, month_id in months:\n month_averages = {city: city_avg_cc(city, month_id) for city in cities}\n f = figure(title=\"{} Average Cloud Cover\".format(month),\n x_axis_label='Year',\n y_axis_label='Cloud Cover Percentage')\n for city in cities:\n f.line(years, [x[0] for x in month_averages[city]],\n legend=city, color=city_colors[city])\n show(f)\n"})}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.img,{alt:"July average cloud cover chart",src:n(34326).Z+"",width:"600",height:"600"}),"\n",(0,i.jsx)(t.img,{alt:"August average cloud cover chart",src:n(46529).Z+"",width:"600",height:"600"}),"\n",(0,i.jsx)(t.img,{alt:"September average cloud cover chart",src:n(70731).Z+"",width:"600",height:"600"}),"\n",(0,i.jsx)(t.img,{alt:"October average cloud cover chart",src:n(45716).Z+"",width:"600",height:"600"}),"\n",(0,i.jsx)(t.img,{alt:"November average cloud cover chart",src:n(58564).Z+"",width:"600",height:"600"})]}),"\n",(0,i.jsx)(t.p,{children:"Well, as it so happens it looks like there are some data issues. July's data is a bit sporadic, and 2013 seems to be missing from most months as well. I think really only two things can really be confirmed here:"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:"Seattle, specifically for the months of October and November, is in fact significantly more cloudy on average than are other cities"}),"\n",(0,i.jsx)(t.li,{children:"All cities surveyed have seen average cloud cover decline over the months studied. There are data issues, but the trend seems clear."}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:"Let's now move from cloud cover data to looking at average rainfall chance."}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-python",children:"def safe_precip(frame):\n if frame and 'precipProbability' in frame:\n return frame['precipProbability']\n else:\n return np.NaN\n\ndef monthly_avg_precip(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 precip_vals = list(map(lambda x: safe_precip(forecasts_df[city][x]['currently']), dates))\n precip_samples = len(list(filter(lambda x: x is not np.NaN, precip_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(precip_vals), precip_samples\n\ndef city_avg_precip(city, month):\n return [monthly_avg_precip(city, y, month) for y in years]\n\nfor month, month_id in months:\n month_averages = {city: city_avg_cc(city, month_id) for city in cities}\n f = figure(title=\"{} Average Precipitation Chance\".format(month),\n x_axis_label='Year',\n y_axis_label='Precipitation Chance Percentage')\n for city in cities:\n f.line(years, [x[0] for x in month_averages[city]],\n legend=city, color=city_colors[city])\n show(f)\n"})}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.img,{alt:"July average precipitation chance chart",src:n(15074).Z+"",width:"600",height:"600"}),"\n",(0,i.jsx)(t.img,{alt:"August average precipitation chance chart",src:n(16856).Z+"",width:"600",height:"600"}),"\n",(0,i.jsx)(t.img,{alt:"September average precipitation chance chart",src:n(20619).Z+"",width:"600",height:"600"}),"\n",(0,i.jsx)(t.img,{alt:"October average precipitation chance chart",src:n(26071).Z+"",width:"600",height:"600"}),"\n",(0,i.jsx)(t.img,{alt:"November average precipitation chance chart",src:n(1340).Z+"",width:"600",height:"600"})]}),"\n",(0,i.jsx)(t.p,{children:"The same data issue caveats apply here: 2013 seems to be missing some data, and July has some issues as well. However, this seems to confirm the trends we saw with cloud cover:"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsx)(t.li,{children:"Seattle, specifically for the months of August, October, and November has had a consistently higher chance of rain than other cities surveyed."}),"\n",(0,i.jsx)(t.li,{children:"Average precipitation chance, just like average cloud cover, has been trending down over time."}),"\n"]}),"\n",(0,i.jsx)(t.h2,{id:"conclusion",children:"Conclusion"}),"\n",(0,i.jsx)(t.p,{children:"I have to admit I was a bit surprised after doing this analysis. Seattle showed a higher average cloud cover and average precipitation chance than did the other cities surveyed. Maybe Seattle is actually an objectively more depressing city to live in."}),"\n",(0,i.jsx)(t.p,{children:"Well that's all for weather data at the moment. It's been a great experiment, but I think this is about as far as I'll be able to get with weather data without some domain knowledge. Talk again soon!"})]})}function h(e={}){let{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},34326:function(e,t,n){n.d(t,{Z:function(){return a}});let a=n.p+"assets/images/1-2d6670430a11b01011e4c231ea594db1.png"},1340:function(e,t,n){n.d(t,{Z:function(){return a}});let a=n.p+"assets/images/10-b7987a0ff93705d5045057cbdaa2ede9.png"},46529:function(e,t,n){n.d(t,{Z:function(){return a}});let a=n.p+"assets/images/2-46bb7cc9cf739d97050c199eedced1a7.png"},70731:function(e,t,n){n.d(t,{Z:function(){return a}});let a=n.p+"assets/images/3-2f5c483659f81d741809de6d095bd577.png"},45716:function(e,t,n){n.d(t,{Z:function(){return a}});let a=n.p+"assets/images/4-63dc81954b1604cfa91f4c789da144a5.png"},58564:function(e,t,n){n.d(t,{Z:function(){return a}});let a=n.p+"assets/images/5-ae210d26729cea1700924579adf2c44c.png"},15074:function(e,t,n){n.d(t,{Z:function(){return a}});let a=n.p+"assets/images/6-f07e72ff0b4639453034c75b2e62faba.png"},16856:function(e,t,n){n.d(t,{Z:function(){return a}});let a=n.p+"assets/images/7-e0793eed6c42845d8ce4e3e79c1d44d8.png"},20619:function(e,t,n){n.d(t,{Z:function(){return a}});let a=n.p+"assets/images/8-3eb2ad63e4c40b6717ee4516223d73ed.png"},26071:function(e,t,n){n.d(t,{Z:function(){return a}});let a=n.p+"assets/images/9-630bd32c43e654f068e3c3bea79810e5.png"},50065:function(e,t,n){n.d(t,{Z:function(){return o},a:function(){return s}});var a=n(67294);let i={},r=a.createContext(i);function s(e){let t=a.useContext(r);return a.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),a.createElement(r.Provider,{value:t},e.children)}},63628:function(e){e.exports=JSON.parse('{"permalink":"/2016/01/cloudy-in-seattle","source":"@site/blog/2016-01-23-cloudy-in-seattle/index.mdx","title":"Cloudy in Seattle","description":"Building on prior analysis, is Seattle\'s reputation as a depressing city actually well-earned?","date":"2016-01-23T12:00:00.000Z","tags":[],"readingTime":3.965,"hasTruncateMarker":true,"authors":[{"name":"Bradlee Speice","socials":{"github":"https://github.com/bspeice"},"key":"bspeice","page":null}],"frontMatter":{"slug":"2016/01/cloudy-in-seattle","title":"Cloudy in Seattle","date":"2016-01-23T12:00:00.000Z","authors":["bspeice"],"tags":[]},"unlisted":false,"lastUpdatedAt":1730683607000,"prevItem":{"title":"Guaranteed money maker","permalink":"/2016/02/guaranteed-money-maker"},"nextItem":{"title":"Complaining about the weather","permalink":"/2016/01/complaining-about-the-weather"}}')}}]); |