Tuesday, March 19, 2013

Python Programming Programme

The first three days of this week we're having a Python training course at my work, which I've been attending. Having no formal training in Python (or any computer language for that matter), I've been looking forward to this. While the first day was mainly an introduction to Python itself (and thus covered a lot of what I've learned myself), I still learned several new things, including some that have been mysteries to me for years.

Today we dove into efficient numerical processing with the NumPy package, something I don't really have much experience in (although much of the morning was spent working with the matplotlib graphing package, which I have been working [and struggling] with extensively for the last three weeks). I was quite excited at the end of the day when I managed to read a FITS image and display it, with a crude image stretch, entirely with Python code. It was quite exhilarating. It was cool to discover that our instructor was also an amateur astronomer, and used code he'd written to help process his images.

Tomorrow we're supposed to jump into the SciPy suite of scientific tools. I've at least used NumPy a little bit from time to time, but I haven't ever really found a need to use SciPy before so this should be very informative.

Saturday, March 16, 2013

Pi Day!

So it turns out that Pi Day was this past week (3/14), and I forgot all about it as usual. However, entirely by chance, I actually engaged in some appropriately pi-involving activities that day, and thought I'd put it up here.

It started with me and some coworkers at tea-time in the break room, where there was a newspaper-insert advertising a set of nine miniature pizzas for sale. One of my coworkers jokingly said that it was a ploy by the pizza company to sell half the pizza for the same cost.

There was a pause of a few seconds during which I could practically see the wheels turning in his head. I'm sure I looked the same way, as we both mulled over the implications of what he had said. “Actually...”

We both dived for calculation tools, and began scribbling figures and formulae. The result was interesting enough that I thought I'd share it.

First of all, assume the following picture (representing an idealized pizza in a box):


This pizza has an area of \(\pi r^2\). Now, take a look at the following picture, representing nine miniature idealized pizzas in a box of the same size:



The radius of each of these mini-pizzas is \(1/3\) that of the original pizza, or \(r/3\). Thus, the total area of the pizzas is \(9\times\pi(r/3)^2=9\times\pi(r^2/9)=\pi r^2\). Which is exactly the same as the original, single pizza! So the nine mini-pizzas actually give you just as much bang for your buck as the single large one. (In reality I've ignored some details, such as the fact that the nine pizzas have twice the circumference as the single one so you're getting twice as much crust, which means that the actual area covered by condiments will be slightly smaller than the single pizza.).

I noticed something else interesting about this. Let's imagine an arbitrary number of little circles packed into a square in a regular grid, such as that shown in the picture above. We'll let \(n\) stand for the number of circles on a side. Then the area of the pizzas is \(n^2\times\pi\times (r/n)^2=\pi r^2\). The circumference, however, is \(n^2\times2\pi\times(r/n)=2n\pi r\). So if we take the limit as n goes to infinity – if we imagine squashing more and more smaller and smaller circles into the square – the area stays constant, but the circumference goes to infinity. Yet the area of the circles remains \(2\pi r^2\). So if we imagine throwing darts randomly at the whole area, we would always have the same change of hitting the underlying square. (The area of the square is \(4r^2\), the circle area is \(2\pi r^2\), so the ratio of their areas is \(4r^2/\pi r^2=4/\pi\approx1.2732\). Thus the chance of hitting the square rather than one of the circles remains a constant \(1-(1/1.2732)\approx0.2146=21.46\%\).) So even though there could be an infinite number of circles, with an infinitely long cumulative circumference, you'd still have exactly the same chance of hitting one (78.54%) as you would if there were just one circle.

It reminds me a bit of the Koch Snowflake, a geometrical figure with an infinitely long perimeter that encloses a finite area.

Sunday, March 10, 2013

In Search of Platyhelminths

"What on Earth is a platyhelminth?", I hear you ask.

A platyhelminth is a flatworm, from the Greek roots πλατύ- (platy) meaning "flat" and ἑλμνθ- (helminth) meaning "worm." Platyhelminths are pretty amazing creatures that lack some of the features we multi-cellular animals find pretty important, such as a digestive system. And a respiratory system.

Now, there are many other creatures out there lacking those systems that make their livings as parasites, and while it's true that there are a lot of parasitic platyhelmithes, there are also a decent number of them out making a living for themselves just fine without these trivial systems that we might consider indispensable. They do it by having a very simple body plan. It has to be, because the only way for oxygen and nutrients to reach all their cells is by diffusion, which has practical limits on how far it can work.

Within the platyhelminths, there is an order called Tricladida, whose members are commonly known as planarians. They have some remarkable regeneration abilities; some of them reproduce by simply leaving their tails behind, which then grow into a whole new planarian! In fact, cutting them into pieces merely causes all the various pieces to regrow into new flatworms. There have even been experiments performed where people cut a planarian's head in half longitudinally, and both halves regrew into new complete heads, leaving a two-headed planarian! (I have never heard if anyone ever took this to the logical next step and created a nine-headed hydra planarian.)

Planarians, like the rest of the platyhelminths, are mostly very small creatures, a few inches long at the most. This is due to their simple body plan as mentioned above. But there is one species, Bipalium kewense, that grows much longer than that, reaching up to 60 cm (about 2 feet) in length! What's even more interesting is that this particular species lives on land rather than in water...and it lives in Hawai‘i. (They also live in many other parts of the world besides Hawai‘i, having been inadvertently introduced around the globe by humans. They are believed to be native to Southeast Asia, however.)

Often while walking in the early morning I would see these strange, worm-like creatures sliding along across the sidewalk without knowing what they were. Recently though, I learned that B. kewense was the largest known planarian in the world and realized that was what I had seen all those times, at which point I thought it would be neat to get some pictures or maybe a video of one of them.

With that goal in mind, I got up early one morning this past week and set out to look for them before going to work. After a lovely early-morning walk of twenty minutes' duration along the sidewalk next to the uncleared jungle on the UH campus, I found what I was looking for, a B. kewense a good eight inches long out for an early-morning squirm.

Bipalium kewense on a sidewalk in Hawai‘i.
I realize that picture doesn't give you much sense of scale, so here's another one with my hand in it for comparison:


(I discovered that it's really difficult to hold a phone in one hand to take pictures while trying to position your other hand and an oblivious piece of wildlife in a nicely framed photograph taken by that same phone.)

You may be wondering about the shovel-shaped appendage on one end of this particular flatworm. That's its head, and it contributes to their endearing common name of "hammerhead slug," despite them not being related to slugs at all (other than both of them being in the kingdom Animalia). Here's a closeup if you want to see it better:

Close-up of the head of B. kewense, also called the "hammerhead slug."
(Apologies if you did not, in fact, want to see it better.)

I don't think the reason for the head's peculiar shape is exactly known, but since they are known to eat earthworms, it may serve as a method to increase the area of their sensory apparatuses, allowing them to better find and follow earthworm tracks.

Finally, if you'd like to see one of these strange creatures in glorious motion, you're in luck! I took a video (if you don't care enough about the planarian to watch the video, there's also some nice early-morning birdsong recorded in it):


All in all, planarians are fascinating creatures, and I think it's really neat to be able find them in the wild around here.

Sunday, March 3, 2013

Snow Chains and Volunteering

Though thankfully unrelated.

Last Friday I had some Snow Chain Installation Training, which was interesting because I've never installed snow chains before, never having lived any place where they would actually be necessary. Having said that, I was under the impression that it involved driving the vehicle to be snow-chained over and onto the chains with which to snow-chain said vehicle. However, the chains we have (at least for some of the vehicles) are a different design that simply engulfs the wheel like a hungry starfish engulfing a tasty bivalve. No driving involved, other than simply driving off afterwards with snow chains attached.

All of it which underscored by the fact that I have no official reasons to go up to the summit in an official vehicle as part of my job at the moment, and would be extremely unlikely to do so on a day which was snowy enough to require chains if I ever did. But at least it was interesting.

Also, tonight I went up and volunteered at the Visitor Information Station for the first time since I've been back. I could tell I needed to build up my high-altitude tolerance again! It was a beautifully clear night, though the biting wind drove most people away after a few hours (I also need to build up my cold tolerance again). An enjoyable evening altogether, though, and I got a chance to catch up on what the sky's been doing the last few months (which is hard to do with all the clouds in Hilo). I'm hoping to get back into the astrophotography scene soon as well. Anyway, I should get to bed to be ready for work tomorrow. A hui hou!

Sunday, February 24, 2013

Anonymous Functions

There's a certain joy that comes of figuring out something yourself that you don't really get when someone else teaches you (although the best teachers teach in such a way that you're constantly figuring things out yourself).

I've never taken a computer science class in programming, so most of what I've learned I've figured out for myself. There are many little milestones along the way, but there are some big ones that stand out as large leaps forward in understanding. The day I suddenly understood classes in Python, for instance. I'd read the documentation on them several times before, but had never been able to make heads or tails of it, until the day when I really needed to use one...at which point it all suddenly clicked, and I reread the documentation and understood everything. It was an exhilarating, empowering feeling. My abilities as a programmer grew a bit that day, and I've used classes often since to write better code than I otherwise could have.

Last Friday I had a similar experience, suddenly understanding lambda functions in Python (known more generally as anonymous functions). (I also understood two specific functions last week, but that's not quite as interesting or exciting as understanding a whole new class of object.)

Lambda (or anonymous) functions are functions that you create when you don't need or want to go to the bother of defining a full-fledged function. Sometimes all you need is a simple function for one particular part of your code that you don't intend to use anywhere else, for instance if you need to square each item in a list of numbers. It's such a trivial thing that it isn't worth the trouble of writing a separate function for, especially if that's the only place you're going to need it.

Instead, you can write a simple lambda function to do the work for you. For example, given a list of numbers:

someList = [1, 2, 3, 4]
for number in map(lambda x: x * x, someList):
    print(number)
This code would then print out 1, 4, 9, 16. (Incidentally, the map function is one of the other functions I understood last week, as it works closely in conjunction with lambda functions.)

Basically, the map function takes all the items in an list (such as someList) and applies another function to them. The "lambda" there signifies that I'm defining a function, and the "x" means that it's only got one variable; the part after the colon, "x * x" means to take the input of the function and multiply it by itself (squaring it). So, "take each item in someList, and multiply it by itself". The print(number) part simply tells the computer to display the results of the operation on screen; it has nothing to do with printing on paper.

Anyway, it's really wonderful to be exercising the creative aspects of my brain in my job, and learning new things as I go along. A hui hou!

Tuesday, February 19, 2013

Multilingual Machine

Partly as a result of my new job, I've begun stopping at the local Subway restaurant more often for lunch. Having also developed an appreciation for toasted sandwiches I've had ample time to notice things about the place while waiting for my sandwich to toast, including the fact that the toaster oven is apparently multi-lingual.
The LCD panel that displays things like the time helpfully informs people that the door is open whenever it is, but it does so in different languages each day. I've seen it in English, Spanish ("la puerta está abierta"), Portuguese ("a porta está aberta"), French ("la porte est ouverte") and even German ("Tür ist offen").
I'm not sure if the machine rotates of its own accord in an oddly touching attempt to facilitate communication with as linguistically diverse a group of sandwich-toasters as possible or if it's trying to teach them new languages one sentence at a time, but it's fun to notice. I wonder if the ovens in other Subways do it as well? Anyone care to confirm or deny?

Monday, February 18, 2013

Mystery Meteor (and poor upstaged 2012 DA14)

Given the amount of news coverage it's received, I doubt many of my readers are unaware of the meteor that exploded in Earth's atmosphere over Russia last Friday.

However, in case some of you are: at about 9:20 in the morning (local time, and I'm not even going to bother trying to convert) on February 15, a meteor entered the atmosphere and exploded over the city of Chelyabinsk, Russia. It and its effects were recorded on dozens of different cameras, and boy howdy did it have an effect. It briefly outshone the rising morning sun in brightness (!) before exploding in the atmosphere with a force comparable to a good-sized nuke, shattering windows in at least six cities around the region, collapsing the roof of a nearby zinc plant, and putting over a thousand people in the hospital (mostly with injuries from the flying glass caused by the explosion). (Contrary to what is commonly assumed, things entering the atmosphere don't heat up because of friction, which is negligible at that speed, but because they're traveling so fast the air in front of them doesn't have time to get out of the way and is instead compressed. And compressing air makes it hotter, which causes it to glow at visible wavelengths.)

By remarkable coincidence, this meteor struck the Earth only about 15 hours before the (expected) closest approach of the asteroid 2012 DA14, which whizzed harmlessly past as predicted and pretty much got lost in the commotion. Astronomers world-wide will now have to spend countless hours trying to refute the conspiracy theories that we knew about this beforehand, or that the predictions about 2012 DA14 were wrong and the objects were related (which they weren't, coming from almost completely opposite directions). C’est la vie for an astronomer, though.

Anyway, there are no hard numbers on the impacting object, but there are some educated guesses. Estimates of its size range up to 7,000 tons, making it the largest object to strike the Earth since the 1908 Tunguska event that flattened trees over 1,250 square kilometers (830 square miles) in a remote part of Siberia. The Tunguska event due to its remote location had very few witnesses so details are sparse, but it is estimated to have released energy on the order of 10-15 megatonnes of TNT (about 43-62 petajoules). This was actually about 20 to 30 times more than the energy from the meteor that hit on Friday, which is estimated at about 300-500 kilotonnes of TNT, (2,100 terajoules, about 2.1 petajoules). However, that amount is still about 20 to 30 times larger than the amount of energy given off by the fission bombs dropped on Hiroshima and Nagasaki. The explosion it caused was large enough to register on systems that listen for clandestine nuclear tests.

(Note that I'm calling these event "impacts" and saying they "struck the Earth", despite the fact that neither object actually hit the ground. From the point of view of an astronomer, the atmosphere is a practically infinitesimally thin covering compared to the size of the Earth itself, so something hitting it is basically equivalent to hitting the Earth.)

It's a good thing this object – estimated to be perhaps 15 meters (50 feet) across, smaller than 2012 DA14's 50 meters (160 feet) – hit the atmosphere at the low angle it did (about 20 degrees) rather than more head-on, considering it was probably traveling at 15 kilometers per second, over 10 times faster than a bullet from a high-muzzle-velocity rifle. Videos of the event show what appear to be two separate contrails, implying the object split up prior to entering the atmosphere (it may even have been a binary asteroid). Exploding as it did with the power of a mid-sized nuclear bomb, it's a miracle nobody was killed, though Russian sources still report almost 1,200 people checked into hospitals as a direct result.

This number of injuries and the amount of property damage it did, though, instantly catapults this object to the top of "most destructive meteor in recent history". Prior to this, there have been reports of one or two people hit by (small) meteors with no lasting results, and unsubstantiated reports of a dog in Egypt killed by a meteor in the early 1900s. It's going to be very, very, interesting to see what, if anything, this event does to change public perceptions of asteroids. Objects this size are predicted to hit the Earth about once a century, and astronomers have long been aware of much larger objects – such as 2012 DA14 – that also have the potential to hit the Earth.

Up until February 15th, though, it's always been a pretty theoretical argument. Astronomers have had a hard time convincing people to give them money to build monitoring systems that could warn us of such things in advance because there wasn't much in the way of perceived need, although thankfully the U.S. government has put some money into building such systems, such as the PanSTARRS telescope located on Haleakalā, Maui. However, this object, which could have obliterated the city of Chelyabinsk rather than merely damaged it had it come in at a different angle, would have been very difficult to detect before it hit with the current asteroid-detection systems we have (as evidenced by the fact that we didn't detect it prior to impact). Astronomers estimate there are still tens of thousands of objects capable of destroying cities out there that we haven't found yet, and it's only a matter of time until one hits us again.

Of course, simply knowing something is going to hit you and destroy X city or cause widespread tsunamis around the shores of Y ocean isn't very useful unless you can do something about it. I'll be honest: we don't actually know if we could stop an asteroid from hitting the Earth. But that's mostly because we've never tried, because we've never seen a strong enough need to do so, because asteroids have always been "something up there that doesn't bother us". I'm sorry for the pain of everyone who was hurt by this asteroid, but I hope that it will help wake up the general public to the fact that asteroids are not just a theoretical danger – that living on the exterior of a giant ball of rock hurtling around the sun at 30 kilometers per second, surrounded by thousands of similarly-speedy rocks is not necessarily safe. And maybe, just maybe, the next time one of these objects is going to hit us we can spot it while it's still far enough out for us to do something about it.

Monday, February 11, 2013

A Long Day of...Not Work.

I got in to work this morning only to be informed that the internal office network was down, barring everyone from logging on to their computers and bringing productive work to a screeching halt (except for the people with laptops and stuff able to be done on them). We weren't sure how long it would take to fix, so everyone waited around (more or less) the whole morning, before our boss told everyone not to bother hurrying back from lunch since it didn't look like it was going to be fixed very soon. After a nice relaxing two-hour lunch break I spent another hour twiddling my thumbs and reading up on a book about the Perl scripting language one of my coworker had lent me, before our boss finally called it a day at afternoon tea and sent everyone home early.

So that was an interesting experience. Hopefully things will be back to working tomorrow, and I can find out if my projects I left running over the weekend finished successfully.

(Edit: Thankfully, my computer was back up and running by Tuesday, and everything else was up by Wednesday, so I managed to still be fairly productive this week.)

Sunday, February 10, 2013

Weather in Hilo

One of the nice things about living in Hilo is getting to see weather displays like the one below from time to time.

This comes from the Sun going down above the roof of the building next to where I work. It had been raining off and on all day, and on my way to work in the morning I was actually trying to get pictures of the puddle-reflection of a vibrant rainbow that was in the sky. None of them really came out well enough to post, sadly. Maybe next time. It sure made a pretty reflection in the puddle, shivering each time a drop of water well from the power line above or a passing car stirred the surface in its wake.

Sunday, February 3, 2013

Experimental Fudge

So having (re)discovered last year how easy it is to make fudge, and being the fudge-lover I am, it is perhaps not too surprising that I would begin experimenting with different kinds of fudge, as I tend to do with every new recipe I learn to make.

This time, specifically, I was waffling between different brands and bag sizes of chocolate chips at the grocery store, when I noticed a bag of white chocolate chips. I love white chocolate, so on a whim I bought some and used them to make fudge over the weekend.

It actually turned out quite good, something I wasn't sure of given the different compositions of white and regular chocolate. It may have helped that I deviated slightly from the recipe and kept heating it after I was supposed to stop to make sure all the marshmallows and white chocolate chips melted, which made it nice and molten when I poured it into the pan.

So, the conclusion appears to be that white chocolate chips are a perfectly suitable substitute for brown ones in fudge, although the resulting product may be ever-so-slightly crumblier than normal. It still tastes delicious, though. Try it sometime!