To set up my package so it can be installed via pip, I’m following the somewhat outdated tutorial here – https://python-packaging.readthedocs.io/en/latest/index.html.
I’ll make more notes and update this post as I go along.
As the second entry in my series on learning how to write scientific software, I’m going to describe choosing and configuring my integrated development environment or IDE. This is the program I’ll use to write and edit the source code for my project. It’s more-or-less a fancy text editor.
My text editor of choice is vim or vi improved. It’s highly customizable, powerful, and there’s lots of online help to use it. However, it has a very steep learning curve and the commands, while fast to type out, can be very cryptic. In fact, vim is famously difficult to exit.
In any case, I started using vim back when “Pirates of the Caribbean” movies were still good, so while I’m no vim guru, I feel pretty comfortable at least exiting the program.
Opening a terminal window in Mac, I fire up vim just by typing “vim” or “vi”. That opens an editor window. vim can automagically interpret and color source code, as follows:
To turn on syntax coloring, go to your home directory (type “cd” in the terminal window), and edit the vim configuration file .vimrc by typing “vi .vimrc”. That should open an editor window.
Then, in vim, type the letter “i” (that starts “insert” or edit mode, allowing you to enter text into the file) and type “syntax on” <ENTER> “filetype indent plugin on”, giving a file that looks like this:
Press the escape key (which exits insert mode and enters command mode). Save the changes by typing “:wq”. That should save and exit.
Unlike many other languages, Python considers whitespace in its interpretation, and the Python style guide recommends using four spaces for each level of indentation. It would be nice to have the tab key implement that spacing in vim. Ynfortunately, my vim by default inserts eight spaces for each press of the tab key.
But you can modify that behavior by adding file-type plugin files to a special vim configuration folder. I followed the instructions here to create an ftplugin directory inside the .vim directory (by typing “cd && cd .vim && mkdir ftplugin && cd ftplugin” in the terminal window). Then, inside the directory, I created python.vim (“vi python.vim”) and again pressed “i” to enter insert mode.
I typed the following lines into the file:
Then pressed the escape key and typed “:wq”.
Next, I tested the new configuration by typing “vi test.py” (the “.py” is important because that’s how vim knows you are editing a python file and want to use the new python configuration). I pressed tab and got four spaces instead of eight.
I’m sure there are other configuration settings that would be useful, but this’ll do for now.
In the eons before my graduate career, scientists rarely, if ever, publicly distributed their codes, with authors zealously guarding their coding projects.
But just as I was finishing my PhD, it was becoming common for scientists to make the code they developed as part of a published project readily available on the internet. However, the methods to post code online (at least those I knew about) were pretty clunky.
Nowadays, the infrastructure for posting and sharing code online is robust, mature, and relatively easy to use. Consequently, scientists are creating beautiful code repositories, along with accessible documentation.
Open-sourcing code is becoming ever more important: as codes become more complex and capable, readily available codes with good documentation are critical to support reproducibility, a cornerstone of the scientific process. Moreover, federal funding agencies are starting to require investigators to make their code and data products public.
Unfortunately, since I was one of the last generation of grad students before these repositories were common, I never really learned how to distribute and document code properly.
So as part of an ongoing effort to improve my science output (and as an aide to my future students), I’m going to begin a series of semi-regular blog posts describing my process of learning how to write, document, and post scientific code.
A few caveats upfront:
- I intend to mostly (probably exclusively) write the code in python, which has become (at least in astronomy) the language of choice, so not all of what I write will be generally relevant.
- I was ushered into the Cult of Mac many years ago, so not all of what I write will be relevant for other OS’s. Here again, though, I’ve found anecdotally that most astronomers use Mac.
- This blog series is in no way intended to be comprehensive or rigorous. I’m just planning to describe what I learn as I go along, and what time I can devote will almost definitely not suffice to explain all the details, nuances, or technical aspects that intersect the project.
As to the actual science code I intend to write, several years ago my colleagues and I wrote a paper about ellipsoidal variations induced by massive exoplanets orbiting very close to their host stars. The accompanying code, EVIL-MC was written in IDL, an older language still widely used in astronomy but proprietary and requiring the purchase of an expensive site license.
My plan is to convert that IDL code into a Python package over the next several weeks.
Tidal distortion (exaggerated) of a star (orange-yellow disk) orbited by planet (white/black disk). The plot below shows the brightness variation of the star due to the tidal distortion.
I’m sitting in the hotel lobby at the Woodlands Marriott, waiting for my supershuttle to IAH and recouperating from my second Lunar and Planetary Sciences Conference, LPSC. Before I’m whisked away back to Boise, I thought to write about a few of the fascinating and mind-blowing things I saw this week.
First of all, LPSC is an annual conference that focuses on the geology, geochemistry, and geophysics of planetary science. There’s a lot of focus on solar system bodies with solid surfaces, as opposed to the annual DPS meeting, which has a bit broader focus.
I arrived on Sunday evening and dove immediately in, helping with the First-Timers’ presentation review, an opportunity for new-comers to the meeting to have more senior folks provide feedback on their posters or oral presentations.
Monday dawned cloudy, and I sat through several talks about our sister planet Mars. One that stuck out for me was one about field experiments to explain the perennially mysterious gully formations found on martian slopes with sleds of dry ice.
Tuesday saw me in a session on Saturn’s moon Titan, a cornucopia of geology and atmospheric physics. One particularly impressive talk discussed work to understand how methane deluges on Titan modified the surface.
— Brian Jackson (@decaelus) March 20, 2018
Tuesday evening, I presented our group’s work flying drones through active dust devils.
Wednesday was packed with talks on sediment transport experiments and analyses, attempting to decipher the martian aeolian cycle, including a neat study of time-lapse imagery of martian dunes.
— Brian Jackson (@decaelus) March 21, 2018
Thursday was packed with Pluto and results from New Horizons. One talk that stuck in my mind was an analysis of landslides on Pluto’s moon Charon, which, frankly, was a little bit of a tear-jerker. Hard to believe that not one hundred years ago, we didn’t even know Pluto existed. Now we’re trying to understand the system’s geology.
— Brian Jackson (@decaelus) March 22, 2018
Friday morning wrapped up the meeting with a series of talks about glacial geology on Mars, including a fabulous presentation on mysterious geomorphic features on Mars. Even though these features look for all the world like glacial flow, they appear on totally flat ground, where flow shouldn’t be possible.
— Brian Jackson (@decaelus) March 23, 2018
And now to catch the shuttle.
Among the mind-blowing discoveries of the Kepler Mission is that the most common type of planet in the galaxy is the super-Earth/sub-Neptune. This unexpected type of planet straddles the boundary between Earth and Neptune in size and mass, and so they may be super-sized rocky planets or anemic gas-rich planets. We just can’t tell.
Stranger still is that this bizarre chimera orbits one out of every four stars in the Milky Way, but we don’t seem to have one in our solar system (unless the Planet Nine hypothesis pans out).
If that wasn’t enough to make you feel like a planetary outsider, a recent study suggests most planet systems have very different architectures from our own.
In their paper, Prof. Ilaria Pascucci of the University of Arizona and her colleagues studied the distribution of masses for planets discovered by the Kepler Mission. Unlike other recent work, though, they considered not just the planet masses but how they compare to the masses of their parent stars.
Naively, we might expect that more massive stars grow more massive planets, and there is good evidence that more massive stars host more massive dust disks. So as long as the processes that make planets are happy to operate around most any kind of star, then we can use the distribution of planet-star mass ratios to disentangle the influence of stellar mass from other effects.
And Pascucci et al. found exactly what we expected – big stars, small stars, they are all more likely to host planets more massive than Earth — but only up to a point. As shown in Figure 1, the number of planets per star increases with the planet-star mass ratio until it reaches about 0.00003 (or 10 Earth masses for one solar mass) — somewhere between the Earth and Neptune. Above that ratio, the occurrence rate drops, meaning more massive planets are less and less common.
But something even more interesting emerged when Pascucci et al. compared their results based on the Kepler Mission to other surveys. Because Kepler is good at finding planets close to their host stars and not at finding planets farther away, Pascucci’s results don’t tell us much about planets in orbits like Jupiter’s. But microlensing surveys, which use a totally different planet-finding technique, *are* good at finding these more distant planets.
Comparing mass ratios from the two kinds of surveys, Pascucci et al. showed more distant planets found by microlensing also show a preference, but for a ratio several times larger than what’s preferred by closer-in planets — somewhere between Neptune and Jupiter in mass, as shown by the figure above.
What does this all mean? Apparently, the universe seems to like make planets about ten thousand times less massive than their host stars, whether the stars are tiny red dwarfs or massive F-stars. And the farther away the planet is from its star, the more likely it is to be more massive.
But these results also make our solar system look even stranger than before. In most solar systems, orbits like Earth’s (and closer) are occupied by planets somewhere between Earth and Neptune in mass, and more distant orbits like Jupiter’s are occupied by planets between Neptune and Jupiter.
It’s tempting to speculate that things that make the solar system unique in one way (in this case, the type of planets we have) are related to other unique things (like, the fact that there’s life here). We don’t know much about super-Earths, but if they turn out to be more Neptune- than Earth-like, it’s not hard to imagine they wouldn’t be good places for life to get started.
Life as we know it needs a planet with a solid surface and lots of liquid water, and so maybe it’s not surprising we haven’t found life elsewhere in the galaxy yet: most of the planets are lifeless, gas balls.
With the very first discovery of an exoplanet around a Sun-like star (51 Peg b), astronomers were introduced to hot Jupiters. These totally unexpected planets resemble Jupiter in mass, composition, and size, but they have orbits that nearly skim the surfaces of their host stars. Some of them are even losing their atmospheres under the apocalyptic glare of their host stars.
How their lives began remains a mystery, but we have a pretty good idea of how their lives will end – they will be engulfed or torn apart by their host stars. That’s because hot Jupiters are big and close enough that they can actually raise a tidal bulge on the stars (and we can actually see the bulge in a handful of cases).
This tidal interaction can cause the planets to spiral downward toward the stars, and at the same time, it causes the spins to spin faster until the planet is destroyed by the star. The same tidal effect, just in reverse, is driving the Moon away from the Earth, while slowing down the Earth’s spin. But here’s the key: we don’t know how quickly the planets are spiraling in.
Enter Prof. Kaloyan Penev of UT Dallas Physics Dept. On Valentine’s Day last week, he and his colleagues published an academic love note exploring planetary tidal decay. To do this, they modeled the evolution of planetary orbits and stellar spins under the influence of tides. The tracks in the figure at left show how a planet’s orbital period (or distance from its star) might shrink over billions of years, thanks to tides. The clump of spaghetti noodles in the figure shows that evolution for a range of assumptions about the rate of decay.
By comparing the stellar spin rate and planetary orbit predicted by their model to those we actually observe for each system, Penev and colleagues showed that the tidal decay rates might actually slow down as the planets approach their stars. So perhaps instead of an reckless death dive into the star over a few million years, the planets make like Zeno’s tortoise and tiptoe closer and closer without plunging in.
Upcoming surveys such as the TESS mission and the Large Synoptic Survey Telescope may soon allow us to test whether planets do or do not plunge into their stars. Theoretically, we expect stars that eat their planetary children dramatically brighten up by a factor of 10,000 over a few days – faster than a supernova brightens but nowhere near as bright. These surveys might able to see stars engaged in this act of cosmic infanticide.
In astronomy, when you look for evidence supporting a hypothesis and don’t find it, that’s called a “null result“. The null result is usually not all that exciting, but last week, an attempt to detect the atmospheres of potentially habitable exoplanets came up null, and that, as it turns out, may mean the planets are habitable.
In a recent study published last week in Nature Astronomy, Dr. Julien de Wit of MIT and colleagues observed the transits of four of the planets in the TRAPPIST-1 system. The discovery of this system was announced last year and generated a lot of interest — it comprises seven Earth-sized planets orbiting a red-dwarf star, and at least four of the planets orbit in the star’s habitable zone. So astronomers are scrambling to determine the climatic conditions on these planets and find out whether they host life.
Key to those conditions is the composition of the planets’ atmospheres, and the best way to probe atmospheres lightyears distant is to detect the colors of the planets’ shadows as they pass in front of their host stars, i.e. as they transit. When light from the star passes through a planet’s atmosphere, the cool gases can imprint spectral signatures, which we can then detect using a very sensitive telescope — de Wit used the Hubble Space Telescope.
Now, even though the TRAPPIST planets are Earth-sized, that doesn’t mean their atmospheres are Earth-like — astronomers have founds lots of weird planets in the last several years. The atmospheres could be hydrogen-rich like Jupiter, hydrocarbon-rich like Neptune, or rich in nitrogen and oxygen like Earth.
In principal, each kind of atmosphere would give a distinct spectrum, but in practice, atmospheres rich in hydrocarbons or nitrogen, potentially good atmospheres for life, are difficult to detect because they are weighty and drape over the planet like a heavy blanket. By contrast, a hydrogen-rich atmosphere, although probably not great for life, can be light and fluffy, relatively easy to detect.
When de Wit and colleagues analyzed transit data they collected from Hubble showing transits for planets TRAPPIST-1 d, e and f, they found no atmospheric signals down to their detection limits. The spectra below show this lack of atmospheric coloration and what they would have detected if the atmosphere was hydrogen-rich.
Now, of course, this non-detection does NOT mean the planets are habitable or even Earth-like. As the figure shows, their atmospheres could still be radically different from the Earth’s (drenched in water vapor or carbon dioxide-rich like Venus), but it rules out the possibility that they are Jupiter-like — potentially good news for life there.
Very likely, when the James Webb Space Telescope finally launches next year, the TRAPPIST-1 system will be one of its first targets. JWST’s vastly improved sensitivity will help reveal not just a potent null result for the TRAPPIST-1 system but may also reveal the glimmer of distant Earth-like worlds.
I’m a participant this academic year in the Boise State Teaching Scholars, a program to promote the scholarship of teaching and learning. As part of that program, participants are asked to give presentations on various topics, and I led a discussion last Friday on inclusive teaching. In case the presentation and the links provided are useful to anyone else, I’ve posted it below.