Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Configuring a Range of Times

00:00 Welcome to the future. If only my crystal ball would tell me the lottery numbers.

00:05 I’m back in conf.py, where in the previous lesson I defined a bunch of values for location, which I need again, and this time I’m going to have some new stuff as well.

00:14 One new constant I’m going to create is my local time zone, so I’m going to need the ZoneInfo class.

00:20 You’ll recall I mentioned that I’m going to use a NumPy array to contain the range of times like with pandas. It’s common practice to alias NumPy out, and the alias for NumPy is np. Once again, who am I to argue with the majority? My actual first line of code here is to create an instance of a ZoneInfo object.

00:44 I’m setting it to my home of America, Toronto. If you’re familiar with the Eastern seaboard of North America, you might be wondering why I didn’t just put in EST.

00:54 I could. ZoneInfo actually knows what that means. But then you have to be careful as to whether it’s daylight savings time or not. EST becomes EDT in the summer.

01:03 Also, when dealing with historical data and possibly in the future, you can get variation just because Toronto and New York City are in sync. In the distant past they were not.

01:12 And so it’s best practice to use the fully named zone.

01:16 The lines under this call are the location stuff that I created in the previous lesson. I’m just reusing it. And then the final line of ktop.py is a constant that specifies a range of viewing times.

01:30 This is the NumPy linspace() function that I mentioned. It creates an array of values evenly spread between two numbers. This one starts at minus three, which I’m using to mean 9:00 PM. That’s three hours before midnight and goes to 10 or 10:00 AM. I’m asking for 100 divisions between those two values.

01:49 This will give me a hundred data points, keeping the line in the graph relatively smooth. I probably should have picked something that was a factor of 60 to give pretty minute values inside, but I have no intention of looking inside and all I need is a spectrum of values for the graph.

02:05 That’s the constants. Let’s go do our actual calculations.

Become a Member to join the conversation.