Resources

Lightning Talks (PyCascades 2024)

video
Aug 8, 2024
34:03

image: thumbnail.jpg

Transcript#

This transcript was generated automatically and may contain errors.

Hi everyone, I'm Christy Heaton and I like making maps with Python. So today I'm going to talk about mapping tomorrow's eclipse path with Geopandas and PyScript.

So if you haven't heard, there's a total solar eclipse happening tomorrow, passing over much of North America from Mexico up to Eastern Canada. So total solar eclipse is when the moon comes directly between the sun and the earth and casts a shadow where right below where the moon and sun are. And if you look at the sun and moon, when this happens, it looks something like this. The skies get dark. It's pretty cool.

2017, there was another total solar eclipse that was much more conveniently located to Seattle. So I went to Oregon and saw the totality and this is me watching the, well, not the totality because it's light up, but after it was partial.

So let's look at a map made with Python of the eclipse happening tomorrow.

So this is a web map, has the total solar eclipse path and it has the cities that are going to be covered by the eclipse and the cities are sized dots by population. So we can see the most populated city, Dallas, Montreal, we got Cleveland, Indianapolis, and a bunch of others.

Building the eclipse map with Geopandas and PyScript

So I use Geopandas a lot for spatial data. So Geopandas is like spatially enabled pandas. It makes it super easy to read in spatial data, make maps with it, do analysis to it, and then you also have, like, all the power of pandas to do tabular manipulation. So Geopandas is my preferred Python library for working with spatial data in Python.

And then PyScript is a totally different thing. We learned about it yesterday. It's a framework for running Python in the browser. So watch that talk from yesterday if you missed it, but, yeah, we're going to be making this map such that we're going to be running the Python, but you don't have to use any local Python installation.

So back to the map. So we're here and anyone could go to this link and see the eclipse, and if you go down to view code, we can see all the code that I used to make this map. So I'm in PyScript.com. I really like using PyScript.com to make my PyScript projects because then PyScript.com hosts it and I don't have to deal with any of that. I just make an account on PyScript.com, make projects in there, I can share the links, and that's it.

So the Python code to make the map is in this main.py file, and you're looking at oops. You're looking at all the code. So I import Geopandas and some PyScript libraries. I already have my data prepared, so I have these cities that were clipped to the eclipse path already online, so I can load that in, as well as the eclipse data. Same thing. I have it prepared. I downloaded it from NASA and loading it in.

These two variables now hold geodata frames representing my data, and Geopandas has this explore method, which is like, I mean, you can make a web map with one line of code. So you take a geodata frame, run explore method, you can customize how the map looks. You don't even have to add any of this stuff. There's defaults for everything. So you put that in a variable, and then any other layers you want in the map, you set them. And then PyScript has a display method, so this will just put the map on the page.

These two variables now hold geodata frames representing my data, and Geopandas has this explore method, which is like, I mean, you can make a web map with one line of code.

Another thing I'll mention is PyScript.toml is where you put the packages you want access to. And caveat that this page takes, like, 30 seconds to two minutes to load, because you're not — you have to, like, load in all of Python and all of those libraries. So beware if you go to this link.

So tomorrow, here in Seattle, we won't be able to see the total solar eclipse, but we'll see a partial eclipse and about 20% totality around late morning. So if we're — we have clear skies, check it out with safety glasses. And yeah. Enjoy. Thanks.

Scheduling recurring data updates with Google Cloud

Hi. I'm here to talk to you about how to do the same thing over and over and over again. My name is Jessica, Jessica Garson, most people call me. I'm on the Internet, most places, at Jessica Garson, and I'm a senior developer advocate at Elastic.

And a big part of my job is making demos and talks and quick kind of fun, engaging, technical demos that show you how to do something. But I keep using kind of the same paradigm for many, many projects where I have to run code at a specific time interval. And when I first started working at Elastic, I was working with Elasticsearch and my data was held in an index and it would very quickly go out of date.

And you might be wondering, what is an index? An index inside of Elasticsearch is a data structure where you can store your data in documents.

But I use this paradigm all the time for everything from a Twitter bot that will tweet pictures of cats to things for just, like, letting me know when the Celtics are playing. I basically run the same sort of paradigm over and over and over again. And so I've used everything from Google Cloud Platform, I've used Render, I've used Railway, I've used just pure Cron jobs. But basically the solution is pretty much the same. You create a script for uploading your data, you create a Cloud function, and then you use some sort of Cron scheduling service.

I'm going to show the demo today using Google Cloud Scheduler to update your index at a specific time interval of your choosing. And I also love space APIs and NASA APIs as well. So I love using the NASA's near earth object web service, which is a restful service which tells you when asteroids are coming or when they came. Which is awesome.

So let me just show you the code really quickly in GCP. So I'm just going to give a really high level overview of the code. And you can kind of just store everything inside of Google Cloud Functions, which makes it really easy. So I connect to Elastic, connect to NASA, create a data frame just because I like having my data in a modular format. From there I can actually convert my data frame into documents. And then I can also see the last time that my index was updated just to get the date. And then I can update all the new data.

And I basically will take my local main function and I'll just convert it into a Cloud function. And that basically serves the same purpose as a main function would serve as well. And you can also load in your requirements.txt file and save all your local variables and things like that. And then you can set it to run on a schedule.

So I have this. You can actually see my cats and my Celtics updates as well. But for the NASA data, I can actually set it to run. So it runs every morning in my time zone, which is New York, at 8 o'clock. And I can force a run right now if I want as well. So yeah. That's kind of a lot of how I do a lot of my creative posts. I've used this paradigm a lot. So if you want to see a full blog post of this and the code that I used as well, you can find it here. Thank you so much. And I really appreciate you all. Thanks a lot.

Reproducible reporting with Quarto

All right. Hey, everyone. My name is Sam Edwards, and I'm here to talk to you about Quarto today.

So if you haven't heard of Quarto before, Quarto is an open source scientific technical publishing system. It's really similar to Jupyter Notebooks or R Markdown if you've used those before. So I want to give you an overview of what is Quarto and how I use it for reproducible reporting.

So we're in VS Code, and there's a Quarto VS Code extension that I can use to preview my Quarto documents. This is an example of Quarto slides that I'll use to walk through Quarto today. So a little bit about me. I work at a company called Posit. We create open source software for data scientists. Some of our most popular stuff that we've created is the RStudio IDE, Shiny for R and Python, Quarto, and there's lots more stuff that we create as well.

And again, about Quarto, it's a scientific and technical publishing system, but the simplest way to think about it is it's like Jupyter Notebooks, but you can create more beautiful outputs. So why Quarto? There's one tool. You can create many different outputs. We'll look at a few examples. You can author in Jupyter Notebooks or in plain Markdown, whatever you prefer. I prefer plain Markdown, like you can see on the side here. You can have inline Python code, which is one of the killer features for me, and I'll show you what that looks like. You can create dynamic content, and then you can easily share with others. You can publish to Confluence, an HTML page, Deposit Connect, PDFs, Word documents, many different formats, all from Jupyter Notebooks or Markdown files.

So here's an example of authoring in Jupyter Notebooks. Not sure how well you can see that, but it's just a normal Jupyter Notebook, but we put some special syntax here to tell Quarto how to render it, and you can see the output on the right-hand side.

You can create single-page HTML files. So this was a plain Markdown file, and the output I get is a somewhat interactive HTML document. You can see there's tabs. You can see there's embedded links. There's interactive plots.

This is probably my favorite feature, and it's a very small thing, but you can do inline Python code. So imagine I had some Python code at the top here that created a user object. In my Markdown, I can say hello, and then backtick, backtick. Anything in here is going to be executed as Python code. So I get user.name, and then user.balance. I use F strings to format it with a comma, and then the output would be something like this. Hello, Sam. It is nice to meet you. So inside your prose, you can embed the output of your Python code.

You can create emails with Quarto. So this is a screenshot from a Gmail email that I sent to myself, and it's just giving me some reporting on an application I have deployed in Kubernetes. You can create dashboards with Quarto. So this is just a plain HTML file. There's no server on the back end, but what we can do is you can use Quarto syntax and plain Markdown to create these really nice interactive outputs. You can publish to Confluence.

And now I want to show you a really quick demo. So I have this report here, and let's render the report. So I run Quarto render. It's going to take a few moments, because we're actually going to create many different outputs here, all with one document. You can see we're creating a PDF. We created a Word document.

Let's take a look at my output here. So pause it, connect deployment reports. I have a timestamp here. If we take a look at how this is generated, this is that inline Python code. So here you can see the inline Python code. I'm getting the current time, and I'm formatting it. I create a plot. I have more inline Python code here. It's counting the number of items that I've deployed in my Kubernetes cluster here. This is a dash plot, so interactive output. Again, there's just a plain HTML file. There's no server on the back end, so everything's just embedded.

And then I have another plot here. And lastly, I want to identify inactive users. So I have this interactive table here, and this is giving me a list of 96 users who are no longer using this service, so maybe I should delete them to free up some licenses. So this is my favorite format, HTML. We can also create PDFs. The PDF was created from the exact same code. So PDF is embedded here. It's not interactive because it's a PDF, but some people like to have PDF outputs for some reason still. So you can make those people happy. I can even have Word documents to make those people who like Word documents happy as well.

All right, well, I think my time is up, so thank you for learning about Quarto today.

PyOpenSci: peer review and packaging for scientific Python

Hi again. I'm here to tell you about PyOpenSci. Why? Because I'm going to be sprinting at it on Monday, and also I think it's really neat just to find out about it.

PyOpenSci is a community built around Python scientific packages. It focuses on reviewing key packages for the scientific community and keeping them up to date with best practices and also just making sure that the code itself is doing what it should in a way that an engineer would be kind of proud of.

So it focuses on two main areas. One is the peer review. It has a board of many very talented editors, but they also have a mentorship program where they bring in people who have maybe never code reviewed any code anywhere before, and they combine these views of the expert and the beginner so that these packages have a broad appeal.

Also if you get reviewed by PyOpenSci, you get free entry into the journal open source software. Well, not entry, but you pass a review.

So this is the review guide. So there's already many packages reviewed, and there's more up for review, and you can submit your own if it's scientifically related.

But there's also a packaging guide. It is geared towards beginners who have never packaged anything, but it really has information to guide anyone no matter how many years you've been packaging Python, and I think it's a great place to go if you want an opinion on Python packaging no matter what you're actually building.

So that guide is here, and it tries to go through the entire software development life cycle not only once, but how do you maintain that and have a package that's healthy and has contributors?

So if you want to come sprint on this, you can join me, and there's a backlog of new things to add to the guides, or if you just participate in the guide and tell us what went wrong for you, that would be very valuable, or if you want to just come by and say hi in our online communities, any of that is totally fine.

Trading with Renko charts and Python

Good morning. My name is Sameer Jain. Today I'll be talking about trading and how Python can be leveraged, or I leverage Python in my day-to-day trading. A little about me, I'm a software engineer. I'm actually a UW alumni, so it's great to be back and being on the other side of the classroom. I play the guitar as well, I've performed at concerts, things like that, and I'm really passionate about trading. I've been trading US equities commodities for about eight and a half, nine years at this point.

Particularly in trading, I'll be talking about how I build my setups, particularly how I use the Renko charts to kind of screen through all the thousands of tickers we have.

Firstly, I believe many of us have heard about candlestick charts. Those are the most common. You'll find them on all billboards of all the advertisements of all the trading websites.

The main difference over here, if you could see, the left one is a candlestick chart. Candlestick chart has both price and time integrated and visualized. On the other hand, Renko charts is just based on price action. Renko is derived from a Japanese word, renga, which basically means bricks. Each brick in the Renko chart represents a certain price or a certain quantity of price. It's on a timeline, but there could be a day, let's say, each brick size, you set it up as $10, but the price didn't move $10 on that particular day, so you wouldn't get a brick for that day. But let's say the next day, you get $10 worth of movement, you will see a brick. It's a great way to build setups or understand what the general price pattern has been.

On the other hand, candlesticks, it can get confusing a little bit. It's more for technical analysis, and if you're doing scalping intraday, then candlesticks are great. Even if you use Renko, Renkos are great for screening what you need to trade on or what you want to trade on, and candlestick is more where you actually trade on because you have much more detailed data, which also includes granularity of time.

So in Python, you can simply install some libraries, Y-Finance. Y-Finance is for getting Yahoo finance data in an OHLCB data format, and MPLfinance is the library that we use for visualizing a dataset, at least in this case, Renko charts.

So to build Renko charts, there are different methods, there are different ways one can approach it. It's more of a personal preference for each and every trader. I personally prefer the ATR formula. ATR is basically average true range, I mean, it's called average true range.

So what we are basically doing over here is we are averaging the maximum of three prices. The first price is the highest and the lowest price in that particular time frame, or the ticker in question. Second is high price minus the previous close, the previous break close, and third is lowest minus previous close. We take the max and we average it out.

It's more, at least what I feel, what I've learned from, what I've gained from my experience is the most useful way of getting, of building a Renko chart, because it's more detailed and it's not just focused on just one indicator, like, oh, high, low, and then you sort of compare it. It's more detailed, it gives a better, accurate picture of how the price movement is for that particular ticker.

And then the library that we imported, the MPL Finance, we can just plot the Renko charts. This is the format. And in this, if you can see, we set brick sizes, the ATR lens, and this is where you can tweak the Renko charts to your taste. You know, some people, let's say Apple, for example, it's trading at, I don't know, $100 per stock. You want your brick size to be $1. You can set it up over here. Some people like to see higher or lower volatility timeframes, so someone would set it as $5. So things like that, you can change it over here.

As, like I mentioned, Renko charts are great for price action type strategies and could be used in your day-to-day trading, so thank you so much.

Effective teaching and Bloom's two sigma problem

Hello, everybody. So I have an old version of this talk here. That's exciting. Anyway, so, hi. I have been coding for a while. I've been working in tech education for a long time as well, and I want to tell you about education because I have some experience and I'm pretty good at it. About 90% of the people who have graduated from courses that I've put together over the last while, they just get jobs immediately, so it's quite good. And this happens in the South African market.

So the reason I want to talk to you guys about education is because there are a lot of people in this room who are educators in some form. You're not necessarily professional teachers or lecturers or anything like that, but a lot of you would perhaps take part in a workshop or mentor someone at work or something like that. And so I do think that there are certain fundamental skills and mindsets that are helpful in many different circumstances, and I want to amplify you guys.

So the first thing that I want to tell you about is this thing called Bloom's Two Sigma Problem, and that is, it's a bit of a heavy, heavy sentence, brace for impact. The average student tutored one-to-one using mastery learning techniques performs two standard deviations better than students educated in a classroom environment.

The average student tutored one-to-one using mastery learning techniques performs two standard deviations better than students educated in a classroom environment.

So a picture's worth a thousand words. So let's assume that this normal distribution here is a perfectly normal classroom situation. You have a bunch of butts in chairs, and you have a teacher at the front. The stronger learners are on the right, the weaker learners are on the left, or like the faster learners are on the right and the slower learners are on the left. Now imagine if you were to pace the class so that exactly 50% of the people passed and 50% of the people failed. If you were to change the delivery mechanism to be mastery-based and one-to-one tutoring, then the line wouldn't be at the 50% mark. It would be two standard deviations over, so like 2.2% of people would fail instead of 50% just by changing the delivery mechanism. And that's pretty awesome, but it's also kind of hard to pull off. But it's useful to look at this mechanism and get an idea of why it works.

So there are two things that were mentioned, mastery-based learning and one-to-one tutoring. So mastery-based learning basically means like you teach a person a thing, and then you teach them the next thing when they're ready for it. It doesn't sound like that strange, but it is not applied in traditional education systems. Generally, you get the class to move as a unit.

So if you think about mastery-based learning and apply it to code, it's pretty clear. You can't teach recursion to a person who doesn't know what a function is. You can't teach people how to loop over multidimensional lists until they know about lists and loops. So it's pretty clear that it makes some sense.

The next part of that is one-to-one tutoring. So if you just picture it for a moment, you'll immediately jump to certain conclusions about why it's effective. You can't have somebody hiding at the back of the class. You can't have a person who is being distracted by their friends, and the learners have to be engaged. But really, the most important part, in my opinion, is that the teacher is engaged. The teacher is able to fully understand each of the people that they're interacting with because it's just one person that they're interacting with. And that makes them into a better teacher.

The next concept I want to talk about is time. So if I'm teaching a person a thing, like maybe I'm teaching them for an hour over the course of a week, the rest of that week should ideally go well. So what I want to do is instead of thinking about just pushing facts at people, I want to plant seeds and I want to nurture those seeds so that people can keep on growing in their own time.

And the last concept, which is maybe the most important one, and if this is the only thing that sticks, it's very, very worthwhile. So I'm sure many of you have heard of growth mindsets and fixed mindsets. So it's a very, very powerful thing in education. So if somebody's got a fixed mindset, it means that they think that their abilities are static. And if somebody's got a growth mindset, they believe that they can work hard and get better at things. You want to foster a growth mindset in anybody that you're teaching. You want to foster a growth mindset in yourself.

Poetry readings on resilience

Hi, everyone. My name is Madison Swain Bowden and my pronouns are she, her. I'm an organizer for Pi Cascades and I'm also a trans woman. And particularly in today's world, with the violence that's happening constantly against trans people, I have safety on my mind often. Part of that safety involves changing my voice and the way that I talk to match what people expect from my gender. Because if I can never predict how someone might be able to respond seeing me and hearing me with a fully relaxed voice.

These are some of the recitations that I use when training my voice. They speak to the fact that the world may be ending, but it's always ending, and there's joy to be found around us nonetheless. So I'm going to give those to you.

This first one is called Did You Have Something to Do With It? And it's by Minori Sanchez-Fon.

This is our time. The legacy of greed has grown from its seed to infiltrate every place, every face, releasing a suffering recorded in stone and in bone, so old that language can't console it. This was the blow which we struck at first without knowing how deep it would grow. It would grow into a frightening history that fractures hope. First by attacking the body and then by distorting the mind. It would grow and force us to question whether we are a part of this world or its affliction. Whether our addiction to power will consume the beauty that was once our birthright.

This is our time. What is certain is life growing out of itself greater than the moment before. Within us, around us, in spite of us, proving we can't control the thing that brought us up from the cold and will press us back like flowers into the mold. We are tethered to a circuit that excludes nothing, a song the dead can hear. Being resilient, forming all, something that makes time small, so old that language can't dispose of it, still gold over the violence. Don't forget this too, this too is our time. Our spirit is not weaker, it is waiting on us to decide what it is that we will honour while we are alive."

Our spirit is not weaker, it is waiting on us to decide what it is that we will honour while we are alive."

In the kingdom of fear, a shadow hovers over my cover of leaves and violets. A shadow is whispering, I have agony on my side. I have experts on violence. I have control of the tide. We get plucked one by one. We get pruned before we can behold the fruit that is our offering. I have pleaded to see at long last what blooms I produce, what magenta will effuse from this labour and truly reflect my heart. I have pleaded to consult the chorus of night, to hold the strands of moon that tether me to beauty and lets me rest. I have pleaded, let me return these songs to the dirt, cognizant of the wound that has yet to heal.

If I am denied the kindness needed to transform sorrow. If I am denied the simple gentleness of existing, then I will leave my gifts like lichen over the oak branches, trusting they will be safe until you find them. Even in the kingdom of fear, the air murmurs its song through the streets. Joy remains wild. It has baffled the cage again. It has cut through the horror using only what is already there, what you did not perceive as strong, as long lasting. Thread the fine eye of time's needle with your heart and begin to mend, begin to mend, begin to mend. Thank you.

Game development with PPB

All right. So, hi. I'm here to talk about PPB real quick. I'll be running sprints on Monday, so if you want to come check out more than I'm about to show you, please do.

So this is my 15-line demo. So just to show you how easy it is to use PPB, we start with the most classic two-line demo. This gives you a window. This is actually a lot more than you would think about. The best comparison I have is to get to this in Pygame is about 50 lines of code.

So we're going to build ourselves a sprite. For now, we're just going to give it a position. These have to be vectors. There's historical reasons for this.

And now we need one more thing. So our setup function takes a scene object, and we're going to add a player, our ship, to the scene. And then we have to tell PPB to actually run that setup function. So we run this. I'm a block on the screen. Just for everyone's sake, I'm actually going to add one other thing here. We're going to just double this in size. So block on screen. Not really interesting. So how do you make it move?

All of our handlers look like this. On and the name of an event. They receive the event that has happened. So in this case, it's our update event, which would be... The signal function is how you would put new events into the system. We're not going to use it today, but I want to let you know it's there. And so self.position plus equals... We're going to reach into our directions module. These are a bunch of unit vectors that we can use for various things. We'll give it 10 units per second, and then we multiply this by the time delta of the event. All right? So hit play. We have a moving box.

And now for the greatest trick. Right now it's just a box. It's kind of boring. If I put this ship.png into the same folder I'm running from, we have rendering!

There's a bunch of knobs you're allowed to pull on this that I have not shown off. But this is how quickly we want to get you started with this engine. Pretty much everything in this system is customizable. You can even rip out the render if you don't like it. And like I said, I'll be around. You can always come and ask questions. I'm happy to demo and show you all the moving pieces. And that's it. Thank you.