Saturday, December 29, 2012

Shun the Mouse

I am a keyboard fan.  I find switching between the keyboard and the mouse irritating.  I love vim. I find the extensions provided by wonderful netziens make vim go from useful to amazing. Add vundle to the mix as a package manager, and it's a match made in geek heaven. I even use the vinium extension for Chrome when possible (excluding, of course, the Google suite as it provides its own shortcuts in a number of its products).

So, it's a problem when it comes to me using Apple products. Yes, I'm sure there are key commands that I can use. I'm also sure that I could script some new ones if necessary. At it's heart, however, Apple is a consumer UI company. It might have disability access leanings (and be good at it), but it is so very different from everything else I use on a regular basis that I'm inclined not to learn them.

Thankfully, I did find a solution for things like checking my email or my calendar without having to use the mouse or fuss with window management. A wonderful person posted an AppleScript snippet to open webpages in Chrome without duplicating them. By tying this into a Quicksilver, I can quickly open anew or go to an existing gmail or calendar tab in Chrome with a few quick commands.  I've used this a lot in the last few days and enjoy it quite a bit.

I also found that setting my default mail composer to Google Mail also helps avoid the mail app; I think there's something in Quicksilver to do this as well.

The only thing that is missing is a good way to quickly add appointments in Google calendar without having to fill out the form (and get confirmation that they were added quickly).  There used to be a quick add API on the calendar, but I think it's been removed.  However, for now I am happy with my keyboard-focused workflow... until another mouse-driven annoyance pops up.

Wednesday, August 29, 2012

Nonlinear colormap in Matplotlib

One of the difficulties I deal with is data that is not evenly distributed across a particular range. Sometimes, I want to highlight a particularly small set of values with great color contrasts and leave other portions of the range to be much less distinguished. For this, I went looking for a way to have a non-linear colormap in matplotlib. To be clear, I didn't want the data itself to be transformed, rather I wanted the color mapping to progress through a normal colormap like cm.jet but expand and contract portions of the map across the entire of values to provide granular resolution at a specific range of values. The graphs below show the difference when using a linear colormap and a transformed colormap:

Image before:

Image after:

I found a script to perform this mapping. It allows the user to set a number of levels that get used to transform the colormap. My modified version of the script is below:

"""
nlcmap - a nonlinear cmap from specified levels

Copyright (c) 2006-2007, Robert Hetland <hetland@tamu.edu>
Release under MIT license.

Some hacks added 2012 noted in code (@MRR)
"""

from pylab import *
from numpy import *
from matplotlib.colors import LinearSegmentedColormap

class nlcmap(LinearSegmentedColormap):
    """A nonlinear colormap"""
    
    name = 'nlcmap'
    
    def __init__(self, cmap, levels):
        self.cmap = cmap
        # @MRR: Need to add N for backend
        self.N = cmap.N
        self.monochrome = self.cmap.monochrome
        self.levels = asarray(levels, dtype='float64')
        self._x = self.levels / self.levels.max()
        self._y = linspace(0.0, 1.0, len(self.levels))
    
    #@MRR Need to add **kw for 'bytes'
    def __call__(self, xi, alpha=1.0, **kw):
        """docstring for fname"""
        # @MRR: Appears broken? 
        # It appears something's wrong with the
        # dimensionality of a calculation intermediate
        #yi = stineman_interp(xi, self._x, self._y)
        yi = interp(xi, self._x, self._y)
        return self.cmap(yi, alpha)


if __name__ == '__main__':
    
    y, x = mgrid[0.0:3.0:100j, 0.0:5.0:100j]
    H = 50.0 * exp( -(x**2 + y**2) / 4.0 )
    levels = [0, 1, 2, 3, 6, 9, 20, 50]
    
    cmap_lin = cm.jet
    cmap_nonlin = nlcmap(cmap_lin, levels)
    
    subplot(2,1,1)
    contourf(x, y, H, levels, cmap=cmap_nonlin)
    colorbar()
    subplot(2,1,2)
    contourf(x, y, H, levels, cmap=cmap_lin)
    colorbar()
    
    savefig('nlcmap_example.png')
Some of the comments above point to changes that I had to make to get the script to work. Specifically:
  • pylab.stineman_interp gave an error relating to the dimensionality of some of the intermediate calculations
  • one of the backends requested the colormaps N member, which wasn't set in the original
  • the **kw parameter wasn't passed to the __call__ method, causing problems when optional parameters such as bytes were passed.
I'm not entirely sure if the script works correctly at this point, so use at your own risk.

Monday, June 6, 2011

Updating LaTeX on Mac (Hard and Easy Way)

With my dissertation nearing completion, I decided to update my TeX distribution from TeX Live 2009 to 2010. This is not a horribly complicated thing if one uses the right package. However, I tend not to do things the easy way.

Before I get into some of the things I discovered, I do want to point out the simplest way to upgrade a from TeX Live 2009 to 2010 on a Mac is to download and install the MacTeX package. It'll put everything in the correct location, update the distribution information, and select the new distribution as the preferred distribution.

Now, what I did initially (the harder way) was to use the TeX Live net-installer. It's not a horribly complicated thing to use, it just took a rather long time to get all of the packages downloaded; I also had to restart the process a couple of times because of corruption issues.

With the 2010 distribution installed, I figured I'd be ready to go. However, when I'd go to render my documents, I kept using the 2009 package. So, I decided to look more closely at how TeX is setup on my Mac.

By default, the TeX Live distributions install the TeX distribution in the directory:
/usr/local/texlive/XXXX
where XXXX is the year of the distribution release. (Note that thereis also a directory called texmf-local for user-installed packages located in the /usr/local/texlive directory.)

The packages from the net-install were properly installed to the texlive directory, but for some reason the old distribution kept getting invoked. The solution was to add the new TeX Live 2010 distribution to the search path, so I edited my .bashrc file to include the line:
export PATH=/usr/local/texlive/2010/bin/universal-darwin/:$PATH. Alternatively, I could have also updated /etc/paths.

This proceedure works for getting the correct distribution to run on the command line, but the package still didn't show up in the control pannel TeX preference pane (installed from the 2009 MacTex distribution), nor did using the command "texdist --list" (a command line version of the utility) show the 2010 distribution. So, what's going on?

At any one time, multiple TeX distributions can be installed on a system. On the Mac, the texdist utility and preference pane mange which distribution is the default. The utilities don't alter any distribution directly, but do create a series of symbolic links to inform applications which TeX distribution to use. The information about the distributions is stored in the /Library/TeX/Distributions; the installer that I used to install TeX Live 2010 did not update this directory to include an entry for TeX 2010. (More information about what this directory contains can be found here.)

The texdist utilities essentially manage a collection of symbolic links that get used when TeX or its resources are invoked. The texdist utility:
  1. Switches the /Library/TeX/Distributions/.DefaultTeX directory to link to one of the directories ending in .texdist in /Library/TeX/Distributions. Each of these directories contain links to different TeX resources.
  2. The contents of /Library/TeX/Distributions/.DefaultTeX/Contents then contains links to the man, root, and other TeX package resources for the default TeX package.
  3. This switch changes what the symbolic links in /usr/texbin refer to.

Consequently, using the texdist utilities (either via the Preference Pane or using the command texdist --usage=TeXLive-2010) will set anything that uses either /usr/texbin or /Library/TeXDistributions/.DefaultTeX to the correct distribution.

As far as I could tell, I could have created my own .texdist directory for TeX 2010. There is documentation describing this in the file /Library/TeX/Distributions/TeXDist-description.rtf.

Instead, since I didn't completely know what I needed to do at the time, I chose to run the MacTeX package installer, mentioned at the top of this entry. The package installed TeX 2010 overtop of the previous install and created the appropriate symbolic links mentioned above. At this point, everything worked as it should.

Finally, to tidy up, I decided to uninstall TeX Live 2009, following these instructions.

Wednesday, April 14, 2010

Pretty Bubbles

After having seen a link today on Fark about Matthew Brodrick's computer in War Games computer going on sale, I spent a little bit of time looking at some of the other computers from the era. In doing so, I came across the GRiD Compass 1101, which is purportedly the granddaddy of all modern laptops.

Heavy, hot, sturdy, and allegedly used in the quest for global thermonuclear war, it is a sweet piece of machine. What caught my attention, however, was not its sleek metal case or awesome yellow 80x24 character ELD display but the type of memory the GRiD Compass 1101 used for non-volatile memory.

The GRiD Compass had three modules of bubble memory for long-term storage. This type of memory relied upon "bubbles" of magnetic data. Stored on a two dimensional surface, these bubbles were manipulated by external magnetic fields. By altering these fields, bubbles of magnetism could be shepherded down a magnetic surface toward a read/write head. By connecting the output of one edge of the magnetic surface to the other, bits could be looped back to the other side of the module. Putting many of these loops together, multiple bits could be read in parallel.

Contrasted with the spinning disks of magnetic residue we use to this day, it seems like an elegant solution for non-volatile storage in a historically important but less than elegant era of personal computing.

Unfortunately, bubble memory was not to be. As hard drives improved and dropped in price, bubble memory was abandoned in all but harsh operating environments. Still, the idea of little bubbles of magnetism moving down looped pathways is amazing to me. This type of solid state memory would have been an interesting alternative technology to the modern quantum-mechanically based flash storage devices that are ubiquitous today.

Interestingly, the idea using bubbles as information storage is not over. New research into non-magnetic bubbles continues for "lab on a chip"-style tools, giving bubbles a continuing role in the evolution computational machines.