Casey W. Stark

Astrophysics, computation, and code

Code Release: Dimensionful

| Comments

I’m releasing a Python package I named dimensionful. It’s a simple library that attaches symbolic units to any sort of data.

The idea is that you can create Unit objects and associate them to any data, using a Quantity object. You can then perform any operation on the Quantity objects and the units are handled behind the scenes for you, with as few conversions as necessary (almost always zero).

Here’s an example to give you an idea of how it works.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import numpy as np
from dimensionful import Unit, Quantity

# totally fake data
energy_data = np.random.random(4)
time_data = np.random.random(4)

# Create a Unit. Dimensionful knows the unit symbols "g", "cm", and
# "s", but you can provide any string or sympy expression.
energy_units = Unit("g * cm**2 * s**-2")

# Create a Quantity. First argument is the data, second is the units. The unit
# arg can be a Unit object or a string.
energies = Quantity(energy_data, energy_units)
time_intervals = Quantity(time_data, "s")

# Try Quantity operations
power = energies / time_intervals
print power

This outputs [ 0.84771033 1.01795928 0.34694982 0.26888805] cm**2*g/s**3. And a brief version of the same thing:

1
2
3
from dimensionful import Quantity, erg, s

print Quantity(np.random.random(4), erg) / Quantity(np.random.random(4), s)

This package is similar to magnitude and sympy.physics.units, but I think there are some key differences.

Domain Change

| Comments

My new personal website is caseywstark.com.

I decided to get rid of “thestarkeffect” and thestarkeffect.com. Even if you know the physics phenomenon, it’s a bit too dorky for me now. If you don’t know it, it sounds… bad.

I will leave thestarkeffect.com up for some time (serves the same directory), but you might want to update bookmarks and the feed to http://caseywstark.com/atom.xml if you use them.

Git Workflow

| Comments

or “How I Learned to Stop Worrying and Love git rebase -i”.

I’ve been working with git in a more professional setting lately. We maintain our new cosmological code, Nyx, in git now and I can’t be as lazy as I have been with other git repos. We maintain 2 bare repos and about a dozen developers pull from us, so I like to be careful about what I push off.

Problem is, I don’t normally work that way. I like to code things quickly and try them, keeping track of changes as I go. Think “cowboy” development with very frequent commits. So, I could end up with a very messy commit history. Luckily, git rebase comes to the rescue.

So at the end of a bout of local coding, the commit history looks something like this.

… many commits down to …

Pure Joy: My First Citation and a Confirmed Prediction

| Comments

The first citation is a scientist’s coming of age. For the first time, you were referenced as a credible source of the edge of human knowledge.

Last week, my undergraduate research advisor, Vitaly Kresin, emailed me a “nice paper”, saying “I think you might enjoy it.” He was spot on. I could barely read the abstract before I started jumping around and squealing like a little girl.

During my senior year at USC, Vitaly and I published theoretical results of modeling alkali metal clusters inside helium nanodroplets. We called it “Critical sizes for the submersion of alkali clusters into liquid helium” and published in Physical Review B.

The awesome thing is that our intuition for the problem was right. We expected that small alkali clusters end up sitting in dimples on the surface of helium droplets (this was experimentally confirmed for sodium dimers and probably trimers at the time), and large clusters must sink into the center of the droplet.

The new paper is “The submersion of sodium clusters in helium nanodroplets: Identification of the surface → interior transition” by An der Lan et al., in The Jounal of Chemical Physics. Here is the abstract:

Grep Tip

| Comments

I noticed that I’ve been using grep a lot lately to search for text in a directory. I find myself using the same options every time as well:

1
$ grep --color -irn "some text" .

Just to be clear, --color highlights the search string in the output, -i makes the search case-insensitive, -r makes the search recursive, -n outputs the line number of the hit, and the . at the end says to search the current directory. Lazy as I am, I realized I could just add this to ~/.bash_profile:

1
alias ggrep="grep --color -irn"

Now, I can save some time and thought with ggrep "thing" . It’s the little things…

EDIT: As Matt Turk suggests in the comments, the best alternative (especially for the Pythonists) is grin. Much simpler and clearer display of results.

Update at SF11 Cosmology

| Comments

I am currently participating in SF11 Cosmology at St. John’s College in Sante Fe, NM. I am here for weeks 2 and 3, so I’ll be back in Berkeley on July 23rd.

It’s been a great couple of days, meeting lots of fellow cosmologists, having very casual talks and schedule, and nerding out. I have been taking lots of notes, but I decided that I should keep them private, at least for now. I know that’s not being my usually open self, but it would take too much time to clean them up for all eyes. If you would like to know anything about what’s going on, feel free to contact me though.

Just another note: there is very little AT&T reception in Sante Fe and even less at the College, so please email me if you need to get in touch.

Your File System’s Love Life

| Comments

lsss - ls with StarSign

$ lsss /etc/default
total 49
-r-xr-xr-x   1 root           12     gemini Jun  4  2002 cron
-r--r--r--   1 root          204     gemini Jun  4  2002 devfsadm
-r--r--r--   1 root         3388     gemini Jun  4  2002 dhcpagent
-r--r--r--   1 root           10     gemini Jun  4  2002 fs
-r--r--r--   1 root          719   aquarius Jan 23  2004 inetd
-r--r--r--   1 root          379     gemini Jun  4  2002 inetinit
-r-xr-xr-x   1 root          638     gemini Jun  4  2002 init
-r--r--r--   1 root         1182      virgo Sep 15  2002 kbd
[...]

Twinkle Twinkle

| Comments

Twinkle twinkle little star
How I wonder what you are
When my civilization advances
And we can fly to your galaxy
We’ll exploit your natural resources

Miles Guidon Facebook

Note to Self About Python Graphics

| Comments

On a Mac (and possibly other systems), do not install the 64-bit version of EPD. Only install the 32-bit if you want your graphics to work.

This is a bug that has to do with the Mac framework architecture. Basically, you need to install matplotlib to /Library/Frameworks/Python.framework/ or matplotlib will not be able to interact with the Mac OS X Windows Manager properly. I don’t know the first thing about window managers, but I can tell you that this is really important when you want to save your figures.

I tried many things, including installing numpy, scipy, and matplotlib in a virtualenv. I thought it would be much cleaner to “activate” my scientific environment, keeping the Apple Python build as my system default. I got this all setup and when I tried to use matplotlib, I could not type in the textfield in the matplotlib save figure window. That is, I would plot something, click save, and then I could not enter a filename in the dialogue box. Infuriating.

So I gave up and installed the EPD 32-bit academic version. Not ideal, but it works really well and it just means my environment variables are a tiny bit mangled. No bigs.

Paper Hustler Going Beta

| Comments

That’s right, folks.

I am making a web editor for scientists, called Paper Hustler. I just put up the pre-beta site at http://paperhustler.com. You can also follow @paperhustler.

I put up the site yesterday, just before giving my talk at the Grad Student Postdoc Seminar (aka Wine And Cheese Talks). You can check out the slides to see a quick pitch (my thoughts that inspired the project) and new forms of scientific dissemination.

I am looking for lots of feedback on this, so please let me know what you think, good or bad.

In the future, I hope to post details on the tech behind the project. I have really enjoyed obsessing over developing this one.