Prettify my Emacs symbols

Emacs Redux made me aware of a new nifty feature of Emacs 24.4 (the upcoming release; I am currently using one of the nightlies). Emacs 24.4 includes a new mode called prettify-symbols-mode, which replaces tokens within code with more compact symbols (typically unicode characters like λ).

I am using the mode to replace the “function” token in JavaScript — which is used all over the place, since it is the syntax to create functions, modules and closures — with the single character λ. This results in significantly more lightweight expressions:

    
initialize: λ() {
    this.listenTo(this, "planet:drag planet:dragvelocity", 
        λ() { this.elements(true); });
}

The mode is smart enough to only replace tokens (it doesn’t replace function within a string, e.g., var a = "This is a function"; will appear unmodified). To activate the mode, use (global-prettify-symbols-mode 1) in one of your init files, and add new symbols to the mode hooks:

(add-hook 'js2-mode-hook
            (lambda ()
              (push '("function" . ?λ) prettify-symbols-alist)))

Ever been annoyed with the Emacs bell? Aside from disabling it, you can make it slightly less annoying by using a visual error indicator in place of an audible bell. There’s a Visible Bell setting included by default, but I find it quite aesthetically displeasing (at least on my nightly Mac build). I like this snipped a lot better (from EmacsWiki):

 (defun my-terminal-visible-bell ()
   "A friendlier visual bell effect."
   (invert-face 'mode-line)
   (run-with-timer 0.1 nil 'invert-face 'mode-line))
 
 (setq visible-bell nil
       ring-bell-function 'my-terminal-visible-bell)

This snippet will flash your mode line instead.

Data Science at the Command Line webcast

Yesterday, I attended a very handy webcast by Jeroen Janssens called Data Science at the Command Line (a book is on its way). While I do most of my data manipulation from R, it is undeniably convenient to be able to run some simple tasks interactively from the command line, or as part of a shell script or Makefile.

The presentation touched on several command tools that I either wasn’t aware of, or had forgotten about.  If you missed the webcast, this website has a helpful list of commands — of both the well-known and the obscure variety. Below are a few that I had not known about and might be useful to others.

parallel

parallel is a shell command to execute a series of commands in batch, over several CPUs on a local machine or over several computers (using a combination of ssh and rsync to connect and transfer files). I used to use a combination of Xgrid and some homegrown shell scripts to achieve that, but Xgrid is unfortunately no more (RIP!). parallel seems like a way  to quickly get a small subset of Xgrid’s functionality.

cowsay

cowsay is like echo, but with cute ASCII art animals.

~$ cowsay "I'd rather get error messages from a cute animal."
 ______________________________________ 
/ I'd rather get error messages from a \
\ cute animal.                         /
 -------------------------------------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Very useful to add some levity to your error messages! Use cowsay -l to get a list of animal templates.

I used the Node.js cowsay package to create this little Node.js app (for fun, and to learn a minimal amount of Express.js). Install via Homebrew or MacPorts.

asciinema

I saw Jeroen use this tool during the webcast to record his terminal session. Asciinema looks very very cool and potentially helpful to create terminal-based tutorials. Install via pip.

csvkit & jq

csvkit is a suite of command line tools to deal with CSV files, but works quite well for tab-separated data as well (which I deal with often). Particularly useful so far: csvlook (nicely formatted table in the terminal), csvstat (column statistics) and csvsql (SQL queries on CSV files). jq can be used to manipulate JSON data, potentially piped into csvkit to create simple text tables.

Setting up a nice AucTeX environment on Mac OS X

Most people I know use TeXShop on Mac OS X. While it’s a pretty good TeX editor, I think Emacs is overall vastly superior. Of course, I’m rather biased since I already use Emacs for everything else… Perhaps this post will be useful to other Emacs-addicted astronomers.

In my setup, I use the AUCTeX package coupled with the Skim PDF viewer (if you’re not using Skim, download it, it’s brilliant!). One of the advantages of this combination is that Emacs and Skim can be kept in sync, like in the screenshot below.

Skim + Emacs/AUCTeX nirvana. Note that the current highlighted line in Skim corresponds to the cursor position in Emacs.
Skim + Emacs/AUCTeX nirvana. Note that the current highlighted line in Skim corresponds to the cursor position in Emacs.

I found it a bit difficult to set up the AUCTeX package with sensible defaults, so I’ll reproduce here my configuration in hopes that it will be useful to someone else.

The salient lines are the ones configuring latexmk and Skim. You should have latexmk installed if you are using the TeX Live distribution; Skim can be downloaded for free here. You can stick this script in your Emacs initialization file (see my dotemacs repository if you’d like to see my other Emacs configs). I shamelessly copied those lines from this Stack Overflow answer.

Two LaTeX gems: ShareLaTeX and latexdiff

Here are two really cool LaTeX tools every astronomer should enjoy.

ShareLaTeX is an online LaTeX writing tool. It’s great for collaboratively writing LaTeX documents of any size, and a life-saver when you don’t have access to your own laptop with a TeX installation on it — just grab a web browser, navigate to ShareLaTeX and write away, then grab the PDF product. (You can also chat with collaborators, browse revisions, and a bunch of other useful niceties.)

A sample ShareLaTeX project.
A sample ShareLaTeX project.

The folks behind ShareLaTeX generously announced today that they made their product open-source. Here is the GitHub page with their source code. It appears to be extremely easy to run your own local installation, if you so desire.

While working on a grant application (in the old, inefficient fashion: on a Dropbox shared folder) I wished there was some way to send “diffs” of my changes to the PDF to my collaborators, in order to save them the time to hunt for the changed word or sentence. Emery Berger’s blog directed me to the latexdiff tool, which I had somehow never heard about! It’s quite easy to install (if you use MacPorts, it’s a simple sudo port install latexdiff), and the resulting PDF diffs are nice and clear.

A sample latexdiff output.
A sample latexdiff output.

 

Link: The Sound Of Mandelbrot Set

The Ripples blog  published a very nice post about “sonifying” the Mandelbrot set. The resulting sound files (linked in the post) are quite interesting, especially the “SlowDivergence” soundbite. The post also tipped me off about  playitbyr, an R package that converts a data.frame (a table of values) into an auditory graph. The soundbites demoed on the webpage are really cool — you should check them out!

The sonification window of Systemic v1.
The sonification window of Systemic v1.

The “classic” version of Systemic (v1, Java) has a feature for sonifying the orbital dynamics of exoplanets, originally written by Aaron Wolf (now a Turner Postdoctoral Fellow at the University of Michigan).

Non-interacting planets only generate pure sine-wave tones — not very interesting. It gets much more exciting once you introduce planetary interactions. Resonant and unstable systems, in particular, generate much more delicate or dramatic samples. Oklo.org has a few posts about the sonification feature, with downloadable soundbites.

I have not been a very good steward of this feature — it didn’t make it into Systemic2 (or the web app) since I didn’t want to work on migrating the Java code.  The existence of playitbyr, though, means I do not have to reinvent the wheel, definitely reigniting my interest in implementing this feature!

[Via R-bloggers.]

Two useful tools: git-flow and git-gutter+

This is just a quick post linking to two very useful tools I just started incorporating into my workflow.

The first is git-flow. Git-flow gives a very nice structure to feature development using git: it imposes some discipline on branching and committing features to the “master” branch, while also providing a very helpful branching naming scheme and a clear path from developing a feature to incorporating it into a release. This post gives a clear overview on how to get started with it.

Fringe Git indicators in Emacs.
Fringe Git indicators in Emacs.

The second is an Emacs package called git-gutter+ (in its “fringe” flavor). It lets you view Git changes directly from the current buffer (the graphical symbols in the fringe shown in the screenshot). Install it from the package manager (MELPA) and add to one of your .el initialization scripts.

Using Celestia for fun and profit

Celestia is a stunning program for visualizing 3D objects in space, in real-time.  It has a large database of astronomical objects (stars, planets, moons, minor bodies, etc.) that are rendered realistically and are positioned accurately in space and time.

A screenshot of Celestia running on my laptop.
A screenshot of Celestia running on my laptop.

One thing I discovered recently is that Celestia is also eminently programmable. What I mean is that, instead of manually zooming, flying-by and orbiting objects, Celestia can run scripts that execute complex macros. These scripts let you create engaging visualizations — either interactively initiated, or recorded into a video. Panning, zooming, orbiting, accelerating and flying through space with a cinematic flair, which makes for great outreach presentations. The scripting language itself is a fully-featured language (Lua, one of my favorite languages!), so math, looping constructs, data structures are all available.

I am using Celestia to prepare a short talk about how the discovery of exoplanets revolutionized planetary science, and shook a lot of the assumptions that were rooted in centuries of observing our Solar System.

Westcave
Cover slide of my talk.

Above is the (draft) first slide of the talk. Each planetary slice is a screenshot from Celestia, using one of the planetary objects that will be touched during the talk. The composition of the slide was inspired by a recent posting on Reddit — a beautiful painting of the planets of the Solar System (I would have died of happiness if I got this painting when I was little!)


Another great feature of Celestia is that every single object is defined within a text file (with references to 3D models, textures, etc.) that are easily modifiable and extendable; a bundle of files placed in Celestia’s extras/ folder is loaded at startup, and the astronomical objects come to life.

This spawned another amazing resource for people doing astronomy outreach, the Celestia Motherlode. The Celestia Motherlode is an extensive repository of mods, textures and objects (even fictional ones!) that are freely downloadable. Some are high-resolution textures of the Solar System planets; others are exoplanetary systems that have been discovered since the discovery of Celestia; others still are beautiful renderings of hypothetical systems.

For my talk, I made several videos. Among them, these will be the background as I explain the basics of planet formation.

A zoom into the inner parts of a protoplanetary disk reveals planetesimals and embryos embedded in it…

[videojs poster=”http://www.stefanom.org/wp-content/uploads/2014/01/planetesimals.png” mp4=”http://www.stefanom.org/wp-content/uploads/2014/01/planetesimals.mov”]

…while outside the ice line, giant cores accrete massive atmospheres from the disk.

[videojs poster=”http://www.stefanom.org/wp-content/uploads/2014/01/giantplanets.png” mp4=”http://www.stefanom.org/wp-content/uploads/2014/01/giantplanets.mov”]

(Please attribute this website if you’d like to reuse them!). These shots were accomplished using scripts and custom textures and models from Motherlode (this add-on which I heavily modified, and this model for the impacted protoplanet).


Since I found Celestia such an useful, little-know tool,  I decided to write a series of blog posts on how to use its scripting facilities and create custom planetary systems. Hopefully they will be useful to fellow astronomers!

In the next post in this blog series, I will show how to create this simple animation that shows the orbits of the planets in the Solar System, and then rotates the view to show that the Solar System is rather flat (planet sizes not to scale, of course!):

[videojs poster=”http://www.stefanom.org/wp-content/uploads/2014/01/solar.png” mp4=”http://www.stefanom.org/wp-content/uploads/2014/01/solar.mov”]

Some useful resources to get started: