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.

Transcontinental Express

May 31st, 2013 | Posted by admin in Education | Fun! | Ideas | Inspiration | Michigan | New York | RaspberryPi - (Comments Off on Transcontinental Express)

Recently I found myself with a couple months of time off. I decided to use it in the most productive manner I could think of so I booked a one month rail pass on Amtrak. I already had plans to go to Ada Camp in San Francisco and my sister’s high school graduation in Mechanicsville, Virginia. At $670 the rail pass was cheaper than plane tickets and I got to see most of the country. Tentatively I plan to visit Portland, San Francisco/Silicon Valley/Oakland, Iowa City, Richmond Virginia, and New York City. I was able to schedule my trip so I could take the Empire Builder line, the California Zephyr, and a good chunk of the Coast Starlight. My tentative schedule is below.


View Transcontinental Express in a larger map

My exact schedule for the first leg of the trip can be found here. Packing for this trip has been a little crazy. I want to squeeze everything I need into a back pack, but train travel is tough as traveling in coach requires that you bring a lot of necessities (and entertainment).

Try squeezing a month's worth of clothes, electronics, supplies, and food into a backpack!

Try squeezing a month’s worth of clothes, electronics, supplies, and food into a backpack!

I purchased a Nexus 7 tablet for the journey and I have a tupperware container with a raspberry pi, arduino, makey-makey, breadboard, and various component to keep me entertained on the train. The transcontinental trips are almost three whole days so I should have lots of time to read, code, and build cool stuff with my fellow travelers. Hopefully I will post some cool stuff from the road, and have 4G coverage for most of the trip.

My home for the next month.

My home for the next month.

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.

Sight-Machine-staff-car-620x413

Last week the SightMachine crew had the pleasure of meeting with a reporter from O’Reilly media. They just released a really nice write up about how we are helping to build the industrial internet right here in Michigan. This is a follow on to the really excellent piece about SightMachine in the Atlantic a few months back.