Musings of a dad with too much time on his hands and not enough to do. Wait. Reverse that.

Tag: tools (Page 21 of 35)

Graduation Party media

My eldest graduated high school this year and, to celebrate, the wife and I threw her a graduation party. I’ll spare you the to-dos and checklists for throwing a graduation party–I left those largely to my wife as it is. Instead, I’d like to focus this post on the media aspects of the party.

I’m a big proponent of taking pictures and videotaping those magic moments–and even mundane moments–throughout the lives of your children and family. So, I figured this was the perfect time to pull out those embarrassing pictures and video from the past so that all her friends could see.

For the party, we rented an outdoor facility at a local park. We would have access to electricity and I decided to bring two large flat screen monitors to display the media, but I did not want to bring along expensive laptops or desktops to play the media as I didn’t want to risk damaging that equipment. So, what to do? I know: run my media on cheap Raspberry Pis!

The Slideshow

For my picture slideshow, I pulled out about 700 pictures I had of my child from over the years. However I was going to run the slideshow, I knew I wanted to show the pictures in chronological order. So, I came up with this quick PowerShell script to rename the pictures in increasing numbers so that sorting the pictures alphabetically would effectively sort them chronologically:

$pics = gci "C:\grad_party\data\*" | sort {$_.LastWriteTime}

$count = 0
foreach($pic in $pics){
    $count = $count + 5
    mv $pic.FullName ("C:\grad_party\data\{0}{1}" -f ($count), $pic.Extension)
}

(I increased the count by 5 with each loop so that I could easily, manually reorder pictures if needed.)

Now the big question was, on a Raspberry Pi, what are my options to run a snazzy slideshow?

feh

feh is a linux utility for displaying images and its relatively easy to get it started on a Raspberry Pi. The challenge I encountered was getting it to do anything else other than hard transitions from slide to slide. Ideally, I want a slideshow where the slides are in motion and have nice cross-fade transitions: something like this. I don’t know if feh has those capabilities, but I certainly couldn’t get it to inject those effects, so I continued my search.

Python and Pi3D

A solution using Python?! Tell me more! I happened upon a post from TheDigitalPictureframe.com that used a home-grown Python script leveraging a package called Pi3D. The demo video looked close to the solution I was pursuing, so I gave it a try. Unfortunately, despite all the parameter tweaking I tried, I just couldn’t get the final product I wanted. Nevertheless, I would like to circle back someday and do some more experimentation with this approach.

Make the slideshow myself

In the end, I simply used PowerDirector–the software I use to make my annual family movies–to make a video of my slideshow. Then, I just dropped the video on the Raspberry Pi and played it with the built in VLC Player. I even set VLC to continuously loop the video and set the player to full screen to take up the entire monitor. It worked out pretty well and even garnered a few compliments.

The video montage

On a second flat screen monitor and second Raspberry Pi, I played a video montage of nearly 18 years of video highlights of my child’s life. As I’ve been making annual family movies for most of my daughter’s life, it was pretty easy collecting a few minutes of video of her from each year. Here again, I turned to PowerDirector for my solution. I spliced together the video from over the years separating each year with a “year” title and then created a single mp4 video that I copied to my Raspberry Pi and played with VLC player. Like the slideshow, it turned out pretty well.

Background music

“Dad, your music is too old!”

the kid

For the party background music, I pulled out my reliable portable speaker. Initially, my plan was to copy a bunch of my mp3 files to a third Raspberry Pi, play those files with VLC player, and run the audio out into my speaker. Then, the kid complained that my music was too old.

As an Amazon Prime member, I get access to lots of free music. So, I downloaded a few “modern pop” playlists to my phone. My speaker is bluetooth enabled, so I paired my phone to my speaker and then just played those playlists from my phone through the speaker. That worked out pretty well and I was surprised that both my speaker and phone batteries outlasted the three hour party.

So, there are your media suggestions for your child’s graduation party:

  1. Create a slick slideshow “video” and run it from a Raspberry Pi into a large flat screen monitor,
  2. Create a video montage “video” and do the same thing on a second monitor and Pi, and
  3. Download some music for offline play to your phone and bluetooth your phone to a nice, portable speaker.

The slideshow and video all presume that you’re actively photographing and videoing all your family activities. I highly recommend you do that: family vacations, basketball games, and banquets might feel mundane now but they’ll be gold at your child’s graduation party and beyond.

Python bingo

Have a road trip planned this summer? Want to keep the kids from driving you crazy as you drive to Walley World? How about playing the ol’ standard License Plate game but with a twist: License Plate Bingo!

Run this code a couple of times and print out the chart on separate pieces of paper. There are your bingo cards. Give one to each kid and/or adult. Now, hit the road! If you see a license plate from, say, Texas, and you have a “Texas” square, mark it off on your bingo card. If you can mark off a row horizontally, vertically, or diagonally, you win!

Step 1: Import your packages

import matplotlib.pyplot as plt
import matplotlib.style as style
import numpy as np
import random

%matplotlib inline
style.use('seaborn-poster')

Step 2: Get your State names

# compliments of this forum: https://gist.github.com/JeffPaine/3083347
states = ["AL - Alabama", "AK - Alaska", "AZ - Arizona", "AR - Arkansas", "CA - California", "CO - Colorado",
"CT - Connecticut", "DC - Washington DC", "DE - Deleware", "FL - Florida", "GA - Georgia",
"HI - Hawaii", "ID - Idaho", "IL - Illinios", "IN - Indiana", "IA - Iowa",
"KS - Kansas", "KY - Kentucky", "LA - Louisiana", "ME - Maine", "MD - Maryland",
"MA - Massachusetts", "MI - Michigan", "MN - Minnesota", "MS - Mississippi",
"MO - Missouri", "MT - Montana", "NE - Nebraska", "NV - Nevada", "NH - New Hampshire",
"NJ - New Jersey", "NM - New Mexico", "NY - New York", "NC - North Carolina",
"ND - North Dakota", "OH - Ohio", "OK - Oklahoma", "OR - Oregon", "PA - Pennsylvania",
"RI - Rhode Island", "SC - South Carolina", "SD - South Dakota", "TN - Tennessee",
"TX - Texas", "UT - Utah", "VT - Vermont", "VA - Virgina", "WA - Washington", "WV - West Virginia",
"WI - Wisconsin", "WY - Wyoming"]
state_names = [s.split('-')[1].strip() for s in states]

Step 3: Generate your bingo card

random.shuffle(state_names)
rowlen= 4  # make any size card you'd like

fig = plt.figure()
ax = fig.gca()
ax.set_xticks(np.arange(0, rowlen + 1))
ax.set_yticks(np.arange(0, rowlen + 1))
plt.grid()

for i, word in enumerate(state_names[:rowlen**2]):
    x = (i % rowlen) + 0.4
    y = int(i / rowlen) + 0.5
    ax.annotate(word, xy=(x, y), xytext=(x, y))
    
plt.show()
Python Bingo, FTW!

Grab my full source code here.

Choosing the best coffee

Here’s another post in my quest to recreate many of the charts from Machine Learning Plus’s Top 50 matplotlib visualizations:

The perfect cup of coffee

Back in March, TowardsDataScience.com published an article that analyzed a coffee dataset from the Coffee Quality Institute (sounds like a great place to work!). Since I’m always looking for cool datasets to work with and since I love coffee, I thought this would be a great dataset to pull down and visualize in some fashion.

In the article, the author visualizes median coffee data from several countries around the world in polar charts. The polar charts worked well to get all 11 features on the chart at the same time, but every polar chart–from Ethiopia to the United States–looked the same. It was difficult to see how one country’s coffee differed from another’s. I wonder if there might be a better way to show the subtle variations among each country’s coffee? Enter in another article I talked about previously: Top 50 matplotlib Visualizations. I thought one chart in particular from that article, the Diverging Bars Chart, might do the trick.

Since each country can produce tens of different brands of coffee, I followed the lead of the original article and grabbed the median value from each country. I then applied the Diverging Bars technique to plot how far each country’s coffee varied from the mean.

One thing that puzzles me, though: in several of the categories, Papua New Guinea comes out on top. Yet if you look at the original article, the author lists the median Ethiopian coffee as coming out on top more often than not. What’s the reason for this discrepancy? I’m not really sure. I think I calculated the medians correctly–my Ethiopian values certainly match the author’s. Perhaps I’m working from a newer dataset than he did?

At any rate, I accomplished my main goal of creating some cool diverging bar charts. Enjoy with your favorite cup of java!

Step 1: Load the data

# https://github.com/jldbc/coffee-quality-database
df_coffee = pd.read_csv('./data/arabica_data_cleaned.csv')
df_coffee.head()

Step 2: Code the chart

Since the dataset has multiple features, each of which I’d like to chart, I decided to place my chart-generation code in a function so that I could easily reuse it from feature to feature:

def generate_chart(feature_to_chart, xlabel, title):
    df_chart = df_coffee.groupby('Country.of.Origin').median().loc[:, [feature_to_chart]].reset_index()
    df_chart['z'] = (df_chart[feature_to_chart] - df_chart[feature_to_chart].mean()) / df_chart[feature_to_chart].std()

    df_chart['colors'] = ['red' if x < 0 else 'green' for x in df_chart['z']]
    df_chart.sort_values('z', inplace=True)
    df_chart.reset_index(inplace=True)

    # draw plot
    plt.figure(figsize=(14,10), dpi=80)
    plt.hlines(y=df_chart.index, xmin=0, xmax=df_chart.z, color=df_chart.colors, alpha=0.4, linewidth=5)

    # decorations
    plt.gca().set(ylabel='$Country$', xlabel=xlabel)
    plt.yticks(df_chart.index, df_chart['Country.of.Origin'], fontsize=12)
    plt.title(title, fontdict={'size':20})
    plt.grid(linestyle='--', alpha=0.5)
    plt.show()

Step 3: Generate the chart

Finally, I can call my function and generate the chart:

feature_to_chart = 'Flavor'
xlabel = '${0}$ $Variation$'.format(feature_to_chart)
title = 'Diverging Bars of Median Coffee {0} Rating'.format(feature_to_chart)

generate_chart(feature_to_chart, xlabel, title)
Median Coffee Flavors

Two other interesting charts:

Divergence of the “balance” feature
Divergence of the “acidity” feature

Check out my complete code here and look for more cool charts to come!

« Older posts Newer posts »

© 2024 DadOverflow.com

Theme by Anders NorenUp ↑