Latest / Talk Python To Me / #320: Python in the Electrical Energy Sector
Transcript
- 0:00In this episode, we cover how Python is being used to understand the electrical markets and grid in
- 0:04Australia. Our guest, Jack Simpson, has used Python to uncover a bunch of interesting developments
- 0:09as the country has adopted more and more solar energy. We round out the episode looking at some
- 0:15of the best practices for high-performance, large data processing in pandas and beyond.
- 0:19In addition to that, we also spend some time on how Jack used Python and OpenCV,
- 0:24computer vision, to automate the study of massive bee colonies and behaviors. Spoiler alert,
- 0:30that involved gluing wingding fonts on the backs of bees. This is Talk Python To Me,
- 0:35episode 320, recorded June 6th, 2021.
- 0:52Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the ecosystem,
- 0:57and the personalities. This is your host, Michael Kennedy. Follow me on Twitter where I'm @mkennedy,
- 1:02and keep up with the show and listen to past episodes at talkpython.fm,
- 1:06and follow the show on Twitter via at Talk Python. This episode is brought to you by Square and Linode,
- 1:12and the transcripts are provided by Assembly AI. Please check out what all three of them are offering.
- 1:17It really helps support the show. Jack, welcome to Talk Python To Me.
- 1:21Thank you, Michael. It's great to meet you after hearing your voice for so many years.
- 1:24It's so great to have you on the show. It's always fun to have people who are listeners,
- 1:29but have interesting stories to tell. Come on the show, and you definitely have some
- 1:33interesting stories about the energy grid and doing data science around really important stuff like
- 1:40keeping the lights on in Australia.
- 1:42Absolutely.
- 1:43Yeah, I'm definitely looking forward to diving into that stuff. It's going to be a lot of fun,
- 1:46I think.
- 1:46Absolutely.
- 1:47Before we get to it, though, let's start with your story. How did you get into programming,
- 1:50and what brought you to Python?
- 1:51Yeah. Well, I guess I have a very strange background. I actually started off at university
- 1:56enrolling in journalism and politics right at the start of the GFC. I had never programmed before,
- 2:02and I didn't even realize I was interested in it. And my lecturers kept telling me how many
- 2:07journalists were losing their jobs during the financial crisis. And so I actually dropped out,
- 2:14and I was trying to consider what I wanted to do. And I'd always had a passion for biology and science.
- 2:20And my hobby was I was actually a beekeeper. I had six of my own hives at home. I really love that.
- 2:27Amazing. Are these like honeybee type of bees or what kind of bees?
- 2:30Honeybees. Yes, absolutely. The ones that stink. I actually also had a couple of Australian native bees,
- 2:38tetragongula carbonaria, which I'm not sure if you've heard of them before, but they're actually,
- 2:43they almost look like tiny little flies. They're stingless bees. And they will actually make their
- 2:49hives out of the resin of trees. And they will build their brood in this beautiful kind of spiral
- 2:55pattern going up through the hive. And so I was just really interested in, I guess, all things bee and
- 3:00insects related at the time. And so I actually started blogging about bees and beekeeping. And
- 3:07that was actually my introduction to code because I had, I think I had a website on blogger. And one
- 3:12day I suddenly thought, well, I'd love to actually be able to make my own website. How do I do that?
- 3:18And so I started learning HTML and JavaScript. And it was literally just so I could talk about my bees.
- 3:24I had no interest in programming. Amazing. Well, I think so many people get into programming that way
- 3:29who don't necessarily feel like my goal is to go be a programmer, but they just really have something
- 3:35they're into. And programming is almost in the way, right? It's just like something you've got to figure
- 3:39out so that you can actually get to the thing that you actually like. But then a lot of people find out,
- 3:43well, hey, this is actually kind of cool. And what else can I do now that I know this, right?
- 3:47Absolutely. That was really what made me change my degree. So initially I was going to do
- 3:51a pure biology degree. And so I decided I would do biology and web development. And as I kind of went
- 3:57along with the degree, I suddenly started realizing that the programming skills I was picking up during
- 4:04my degree. So I learned, you know, PHP, Perl and Python. Suddenly I realized that these skills could
- 4:10actually help me with working with scientific data. We kind of hit this point where there's just so much
- 4:16genomic data. Really, most people at the time I was doing undergrad, but one of the things I've
- 4:21really noticed is most people these days that enroll in a biology PhD, you join the lab and it's
- 4:27almost like, right, you're learning Python or you're learning R. There's no other way you're working
- 4:32with this data. And so suddenly I kind of hit this point where I was like, wow, these kind of technical
- 4:38skills were letting me do things and be useful in ways that I never thought. And it let me answer
- 4:43research questions that I was really fascinated by. And that was my motivation to actually, I guess,
- 4:49go into and do a PhD and then try and take those skills further.
- 4:53What was your PhD in?
- 4:55So it was in computational biology. It was trying to develop software to automate the analysis of
- 5:01honeybee behavior in the hive. So the thing that was interesting was it was both a physical setup and
- 5:08the code as well. So the physical side was actually, how do we set up a beehive in a building with a kind
- 5:16of like a glass window in so that I can film them with an infrared camera in the dark? And how do I
- 5:21put little tags with patterns on them on the backs of the bees that I can then use Python and machine
- 5:27learning to identify and track over the course of several weeks? And that kind of process ended up being
- 5:35much harder than I had anticipated. Because when I started out, I read a couple of papers
- 5:39by some computer scientists who mentioned that they'd printed out some card tags. And they said
- 5:45that they filmed the bees for a couple of hours, got the data and did an analysis. And I thought,
- 5:49great, I'm going to do that. Problem solved. It was only until later that I realized the reason that
- 5:54they only filmed them for a couple of hours was because that was how long it took the bees to chew the
- 5:58cardboard off each other in the hive.
- 6:01I know. Oh, did they help each other? Like, hey, I've got this thing on my back, get it off me?
- 6:05Yes. Yes, they actually did. They actually, and that was the thing I came, I would actually find time
- 6:10and time again, I would come up with a material and I would try and stick it on the back of the bees.
- 6:13And you would see their friends effectively come over and start trying to pry it off them in the hive.
- 6:19And so it was actually a process to find something that didn't, I guess, trigger them, so to speak.
- 6:25And one of the things, a really immensely frustrating experience I had when I was doing these experiments
- 6:30was I thought I had found the perfect fabric and the perfect glue to put them on the bees.
- 6:36And I'd spent hours tagging hundreds of them. I put them into the hive. And then I came back,
- 6:43I would come back a few hours later and all my tags had disappeared. And I couldn't understand why. And I kept doing it.
- 6:48And then at one point I thought, you know what, I'm going to put a bucket outside the hive entrance just to see what happens.
- 6:53And I'm going to watch in the dark. And what actually happened was the bees didn't like the smell of the glue.
- 6:59So they were actually physically grabbing bees that I'd tagged, dragging them to the entrance and flinging them out of the hive.
- 7:06And because the hive, because these bees were juvenile bees, they were too young to fly yet.
- 7:14The ants were actually dragging them away. So I thought my tags were dropping off or being pulled off.
- 7:19But actually, my poor bees were getting eaten by the ants because they couldn't fly away.
- 7:24Oh my goodness.
- 7:25And so I guess it's another example as well. You know, when you've got missing data, understand the process.
- 7:30Sometimes the process that made that data missing is significant in a way.
- 7:34I would have never guessed. That's really pretty insane, actually.
- 7:37And so the solution for dealing with this was I would actually go through the process of tagging the bees.
- 7:44Then I would put them in this heated incubator on a frame of honey for several hours until all of the smell had kind of faded away.
- 7:53And then I could introduce them to the hive and they would be accepted.
- 7:56Oh, I see. Okay. Wait, basically wait till they dried and it was really on them.
- 7:59Yeah. Yeah. Well, wait until all the fumes were gone and then they would be accepted and then it would work.
- 8:04Because I think this was the real challenge of my project was we weren't interested in tracking, showing that we could write software that could track the bees.
- 8:13We had a specific application was to look at the social development over several weeks of these bees.
- 8:19So we needed a kind of experimental setup and the code to support it that would let us look at these extended periods of behavior.
- 8:27Did they have different markings based on like their age or their role in the colony or something?
- 8:35Like were they all tagged the same and you just said, well, they kind of move around like this or were they're like, did you group them or something?
- 8:40What I would often do is I had use a laser engraver to burn patterns in the fabric that I would put on them.
- 8:46And so each bee had a unique pattern that I could use to identify it.
- 8:50Like a QR code on the bee?
- 8:51Kind of like that, but not.
- 8:53In fact, I think if you scroll through the website to the bottom of the page.
- 8:56Yeah, there's some right there.
- 8:58There's some little patterns.
- 8:59This was some initial prototypes for the bottom.
- 9:01Just if you scroll up a little bit more, the last image.
- 9:04Yep, that one.
- 9:05I was literally using a wingdings pod to try out different patterns.
- 9:10Wingdings.
- 9:11Okay.
- 9:11On the bees.
- 9:12Because I just had the idea was to have a relatively inexpensive 4K camera that could pick up the different patterns.
- 9:19Of course, if you had a really expensive high resolution camera, then you could do more with QR codes, for instance.
- 9:25And what I would do is I would do these experiments where I would, half of the bees would be that I would introduce.
- 9:31They would all be juvenile, except I would also mark the queen so I could know how they were interacting with the queen.
- 9:37But half the juvenile bees I would introduce into the hive would receive a label that I could reference later on.
- 9:44And half would receive a different label that I knew about.
- 9:49And the reason I did this was so I could actually do these, have these control and treatment groups in my experiment.
- 9:54Because I would do these experiments where I would treat the bees with caffeine to see how it would actually affect their social development in the hive.
- 10:04I guess to give a little bit more context to that, diving a little bit into the way that bees develop.
- 10:10You could almost think of a worker bee in the hive like the pictures I have on my site.
- 10:14The jobs that a bee does over its lifetime are influenced by how old it is.
- 10:19So these juvenile bees I was first introducing to the colony.
- 10:23They really would just have quite menial colonies.
- 10:25They would do little cleaning tasks around the hive.
- 10:28They wouldn't do much.
- 10:29Then when they're a little bit older, they would start nursing other juvenile bees.
- 10:33And then the eldest bees are the ones that you actually see out and about flying and collecting nectar and pollen.
- 10:40So those are actually the eldest of the bees in the colony, typically.
- 10:44And so I wanted to see how this caffeine would affect that kind of behavioral process in the juvenile bees.
- 10:53How interesting.
- 10:54Short, briefly, what did you find that caffeine does to bees?
- 10:56One of the things I found was it effectively meant that bees sped up how quickly they adjusted to the rhythms of the colony.
- 11:06So for a bit of context, if you're a juvenile bee in the hive, you don't really care about circadian rhythms, day-night cycles, because you're in a hive, it's completely dark all the time.
- 11:19And so what we found was that we hadn't seen before was these juvenile bees, even though they weren't exposed to the light on the outside, they would actually pick up these circadian rhythms by interacting with the older bees that were coming back.
- 11:34It was effectively like a socially acquired circadian rhythm.
- 11:37And so what we found was that bees that were treated with caffeine effectively picked up this rhythm more quickly than bees that weren't and kind of progressed in their roles in the colony more quickly.
- 11:49So there was that.
- 11:50Okay.
- 11:50Yeah.
- 11:51So there was that.
- 11:52And I had a few other areas, but yeah, to be honest, a lot of the work was really just making the software and the bees all play nice together.
- 12:01Yeah.
- 12:02Yeah.
- 12:03Absolutely.
- 12:04It was probably one of the most immensely, I will say one of the things that is quite nice about the energy sector is I don't have to deal with, I guess I can deal with machines, which are a little bit less frustrating at times.
- 12:14More reliable, more predictable and certain, that's for sure.
- 12:17This portion of Talk Python To Me is brought to you by Square.
- 12:22Payment acceptance can be one of the most painful parts of building a web app for a business.
- 12:27When implementing checkout, you want it to be simple to build, secure, and slick to use.
- 12:32Square's new web payment SDK raises the bar in the payment acceptance developer experience
- 12:38and provides a best-in-class interface for merchants and buyers.
- 12:41With it, you can build a customized, branded payment experience and never miss a sale.
- 12:47Deliver a highly responsive payments flow across web and mobile that integrates with
- 12:52credit cards and debit cards, digital wallets like Apple Pay and Google,
- 12:55ACH bank payments, and even gift cards.
- 12:58For more complex transactions, follow-up actions by the customer can include
- 13:03completing a payment authentication step, filling in a credit line application form,
- 13:07or doing background risk checks on the buyer's device.
- 13:10And developers don't even need to know if the payment method requires validation.
- 13:15Square hides the complexity from the seller and guides the buyer through the necessary steps.
- 13:19Getting started with a new web payment SDK is easy.
- 13:22Simply include the web payment SDK JavaScript,
- 13:24flag an element on the page where you want the payment form to appear,
- 13:27and then attach hooks for your custom behavior.
- 13:30Learn more about integrating with Square's web payments SDK at talkpython.fm/square,
- 13:36or just click the link in your podcast player's show notes.
- 13:39Before we move on to the energy sectors, just give us a quick overview of the software that you use.
- 13:48Was Python part of this role here?
- 13:50Yes, absolutely.
- 13:52So I used a mix of Python and OpenCV for a lot of the image processing.
- 13:58And of course, TensorFlow and Keras for training my neural network to identify the different tags.
- 14:07And that actually ended up being quite an interesting process,
- 14:10building up that data set and improving it over time.
- 14:13Because one of the things I found when I started trying to train that data set was I thought,
- 14:19okay, I can take my patterns, film them, add a little bit of noise and rotation,
- 14:24and then that's my kind of starter, you know, machine learning model.
- 14:27The problem was that when you put the tag on the bee,
- 14:31the way that they kind of walk around the hive,
- 14:34you'll see different kind of angles of,
- 14:38they kind of have this bit of wobble walk as they go around.
- 14:41So it kind of introduces this level of distortion to the tag.
- 14:45And then other, and so then also you could have other situations where
- 14:49bees would walk over each other, the block occluded tags as well.
- 14:53So one of the things I ended up having to do was I had to introduce a class to my,
- 14:59a predictive class to my model that was literally just like the,
- 15:02I don't know what this is class.
- 15:04And effectively, the idea was, I'm going to see this bee,
- 15:09I'm going to have multiple attempts to classify this bee as it's walking around.
- 15:13So I want to only attempt a classification when I'm seeing enough of the tag
- 15:17and I'm confident enough in that to attempt it.
- 15:20And so that was one of the,
- 15:21one of the techniques I found that helped improve the classification.
- 15:24And really it ended up just becoming a process where I would,
- 15:30I had a bit of a pipeline that would go through,
- 15:32it would extract tags,
- 15:34it would use the model at the current iteration to label them.
- 15:37I would then go in and manually review it and then figure out where it had stuffed up,
- 15:41where it was doing well,
- 15:43and then use that corrected data set to retrain the model and then improve and see how well that
- 15:48iteration did.
- 15:48And it became kind of like a,
- 15:50almost like a semi-supervised problem to an extent when I was building it out.
- 15:54And at a certain point,
- 15:55it became just as good as me at doing these classifications.
- 16:00And then it was fully automated as well.
- 16:03But I think I ended up labeling about seven or 800,000 images as part of doing this.
- 16:09And my,
- 16:09my wife was actually,
- 16:10she was a PhD student in working in genetics at the time.
- 16:14She was helping me in her spare time.
- 16:16So she does not look favorably upon that,
- 16:20on that project.
- 16:22She probably doesn't love wingding fonts.
- 16:25Maybe in a bit of a surprise,
- 16:27she's like,
- 16:27oh,
- 16:27not you again.
- 16:28Yeah,
- 16:29absolutely.
- 16:30But I'd say,
- 16:31yeah,
- 16:31so Python and OpenCV were big ones.
- 16:33And then the other tool I was using a lot of was Python Cython library,
- 16:38where I would,
- 16:39for certain parts that I wanted to run really efficiently,
- 16:42I wrote those in C++ and then used Cython to expose some of those methods to it.
- 16:48And that worked amazingly well.
- 16:50It was so impressive how you could call,
- 16:53pass a list,
- 16:54a Python list to my,
- 16:56my C++ class,
- 16:58and it would interpret that as a vector.
- 16:59And then it would pass back the information as well.
- 17:02I think this is the reason I'm such a fan of Python is just how well it lets me
- 17:06do so many different things that I'm working on.
- 17:09That's a really interesting point.
- 17:10you know,
- 17:10a lot of people talk about,
- 17:11well,
- 17:12Python is slow for this or it's slow for that.
- 17:14And yet here's all these really intensive computational things that Python seems to be
- 17:19the preferred language for.
- 17:20And I think this is one of the hidden secrets that's not apparent as people come into the
- 17:25ecosystem,
- 17:25right?
- 17:25Obviously people have been here for a long time and they,
- 17:27they kind of know that story,
- 17:29but you know,
- 17:29as people come in,
- 17:31because there's,
- 17:31there's all sorts of people coming into the Python world drawn in a little bit like
- 17:36you,
- 17:36you talked about how you started out in biology,
- 17:39not necessarily to be in software development specifically,
- 17:42but then you kind of got sucked into it.
- 17:44Right?
- 17:44Absolutely.
- 17:45Yeah.
- 17:45I think all of the conversations around the performance of Python is super interesting.
- 17:49It's like,
- 17:49oh,
- 17:50it's,
- 17:50it's really slow,
- 17:51except for in this time where it's like as fast as C++.
- 17:53Wait a minute.
- 17:54Is it,
- 17:55is it slower?
- 17:55Is it fast as C++?
- 17:56Well,
- 17:57it's both,
- 17:57right?
- 17:57it varies,
- 17:58but you can bring in these extra like turbo boosts,
- 18:02right?
- 18:02Like Cython and,
- 18:03or do your work in NumPy rather than in,
- 18:06in straight lists and stuff like that.
- 18:08Absolutely.
- 18:09And like one of the,
- 18:10initially when I started off my PhD,
- 18:12I actually wrote an initial prototype version of it all in C++ using open CV,
- 18:19open C++ library and a machine learning,
- 18:21a deep learning library called cafe,
- 18:23which was a bit of a thing back in the day.
- 18:26And the pro that process for dealing with data and even just converting data
- 18:31between like,
- 18:32I think the best thing about Python is the fact that NumPy arrays is just
- 18:36understood by all the scientific libraries,
- 18:38whereas sometimes with other languages,
- 18:40it can be painful moving data between different libraries and tools.
- 18:44Oh,
- 18:45interesting.
- 18:45Yeah,
- 18:45you're right about that.
- 18:46Yeah.
- 18:47And so like,
- 18:47I,
- 18:47I remembered at one point during my PhD with,
- 18:50with that initial C++ version,
- 18:51I had like a page of code to convert between an open C,
- 18:56the matrix and a cafe,
- 18:57I think blob.
- 18:58And it was a page of code that I was terrified of breaking because I didn't understand how it
- 19:03worked.
- 19:04Whereas Python,
- 19:04it was like everything I can move between,
- 19:07you know,
- 19:07scikit-learn,
- 19:08pandas,
- 19:09and all these other libraries.
- 19:11And it's all kind of got that common foundation that makes me really efficient.
- 19:14Yeah.
- 19:14And that I understand really well.
- 19:16That's a really interesting insight that there's this sort of common data structure across the
- 19:21libraries,
- 19:21because you're right.
- 19:22I remember in C++ and other languages like C# and whatnot,
- 19:25this one will take something like this and you've got to reorder the data and reformat it to pass it over.
- 19:31And if you have to do that back and forth,
- 19:33it would completely slow things down.
- 19:35All sorts of stuff.
- 19:36Yeah.
- 19:36Very interesting.
- 19:37In a way as well.
- 19:38I really loved that the Python stack has let me do things in during my PhD and then post PhD as well.
- 19:47In just the skills that I developed in analytics here,
- 19:50I've gone on to be able to use that in so many different places.
- 19:53For instance,
- 19:54one of the pieces of analysis I did was look,
- 19:57I used Python's network X library to look at the social interactions between the queen and worker bees.
- 20:03And I would build out these network graphs that would explore the number of interactions and the length of time of those interactions between the queen and the worker bee.
- 20:14And this actually recording independent interactions actually became important because sometimes the queen would literally fall asleep behind another worker.
- 20:23And it would look like she loves that worker,
- 20:25but she just was resting for like over an hour or two.
- 20:28What I've actually found is that those skills for working with data and with network analysis,
- 20:32when I was working consulting,
- 20:34I would use network X to analyze the corporate structure of organizations that we're doing an org review for.
- 20:41And then more recently I have done work in the energy sector,
- 20:44looking at building out networks of power stations as well.
- 20:47And so it's,
- 20:48I think that's,
- 20:49that's one of the things I love about this area is that you have this kind of transferable skill set that you're more limited by what you can think of,
- 20:58but using it by rather than what you can actually do with it,
- 21:01with it itself.
- 21:02Yeah,
- 21:02absolutely.
- 21:03And I think for a lot of people,
- 21:05if they're out there listening and they're doing,
- 21:06you know,
- 21:07academic type stuff or working in one area,
- 21:11but maybe that's not the area they necessarily want to stay in.
- 21:14A lot of these skills are super transferable.
- 21:16One of the things that's blown my mind as I've spent more and more time in the software industry was,
- 21:22I remember I was doing professional training and I spent one week at a stock brokerage in New York City teaching programming.
- 21:30And then I spent two weeks later,
- 21:32I was like at an air force base working with some of the engineers there.
- 21:36The stuff that those two groups need to know,
- 21:38it sounds like it's entirely different worlds,
- 21:40right?
- 21:40It's like 90% identically the same.
- 21:43It's just a little bit of what do you do with that once you know it?
- 21:46Like what's the secret sauce on top of it that puts it together?
- 21:49But yeah.
- 21:49And it sounds like you kind of got that skill in your research.
- 21:52Absolutely.
- 21:53And I think this is one of the things I've noticed is that some PhDs can struggle to transition into industry.
- 22:00And often it's because there's people on the industry side that don't really understand how those skills can help them.
- 22:08But at the same time,
- 22:09I think it's actually a skill to be able to explain how you can link what you already know,
- 22:15what you're capable of and solve their kind of business problem.
- 22:18And in fact,
- 22:19I think when I went into management consulting and I would do some work for some of the partners,
- 22:23eventually it took me a little while to figure out that they weren't that interested in,
- 22:28you know,
- 22:28the code I was doing or even some of the raw data.
- 22:31But if I could figure out a way to link that to the business problem they were trying to solve,
- 22:35then they were interested.
- 22:36Yeah, absolutely.
- 22:37Being able to kind of communicate and act as like a bridge between those was something I didn't realize was a skill,
- 22:43but it is hugely valuable in organizations.
- 22:46I've really noticed.
- 22:47Yeah, absolutely.
- 22:48All right.
- 22:49One final question about your research before we get into the energy sector.
- 22:52That what year did you do that?
- 22:54Oh,
- 22:55so 2014 to 2017.
- 22:57Yeah.
- 22:57And that's not that long ago.
- 22:59And yet the machine learning story has probably progressed really quite a bit with deep learning,
- 23:06transfer learning,
- 23:07all sorts of stuff going on,
- 23:09the different use of GPUs and tensor compute units and whatnot.
- 23:13What would it look like now if you're doing it versus then?
- 23:16What would be different?
- 23:17I think now one of the big differences was really that TensorFlow only came out towards the second half of my PhD.
- 23:25So I think a lot of the,
- 23:27so I think that was a difference.
- 23:29Having more accessible machine learning libraries and tools really made a big difference.
- 23:34The other one was,
- 23:35I think when I started my project,
- 23:37I actually spent a lot of time playing around with,
- 23:40you know,
- 23:41now if you started your PhD,
- 23:42you would go image analysis,
- 23:44it's going to be deep learning.
- 23:45Whereas when I started,
- 23:47I was actually pointed in the direction of,
- 23:50oh,
- 23:50go check out,
- 23:51you know,
- 23:51support vector machines,
- 23:52try out a random forest,
- 23:54try out a whole bunch of different feature engineering and machine learning techniques.
- 23:58And so I spent a lot of time kind of moving around between those before I literally had a,
- 24:03I got in touch with a researcher in the computer science department because I was in the biology department doing this work.
- 24:09And he literally,
- 24:10I had a chat with him and he literally looked at what I was doing and he said,
- 24:14use deep learning.
- 24:15And he said,
- 24:15go check out,
- 24:17check out these libraries,
- 24:18but this is what you need to do it.
- 24:19And I think,
- 24:20yeah,
- 24:21in a way like that type of,
- 24:23the libraries and the understanding about how you would solve this problem now is,
- 24:26is a lot further along and probably would have shortcut a lot of my initial frustration compared to previous.
- 24:33Yeah,
- 24:33probably.
- 24:33But think of all the lessons you've learned with those late nights of it not working and,
- 24:37and whatnot.
- 24:38Right.
- 24:39One other thing really quickly is I love to look at this graph here,
- 24:43this,
- 24:44the stack overflow trends,
- 24:46and I'll link to this in the show notes.
- 24:47There was,
- 24:49back in 2017 article by stack overflow,
- 24:52their data science team set called the incredible growth of Python.
- 24:55And they predicted,
- 24:56Oh,
- 24:57Python's going to overtake some of these languages.
- 24:59And you're not going to believe it.
- 25:00It's going to be more popular than JavaScript,
- 25:02more popular than Java.
- 25:04And people are like,
- 25:05no way.
- 25:05This has got to be something wrong with the data.
- 25:07And obviously,
- 25:08here we are,
- 25:09you know,
- 25:10in 2021,
- 25:11where I think they underestimated.
- 25:13Honestly,
- 25:13I don't want to have the exact picture in my mind,
- 25:16but I'm pretty sure they underestimated the last couple of years,
- 25:19which is pretty interesting.
- 25:20But that's not what I want to talk about.
- 25:21What I want to talk about is that 2012,
- 25:23you know,
- 25:24Python had been around for at that time,
- 25:2725 years or something.
- 25:28It was well known.
- 25:29It was a fairly popular language,
- 25:31but it was kind of just steady state.
- 25:33And then it's like somebody just lit the afterburner on that language.
- 25:37And it just,
- 25:38you know,
- 25:38it just started going up and up right around that time.
- 25:41And this is the time that you got into Python as well,
- 25:44more or less,
- 25:45right?
- 25:45Absolutely.
- 25:45I feel like so many people came from these not traditional programming spaces.
- 25:52I mean,
- 25:52still interested in programming,
- 25:53but not like a CS degree type of programming in.
- 25:57And it just brought so much diversity in terms of the problems being solved.
- 26:01And I think this graph is exactly what's happening here.
- 26:04It sounds like you're part of that,
- 26:05making that curve go up there.
- 26:06Yes.
- 26:06Yeah,
- 26:07I guess so.
- 26:07And I think for me as well,
- 26:09when Pandas came out,
- 26:11I think around in 2012 for working with,
- 26:12you know,
- 26:13data frames as objects,
- 26:14I've used R.
- 26:15I really liked that kind of data frame feature in R initially.
- 26:18And it was a little bit frustrating before Pandas was a thing,
- 26:22being able to,
- 26:23having to deal with,
- 26:24you know,
- 26:24CSV files and having to treat them as lists and indexing.
- 26:28So when Pandas became a thing,
- 26:30that was almost one of the big reasons I pushed into using Python for so much.
- 26:34And I still feel like I've been using Pandas for,
- 26:37yeah,
- 26:37I guess eight or nine years.
- 26:39And I'm pretty sure the project I'm on currently,
- 26:42I'm pretty sure I've learned a few extra things about the library just in the last couple of weeks.
- 26:46Yeah.
- 26:46It's crazy how that works,
- 26:47right?
- 26:47You're like,
- 26:48I've been doing this forever.
- 26:48How did I not know about this part of it?
- 26:51Right?
- 26:51Absolutely.
- 26:52Amazing.
- 26:52Amazing.
- 26:53All right.
- 26:54Well,
- 26:54super cool project you had there.
- 26:55Let's talk about energy.
- 26:57So you work for the Australian Energy Market Commission?
- 27:01Yes.
- 27:01Yeah.
- 27:01What's this?
- 27:02What do you do there?
- 27:02You can almost think of them as the rulemaker for the energy market.
- 27:06We don't run the energy market.
- 27:08That's the Australian Energy Market Operator.
- 27:10But they effectively pass the legislation that determines how people have to act within the
- 27:17energy market.
- 27:17The reason I really joined the organization was because when I was working in consulting,
- 27:23I started doing work in the energy sector.
- 27:24And I do work for energy retailers, the people that you pay for your electricity.
- 27:30I just work for some industrial companies.
- 27:33And one of the things I found was when I bumped into the wholesale energy data, it was almost
- 27:38like this, what was it?
- 27:40The, you know, the city of gold in some way.
- 27:43It was immense amounts of reasonably well-structured and cleansed data where the limitation wasn't,
- 27:51you know, the data or cleaning it.
- 27:53The limitation was understanding the domain well enough to do interesting things with it.
- 27:58Right.
- 27:58Okay.
- 27:58And so that's really became my obsession was to learn as much as I could.
- 28:03So I could actually do more and more interesting things with the data.
- 28:06And so the reason I joined the AAMC was because it's one of the most amazing workplaces in terms
- 28:13of the capability of everyone there is so passionate and incredible at what they do.
- 28:19And so just being around these people and learning from them is just an experience in itself.
- 28:25Yeah.
- 28:25Fantastic.
- 28:25That sounds super interesting.
- 28:27And it sounds like things like your network experience, you know, there's probably a lot
- 28:30of networks and energy and suppliers and whatnot.
- 28:33There might go together.
- 28:35Absolutely.
- 28:35Yeah.
- 28:36Basically there's, it's kind of a market that they set the price energy and then generators
- 28:42like private companies that are, you know, have power plants and solar forms and whatnot.
- 28:47They can decide whether or not they want to participate at that very moment in the grid or how does
- 28:52it work?
- 28:52Yeah, absolutely.
- 28:53So yeah, this is one of the fascinating things about the wholesale energy market.
- 28:57You can almost think that every five minutes, the market operator is effectively running
- 29:02an auction where all power stations around on the East Coast of Australia are bidding in
- 29:08bids for how much they were willing to sell different volumes of electricity at.
- 29:12So for instance, a wind farm might say that they will sell this volume of power quite cheaply,
- 29:19whereas a gas generator that has quite a high cost of fuel will set a higher price.
- 29:25And the market operator will take all of these bids and it knows the locations of these generators.
- 29:31It knows the capabilities of the transmission lines and the network.
- 29:35And it will run this linear optimization to figure out, okay, what is the cheapest mix of
- 29:42generators that I should dispatch to satisfy demand while still making sure the network is secure?
- 29:48Okay.
- 29:48So it's like trying to optimize certain goals.
- 29:51Like we are going to need however much energy in the grid at this very moment.
- 29:55And these people are willing to supply it at this, like, you know, who do we take however
- 30:00much energy from until we get like both enough people that are willing to participate from a
- 30:05financial perspective and then what people also need, huh?
- 30:08Yes, absolutely.
- 30:09And that's the thing that's so fascinating about this market is that at all times, supply
- 30:14and demand have to be matched.
- 30:16Very, very carefully because it'll break the grid if there's, well, too much is probably
- 30:20worse than too little because you just get a brownout, right?
- 30:23But too much could destroy things, right?
- 30:25Yeah.
- 30:25You don't want too much.
- 30:26If you have too much, then you need generators to start to try and reduce the output.
- 30:31And at the same time, if you have too little, then it can also create problems.
- 30:36And in fact, the grid has to be kept at this such a precise level of balance that if it
- 30:43actually you have too much or too little for too long, it will damage the machines that are
- 30:47connected to it.
- 30:48And in fact, to protect themselves, you will actually see them start to disconnect and it
- 30:53can actually create these kind of cascading problems.
- 30:55So unless you, we actually had a fascinating example recently in Queensland where a turbine,
- 31:05a coal turbine blew up and it then tripped a whole bunch of other coal power stations that
- 31:12then couldn't, that then stopped creating load.
- 31:15And so you suddenly had this situation where you had all this demand for electricity and
- 31:21suddenly they just lost all of this generation ability.
- 31:24And what actually happened is the system just started disconnecting.
- 31:28Well, it caused a blackout.
- 31:30But there was this automated system in a fraction of a second that just started disconnecting
- 31:34load or demand to try and balance it as quickly as possible to try and arrest the problem.
- 31:39So, and one of the things I've actually been doing has been looking at this at like a, on a four second basis, the events that happened on this day and how different units responded to these events.
- 31:50It's amazing.
- 31:51Like there's, there's almost like the energy sector and the market.
- 31:54It's almost like there's the physical infrastructure of make and making everything work and all that amazing engineering.
- 31:59And then there's the financial market and the bids and everything like that, that's built on top of it.
- 32:04And the market and the bids are fascinating, but at the end of the day, everything has to bow to the engineering.
- 32:10It has to work.
- 32:11Right.
- 32:11It has to work.
- 32:12Yeah.
- 32:12Yeah.
- 32:13Or it's all just going to come apart.
- 32:14Interesting.
- 32:15Yeah.
- 32:15AR out in the live stream says, is AEMC doing anything with energy web?
- 32:20I'm not sure if I've come across that before, but I'd be interested in looking into it.
- 32:24Yeah.
- 32:25And then also, it sounds like DERMS, what you're describing or D-E-R-E-M-S.
- 32:29I'm not sure whether, how you pronounce it.
- 32:31That might be something, an acronym from the, from the U.S. energy markets.
- 32:36Everyone has their own kind of different acronyms.
- 32:38Oh yeah.
- 32:40That makes it easy, right?
- 32:41To not even be consistent.
- 32:42If you go to the market operators website, they have a glossary page where you can just
- 32:47scroll for, for all those days on all the acronyms that are used in the sector.
- 32:52Probably like an acronym thesaurus.
- 32:53We call it this, what do they call it?
- 32:55Exactly.
- 32:56Exactly.
- 32:56This portion of Talk Python To Me is sponsored by Linode.
- 33:01Visit talkpython.fm/Linode to see why Linode has been voted the top infrastructure
- 33:06as a service provider by both G2 and TrustRadius.
- 33:09From their award-winning support, which is offered 24, 7, 365 to every level of user, to the ease
- 33:16of use and setup, it's clear why developers have been trusting Linode for projects both
- 33:20big and small since 2003.
- 33:22Deploy your entire application stack with Linode's one-click app marketplace, or build
- 33:27it all from scratch and manage everything yourself with supported centralized tools like Terraform.
- 33:32Linode offers the best price-to-performance value for all compute instances, including GPUs,
- 33:38as well as block storage, Kubernetes, and their upcoming bare metal release.
- 33:43Linode makes cloud computing fast, simple, and affordable, allowing you to focus on your
- 33:48projects, not your infrastructure.
- 33:50Visit talkpython.fm/Linode and sign up with your Google account, your GitHub account,
- 33:55or your email address, and you'll get $100 in credit.
- 33:59That's talkpython.fm/Linode, or just click the link in your podcast player's show notes.
- 34:04And thank them for supporting Talk Python.
- 34:06So we have on the graph here, this picture on the screen, where energy went negative, actually.
- 34:13And so this is where people are willing to pay to take energy that you've generated?
- 34:18Like, that sounds completely insane.
- 34:20Yeah, I know.
- 34:21It sounds weird.
- 34:21So yeah, to explain this figure, what's been happening this year in South Australia, the
- 34:27wholesale price of electricity has been around, averaged around negative $20 during the middle
- 34:34of the day, pretty much consistently.
- 34:36And so the way this works is because the generators submit bids for how much they're willing to
- 34:42sell their electricity for, because they'll effectively, when they run the optimization,
- 34:47the price of the bid that satisfies demand is the price that everyone gets paid.
- 34:52So what a lot of generators will do is they'll bid in quite cheaply at negative prices so that
- 34:58they're sure that they will get dispatched.
- 35:00But if everyone bids in a negative prices, then everyone gets the negative price.
- 35:04And so what we've actually been seeing is because there's now so much generation in the middle
- 35:09of the day, you're ending up with these really fascinating market events.
- 35:13Like, yeah, these negative prices where literally you can get paid to consume electricity.
- 35:18As a consumer, that sounds pretty good.
- 35:20You know, get it nice and chilly and we'll all be fine.
- 35:22True.
- 35:23Yeah, that's true.
- 35:23One of the drivers of this, it sounds to me like, is solar energy in Australia, right?
- 35:28Yes.
- 35:29Yes.
- 35:29We now have so much rooftop solar.
- 35:31I can't remember the exact percentage, but a significant percentage of Australian households
- 35:35now have solar panels because the cost has come down so much.
- 35:39And so a lot of our work has involved looking at how that is impacting the grid.
- 35:44Because if you imagine historically the energy market, it was a process where, you know, the
- 35:50market operator could instruct generators to turn on or turn off.
- 35:54And now we're in a world where there's so much of these kind of small scale solars that
- 35:58solar that you can't tell what to do.
- 36:01How do you factor that into balancing supply and demand in the grid?
- 36:05Yeah.
- 36:05Well, it definitely sounds like some interesting Python must be at play there.
- 36:09So give us an overview of sort of the kind of tools you're using, the types of problems
- 36:13you're solving.
- 36:14Yeah, sure.
- 36:14In the solar place, we've been using a Python, a software package called SAM, which is a system
- 36:21advisor model, which is actually released by the National Renewable Energy Laboratory
- 36:26in the States.
- 36:27And so what it lets you do is if you provide solar irradiance data and data from weather
- 36:32stations, you can use it to simulate the generation of rooftop in different areas around the country
- 36:40on a granular, on a half hourly basis over the course of the year.
- 36:43And so what this lets us do is I can use, they've got a Python library that lets me kind of call
- 36:49and run this tool.
- 36:51And I can simulate different PV system sizes and different locations and angles and all
- 36:57for setups all around the country.
- 36:59So I can effectively simulate hundreds and hundreds of different PV systems.
- 37:03And if I combine that with how much the household is consuming and what the actual cost of electricity
- 37:11was and those half hourly intervals, you can suddenly build up a picture for the economic
- 37:17effect of different PV panels for different households around the country.
- 37:22Yeah, how interesting.
- 37:23Is this the right thing I pulled up here?
- 37:24This Pi Sam?
- 37:25Yes.
- 37:25And I will say that for your US listeners, the laboratory release all of the data for
- 37:32the US mainland in a format that's ready for you guys to go.
- 37:35I had to, a big part of my project was actually trying to turn the Australian data into a format
- 37:41that this program could understand.
- 37:43And that in itself was an interesting exercise in data cleaning and manipulation because, for
- 37:50instance, all of the data on the irradiance for the country came as tens of thousands of
- 37:56these text files that were just these kind of grids, which pretty much they said, each value
- 38:01represents a five by five kilometer grid on the Australian mainland.
- 38:05It starts at this coordinate.
- 38:07So I had to pretty much try and convert this text file into a map and then convert that into
- 38:12format so I could know where the house fell in that as well.
- 38:16Oh, wow.
- 38:17How interesting.
- 38:17Yeah, you're normally taking a bunch of text files and piecing those together in a map,
- 38:23but I guess you do.
- 38:25Eugene, who was on the show a little while ago about the life lessons from machine learning,
- 38:29brought an interesting quote.
- 38:32It was something to the effect of the data cleaning is not the grunt work.
- 38:36It is the work of so much of this, right?
- 38:39Like it's getting everything right, making sure it's correct, converting it, formatting it,
- 38:44and then you feed it off to the magic library and get the answer, right?
- 38:46Yep.
- 38:47Absolutely.
- 38:48And I think, yeah, the lessons that you learn from working with and cleaning the data often
- 38:54help inform your analysis later on.
- 38:57For instance, one of the things I was doing recently was I've been trying to correct for
- 39:01errors in this really large data set measuring output from these power stations.
- 39:05And so one of the pieces of advice I received was that if I see a data where the generation
- 39:14value from the power station does not change, it effectively says this power station is generating
- 39:19100 megawatts and that value doesn't change for more than a minute, for at least a minute,
- 39:25that means there's an error in the data collection.
- 39:28And so as I was cleaning up the data and I implemented that and I started looking for outliers,
- 39:34and I actually discovered that you could see for some solar farms that it looks like if I
- 39:41used this metric that I'd implemented to pick out the bad data, it was actually removing
- 39:46cases where the power station, the solar farm was deliberately keeping their output perfectly
- 39:54level to match this instruction from the market operator.
- 39:57And so I think this is a case where they were actually foregoing additional generation to be
- 40:03more predictable.
- 40:04And I would have missed this whole interesting power station behavior if I just, you know,
- 40:09if I wasn't thinking about what the implications were of these different, you know, cleaning
- 40:14techniques that I was doing.
- 40:15Okay.
- 40:16Yeah.
- 40:16Because maybe that advice comes from, I don't know, a gas power plant or a coal plant where
- 40:22they have to fluctuate because, you know, whatever reason, right?
- 40:25And this new world, the assumptions changed or the situation changed and the assumptions didn't,
- 40:31right?
- 40:31Absolutely.
- 40:32Absolutely.
- 40:32And I think, yeah, like in a way, like part of the reason I think I've always gravitated towards
- 40:39being passionate about combining the programming and the analytics with like deep domain expertise
- 40:44is that I really love when I'm working with the data set, when I see something weird, I
- 40:50love that I can go, that's wrong.
- 40:52I can remove that or that looks weird.
- 40:55I'm going to investigate this because I think that's interesting.
- 40:57And one of the things I found in consulting was the projects where I didn't understand
- 41:02the data or the industry as well were always a bit, and I was brought into the team to provide,
- 41:09you know, the analytics capability, but I was effectively, you know, turning the understanding
- 41:14of others into code.
- 41:16I've always found them a little bit less satisfying from a personal perspective because I didn't
- 41:21feel like I was the one who was really, you know, getting, I felt like I was a vehicle other
- 41:27people turn their thoughts into code.
- 41:28Whereas I really like that if I understand the domain, then suddenly I can investigate and
- 41:33understand the area that I'm working in.
- 41:35Yeah.
- 41:36It becomes a puzzle, not just, I don't know, just more, get information from these people,
- 41:41apply it to the data, see what comes out.
- 41:43Yeah, for sure.
- 41:44You know, someone asked me recently, they were looking to hire somebody.
- 41:47It was, I don't know if it was exactly in the data science world, but it's close enough.
- 41:51They were asking something to the effect of, should I go and try to find a computer science
- 41:56type of background person who I can then teach the subject matter to and kind of get them
- 42:03up to speed there because we need good programmers.
- 42:05Or should I find some people who really understand what we're doing and then try to teach them
- 42:10Python?
- 42:10Yeah.
- 42:10What would you say to that?
- 42:12I had a thought on it, but I'd love to hear yours.
- 42:14I think to a certain extent, the experience, you want to have, I guess, the passion for learning
- 42:21about the domain.
- 42:22And obviously, if they understand the domain, that's really valuable, but you probably want
- 42:27them to be exposed at least a little bit to some programming concepts for them to know
- 42:31that they like it.
- 42:32In fact, I remember when I had a chat with my former boss who hired me into my current
- 42:38role.
- 42:38And he said that he's hiring philosophy is he looks for people with interesting backgrounds.
- 42:44You know, my background, he saw computational biology.
- 42:47And, you know, a lot of people would be like, oh, how does that apply to the energy sector?
- 42:52Yeah.
- 42:52That does.
- 42:52That's not for us.
- 42:53That's something totally different, right?
- 42:55Exactly.
- 42:56But he said, you know, for him, that's an interesting story.
- 42:59And he could see how those skills can generalize to different areas.
- 43:02And then it's more about, are you passionate about the thing you're working on as well?
- 43:06So like, I think people can learn, you know, people with domain expertise.
- 43:09I think learning Python can be like adding a bit of a superpower to your, you know, your
- 43:14skills and domain skills as well.
- 43:16But I also think that you wouldn't want to say, for instance, you wouldn't want to hire
- 43:21someone who had good domain expertise into the team to be a programmer who'd never programmed
- 43:26before and discovered they hated programming as well.
- 43:29Yeah.
- 43:29I think the assumption was that they had a little bit of programming experience or they were super
- 43:33interested in it, but maybe not all the way there.
- 43:35I think the subject matter expertise is really valuable.
- 43:39It's, I think these days there's so many amazing libraries and Python so accessible that it's
- 43:46really important to understand like deeply what's happening.
- 43:49But you should probably also have one or two people who have like a true software engineer
- 43:53experience like, hey, has anybody told anyone around here about Git?
- 43:57We need to be using source control.
- 43:58And what about continuous integration?
- 43:59And have you heard of testing, right?
- 44:01Like those kinds of things matter.
- 44:03But I think also having this like deep understanding of it really matters.
- 44:06Absolutely.
- 44:07Cool.
- 44:08Cool.
- 44:08Cool.
- 44:08Cool.
- 44:09All right.
- 44:09So are there, I mean, you talked about this system advisor model.
- 44:13Are there other things like in say the astronomy space, there's AstroPy, like all the astronomers
- 44:18talk about, this is the library.
- 44:20These are the things you talked about pandas and numpy and whatnot already, but is there something
- 44:26like that or a couple of libraries like that in the energy space?
- 44:29The closest I would probably say is the Pyomo optimization library.
- 44:32So that I think Clark mentioned in a previous interview.
- 44:36Yeah, yeah.
- 44:37We had Clark come on to talk about that.
- 44:39And he was doing really cool stuff.
- 44:41Clark, yeah.
- 44:41I'm trying to, I'm going to set up a chat with our team with Clark.
- 44:46And that's the plan at a later date.
- 44:47Because, yeah, it was very interesting that what he was able to do during his masters with
- 44:53linear optimization.
- 44:54And so I think, yeah, like really, there may be libraries out there that I haven't come
- 45:00across yet at this point.
- 45:01But I've really found that the whole, yeah, the Python stack of your pandas, Pyomo for
- 45:07optimizations, and even things like, have you come across a library called Geopandas at all?
- 45:13Yes.
- 45:14Which adds spatial elements to data frames.
- 45:16I use that for a lot of analysis.
- 45:18Yeah.
- 45:18Geopandas sounds cool.
- 45:19I haven't done anything with it, but I would love an opportunity to do something fun with
- 45:23Geopandas.
- 45:23I did that when I was working in consulting.
- 45:26I used that library once for looking at data from the Australian Bureau of Statistics.
- 45:30And then suddenly, I was in demand for every proposal to be making these heat maps of the
- 45:35country.
- 45:36I suddenly was just making, I had heat maps coming out everywhere.
- 45:40Yeah, they're like, if Jack knows how to make these graphs, give it to Jack.
- 45:44He'll build a flag.
- 45:45Exactly.
- 45:47But Geopandas, if you know a bit about using, you know, pandas and data frames for working
- 45:51with data sets, it's pretty much like using a pandas data frame, but it just adds a whole
- 45:56bunch of capability for working with spatial data sets and creating beautiful figures as
- 46:01well.
- 46:01It's amazing.
- 46:03Yeah.
- 46:03Oh, it sounds super cool.
- 46:04Super cool.
- 46:05Yeah.
- 46:05It works with Shapely.
- 46:06It sounds like it would work really well with your 10,000 text files almost even.
- 46:10Yeah.
- 46:11Some of those things linking it up.
- 46:13Yeah.
- 46:14Yeah.
- 46:14Yeah.
- 46:14Alexander out in the live streams coming back.
- 46:17Just one quick thought says, I wish people learned at least some programming.
- 46:20Making customs software to cover simple cases is definitely tiring.
- 46:23And most of the time, it's just a simple script.
- 46:25Yeah.
- 46:26I mean, kind of the automate the boring stuff could take a lot of people a long ways for sure.
- 46:30Yeah.
- 46:30At that level.
- 46:31Absolutely.
- 46:32In a way, a lot of the little things that I would go around and be useful for when I
- 46:36was working in consulting, if people had a little bit of programming background, then
- 46:41yeah, they almost wouldn't need my input because they understood the area better than me.
- 46:46And if they had a little bit of Python and knew how to link up some data sets, then it would
- 46:52be like they could just automate so much of some tedious things in their lives.
- 46:56One thing I heard a lot in that sort of realm was, if you automate all these things, you're
- 47:01going to take our jobs away.
- 47:02What are we going to do?
- 47:03Like this painful, tedious manual stuff that should be automated.
- 47:07Like that's our job because that's what a lot of the people that I had worked with for
- 47:12a while.
- 47:12That's what they did.
- 47:13And they were legitimately a little concerned that if we wrote software that would do those
- 47:18things automatically, well, then what would they do?
- 47:20And I saw year after year, we would write that software.
- 47:23They would say, thank goodness, we don't have to do this again.
- 47:26And they would just solve more problems, take on more data.
- 47:29Like they would just do more and almost never did it result in, well, we don't need these
- 47:33people anymore.
- 47:33It just meant they got to do more interesting stuff in a bigger scale.
- 47:36Absolutely.
- 47:37Like this is what I find that when I work with new data sets or problems, and once you've
- 47:42kind of, you know, solved the problem, you understand that data, you fix the issues with
- 47:45it.
- 47:46Suddenly having that kind of foundation and curated data set lets you actually build on it and do
- 47:52more interesting things going forward.
- 47:54It's not like, you know, you've done that.
- 47:55You can, you know, you never need to do that again.
- 47:58Yeah.
- 47:58And that's what drew me to the energy sector because it was like, the more I worked with
- 48:01these data sets, the more I understood and the more interesting questions I could answer,
- 48:05which is really satisfying.
- 48:07Yeah.
- 48:07Yeah.
- 48:07And the more things that are batch processes can become almost real time and really change
- 48:13things.
- 48:13So speaking of data, it sounds like you guys work with a ton of data over there.
- 48:17Give us a sense for the scale.
- 48:19Yeah.
- 48:19So I guess the more standard data set is there's a database that has pretty much everything
- 48:26going on in terms of dispatch on a five minute basis.
- 48:29And so for most of your users, if you just want to see what the power station is doing,
- 48:32what it's bidding, you can use that data.
- 48:34It's large, like pulling out some of these data sets in, it's in, you know, a hundred or
- 48:39200 million rows looking at certain parts of it.
- 48:42But the thing I'm working on at the moment, it almost makes this kind of look small.
- 48:46And this is kind of that same data from that same database, but it's on a four second basis.
- 48:50So a single month of data is about 750 million rows.
- 48:55And it gets all released as thousands of zip holders containing CSVs.
- 49:00One CSV for every half hour.
- 49:02Oh my goodness.
- 49:04And so is there like a big process that just goes along, unzips it, grabs it, inserts it
- 49:08into some database or something along those lines?
- 49:10I think that was how it gets shared in some format.
- 49:13So what I actually, so this is how I was given the data on my current project.
- 49:16And so it's so big, I can't actually unzip it on the machine.
- 49:20So I have to use Python to kind of spin up a number of separate processes that will kind
- 49:25of work through the different zip folders.
- 49:28It will then use, I think Python has a library called zip file.
- 49:31So it will unzip the folder in memory, read in the CSVs, process them, and then it will
- 49:37eventually concatenate it all back into a cleaned data frame that I can work with going forward.
- 49:44And so, and so then I'm trying to use those sets of tools to try and then turn this into
- 49:49a more compressed, cleaned data set that I can work with going forward.
- 49:53So does that fit in memory or do you have to like only pull out slices sort of dynamically
- 49:58with the zip file processing?
- 49:59Yeah.
- 50:00So I can fit about a month in memory on my machine.
- 50:03We do have some large servers.
- 50:05And so I will transition to processing this in parallel on the servers, which should get
- 50:10an even better speed up.
- 50:12But yeah, at the moment, I really just kind of look at things on a monthly basis.
- 50:15And so what I can actually do is, and then there's a ton of processing I have to do with
- 50:20this four second interval data, because what I can see is I will break the data up then into
- 50:26five minute intervals.
- 50:27And I, what I can do is I can see what the generator was doing on a four second basis.
- 50:31And then I can see what its target was.
- 50:34So when they run their optimization, they will say, we know you're sitting at this point here,
- 50:38you have to ramp up to hit this target here at the end of this five minute period.
- 50:43And so I can use this data to tell how well the generators are actually hitting their targets
- 50:48and how well they're following instructions.
- 50:51But the funny thing is, even though, you know, you think of four second data as being, you know,
- 50:55very, very, such a short interval of time.
- 50:58But if you look at some of the big batteries in the grid, that data is actually too slow for
- 51:04some of the batteries, because batteries can actually turn on, inject power into the grid.
- 51:08turn off again, and I can miss it in the four second data.
- 51:11It's amazing.
- 51:12Some of these big grid scale batteries are like the big Tesla battery in South Australia at
- 51:19Hornsdale.
- 51:19They're amazing feats of engineering that you really appreciate when you realize you're
- 51:23missing things at a four second interval.
- 51:24They break your sensors and things like that.
- 51:27Yeah, Australia is really well known for having some of these big batteries in the energy sector.
- 51:32I think for some reason, Tesla seemed to have partnered up with you guys to build these.
- 51:36Yeah, the plan is to roll out a bunch more of these batteries around the grid as well.
- 51:42And they're just really impressive.
- 51:44You know how I mentioned the whole challenge of constantly balancing supply and demand?
- 51:50And really, that's what batteries are so good at doing.
- 51:52Right.
- 51:53Their response time is almost instant.
- 51:55Yeah.
- 51:55So you could just, they could take it in.
- 51:57Exactly.
- 51:58They could eat the energy or they could initially fill, like immediately fill the gap, right?
- 52:02For a while.
- 52:03Exactly.
- 52:03And sometimes with some of this data, you can actually see the battery will receive an
- 52:08instruction.
- 52:08It will quickly turn on.
- 52:10It will discharge some power.
- 52:11And then a couple of seconds later, it will actually then, because there's too much power
- 52:16in the grid, the battery will actually then suck up some of that power and recharge and
- 52:20do the opposite effect.
- 52:20It's just amazing.
- 52:22Yeah.
- 52:22Fantastic.
- 52:23I would love to dive into that, but let's say I'm super fascinated with batteries and
- 52:27their potential.
- 52:28Talk Python To Me is partially supported by our training courses.
- 52:34When you need to learn something new, whether it's foundational Python, advanced topics like
- 52:39async or web apps and web APIs, be sure to check out our over 200 hours of courses at Talk Python.
- 52:46And if your company's considering how they'll get up to speed on Python, please recommend they
- 52:51give our content a look.
- 52:52Thanks.
- 52:52With all of this data, you said that you had basically learned some good advice, like certain
- 52:59things you can just easily do in Pandas and NumPy on small data sets, maybe not so much on
- 53:05large data sets like that.
- 53:07Give us some of the things that you found to be useful and some of the tips and tricks.
- 53:10Absolutely.
- 53:10So there's a concept called vectorization.
- 53:13I'm not sure if you've come across it, but it's effectively, how can you apply an operation
- 53:17to a whole column?
- 53:18So you're not writing a manual loop or using conditionals.
- 53:22For instance, if I try to multiply a column with millions of rows by a number, it's really,
- 53:28really fast because that's all kind of optimized to see under the hood.
- 53:32And so with a lot of this, when I'm working with smaller data sets, you can get away with
- 53:37doing some manual loops yourself or using Pandas to group by a column.
- 53:42For instance, I would often say, this is the identifier for a power station.
- 53:46I want you to group by this column identifier and then sum up.
- 53:52And even those things start to become too slow once your data is kind of at this scale.
- 53:57And so the real trick I find is, yeah, it's how do you find ways where you can apply some
- 54:03operation, a calculation to the whole column?
- 54:06And, but the tricky part with that starts to be what happens if you want to do conditional
- 54:10calculations?
- 54:10And so one of the things I find is sometimes I want to see how much the output of, on a four
- 54:17second basis, how much is the generation of a power station changing?
- 54:21And so you can imagine that Pandas has a calculation that lets you effectively calculate the difference
- 54:27between the previous value that came before really, really efficiently.
- 54:31But because, you know, I've got all these different generators and intervals, like kind of all
- 54:36in the same, you know, data frame, I don't want to consider the first value in a five minute
- 54:41interval, because that's affected by, you know, a different time interval as well.
- 54:46So what you can do is NumPy has these great functionality called where or select, where you can pretty much
- 54:55pass it a column that turns out to be true or false for the whole data set.
- 55:00And it will then replace the value with something else really efficiently.
- 55:04So what I can do is I can, I can run my calculation for the whole column.
- 55:08And then I can use a NumPy where to replace the first value in each five minute interval with a
- 55:14missing value.
- 55:15And that pretty much does things in, you know, a few seconds that would have taken, I don't
- 55:21even know how long with the other way hours, at least.
- 55:23Wow.
- 55:24It's amazing.
- 55:25Yeah, I think that the whole computational space with pandas and with NumPy's, there's,
- 55:30you know, like in Python, we speak about Pythonic code, right?
- 55:33You would use a foreign loop instead of trying to index into things and so on.
- 55:37And then there's a whole special flavor of that in the pandas world, right?
- 55:41And a lot of it almost has the guidance of if you're doing a for loop, you're doing it
- 55:47wrong, right?
- 55:47Like there should be some sort of vector operation or something passed into pandas or something
- 55:53along those lines, right?
- 55:54Absolutely.
- 55:55Like, yeah, it's almost like its own kind of type of problem solving in a way, because it's
- 55:59like, how can I apply this calculation to everything in a column, but also in these cases, do something
- 56:08else.
- 56:08That's really the problem solving in a lot of ways.
- 56:10Yeah.
- 56:11Yeah.
- 56:11It's a lot more set-based thinking, almost like databases.
- 56:14Yeah.
- 56:14What about things like threading or multiprocessing or stuff like that?
- 56:18Like, have you tried to scale out some of the things that you're doing in that way?
- 56:22So yeah, so we have a server that has about 60 cores and about 700 gig of RAM on it.
- 56:28So that's the plan is I can shift my things over there once this project-
- 56:3160 cores?
- 56:32That's pretty awesome, actually.
- 56:34Yeah.
- 56:34We've got a couple of them, which is very useful for all of the energy modeling that we do.
- 56:38And usually what I'm doing is kind of a mix of, yes, using Python's multiprocessing library
- 56:46to try and, yeah, just split.
- 56:49Usually what I'm doing is I'm just processing a whole heap of data frames in parallel and then
- 56:56concatenating them back into a single data frame once they're kind of processed.
- 57:00That workflow seems to work pretty well for a lot of the requirements that I have on projects.
- 57:06Yeah.
- 57:06Because you can get each subset data frame bit to do its own computation in parallel, right?
- 57:12Yes.
- 57:12Yeah, exactly.
- 57:13And the other thing too that can also benefit is that usually as part of the cleaning process,
- 57:19I'm kind of subsetting the data as well.
- 57:20So while the data is starting off at an immense size as well, I'm figuring out which parts of
- 57:27it I need and cleaning it.
- 57:29And then so then the data frame I end up concatenating back together can be a more manageable size as
- 57:35well.
- 57:35Right, right, right.
- 57:36Interesting.
- 57:36Have you looked at Dask for any of this?
- 57:39Yes.
- 57:39We've had, I did some work on the server for a different project looking at it.
- 57:44And I think Dask might be, once I've kind of built up a more curated version of this four
- 57:50second interval data, I think Dask will probably be what I'll use on the server for working with
- 57:55the whole data set in the future.
- 57:57Yeah.
- 57:58It sounds like it might really be, I mean, I haven't actually tried to apply to that much
- 58:02data that you got there, but it's sort of its functionality.
- 58:05It sounds like it really might be the thing to do because it'll take, it basically, your
- 58:10description of breaking into the many data frames, having them run and then bringing it back
- 58:13together.
- 58:13That sounds to me like what Dask is built for, right?
- 58:16Yeah.
- 58:16And the brilliance as well, I think of the Dask project is how they were able to kind of
- 58:20emulate the Python, sorry, the Pandas way of doing things as well, which is great because,
- 58:25you know, it's nice not to have to relearn too many things and be efficient from the beginning.
- 58:30Also, I should probably just flag as well that these data sets that I'm working with, the four
- 58:36second interval, and then the actual database on the five minute basis, one of the things
- 58:40that got me so into the energy sector, and that's, I think, unique in a way about the Australian
- 58:45energy market, although I stand to be corrected, is that this is all public data.
- 58:48If you want, you can go and download all of this data from the market operators website, which
- 58:53is, you know, an amazing amount of kind of openness to be able to go in and look at what
- 58:58these power stations are doing and what prices that we're getting on such a granular basis
- 59:02as well.
- 59:03That's been really what fascinated me.
- 59:05Yeah, that's super cool.
- 59:06You know, if people are out there trying to do research, working on a thesis or something
- 59:11like that, they could just grab this data.
- 59:12And it's like you said, it's real.
- 59:14And a lot of people have both physical machine reasons and financial reasons.
- 59:18Keep it accurate, right?
- 59:19Yes, absolutely.
- 59:20And really, I guess I come back to that original point where the limitation for this data isn't
- 59:26how clean it is or the amount of data.
- 59:29It's just understanding the processes well enough to know what you can do with it.
- 59:33Right.
- 59:33A little bit like that example you had about the solar farms versus coal generation, right?
- 59:40Exactly.
- 59:40Exactly.
- 59:41Yeah.
- 59:41Know that I mean different things.
- 59:42Yeah.
- 59:43Yeah.
- 59:43Very cool.
- 59:44All right.
- 59:44Other advice or interesting things going on before we're getting short on time, but
- 59:49anything else you want to throw out there?
- 59:50Work with all this data?
- 59:51One of the areas I'm quite interested in at the moment is Python's number library.
- 59:55N-U-M-V-A.
- 59:57Yeah.
- 59:57I think it uses the able to kind of compile Python code under the hood to get really high
- 1:00:03performance.
- 1:00:03And it can be perfect for my use.
- 1:00:06And the reason I'm rather interested in it is that if I can vectorize a calculation,
- 1:00:11you know how I'm applying it to the whole column.
- 1:00:13But for instance, if I'm trying to do some calculation where I want to loop through it
- 1:00:20because my current calculation depends on the state of a previous calculation, then that can
- 1:00:25be a limitation of this kind of vectorization approach.
- 1:00:29Whereas...
- 1:00:29Right, right.
- 1:00:29You can't just apply it to the set and go, hey, every row here, just look back at yourself
- 1:00:35a little bit in that place and then do the thing.
- 1:00:38It's got some dependencies on what happened before, right?
- 1:00:42And that, I have no idea how you would fix that.
- 1:00:44Maybe it's possible, but it's very tricky, right?
- 1:00:46And so number does that, okay?
- 1:00:47So number is effectively a way to write Python loops that run as fast as C, but within for
- 1:00:54numeric calculations.
- 1:00:55So this is why I'm very interested in this for some of the areas that are a little bit
- 1:01:00trickier for me to vectorize using data frames.
- 1:01:04I'm very interested in the number library as a solution for some of those challenges.
- 1:01:08Yeah.
- 1:01:08So number makes Python code fast.
- 1:01:10It says it's an open source JIT compiler that translates a subset of Python and NumPy
- 1:01:15code into fast machine code.
- 1:01:17So I haven't used it, but it sounds like it really knows about NumPy in addition, right?
- 1:01:22Because you could use Cython, but Cython doesn't necessarily know anything about NumPy, for
- 1:01:25example, right?
- 1:01:26Yes.
- 1:01:26Yeah, you're exactly right.
- 1:01:28Like in a way, number has kind of replaced what I would have used Cython for in the past,
- 1:01:33but for my application.
- 1:01:34What I could do, say for instance, if I have a NumPy array and I want to loop through it
- 1:01:40and there's some calculation I want to do and then my next calculation depends on that previous
- 1:01:44calculation going forward.
- 1:01:45This lets me do that.
- 1:01:47Yeah, in a way, and I'm writing Python code.
- 1:01:49I don't have to write C or C++.
- 1:01:51You can see it.
- 1:01:52You're literally adding decorators, just like how Flask has that lovely kind of decorator
- 1:01:58syntax.
- 1:01:59It's almost like that to an extent.
- 1:02:01Yeah, exactly.
- 1:02:01You say at number.jit and then do you want this to run in parallel or not?
- 1:02:06Yeah, sure.
- 1:02:07Why not?
- 1:02:07Exactly.
- 1:02:08And also it even lets you run your calculations in parallel as well.
- 1:02:12You can see that little parallelism true.
- 1:02:14And it's actually true parallelism without the GIL as well, which is amazing.
- 1:02:19Yeah, this is super interesting.
- 1:02:20I knew that it was a compiler along the lines of Cython, but I didn't realize that it had
- 1:02:25this special integration with NumPy.
- 1:02:26That's very neat.
- 1:02:27Yeah, I really recommend, like, I think for most people, Pandas is probably what you need.
- 1:02:33But if you're running into these kinds of, yeah, these types of problems, then I think
- 1:02:37NumPy would be a solution before you would have to look to, necessarily have to look to
- 1:02:43a different programming language.
- 1:02:44Yeah, absolutely.
- 1:02:45And like, this is how I started off our conversation together.
- 1:02:48The performance side of Python is super interesting because it's like, oh, well, it's not really
- 1:02:53fast enough.
- 1:02:54Until you apply this decorator, then all of a sudden it's just as fast and it's amazing.
- 1:02:57There's just all these little edge cases that are super neat.
- 1:03:00Yeah.
- 1:03:00Very, very cool.
- 1:03:01I look back to some of the code I wrote during my PhD and I cringe at some of the bad performance
- 1:03:07practices I probably had for working with them.
- 1:03:09And I think this comes back to your point about having people in the team who are a bit more
- 1:03:14experienced in this area.
- 1:03:15Because if you can have people who understand this and point team members to these tools
- 1:03:20for optimizing their code, then I think that can deal with a lot of the issues for people
- 1:03:23who may not be as experienced with writing Python themselves.
- 1:03:27Yeah, that's super advice.
- 1:03:28And then if you've got data that maybe is like the other side of your story, it's like
- 1:03:32too big to fit in RAM or you want more sort of automatic, rather, parallelism across, say,
- 1:03:39a large data frame, then Dask is definitely a good thing to look at.
- 1:03:42Absolutely.
- 1:03:43All right, Jack.
- 1:03:44This has been super interesting.
- 1:03:45I think we're getting a little long on time.
- 1:03:47I don't want to take up your entire day.
- 1:03:49So I will have to call it a show on that bit.
- 1:03:52No problem.
- 1:03:52But before we get out of here, of course, you have to answer the two final questions,
- 1:03:56as always.
- 1:03:56So if you're going to write some code, work on some of these projects, what editor do you
- 1:04:02use?
- 1:04:02VS Code.
- 1:04:02Especially since they added Jupyter Notebooks into the editor as well.
- 1:04:07Yeah, it's really interesting to see both what VS Code and PyCharm are doing to try to bring
- 1:04:12either just bring notebooks into the space or try to come up with a more native alternative,
- 1:04:18right?
- 1:04:19Like, well, here's a cell and it's separated by like this special comment, but you can still
- 1:04:23run it in notebook style.
- 1:04:25But it's like feels like a text file you're working with.
- 1:04:27And yeah, it's an exciting time for that stuff.
- 1:04:29Absolutely.
- 1:04:30Yeah.
- 1:04:30And then you've already given a shout out to a couple of different projects.
- 1:04:34But any notable PyPI packages you want to tell people about?
- 1:04:38Yeah, I mean, Numbers is the one I'm fascinated with in terms of learning more about at the
- 1:04:43moment.
- 1:04:43But I think for in terms of getting things done, just Pandas and Geopandas and the kind
- 1:04:49of scientific stack, it's just, it's amazing what people, the code that people have done
- 1:04:54that makes me so effective just by understanding, just being able to use their libraries.
- 1:04:58It's phenomenal.
- 1:04:59It's phenomenal.
- 1:05:00Yeah.
- 1:05:00Are you a Jupyter or a JupyterLab person or something else?
- 1:05:04I use mainly Jupyter, mainly because at least at the time when I tried out JupyterLab, I couldn't
- 1:05:09collapse some of the outputs from the cells as well.
- 1:05:11They may have fixed that, but I'll take a peek at JupyterLab every couple of months or so
- 1:05:16and see what's new.
- 1:05:18All right.
- 1:05:18Fantastic.
- 1:05:19All right.
- 1:05:20Well, final call to action.
- 1:05:21People are interested in, maybe they work in energy somewhere else in the world or they're
- 1:05:26trying to do research with it.
- 1:05:27What do you tell them?
- 1:05:28If you're interested in getting in touch with me, we run a few meetups for energy modelers
- 1:05:32in Sydney.
- 1:05:32So if you're ever interested in getting in touch to chat about some of the data in Australia
- 1:05:36or some of the work we're doing, feel free.
- 1:05:38Is that Zoomable these days or is it in person?
- 1:05:41The plan is for the meetup to be up as a Zoom one.
- 1:05:44So that's the plan.
- 1:05:46Yeah.
- 1:05:46All right.
- 1:05:46Fantastic.
- 1:05:47Well, Jack, it's been great to have you here.
- 1:05:49Thanks so much for sharing what you're up to.
- 1:05:51Thanks so much, Michael.
- 1:05:52It was great meeting you.
- 1:05:53Thanks for having me.
- 1:05:53Yeah.
- 1:05:54Keep the lights on down under.
- 1:05:55Thank you.
- 1:05:56I will.
- 1:05:56Bye.
- 1:05:58Bye.
- 1:05:58Have a good night.
- 1:05:59This has been another episode of Talk Python To Me.
- 1:06:02Our guest on this episode was Jack Simpson, and it's been brought to you by Square, Linode,
- 1:06:07and Assembly AI.
- 1:06:08With Square, your web app can easily take payments, seamlessly accept debit and credit cards, as
- 1:06:13well as digital wallet payments.
- 1:06:15Get started building your own online payment form in three steps with Square's Python SDK
- 1:06:20at talkpython.fm/square.
- 1:06:23Simplify your infrastructure and cut your cloud bills in half with Linode's Linux virtual machines.
- 1:06:29Develop, deploy, and scale your modern applications faster and easier.
- 1:06:32Visit talkpython.fm/linode and click the Create Free Account button to get started.
- 1:06:37Transcripts for this and all of our episodes are brought to you by Assembly AI.
- 1:06:41Do you need a great automatic speech-to-text API?
- 1:06:44Get human-level accuracy in just a few lines of code.
- 1:06:46Visit talkpython.fm/assembly AI.
- 1:06:49Want to level up your Python?
- 1:06:51We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:06:55Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:07:00And best of all, there's not a subscription in sight.
- 1:07:03Check it out for yourself at training.talkpython.fm.
- 1:07:06Be sure to subscribe to the show, open your favorite podcast app, and search for Python.
- 1:07:10We should be right at the top.
- 1:07:12You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 1:07:17and the direct RSS feed at /rss on talkpython.fm.
- 1:07:21We're live streaming most of our recordings these days.
- 1:07:25If you want to be part of the show and have your comments featured on the air,
- 1:07:28be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:07:32This is your host, Michael Kennedy.
- 1:07:34Thanks so much for listening.
- 1:07:36I really appreciate it.
- 1:07:37Now get out there and write some Python code.
- 1:07:39I'll see you next time.
- 1:07:59Thank you.