Another example from our Python study group. This is a quick and dirty script to clip all shapefiles in a given directory by another specific shapefile. The output filenames are appended with “_clip” and the script takes care not to clip the clip file by itself.

import glob
import os
import sys
import arcgisscripting

try:
  # a directory path
  workspace = sys.argv[1]

  # a directory for placing outputs
  filetoclipby = sys.argv[2]

except:
  print 'Usage: superclipper.py <workspace> <clipfile>'
  exit()

gp = arcgisscripting.create()
gp.Workspace = workspace
shapefiles = workspace + "*.shp"

for infile in glob.glob(shapefiles):
  # loop through once for each file, 'infile', matching
  # the pattern. 

  if infile == filetoclipby:
    print infile,"is the file to clip by!"
    continue
  else:    
    print infile + " will be clipped by " + filetoclipby
    outfile,extension = os.path.splitext(infile)
    outfile = outfile + "_clip"
    gp.Clip_analysis(infile,filetoclipby,outfile)

It’s simple in perl: just use backticks. But I guess the pythonic way is to use subprocess. Since I am trying to run drush from python, and drush commands often include single quotes, I’ve deviated a bit from the standard subprocess examples to find something I could get to work…

#!/usr/bin/python

import subprocess

def runcommand(command):
 proc = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
 out,err = proc.communicate()
 return out,err

mycommand,mycommanderr = runcommand("drush status")
print "Standard outputn",mycommand

if (mycommanderr):
 print "Standard errorn",mycommanderr
import glob
import os
import sys

try:
  # a pattern specified on the command line, like *.txt
  pattern = sys.argv[1]
except:
  print 'Please supply a pattern on the command line.'
  exit()

for infile in glob.glob(pattern):
  # loop through once for each file, 'infile',
  # matching the pattern from the command
  # line. do something with each file.
  # for example, open and print it

  # print the filename
  print infile,'n====='

  # open the file, print it, close it
  filehandle = open(infile)
  for line in filehandle:
    print line.rstrip()
  filehandle.close()

  # print a final newline
  print 'n'

Here’s how it looks when it runs in a directory with two identical files called lipsum.txt and lipsum2.txt:

H:python>myglob.py *.txt
lipsum.txt
=====
"Lorem ipsum dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit
in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit
anim id est laborum."

lipsum2.txt
=====
"Lorem ipsum dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit
in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit
anim id est laborum."

The Ektar Project

Around 1989 or so, I picked up a roll of Kodak Ektar 1000 color print film. I didn’t have an application for such high speed film at the time, so I stuck it in the freezer. And it stayed in the freezer for a while, and then another while, and another while after that.

kodak ektar 1000

Kodak Ektar 1000 color print film

Pretty soon, the roll passed its expiration date of 6/1990. I thought ok, I’ll just leave it in the freezer and shoot it in 20 years. Read the rest of this entry »

Just installed the latest version of WP and we’re currently updating all the sub-sites… just want to make sure that posting still works ok.

Intervalometer Test

I’ve been playing with the Canon Hack Development Kit (CHDK), which is open source firmware that can extend the functionality of many Canon PowerShot cameras. It provides a framework for running scripts to capture RAW files, employ ultra-high shutter speeds, trip the shutter when motion is detected, etc. The script I’ve been playing with is an Intervalometer script – this causes the camera to take a photo every x period of time.

Using a Joby Gorillapod, I strapped a Canon PowerShot S3 IS to my bike, set it for a 1/1000 sec exposure every 2 seconds (I think there’s some overhead here because in practice, I got a frame every 5 seconds or so) and took off…

PowerShot strapped to the bars.

PowerShot strapped to the bars.

PowerShot on the bars (back view).

PowerShot on the bars (back view).

The Gorillapod holds the camera secure to the bike, but it doesn’t do anything to dampen the road vibration. I believe this camera has some image stabilization, but some of the frames are still a little blurry. I could go faster than 1/1000 to help that a bit (but didn’t have the light on my side today). Also, the S3 is on the heavier side, and had a tendency to start pointing toward the ground after enough bumps in the road… occasionally, you can see my shifter cables in the shots.

The resulting video is presented at 10 frames/sec. You can watch the video directly on YouTube.

The Forecaster reports that work has begun on the Amtrak leg from Portland to Brunswick.

Scheduled for completion in the fall of 2012, the track rehab is expected to allow the Downeaster to add two daily round trips to Freeport and Brunswick to its current Portland-Boston service.

If I am reading things correctly, each new rail is 1,650 ft in length, and the train carrying the first load weighed 3.2 million lbs! Read more on the Amtrak extension at The Forecaster.

6,000

My Bianchi Vigorelli hit 6,000 miles this past weekend! It’s its special day.

Me and my Vigorelli at 6,000 miles.

Just like Lance, only I can't ride and count at the same time.

6,000 Miles.

6,000 Miles.

First Ride of the Season

Got out for my first ride of the season today! I’m usually a (very) fair weather rider but I have been bored with the trainer and wanting to get out on the road. Add in some inspiration from MnBicycleCommuter and ‘sconnyboy, and thinking well, people ski in this weather, don’t they? …I got out on the bike.

The temperature was about 20 F and the roads were salty but mostly dry. Even in the worst spots, I had 2-3 feet of clear pavement.

It’s oft-said that there’s no bad weather, only bad gear (or something like that). So I dressed for bear…

  • Upper body: two layers of polypropylene, an ancient and heavy LL Bean fleece, and a Pearl Izumi fluorescent yellow cycling jacket. This all made me look like the Michelin Man.
  • Legs: cycling shorts, thermal long johns, and an ancient pair of Hind XC skiing pants.
  • Head: thin fleece balaclava under my helmet.
  • Feet: regular Shimano cleats with fleece-lined (thin fleece) Pearl Izumi covers (booties).
  • Hands: my hands usually cause me the most trouble. So I wore an ancient (there’s a theme here: are you picking it up?) and warm pair of acrylic mittens with waterproof Outdoor Research mitten covers over them.

I went out for about 45 minutes. How did I fare? I started by fixing a flat, and that Michelin Speedium is tough to get back on the rim, so I got good and warmed up before the ride.

I had a stiff headwind on the way out, so my face was a little chilly.

My hands were good, but bulky. I don’t think I’ve ever felt the teeniest bit of cold with that mitten combination, but it winds up being so thick that I can’t get my hands on the bars behind the brake levers, which is one of my preferred riding positions. Upshifting was tricky, because I couldn’t feel the small inner Shimano shifter very well. And between the balaclava and the wind, I couldn’t hear the shifts very well either. But downshifting was much easier, because you use the whole brake lever for that.

My legs and feet were just about perfect. My upper body wound up being a little bit too warm, though. I think, given the weather, I could’ve traded the fleece for something more medium weight, and maybe even shed one polypro layer, and that would’ve been fine.

By the end of the ride, I had a nice tailwind (really!) and was warmed up and having a good time. But the sport top was frozen on my Sigg water bottle. So although the water was not frozen solid, it wasn’t flowing at all. Maybe a traditional plastic water bottle would’ve shaken the ice a bit better. Thankfully it was a short ride, so I just topped off when I got home.

Robin got the flash plugin working here on blogs.usm. Please enjoy this video, one of many showing us how to adjust a Shimano rear derailleur.

Edit: we’re now testing a new plugin. Here’s the video, for real this time!

YouTube Preview Image