3D Printing the Mountains


Hanging on the wall, under the low ceiling in the basement of my childhood home was a map. It was plastic, and it had a 3D texture of the Colorado Rocky Mountains. Flying over the range in my imagination I could see the high mountain valleys bowled in by the snowcapped peaks.

As an adult I want a map of the Sandia Mountains that I watch from my window. Mountains with all the moods of an impressionist painter. Sunshine illuminating the mountain, standing proud before a black cumulus mountain range. With a 3D printer, and the wonderful availability of open source software, I can. Here is the recipe.

First acquire digital elevation model (DEM) data from the source of your choice. I got my data from viewfinderpanoramas.org, you have to drill down to the coverage map. I like these data, at 3 arcsecond resolution each pixel represents roughly a 30 meter square. Most publically available DEM data is coarser, which is fine if you are printing large areas.

Download the data, unzip it, and add the data to your QGIS session. With a text layer, I loaded a reference location so I could select the printable region. A screenshot of my loaded map appears below.


Certainly the region you want to print is smaller than the DEM file tiles. To extract a region of the DEM file, use the Raster > Extraction > Clipper tool. Choose the rectangular region, draw what you want, and save the new file as a GeoTIFF. Load the new GeoTIFF into QGIS. Scale the vertical range of the new layer so that all values are between 0 and 255. Go to Raster > Raster Calculator and then use the layer’s minimum and maximum values to apply a formula

255*(value – minimum)/(maximum – minimum)

The layer summary shows the minimum and maximum values. In this screencap the values range between 1648 and 3091.


Convert the scaled GeoTIFF to PNG with Raster > Conversion > Translate. OpenSCAD can import PNGs and generate the STL file that most slicing programs want. I needed a recent version of OpenSCAD to load PNGs successfully, the following screenshot was made with 2015-03.1.


The OpenSCAD code is relatively straightforward, the only difficult part is getting the scales correct. You need the pixel extents of the image and the geographic extent (km) of the print area.

[code language=”cpp”]
// OpenSCAD file to scale and display a raster

vert_min = 1.609; // km
vert_max = 3.255; // km
horiz_x_extent_km = 14.335; // km
horiz_x_extent_px = 154; //
horiz_y_extent_px = 150; // pixels

h_factor = (1/horiz_x_extent_px)*horiz_x_extent_km;//puts it in km
v_factor = (vert_max – vert_min)/100;

// To keep the object manifold I had to impose a lower layer, this
// also provides strength for the thinnest parts of the plot.
horiz_x_extent_km * horiz_y_extent_px/horiz_x_extent_px,
scale([h_factor, h_factor, v_factor]){
surface(file = "myrasterclipped4.png",
center = true);

From OpenSCAD you can render and export an STL. I print with the excellent Repetier Host software. Repetier loads the STL to produce something like the following screenshot.


And finally 3D print it.


This image is the Sandia Mountains crest, my house is located approximately at the lower right of the print. Each day I look out my back window at the this scene.


In the desert it almost never rains. I know, you know. When I lived in upstate New York, in my foolish youth, I bought a motorcycle in the beginning of April. I was anxious to learn to ride. Too bad, because it rained every day for an entire month. Now I live in New Mexico. Two years ago we had not one drop between the end of December and July.

Where you live the weather turns with a unique step. Here, the summer breaks in July when the monsoon comes. Moist air from the Gulf of California and the Gulf of Mexico flow north over the state and give rise to afternoon thunderstorms. It is the most beautiful weather of the year here. The clouds rise miles—literally—into the sky and continuously billow in fractal glory.

Last week I configured my Raspberry Pi computer with its PiCam to take time-lapse video out my back window. The view is to the east over the Sandia Mountains. I took pictures about every six seconds from 10:30 am until dark, around 8:30 pm. The whole day compressed into four and a half minutes. The best video was from July 14, others are below.

It is hard to understand the desert if you have never lived in one. In the picture below you can see what it would be like if Leeds were in Albuquerque. A nation that ruled the world for a few hundred years fits comfortably in the desert southwest.composite

The rest of the videos I created are here, with the most interesting at the top.

July 11

July 13

July 8

July 7

July 10

July 16

July 15

The Spiraling Shape

The Spiraling Shape will make you go insane
Everyone wants to see that groovy thing

–They Might Be Giants

The chambered nautilus is sometimes called a living fossil. It is the closest living relative of the ammonoids, and cross sections of its shell are familiar to every adult in the western world. Most kinds of ammonoids lived a long time ago. They started appearing in our Devonian strata around 415 million years ago. Pretty cool, since modern humans have been around 0.195 million years. If you consider the chambered nautilus close enough, then you might say that these critters have been around 2000 times longer than humans. That is real staying power.

In June my wife and I visited San Francisco for a vacation. A delightful city for touring because it has such a mix of old turn of the 20th century buildings, awesome bridges, a cool sea breeze, great parks and museums, shopping, cultural diversity, and enough hipsters to feed Cthulhu for an eon. Unless someone can find a more suitable use for hipsters.

In Chinatown we saw all the usual junk. But there was also a rock shop that had a nice assortment of cross-sectioned fossil ammonoids or nautiloids. I dug through and looked for one with the most open inner spirals. And here it is.


I scanned it at absurdly high resolution, the largest diameter is 1.6 inches. The construction of the nautiloid is fascinating. The spiral is logarithmic, as you can find asserted all over the web. Of course, in my entire life I have never seen anyone actually measure the spiral and show its logarthmic nature. But it looks like it a logarithmic spiral.

The structure is self-similar. It is hard to tell how big this little shell is because it would like basically the same to your eye at ten times the size. I love that: fractal without fragmentation.  The creature, I suppose, could grow large just by repeating the same basic step—grow a new chamber. The genetic code to scale up must have been quite an innovation, evolutionarily speaking.


Distilling the spiral of the shell to its simplest shape shows awesome, but not perfect, consistency.


I have never seen a discussion of how the maximum and minimum buoyancy of the creature might have changed as it grew. You can bet that there is a clever relationship between the mass of the cephalopod’s body, the mass of its shell, and the volume of each successive  chamber, at least for those that can move vertically. Seafloor-dwelling species might be marked by a faster-opening spiral that keeps their shell from rising. Why is that a safe bet?

I understand that the nautilus spends the day deep in the ocean, and rises near the surface to hunt at night. They control their depth by pumping water in and out of their shell chambers. A nautilus’ chambers are connected by a little hole, and I can’t see any holes between chambers in my fossil so maybe mine wandered about on the seafloor or floated at a constant depth.

I measured my trace for the distance between spirals. I divided them all by the smallest one and produced the measurements

1 1.3 2.9 5.6 12 25 49
And this spiral does indeed show logarithmic growth. The plot shows the plot of the natural logarithm of the same measurements. Its consistency is so very, very good. I suppose that’s what makes the shell so pretty.

Candle Flame Flicker

For a project I wanted to make an LED flicker like a candle. I searched for the signal statistics of candle flicker, and I found no data. One student web site suggests that candle flame flicker is a 1/f-type random signal with roll-off of 20 dB per decade increase in frequency. Similar processes are typical for turbulence, so this student’s plan seemed reasonable. However, the student did not discuss whether the signal is Gaussian or not, and did not describe the low-frequency characteristics of the signal. 1/f noises may have a spectrum that follows the 1/f curve to very low frequencies, but because they would require infinite power at f=0 they always have some lower frequency change. I had no data.

Candles aren’t hard to get, and I already had a silicon photodiode for an absorptive smoke density measurement system I’m working on. I also had an analog-to-digital converter (ADC) in an ADS1015 on a breakout board from Adafruit. I made the very simple circuit shown below and attached it to a Raspberry Pi to sample the data. There are a lot more details, but those are later.


The voltage measured by the ADC is directly proportional to the current through the resistor. The current through the reverse-biased diode is directly proportional to the incident optical power. Very simple. I recorded a minute of data at a low 250 Hz sample rate, and subjected the data to analysis. The setup was a nominally dark room with the sensor a few inches from the flame. I flapped my hand at the candle to get it to flicker while recording.




The first graph below is a histogram of sample values.


The histogram is about normally distributed, but the right-hand tail is not Gaussian; it is too fat. In other words the candle is occasionally much brighter than normal. The time series (below) shows the same properties. There are clearly visible large excursions.


For human eyes the candle’s flicker will be well represented if the frequency spectrum of the flicker and the distribution of the flicker approximately match a natural source. The spectrum below can be thought of as an average brightness (the peak at the left), a flat spectral region out to about 4 Hz, and then a 1/f-style roll off at 44 dB per decade.


Numerically, we have the recipe for a flickering candle:

  • Samples should be normally distributed with a standard deviation equal to 0.25 of the mean.
  • The power spectral density of the signal should roll off at about 40 dB per decade with a 3 dB cutoff frequency around six cycles per second.

To make this work on the Arduino using the pulse-width modulated outputs, we can further constrain the problem:

  • The maximum value cannot exceed 255 counts—or make the limit that the mean plus two standard deviations is 255.
  • From this, we can derive that 2s+m = 255, use the fact that 0.25m=s to find that the mean m=170 and the standard deviation is about 42.
  • A sample rate of between 30 and 120 Hz should be more than adequate to satisfy the Nyquist criterion for human vision (see Wikipedia).
  • Values may not go below zero or above 255
  • A second-order infinite impulse response (IIR) filter has a roll-off of 40 dB per decade

If we can find a numerically efficient way to generate a time-series of Gaussian random variables inside the Arduino, filter them with a 2nd-order fixed-point IIR, scale them (if needed) then we should be able to make a flickering candle.

Unfortunately, I have failed repeatedly to get a stable fixed point IIR filter. The cookbook solution specification above should be easy to implement, but I have not found it so. A better solution will have to wait for another post.

I Don’t Tell You How to Do Your Job

This article begins with a story from my life, my fatherhood, about the time I was most afraid. The story ends happily with the birth of a healthy baby girl. The article, on the other hand, ends with an analysis showing how medical habit increased the threat to my daughter’s life by a factor of 20.

I learned the principals of acoustic imaging in my first professional job on an air-based passive sound imaging system, and on undersea sonar systems. These systems deal with inhomogeneous media, that is materials that aren’t the same throughout. The human body is an example of the inhomogeneous media, and ultrasound technicians are well aware of the challenges. The science of sonar has much in common with the science of ultrasound imaging.

At the end of June 2008 my wife was 27 weeks pregnant with our daughter. Her first pregnancy had been difficult because she had preeclampsia that deteriorated into HELLP syndrome around the time she was induced. Since the first pregnancy was medically complicated, the second pregnancy came with extra monitoring. She had more ultrasounds and more checkups than a typical pregnancy for a woman of her age.

She was given an ultrasound examination; I was there watching the screen. Part of the test included a cranial artery peak velocity measurement. This test was never prescribed, or at least we were later told there was no reason it should have been prescribed.  Systolic flow is the fastest; it occurs when the heart contracts to push blood throughout the body. To measure the peak systolic velocity of blood flow in the middle cerebral artery, the technician puts the ultrasound in Doppler mode, and then carefully tries to hit a tiny moving target inside another person. That is, to hit a tiny moving target inside the person who is inside the person. The technician must align the ultrasound transducer’s boresight with the artery, to measure the Doppler flow accurately. This is a difficult ultrasound procedure. It took, if I recall correctly, about 15 minutes to generate the single peak velocity number.

Unfortunately, at 54 cm/s the flow rate was considered a strong indicator for for fetal anemia or hydrops. The prescribed treatment for fetal anemia is a transfusion. To give the transfusion a long needle is inserted through the mother’s abdomen, the uterus wall, and into the umbilical cord, where specially treated (irradiated) blood elements can be injected. Ultrasound is used to guide the needle in.

The procedure is risky. About 50% of the time the injection causes the umbilical cord to spasm, cutting off oxygen to the fetus. If this happens treatment is an emergency Caesarian and the delivery of a 27 week old premature baby. The prognosis for life at 27 weeks is about 90% according to babycenter. The same site indicates that 25% of those who live will have serious lasting medical problems—like cerebral palsy. An additional 50% will have some kind of lasting problem.

In my entire life I have never been as afraid, or worried, as I was through the day that followed that diagnosis. My initial reaction was skepticism. I demanded that the doctor defend the diagnosis, that she provide evidence to me that diagnosis was real and accurate.

It is well that I did.

I don’t remember every word I exchanged with the doctor. I can remember sitting in her office, across her desk. I can remember meeting each of her assertions with questions. I cannot remember being uncivil or rude, but I was terrified and may have been. I remember when she answered one of my questions with “I don’t tell you how to do your job!”

The hospital mobilized irradiated blood, and prepared an operating facility, and a prepped a sunny young doctor who had seen fetal transfusion performed (but not recently).

My daughter did not have hydrops.

I believe my skepticism saved the life of my daughter. I do not forgive that doctor. Mistakes happen, and even when bad, frightening things happen to me, I can forgive that. But I will never forgive her arrogance, the casual way she reached a conclusion and decided that nobody, especially the client, had the right to challenge her. May she find justice.

To her credit, she did eventually share some data with me. We walked together to one room, and she unpinned a photocopied graph from the wall. She took it to the photocopier and gave me a copy. This graph.


My questioning led them to delay the infusion by a day and to take an additional measurement. I watched the screen during the rest of the measurements. One ultrasound technician rotated the cart to block my view. I got up and walked around to see the screen. I challenged each of the technicians, and each of the doctors on the measurements. I pointed out that the measurement (54 cm/s) was on the threshold, not clearly over the threshold.

After the team of doctors and technicians finally decided that they could not repeat the high flow measurement, they continued looking. One doctor seized control of the transducer from the ultrasound technician and tried to examine my daughter’s thorax. She thought she could see a dark pocket (which could indicate hydrops). What she could see is a dark pocket, which in sonar is called a “shadow zone”. In this case the shadow zone appeared because the ultrasound had to pass obliquely through the fetus’s rib cage. The sound was refracted away from her abdomen leaving a dark region. The technician was appreciably better with the instrument than the physician.

The bull-dog tenacity was unbelievable. Given one incorrect diagnosis, the propensity to look, and look, and look for more problems is insane.

Analysis of Risk

Risk is a code word meaning that bad things might happen. It is calculated, usually, by counting the number of people to which bad things actually happened. Here I’ve annotated the graph with some numbers, I’ve marked my experience, and I’ve highlighted some samples. This is a very, very, small sample.


By my count there are 8 “well fetuses” whose peak velocity exceeds 1.5 times the median. There are 34 anemic fetuses, all of whose peak measurements exceeded the threshold. By those counts, if you get a high measurement then the odds you are actually sick are about 80% (34/42).

Prevalence of hydrops among the western first world population is quite low. In a study at a single hospital in Belfast, of 25,443 live babies 35 had fetal hydrops, or a prevalence of 1.34/1000. Presumably this excludes stillbirths, which in the U.S. account for 1 in 115 (much, much more prevalent than fetal hydrops live births).  The best data I could find for the rate hydrops among stillbirths is from the Arizona Department of Health Services, which reported 6 of 158 still births to be due to, or coincident with, hydrops.

For purposes of this discussion, assume that:

  • Hydrops affects 1.34/1000 live births
  • 8.7/1000 are stillborn
  • Of that 8.7/1000, Hydrops affects 3.8% of still births, or 0.33/1000 births
  • Thus, hydrops has a prevalence among all pregnancies of about 1.67/1000

Prognosis if the fetus has hydrops is poor, with about a 90% morbidity rate according to  Yong, a crude approximation that is still reasonable if accounting for non-immune and immune hydrops. The data I have is not very strong, rates vary wildly.

First, let us assume Eve has taken a break from her cryptanalysis work and is now pregnant. There is a small chance that Eve’s fetus has hydrops, 1.67/1000.  Her physician sends her for an ultrasound. Due to poor handwriting her fetus is given a cerebral artery peak systolic Doppler ultrasound.

Suppose that Eve’s fetus has hydrops (she was part of the 1.67 of 1000). The ultrasound shows this correctly since there are no false negatives in the chart above. The doctors order a transfusion, which has all kinds of possible complications. We’ll ignore those complications, and just assume that Eve’s fetus has a 10% chance of survival—hydrops isn’t really very curable. She will spend a lot of money, and a lot of fear on procedures. It is not clear if these treatments change the outcomes at all (see, for example, Gynekol 1996 abstract).

Suppose that Eve’s fetus does not have hydrops, which is the much more likely case of 998.33/1000. The ultrasound correctly reports “no hydrops” 81% of the time (34 of 42 dots on the graph). Unfortunately, Eve is part of the other 19%, and the test says her fetus is hydropic. She follows her doctor’s stern council, and has an intrauterine transfusion. This is a gamble, and here are her odds (again from babycenter).

Likelihood Outcome
4% Caesarian, child dies
10% Caesarian, very bad health (e.g. cerebral palsy)
21% Caesarian, poor health
11% Caesarian, good health
51% Transfusion succeeds

The main downside of a successful transfusion is cost, though there are probably rare cases of immune responses or transfusion induced illness. Eve’s cryptography work has grossed her lots of off-book income, so ignore the dollar cost of the operation. Furthermore, assume she does not contract MRSA in the hospital.

Eve had a test. If she had hydrops she changed the prognosis of her child almost none. If she did not have hydrops, she subjected herself and her fetus to really bad risks with no possible benefit.

Consider the population of Eves. Suppose that the doctors test every woman for hydrops. Disregarding the dollar cost, we have increased the risk of pregnancy so that 19% of pregnancies will result in hydrops treatments, of which 49% will result in very early preemies, of which 35% will have severe complications. In other words, testing has replaced the risk of hydrops (1.67/1000) with the risk of misdiagnosis and severe complications 32.6/1000. Testing every woman would increase the US infant mortality rate from 6.81/1000 to about 10.5/1000.

Doctors don’t have much negative risk in treatment. It isn’t their baby, it isn’t their money. Action is to their advantage, it may further their career if the action is relatively experimental. It may further their wealth if they are paid for procedures.

I believe all doctors I have ever met, and probably almost all doctors believe they are doing good. The pressure of this incentive system pushes slowly and gently toward more medical actions. It pushes common practice, the habit of treatment toward more procedures and more tests, regardless of their benefit to the patients.

I am not the first to suggest there is an issue. One indication of overtreatment is the rate at which doctors will cure themselves. Some studies indicate that doctors will undergo some procedures 1/2 to 1/5th as often as the general population. Why does the entire equation change when they have skin in the game? Would you bet the incentive structure is that different?

Would you bet your baby’s life?

Big Centipede

Last August my son’s school started the year with a school-wide focus on insects. When we’d drop him off or pick him up we would see experiments laid out to determine various properties of ant behavior. We collected arthropods to bring in too, butterflies, bees, spiders, whatever we could find.

One evening my wife was sitting on the couch, and I was wandering about the kitchen. We were talking. She noticed something crawling across the floor.


This centipede is about 11 cm long, or about 4.5 inches. This is not that big in an absolute sense. You aren’t going to be carried off. But as crawly critters go, this is really, really big. I think this is desert tiger centipede, but I really don’t have a key or guide that I trust.

The centipede is really a neat animal. Primitive, segmented all over, even the antennae. Alien, though, is the word I think when I see it. Their eyesight isn’t good, their shell isn’t robust and they’ll dry out if left in the sun. I suppose this is why we haven’t seen any of these again.


We brought it in to share with the class. I think it was unwelcome since ti came home the same day.

Birds of My Yard

Most of these pictures were taken through a window, with insufficient telephoto and probably insufficient tripod use.  Nevertheless, you can tell what kind of bird they are, and for me that is interesting.

With luck, I’ll update these with better pictures over the summer, especially the hummingbird.

The broad-tailed hummingbird is my best guess at the identification of this bird.  The throat is reddish-purple, but for New Mexico Peterson’s would suggest that only the broad-tailed hummingbird is likely.

Broad Tailed Hummingbird

The spotted towhee was an exceptionally fun bird to see.  My son thought it might be an oriole—we’ve been laboring to attract those too.  He knew it was not a robin, describing it as having a “black head” and “orange breast”.  Pretty good for a four-year-old.  I don’t think I’ve ever seen a towhee before.

Spotted Towhee

The white-winged dove is the most prevalent bird in our yard.  They typically outnumber house sparrows and house finches.

White Winged Dove

The roadrunner photo credit goes to my wife—what a shot!  A mating pair appear to be nesting in the hedge in our front yard.  They are a shy bird, but their size and displays make for great entertaining.  Like a dog’s ears their topknot rises and flattens to indicate something of their state of mind.  Greater Roadrunner

Giant Juniper Berry

My wife took the baby for a walk yesterday, when the weather was nice.  She grabbed a juniper berry while she was out, because its size was astonishing.   It is pictured below, sitting a US quarter dollar coin.20100206_GiantJuniperBerry


This morning, in the back yard, the ants swarmed. The first picture shows the main cluster of the swarm, the posts in the background are railroad ties, which are about nine inches wide. The swarm footprint is a semicircle cut from a circle about 18 inches in diameter. There was no obvious reason why the ants were swarming. My son asked repeatedly why, and the best guess I could imagine is that two colonies were embattled.

None of the ants had wings, and there was no broad spreading of the swarm. Within two hours all that remained were a scattering of ant carcasses, the bulk of the swarm moved somewhere. This afternoon I will introduce them to boric acid. If you listened carefully you could hear the noise of all these ants moving, which was really surreal.

I do not know the species of ant nor their principal food. They were unaggressive and live in an area of the yard with abundant dirt and plants, it could be they are vegetarians. They do not seem to be damaging my plants, so it could be they are aphid ranchers or perhaps they just eat other invertebrates.

I Googled for “ant swarm” and other related terms; unfortunately, the bio-inspired “swarm” or “ant” algorithms for global optimization of undulating multivariate function spaces have poisoned Google for entomology. I had nearly the same experience with the Big Bee. If you have any thoughts or links, please post them as I am still quite curious. I would like to know why they might have been swarming, and anything interesting about the kind of ants.

Update late the same day

The ants came back in the evening. I noticed them around eight PM. They formed a larger and deeper mound than I saw this morning. Is this diurnal behavior? I have interfered in the research possibility by dusting them liberally with boric acid. I am unlikely to see them swarm again.

Really Big Bee

This morning I had the door open to enjoy some late spring fresh air. We had a visitor enter the house. She is perished, alas, but she is also the largest bee I have ever seen. Tip-to-tip, unfolded, she is just over an inch long without including her stinger. She sounded like a humming bird.

She spent the day at the clerestory windows, except for one short descent down the wall. At sunset she alighted on my infant daughter’s monkey toy which is weirdly orange. Perhaps she was desperate for nectar. I noticed that she was no longer at the clerestory window from the staircase, but it took my dog sniffing wildly in her vicinity for me to notice where she’d gone. The next picture has a millimeter scale. It is hard to appreciate her size since she is curled inward.

Look again at her stinger and the drip of juice on it. I understand bumble bee stingers are not barbed which means that they can sting multiple times and that they do not die after stinging. On the other hand, they are not particularly aggressive.

I have tried to identify her species, but do not have a good key available. I got some help from Fortune Favors the Bold, where the closest match is Bombus fraternus. Please post an identification or a link to a good key if you know of one.