<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>alan.lamielle.net &#187; Python</title>
	<atom:link href="http://alan.lamielle.net/tags/python/feed" rel="self" type="application/rss+xml" />
	<link>http://alan.lamielle.net</link>
	<description>Alan LaMielle</description>
	<lastBuildDate>Fri, 16 Sep 2011 16:50:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Using waf to build LaTeX Documents</title>
		<link>http://alan.lamielle.net/2009/09/29/using-waf-to-build-latex-documents</link>
		<comments>http://alan.lamielle.net/2009/09/29/using-waf-to-build-latex-documents#comments</comments>
		<pubDate>Tue, 29 Sep 2009 19:47:44 +0000</pubDate>
		<dc:creator>Alan LaMielle</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[build system]]></category>
		<category><![CDATA[latex]]></category>
		<category><![CDATA[make]]></category>
		<category><![CDATA[makefile]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[tex]]></category>
		<category><![CDATA[waf]]></category>

		<guid isPermaLink="false">http://alan.lamielle.net/?p=508</guid>
		<description><![CDATA[I&#8217;ve finally made the migration away from make and the horrible system of autofoo and Makefiles.  A few years ago I discovered a build system called waf that does everything make can do, only better! Waf is a Python based build system (or more generally a task execution system).  Directly from the site: Waf is a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve finally made the migration away from <code>make</code> and the horrible system of <code>autofoo</code> and <code>Makefiles</code>.  A few years ago I discovered a build system called <code>waf</code> that does everything <code>make</code> can do, only better!</p>
<p><span id="more-508"></span></p>
<p><a href="http://code.google.com/p/waf/">Waf</a> is a Python based build system (or more generally a task execution system).  Directly from the site:</p>
<blockquote><p>Waf is a Python-based framework for configuring, compiling and installing applications. It derives from the concepts of other build tools such as Scons, Autotools, CMake or Ant.</p></blockquote>
<p>Just like <code>make</code>, <code>waf</code> is a quasi-declarative build system.  You define the tasks and results you require, and <code>waf</code> determines dependences and executes the tasks (in a valid order) necessary to produce the desired output.  However, <code>waf</code> differs from <code>make</code> in that <strong>waf actually uses a real programming language</strong> for declaring tasks and developing the build system (in case it wasn&#8217;t obvious, the language I&#8217;m referring to is Python).  This single fact alone is enough for me to want to move away from <code>make</code> completely.  However, <code>waf</code> also offers a whole slew of other extremely nice features that make it very powerful.  See the project site for more details.</p>
<p>Until now I&#8217;ve been using <code>make</code> to build my <code>LaTeX</code> documents.  However, I&#8217;ve finally taken the time to discover how to do this with <code>waf</code>.  The following script (really just two functions), named <code>wscript</code> in the directory with the <code>LaTeX</code> source, is the result:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">srcdir=<span style="color: #483d8b;">'.'</span>
blddir=<span style="color: #483d8b;">'build'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> configure<span style="color: black;">&#40;</span>conf<span style="color: black;">&#41;</span>:
   conf.<span style="color: black;">check_tool</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'tex'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> build<span style="color: black;">&#40;</span>bld<span style="color: black;">&#41;</span>:
   obj=bld.<span style="color: black;">new_task_gen</span><span style="color: black;">&#40;</span>features=<span style="color: #483d8b;">'tex'</span><span style="color: black;">&#41;</span>
   obj.<span style="color: black;">source</span>=<span style="color: #483d8b;">'source_tex_file.tex'</span>
   bld.<span style="color: black;">install_files</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'${PREFIX}'</span>,<span style="color: #483d8b;">'output_pdf_file.pdf'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>The first two lines define the source directory (the current directory is denoted by the &#8216;.&#8217;) and the name of the build directory (where all the temporary files will be stored).  The <code>configure</code> function simply tells <code>waf</code>, using the <code>check_tool</code> call, to ensure that the tools necessary for building <code>LaTeX</code> documents are present on the system.  The <code>build</code> function defines that we want to create a PDF document from the file <code>source_tex_file.tex</code> using the <code>tex</code> <code>waf</code> tool.  And that&#8217;s it&#8230; seriously.</p>
<p>My workflow with this setup is basically edit <code>LaTeX</code> file, call <code>./waf build install</code>, check the output PDF, repeat.  Easy as pie.</p>
<p>So, if you&#8217;re looking for a fabulous alternative to <code>make</code>, check out <code>waf</code>, I&#8217;m sure you&#8217;ll be impressed.</p>
]]></content:encoded>
			<wfw:commentRss>http://alan.lamielle.net/2009/09/29/using-waf-to-build-latex-documents/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First Day at SiParCS</title>
		<link>http://alan.lamielle.net/2009/06/01/first-day-at-siparcs</link>
		<comments>http://alan.lamielle.net/2009/06/01/first-day-at-siparcs#comments</comments>
		<pubDate>Mon, 01 Jun 2009 16:06:38 +0000</pubDate>
		<dc:creator>Alan LaMielle</dc:creator>
				<category><![CDATA[SIParCS 2009]]></category>
		<category><![CDATA[boulder]]></category>
		<category><![CDATA[cisco]]></category>
		<category><![CDATA[kvpnc]]></category>
		<category><![CDATA[mountain sun]]></category>
		<category><![CDATA[ncar]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[siparcs]]></category>
		<category><![CDATA[southern sun]]></category>
		<category><![CDATA[vpnc]]></category>

		<guid isPermaLink="false">http://alan.lamielle.net/?p=62</guid>
		<description><![CDATA[Today was the start of my internship in Boulder, CO at NCAR (The National Center for Atmospheric Research) in the SiParCS 2009 summer internship program.  It was mostly filled with administrative and logistical stuff, but I did get a few hours of working on my project in. The day started with an almost exactly 1 [...]]]></description>
			<content:encoded><![CDATA[<p>Today was the start of my internship in Boulder, CO at NCAR (The National Center for Atmospheric Research) in the SiParCS 2009 summer internship program.  It was mostly filled with administrative and logistical stuff, but I did get a few hours of working on my project in.</p>
<p><span id="more-62"></span>The day started with an almost exactly 1 hour drive down to Boulder after picking Kate up from her place.  Even at 7am, traffic wasn&#8217;t bad enough to slow us down too much.  We&#8217;ve averaged around 1 hour over the ~3 trips we&#8217;ve made down there.  I&#8217;m guessing it is now safe to say that it takes an hour to get from Fort Collins to Boulder (with our apartment or NCAR as the destination).</p>
<p>As we were early (we were supposed to be at NCAR at 9am), we stopped at our not-yet-paid-for apartment and found that the office was closed.  Resolving to call at lunch to get apartmenty things settled, we headed up the hill towards NCAR.</p>
<p>In contrast with the previous times we&#8217;d been to the NCAR campus, it was fairly windy and cold today when we arrived.  We headed in to the building and found our way to the cafeteria.  We were early (by around 30 mins) and met and talked with some of the other SiParCS interns who were also early.  Once 9am rolled around we headed to a conference room and started the day.</p>
<p>Most of the morning was filled with filling out forms, tours, and getting machines setup, configured, and working.  On the outside the building is really intersting, very cool architecture.  On the inside, you find that the cool architecture requires a complex layout that is initially difficult to find your way around.  Luckily I think I figured most of the useful routes out, but I&#8217;m guessing I&#8217;ll still have trouble at some point.  In terms of machine setup, I had to be the difficult one and use my personal laptop (along with one other inten).  To get access to various NCAR intranet resources, I needed to get VPN working.  However, the vpnc settings I was using weren&#8217;t working for some reason.  Later in the day we finally setup kvpnc and got VPN working with it.  (Later I figured out that I needed to specify my password each time using my recently acquired cryptocard, and got VPN working with vpnc in networkmanager, whooo!).</p>
<p>I ate lunch with Kate, Nick (the third intern working under John) and John in the NCAR cafeteria.  Kate and I learned that food is pretty expensive there ($20 for both of us total) and decided to shop later in the day for lunchy food and save ourselves some money.  The food is decent, just not worth $10 a meal.</p>
<p>After lunch I actually got started on my project, which I&#8217;ll describe in more detail at some point in a future post.  Basically right now I&#8217;m writing some Python scripts to process lookup table access traces from a run of CAM (the Community Atmospheric Model).  I&#8217;m hoping I can get some results to discuss with John by tomorrow.</p>
<p>Kate, Nick, and I decided to attend a welcoming reception and left around 3:30.  Nick headed straight there while Kate and I went and took care of apartmenty things first.  After paying rent and dropping off our stuff in our newly claimed apartment, we headed to the reception.  We were enticed by free food, expecting some sort of BBQ or something, but it turned out to be a more fancy-pants snacky event.  We grabbed some of the food (including coconut chicken on a stick!), listened to some speeches, chatted with Kuo, Nick, Even and Kate (all SiParcS interns) and decided we needed some real food.  We headed to our new favorite brewery, Southern Sun.</p>
<p>Southern Sun is a local Boulder brewery just across from our apartment.  We headed there for food, and ended up getting more than we could handle.  I ordered the Blackberry Wheat beer they had on tap (super tasty!) and Kate ordered a Belgium tripel (also super tasty!).  For food, we had an interesting soup that tasted exactly like a grilled cheese sandwich, very nice!  On top of that, we ordered the chicken nachos, and realized after it came out we had made a mistake:</p>
<p style="text-align: left;">
<div id="attachment_258" class="wp-caption aligncenter" style="width: 310px"><a href="http://files.lamielle.net/wordpress/2009/07/IMG00224.jpg" rel="shadowbox[sbpost-62];player=img;"><img class="size-medium wp-image-258" title="Massive stack of nachos at Southern Sun Brewery" src="http://files.lamielle.net/wordpress/2009/07/IMG00224-300x225.jpg" alt="Massive stack of nachos at Southern Sun Brewery" width="300" height="225" /></a><p class="wp-caption-text">Massive stack of nachos at Southern Sun Brewery</p></div>
<p style="text-align: left;">Needless to say, we didn&#8217;t manage to finish them, but what we did have was delicious.</p>
<p style="text-align: left;">After dropping Kuo off at home, Kate and I headed to our apartment and chilled for the evening and went to bed.  It was a long day and I&#8217;m pretty tired.  This is looking to be quite a fun summer.  I&#8217;m excited to get to work tomorrow on my project!</p>
]]></content:encoded>
			<wfw:commentRss>http://alan.lamielle.net/2009/06/01/first-day-at-siparcs/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reversing Python list/string objects</title>
		<link>http://alan.lamielle.net/2009/05/04/reversing-python-liststring-objects</link>
		<comments>http://alan.lamielle.net/2009/05/04/reversing-python-liststring-objects#comments</comments>
		<pubDate>Mon, 04 May 2009 23:26:00 +0000</pubDate>
		<dc:creator>Alan LaMielle</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[timing]]></category>

		<guid isPermaLink="false">http://alan.lamielle.net/?p=69</guid>
		<description><![CDATA[I was interested in the relative performance of reversing a python list using the idom list[::-1] rather than the reverse method of the list class. Additionally I wanted to see if this idom was efficient for reversing strings compared to converting to a list, reversing that list, and joining the elements again using ''.join(reversed_list). Here [...]]]></description>
			<content:encoded><![CDATA[<p>I was interested in the relative performance of reversing a python list using the idom <code>list[::-1]</code> rather than the reverse method of the list class.  Additionally I wanted to see if this idom was efficient for reversing strings compared to converting to a list, reversing that list, and joining the elements again using <code>''.join(reversed_list)</code>.  Here are the results:</p>
<p>Reverse list, slicing: (0.58000000000000007, 0.64144396781921387)<br />
Reverse list, method: (0.20000000000000018, 0.19551301002502441)<br />
Reverse string, slicing: (0.45000000000000001, 0.49545693397521973)<br />
Reverse string, list: (3.71, 3.7981550693511963)</p>
<p><span id="more-69"></span>I’m using a quick Timer class that I implemented to report the running time for a chunk of code using both of <code>time.clock()</code> (the first item) and <code>time.time()</code> (the second item).  Here is the code used to produce these results:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">collections</span> <span style="color: #ff7700;font-weight:bold;">import</span> namedtuple
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">copy</span> <span style="color: #ff7700;font-weight:bold;">import</span> deepcopy
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Timer<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
   Times=namedtuple<span style="color: black;">&#40;</span><span style="color: #483d8b;">'times'</span>,<span style="color: #483d8b;">'clock time'</span><span style="color: black;">&#41;</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
      <span style="color: #008000;">self</span>.<span style="color: black;">running</span>=<span style="color: #008000;">False</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">def</span> _set_times<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,field_name<span style="color: black;">&#41;</span>:
      times=Timer.<span style="color: black;">Times</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span>.<span style="color: black;">clock</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>,<span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
      <span style="color: #008000;">setattr</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,field_name,times<span style="color: black;">&#41;</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">def</span> start<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
      <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">running</span>: <span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">ValueError</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Timer is already running!'</span><span style="color: black;">&#41;</span>
      <span style="color: #008000;">self</span>.<span style="color: black;">running</span>=<span style="color: #008000;">True</span>
      <span style="color: #008000;">self</span>._set_times<span style="color: black;">&#40;</span><span style="color: #483d8b;">'tstart'</span><span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">def</span> stop<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
      <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">self</span>.<span style="color: black;">running</span>: <span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">ValueError</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Timer is not running!'</span><span style="color: black;">&#41;</span>
      <span style="color: #008000;">self</span>.<span style="color: black;">running</span>=<span style="color: #008000;">False</span>
      <span style="color: #008000;">self</span>._set_times<span style="color: black;">&#40;</span><span style="color: #483d8b;">'tstop'</span><span style="color: black;">&#41;</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
      <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">tstop</span>.<span style="color: black;">clock</span>-<span style="color: #008000;">self</span>.<span style="color: black;">tstart</span>.<span style="color: black;">clock</span>,<span style="color: #008000;">self</span>.<span style="color: black;">tstop</span>.<span style="color: black;">time</span>-<span style="color: #008000;">self</span>.<span style="color: black;">tstart</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#41;</span>
&nbsp;
timer=Timer<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
test_string=<span style="color: #483d8b;">'Time flies like an arrow.  Fruit flies like a banana.'</span>
test_list=<span style="color: #008000;">list</span><span style="color: black;">&#40;</span>test_string<span style="color: black;">&#41;</span>
iterations=<span style="color: #ff4500;">1000000</span>
&nbsp;
timer.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span>iterations<span style="color: black;">&#41;</span>:
   new_string=test_string<span style="color: black;">&#91;</span>::-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
timer.<span style="color: black;">stop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Reverse string, slicing:'</span>,timer.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
timer.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span>iterations<span style="color: black;">&#41;</span>:
   l=<span style="color: #008000;">list</span><span style="color: black;">&#40;</span>test_string<span style="color: black;">&#41;</span>
   l.<span style="color: black;">reverse</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
   new_string=<span style="color: #483d8b;">''</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>l<span style="color: black;">&#41;</span>
timer.<span style="color: black;">stop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Reverse string, list:'</span>,timer.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
timer.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span>iterations<span style="color: black;">&#41;</span>:
   test_list=test_list<span style="color: black;">&#91;</span>::-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
timer.<span style="color: black;">stop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Reverse list, slicing:'</span>,timer.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
timer.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span>iterations<span style="color: black;">&#41;</span>:
   test_list.<span style="color: black;">reverse</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
timer.<span style="color: black;">stop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Reverse list, method:'</span>,timer.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Feel free to use any of this code yourself, consider it under a <span class="caps">BSD</span> license.  Particularly the Timer class has been useful for me in multiple cases.</p>
<p>Based on the timing results, I’d say it looks best to use the slicing idiom on strings and the reverse method on lists.</p>
]]></content:encoded>
			<wfw:commentRss>http://alan.lamielle.net/2009/05/04/reversing-python-liststring-objects/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

