Every year or so, I update my ‘history of exoplanet exploration’ animation, which shows the detections of exoplanets in (roughly) the order of their discovery by plotting the host star locations in sequence.  This year, I decided that I wanted to try to add an audio track, but rather than just playing some copyright-free beats, I wanted the audio to carry additional information.  Based on feedback from astronomer friends (thanks Mark Marley (https://twitter.com/astromarkmarley) and Pauline Arriaga (https://twitter.com/ophiuchusdebris)), I settled on assigning each detection method (which are also plotted using different symbols) a unique note, and modifying each detection pitch by binning planet mass to octave (inversely, so that bigger planets had intuitively pleasing lower pitches).  Sounds super straightforward, until you start looking at the Python audio support landscape.  I dutifully went down the list of available codes from https://wiki.python.org/moin/PythonInMusic.  Most failed to work entirely on my os/python install, some were much too complex to learn just for my simple task, and the remainder didn’t do anything that I actually wanted.  Fine. But all I want is a bunch of sine waves – should be easy enough.  So I coded up a basic frequency generator and piano key mapper (https://github.com/dsavransky/miscpy/blob/main/miscpy/utils/audio.py).  Try it out, and, every single note ends in a loud pop.  This is a well-known phenomenon – you’re driving your computer speakers from something to nothing instantaneously, and they’re trying to comply but can’t.  The obvious solution is to apply a window function.  So I start looking around for what existing DSPs use, and they’re all implementing sines and Gaussians, and other things that don’t make a lot of sense.  What you want is something closely approximating a top-hat, but with smooth ramp up/down.  This is a known function called the Planck-taper window and is not implemented in numpy or scipy. (Loud screams).  Fine, we’ll add the window function to the audio class.  No more clicks.  The overall audio sounds a bit rough due to so many individual tones fighting it out, but a Gaussian filter works fine for smoothing that out.  Last step is to combine the audio and the video, which matplotlib animate seems incapable of, but ffmpeg handles it just fine, so that’s ok.  The final result:

Data was drawn from the NASA Exoplanet Archive (https://exoplanetarchive.ipac.caltech.edu/index.html) and the source code for the video is available at: https://github.com/dsavransky/miscpy/blob/main/miscpy/Animations/exoplanet_history_anim.py 

An Aural Experiment