Consider the following scenario: You’re fresh out of school, or perhaps ready to move on to the next step in your career. You’re looking into a number of cities around the world to live in: Seattle, New York City, Miami, London, Mexico City, and a few others. For many people, myself included, weather is an important factor for a place to live, especially if you’re looking to settle down and build a nest. In this exercise, we’ll process a relatively long weather dataset and look for the most pleasant climate to live in. I know, this is subjective, but bear with me for the sake of this exercise.
What makes a climate pleasant to live in? The answer is different for everybody. Personally, I like it dry, warm, and breezy, with clear skies. I often wonder which city on earth has the ideal climate for me. This question is difficult to answer because of so many different factors that contribute to weather and climate. Some cities are cool and rainy, others are warm and sunny. Some cities have a relatively steady breeze, allowing for good ventilation and clean air, while others can suffer from pollution and smog. For example, Miami (Florida) has gorgeous (warm and dry) winters but gets hot and humid in the summer. On the other hand, Los Angeles (California) is known for its clear and sunny days, but is overall colder throughout the year.
To get to a quantitative and more objective answer, we’ll analyze the time series of weather measurements such as air temperature, humidity, wind speed, and number of clear sky days. In other words, we’ll quantify the climate of different cities around the world.
I often see people confusing weather and climate with each other. Weather is the actual state of the atmosphere at any given time. As I write this sidebar, it’s the evening before New Year’s Eve, and my wife and I just got back from a walk in one of the
wildlife preserves here in South Florida where we live. The weather was clear with few clouds (which made for a beautiful sunset), relatively warm and dry, with a decent breeze. What the atmosphere is like right here and now: that’s weather.
On the other hand, climate is the weather averaged over long periods of time. It’s a statistical concept–you never directly experience climate itself. There are many games you can play or questions you can ask in the context of climate. For example, what were the warmest and coldest temperatures ever measured in New York City on December 31, of all the years on record? Although these are two weather extremes, determining their values requires processing the complete time series of temperatures in that location. You could also ask, Which city on Earth was warmest on average in 2018? The list goes on. In this exercise, we’ll focus on the simplest statistical metric used in climate analysis–the arithmetic average.
What’s the connection between generic procedures and this exercise? The weather parameters in the dataset will be of different types: temperature and humidity are floating-point values (degrees Fahrenheit), wind speed is an integer (in knots), and clear sky data is indicated as a Boolean True or False. In this exercise, we’ll first implement the function to average an array of each of the different types. Then we’ll override these specific functions with a single generic function. Finally, we’ll use the same generic function in the main program to average data of different types.