Pets, Plants, and Computer Vision
Header

Web Scraping with BeautifulSoup and Python

July 1st, 2013 | Posted by admin in Ann Arbor | artificial intelligence | audio | birds | classification | code | Fun! | machine learning | Michigan | python | signal processing | Uncategorized - (Comments Off on Web Scraping with BeautifulSoup and Python)
Tufted Titmouse - I love these guys, so cute.

Tufted Titmouse – I love these guys, so cute.

I’ve been working on building an automated bird call recognition system using python. The first step in getting everything working is to pull down a data set of bird calls from which to train and test my ideas. To get this data I needed a lot of bird calls. It just so happens that there are a couple of large repositories of this type of data including the Xeno-Canto library and the Cornell Ornithology Library. The only problem is that it lives in websites with embedded players and I need the raw data. I decided to try and write a basic web-scraper that would pull down the data I wanted. To do this I first created a list the scientific names of all of the song birds that I am pretty sure live in my neighborhood (at least the common ones I’ve seen before). I checked a couple of websites to cross check my assumptions and developed the following list:

To do the scraping I used the BeautifulSoup python library to help me navigate the DOM from xeno-canto bird library. The code works by crafting a query for each bird species, and parsing the DOM to look for the xc-button-audio in a div element. In that div element there is a sub tag called data-xc-filepath which points to the mp3 file URL. My friend Ben helped me figure out that last little bit as I am barely competent as a web money. Once I have the mp3 file URL I use os.system to call wget on the mp3 url. I also do some book keeping to keep all the bird calls in different directories and navigate the multiple pages of results. If I get some more time I will try to extract all of the metadata and save it to a CSV file, but for right now this works. You can see the code below:

Now that I have the data I need to figure out how to extract individual calls from each file that can contain multiple calls. My working idea is to look for regions where the peak-to-peak audio values are low enough to be considered silence. I will use these silence intervals to split the files into individual calls. Once I get to the short individual calls I am thinking I will run an FFT over the audio and then bin different regions of the spectrum to create a feature vector. I will also probably keep some information about the call length and maybe try to determine the “warblyness” of the call (i.e. how many different sub-tweets make up a call). I am thinking that it may be useful to do the binned FFT over fixed time slices of the call and calculate the FFT on that (e.g. break the call up into five time chunks and get the FFT values for each chunk). I have an idea that a binary descriptor can be used to compress each time slice if I set an appropriate threshold at each frequency (e.g. use a 32 bit int to encode if one of 32 chunks the frequency space are discernible). If I can get that idea to work I could probably encode each call very succinctly in only a few bytes of memory. Once I have my data I suspect that a K Nearest Neighbors classifier will work reasonably well. I may combine the KNN with a final correlation with the truth data to choose between the K best matches.

FIRST 830 Vortex Cannon

May 31st, 2013 | Posted by admin in Ann Arbor | FIRST | Maker Works | RaspberryPi | robots - (Comments Off on FIRST 830 Vortex Cannon)
Commercial vortex cannon.

Commercial vortex cannon from last year’s robot.

FRC Team 830 along with FRC Team 3322 are working on a show robot for the Detroit Maker Fair. Maker Works was even cool enough to give us a small grant to fab the robot! The working concept is a life-size animatronic dragon that shoots smoke rings. With my ample free time I’ve been figuring out how to make it happen using a combination of the standard cRIO FIRST platform and raspberry pi’s. Last’s year’s robot used a vortex cannon to knock over pac-man ghosts, but this year we wanted to go bigger. We are using the drive train from last year’s robot for the new dragon bot so we should have a lot more time to build cool animatronic stuff.

Hole in the bottom of the garbage can.

Hole in the bottom of the garbage can.


Vortex cannon diaphragm using 5mil sheeting.

Vortex cannon diaphragm using 5mil sheeting.


I wanted to see how big of a vortex cannon we could build. Following some examples I saw on the internet I picked up a garbage can at Recycle Reuse and grabbed some 5 mil plastic sheeting I was using for the garden. This weekend we fabbed a prototype smoke cannon. The design is really simple, you just saw out a circle in the bottom of the garbage can and add a plastic diaphragm on the open side of the can (I secured it with some large rubber bands and duct tape). The trick is to provide a good amount of slack on the diaphragm.

The smoke machine makes the vortex rings visible. This weekend I tried to use some dry ice “smoke” to visualize the rings. The results weren’t that impressive, but playing with five pounds of dry ice was really fun (hint, if you put a quarter on dry ice it “squeals”). Today we tried using a professional fog machine and the results were much more impressive as you can see for yourself.

As for the rest of the animatronics we want the dragon’s eyes and eyebrows to move and for the dragon to play sounds. If we have enough time we want the dragon to have some “ground effects” LED lights. Right now the plan is to drive all of this off the GPIO pins on two raspberry pi’s. We plan to drive the pi’s off a separate router system connected to the cRio’s filtered 5V power supply (with a step up converter). The smoke ring mechanism and smoke generator will probably run off the cRio. The plan is to have each of the pi’s run a python script that provides access to PyGame (for sound), pi-blaster, and servo blaster. Tentatively I think we can use the Pika RabbitMQ library to move message between a client control application and servers running on the raspberry pi. Both the raspberry pi’s will be dispatched by running a client python app that also uses PyGame to grab input from the keyboard and a joystick. Right now we have a skeleton github repo for the project that should get filled out over the course of the summer. I must also add that I am really impressed with the AdaFruit Black Raspberry Occidentalis raspian distro. I am going to be gone for the next month so I can point the kids to the tutorials and let them go to town.

How To Build Raised Garden Beds

April 24th, 2013 | Posted by admin in Ann Arbor | domestic life | gardening | Michigan | plants - (Comments Off on How To Build Raised Garden Beds)
The finished product, two 4'x4' raised beds.

The finished product, two 4’x4′ raised beds.

The weather in Michigan was finally warming up so I decided it was time to build some garden beds. I had helped build raised beds in the past but I had never done it on my own. It ended up being a lot easier than I expected and I was able to build two of them over the weekend and still have time to go out.

My backyard is extremely small and a good portion of it is taken up by a platform and stairs that lead to the upstairs apartment. To make matters worse the yard is sloped and has a small wooded area with a few large trees that subdivide my yard from the neighbors. Since I had so little space to work with I opted to build two “square foot” style raised bed gardens. Square foot gardening is a methodology that has been around for almost 30 years and it provides great results in a limited amount of space. The addition of the raised beds helps to prevent soil compaction and generally make the garden a lot easier to maintain. Since my yard is sloped the beds also prevent my soil from running everywhere when it rains.

All told I spent just a little over $100 for all the parts to build the garden including the compost. I also built the beds in such a way that I could quickly add a trellis or hoop house depending on what I wanted to grow and the time of year by snapping the fixtures into some PVC pipe I placed at the corners of the beds. Here is the materials list to create a single raised bed.

  • 4 12″x4’x1″ pre-sawn sections of untreated pine (~$6.50 each)
  • 8 3″ 18Ga steel angle brackets (~$1.25 each)
  • 1 50 count box of #8 3/4″ wood screws (~$4.65 each)
  • 2 4 count packs of 1″ two hole pipe strap (~$1.29 each)
  • 4 sections of 3/4″x24″ PVC Pipe (cheap)

Make sure you use untreated wood as treated wood can leech preservatives into the soil. I got all of this stuff at Home Depot and I was in and out in about 30 minutes.For the fill dirt I picked up a cubic yard of municipal compost from the city for only $21.20. The compost looks fantastic and I mixed with a bit of the fill dirts from the bed and some leaf litter from around the yard to fill up the beds completely. You will want a five gallon bucket to move it around as well as a tarp to put it on so it doesn’t run all over the yard.

To construct the beds I really quickly manufactured four “connector boards” where I placed the L brackets and pipe straps onto the board. I made sure to leave just enough space on these boards so I could get the drill to fit in the corners of the beds.

One side of the "connector" boards. Note the placement of the pipe straps to make it easier to screw everything together.

One side of the “connector” boards. Note the placement of the pipe straps to make it easier to screw everything together.

Once I finished my connector boards I then screwed each one onto a plain board to form four “L” shaped pieces. To do this I put the connector board on the floor up against a wall and then wedged a regular board behind it.

Making "L" sections.

Once I finished the “L” sections I took the whole thing outside and used some cinder blocks to hold everything in place while screwed the sections together. I then started digging out the beds. I wanted each bed to sit level on the sloped yard so I dug out sections that were more or less flat. I had to make the holes slightly larger than the beds. I used rocks that I found while digging to help prop up the corners and provide some extra drainage. Once the beds were in placed I filled out the outer edge with dirt to secure everything, and then I used the flat side of my shovel to drive the PVC pipe into the ground a foot below the beds. This should keep the beds in places. If I decide I want to build out hoop houses or trellises I can remove the pipes and replace them with suitable materials.

Read to fill with compost.

I then proceeded to fill up the raised beds with the compost I got from the city. Residents of Ann Arbor can get a free cubic yard of compost every year from the waste center, I opted to have mine dumped into the back of my friend Joe’s truck which cost $21 but it was money well spent.

Getting compost from the city of Ann Arbor Compost Center.

Getting compost from the city of Ann Arbor Compost Center.

It took me almost three hours of shoveling and filling up five gallon buckets to fill the beds. It was back breaking work and I need a long hot bath afterwards but it was well worth it. I just picked up most of my seed from Downtown Home and Garden. They sell seed for most of the common garden vegetables in bulk so it is a lot cheaper. I also ordered some heirloom tomato and pepper seedling from the Project Grow plant sale. I had a Project Grow community garden plot for five years and it is worth noting that all of the proceeds from the sale go directly to Project Grow. This is my current sketch for what I am going to grow in my beds. As with any landscaping project it is helpful to plan your layout first to take into account lighting and watering contraints as well as views. I will post pictures as soon as I get everything in and sprouting.

My tentative garden layout.

My tentative garden layout.

ROBOTS FIGHT!

March 26th, 2013 | Posted by admin in Ann Arbor | automation | Automation Alley | demo | Education | FIRST | Fun! | robots - (Comments Off on ROBOTS FIGHT!)

FRC830 has our second competition of the season in Livonia this weekend. We had the competition bot unbagged for a few hours today and decided to give our drivers some time to practice.