Photographing the Triangulum Galaxy
&& [ astronomy ] && 0 comments

This will most likely be my last “Photographing X space thing” where X is some object we studied in Observational Astronomy at Cabrillo College. The first was Comet Jacques, a small icy object moving within our solar system. Next up was the beautiful Great Nebula in Orion, a star factory near to us in our own galaxy. Here finally we have the Triangulum Galaxy one of the closest galaxies in our local group.
It was a bit low in the sky, so the photo turned out slightly noisy. Overall, I’m again pleased with the result.
Astronomy 8A at Cabrillo was a great experience and I would recommend it to anyone with even the slightest interest in Astronomy. Hanging out with cool people 3 hours once a week, playing with telescopes, and taking photos on the big one in the dome? Yes please, will do again.
Photographing the Great Nebula in Orion
&& [ astronomy ] && 0 comments

The winter skies bring new treasures. The Great Nebula in Orion, also known as Messier 42, or just the Orion Nebula, is one of the brightest nebula in the night sky located in, you guessed it, Orion. The nebula is actually visible to the naked eye: to find it look at Orion and locate the 3 “stars” that make up his “sheath”. The middle star is not a star, it is the nebula.
Being so bright, M42 is one of the most photographed objects in the night sky so it was just a matter of waiting for it to be high enough for us to shoot at Cabrillo College. We took a series of 5 minute exposures, and after a bit of processing this is the result. It is a bit out of focus, but strikingly beautiful nonetheless.
Photographing Comet Jacques
&& [ astronomy ] && 0 comments

This is Comet Jacques. There are many photos of it online, but this one is mine.
This photo was taken on September 23rd, 2014 when the comet was about 1AU from earth, using a SBIG ST2000XCM color CCD camera mounted on a 12” Meade LX200.
It was a little late to be photographing this comet, but I couldn’t resist the opportunity to caputre it. And with all the excitement about the Rosetta mission recently, I thought it would be a great time to fix up the image. So here it is.
Building a trail map for Android using Ionic and Leaflet
&& [ code, cartography, granitemaps, featured ] && 1 comments

Edit 11/27/2014: GraniteMaps Santa Cruz is now available on the iOS store! link
It took me a while, but over the weekend I officially submitted my first app into the Google Play Store:
GraniteMaps: Santa Cruz is a digital trail map for those looking to hike, ride or trot the trails in and around Santa Cruz, CA. GraniteMaps: Santa Cruz provides an easy to read topographical map, current location, trail list, and extra information on local wildlife.
So technically, how did all this come together? Using a bunch of awesome libraries held together by dirty hacks, of course!
Ionic Framework
When starting a new project the first decision you make is which framework you want to use, if any. The decision usually depends on many factors: familiarity with the technology, maturity of the library, userbase, and of course the name. I’m a bigger fan of Doric architecture but I went with the Ionic Framework anyway because I am already familiar with web technologies. As a bonus your project gets to be “platform agnostic” - whether or not this is true I have yet to see.
Once you get past the unease of installing yet another node application globally getting started with the tooling is very easy. Ionic’s main executable can generate a basic skeleton app with a few tabs and some example code. Then it’s up to you to fill in the rest. Building and deploying to an Android device is a trivial, once you have the Android SDK installed. After bootstrapping the project the only commands I ever found myself running regularly during development were ionic serve to start the built-in development server, and ionic run android to deploy to my phone for testing.
Besides wrapping Cordova to get your webapp running in a web container on smartphones, Ionic is a collection Javascript and CSS libraries nefariously designed to deceive your users into thinking they are running a real app. It works well: your app will have native looking controls and transitions and respond to touch almost as well as native. Angular-JS is the weapon of choice to do the actual work, this should be great news to all those javascript kiddies already familiar with client side JS frameworks.
Ionic is opinionated in some areas and I’m fine with most of them but I must to complain about the choice of using ui-router instead of ng-route. ui-router is overly complex, impossible to understand and horrendously documented. Now that I think about it, so is ng-route. And pretty much the entire Angular library. So really I have nothing to complain about except everything. Moving on…
Leaflet
When it is convenient for me I like to tell Google to suck it. Luckily there exists this great library called Leaflet that is awesome for working with maps, so no Google Maps for me. Leaflet has all the features I need: custom tiles, GeoJSON support, and custom markers.
To generate awesome custom tiles, I used Mobile Atlas Creator. This lets you export a folder structure containing tiles that Leaflet can read instead of using an online source. In my case, I created tiles from USGS topographical maps.
To work with the actual GPS tracks, I used GPS Logger for Android to collect the data, and Viking to massage it into it’s final GeoJSON form.
Then it’s simply a matter of feeding the files to Leaflet. Simple, sort of. I decided to use an angular directive for leaflet instead of using the library directly so I could get some fancy two way binding and stuff. This directive turned out to be horribly buggy and I found myself using leafletData.getMap() constantly anyway to get direct access to leaflet. In hindsight I should have just saved myself the frustration and used leaflet.js directly, which was nothing but awesome.
I did start to see a performance hit as I got to adding the maximum number of trails in the app. On some older phones, it is visibly laggy. This is one of the trade offs you must make when decided to use something like Ionic instead of native. All in all though, performance was good.
Conclusion
Ionic: Good. Leaflet: Great. Actually riding: Better than both.
Building this app was an enjoyable and educational experience. With a few tweaks, I wouldn’t hesitate to use the same stack again, especially as Ionic is continually improving.
As for the app itself I admit it is rewarding to have an app in a smart phone store that you can tell your friends to install. If anyone will actually use it remains to be seen. I even managed to squeeze an easter egg in. There are trails in that map that are hidden, and only nofreds can access them with special knowledge. Good luck and thanks for reading.
Making ng-grid scroll and select naturally with arrow keys
&& [ code ] && 0 comments
The default behaviour of angular’s ng-grid library while using multiselect is a little strange.
By default using the arrow keys will select multiple rows. I was looking for behaviour that would only select rows if ctrl or shift were being held.
ng-grid also seems to have an issue with not showing the currently selected row in the viewport, causing the table not to scroll properly. The following code placed in your gridOptions object addresses both issues:
{{< highlight javascript >}} beforeSelectionChange: function(rowItem, event){ if(!event.ctrlKey && !event.shiftKey && event.type != ‘click’){ var grid = $scope.gridOptions.ngGrid; grid.$viewport.scrollTop(rowItem.offsetTop - (grid.config.rowHeight * 2)); angular.forEach($scope.myData, function(data, index){ $scope.gridOptions.selectRow(index, false); }); } return true; }, {{< / highlight >}}
Here is a plunker demonstrating how the table behaves:
Happy coding.
A Troop of Monkeys Crosses the Road
&& [ photography, featured ] && 2 comments
Over the last week in Nicaragua I’ve seen a lot of new and interesting wildlife. I spotted a fearless pygmy owl on my first day here that let me get within 10 feet while shooting photos! Last night we went to a beach to watch some sea turles lay their eggs, that was pretty cool too. But it’s hard to beat the mantled howler monkey.
These guys are abundant here in SW Nicaragua, and there are several troops alone in Balcones de Majagual. Yesterday I was fortunate enough to witness an entire troop (troop is a group of monkeys) pass me by overhead. Where the road cuts through the forest the canopy is thinned, this makes it difficult for the monkeys to cross as there are few suitable areas to do it. Lucky for me, I just happened to be directly underneath such an area.
Most of the howlers were too quick for me to catch on camera, but there were two younglings in the troop, and the adults they encumbered moved slow enogh that I was able to get some awesome photos.
The tails are amazing. Notice how the youngling’s tail wraps around the adult’s in order to fasten itself on.
If only I could have caputres the sound as well. The quiet ooh ohh ahh ahhs of encouragment spoken from the already crossed howlers to the ones still working up the courage to make the jump were priceless.
Check out this animated gif of an adult howler making the crossing, but oh no! She’s left something behind!

But the youngling must get to the other side and so she does. Not without taking a second to check me out on the way!

How great is community college?
&& [ astronomy ] && 0 comments
Pretty great.
I recently began taking classes at Cabrillo Community College in Santa Cruz California out of interest in astronomy. The college offers an AS that is pretty impressive: it requires an (expected) amount of physics classes but also includes many astronomy specific classes dealing with planetary science, cosmology and observational astronomy. I was surprised and impressed after I took a look at the catalog - it didn’t take me long to enroll.
I suppose I was expecting to be sharing classes with the stereotypical community college crowd.

But I was very, very wrong. Many, if not most, of the students seemed genuinely interested in being there. How could this be? Community college was supposed to be the place you went because you had to, not because you wanted to. I was expecting a class full of bored teenagers taught by a washed up high school teacher looking for a paycheck.
Instead I found a class full of (mostly) willing students taught by Dr. Rick Nolthenius, an accomplished, published astrophysicist. Instantly my perception of community colleges transformed from state mandated academic detention centers to bastions of democratic learning. Here was a place where one could educate themselves in a variety of subjects, with tons of flexibility, on a beautiful campus, all for less than the cost of a Netflix subscription.
Somewhere, sometime, I had gotten the wrong impression.
Now I’m not saying I regret getting my BS. But so far I am very impressed with the value I receive from this public institution as well as what it represents. I see it as something completely different from a university education. For many people receiving a standard degree from a four year university proves they can learn when they must, not because they want to. People will put themselves in obscene amounts of debt to receive a degree because the real world job market demands it. Employers want workers that have the ability to learn how to do a job quickly and effectively.
On the other hand those going to local colleges just for the sake of learning are receiving an education with no ulterior motives. Judging by academia a class at a community college has very little worth and actually this liberates the student to be educated. It means the value derived by the student is 100% intrinsic - the opposite of the perceived value of a prestigious university degree. In this way the student can focus on the content of what they are learning instead of attaining the certification of having done so (thinking critically instead of cramming for tests).
So obviously I am now a fan of community education. I really wish it was more popular, but I’m afraid the lack of involvement may come from people’s preoccupation with their day to day lives, or more likely their simple non-desire to continue educating themselves. But that’s OK. Smaller class sizes are great :)
Observations on observational astronomy
&& [ astronomy ] && 0 comments
Astronomy: So hot right now.
We have the a spacecraft rendezvousing with a comet right now for the first time in history and in a year we’ll get our first look at the has-been planet Pluto with the New Horizons spacecraft. In about 3 years, we’ll be treated to a total solar eclipse right here on the west coast.
I’ve been doing a bit of astronomy myself. While I’ve always had an interest, it never occurred to me that amateur astronomy could be a realistic hobby. I wrongly assumed even the cheapest telescopes would be thousands of dollars, ones powerful enough to see anything interesting at least. How wrong I was.

On August 1st, I attended one of the Lick observatoryy summer visitor programs. I got to observe the cats eye nebula through the 40 inch Nickel telescope (Nickel is a name, not the element) and a star cluster I can not remember the name of through the 120 year old 36 inch James Lick telescope. I left a changed man. Not only did my visit confirm my thoughts that, yea, astronomy is pretty rad - I met some very cool amateur astronomers that had great advice for any newbie interesting in exploring the cosmos. I went home that night seeing stars.
Fast forward all of 12 hours and I’m driving back over highway 17 again, this time with a freshly purchased amateur telescope in the back of my car. I’m not sure I’ve ever looked forward to nighttime before but I sure did that night.
First came the moon and her craters before it even got dark. Tycho forever became more than a band for me. Then came Saturn. I don’t know if I had ever seen Saturn through a telescope before that moment, but it felt like the first time. Those rings… I was hooked.
I tried my hand a public outreach too. A week or so later I attended a full moon event at Henry Cowell and let the public peer though my new scope. I showed many children and adults too their first look at both the moon up close and Saturn’s rings. Saturn in particular literally wow’d people. It felt fantastic.
Since then I’ve gone to a star party at Henry Coe, observed many more objects in the night sky (moving through the Messiers) and exchanged my telescope for a monster 10 inch Newtonian (it works much better for me).
What’s next? Learning, learning, more learning. Astronomy is really a hobby of the mind. And the best part about it is that I yet know Nothing about it.

I decided to craft some clickbait. What happened next will shock and disgust you
&& [ code ] && 0 comments
As evidenced by this website, every once and a while I’ll write something. Although my regular readership approaches nil when you take my mother, google bot, and myself out of the running I’ll still post a link to facebook and see if I can get some clicks. Usually I’ll get 10-20 visits (thanks guys!) and I’ll leave it at that.
Yesterday I was scrolling down my facebook news feed (something I try not to do anymore) and realized my feed was filled nearly completely with crap headlines like this:
“The 9 Most Epic Texting Pranks Of All Time. The 3rd One Killed Me…LOL!”
“The Scary Reason Illinois Just Banned Your Facewash”
“Obama Just Did What No Other President Before Him Has Done”
The first post is just dumb. That person is no longer on my friends list. The other two headlines could be about something important, but what’s up with the baity headlines? Just say what Obama did. Judging by the image they used he was the first president to order the extra spicey schezuan shrimp.
I wondered if I could play the game that sites like Buzzfeed, Upworthy and the Huffington Post have become so good at. And the result was this:

However, the link actually pointed to this page. I considered it a PSA, and thought I’d probably get the same amount of clicks that I usually do for a blog article I post.
Nope.
As of now, the page is up to 350 views. Thats 10x more than a “good article” I write ever gets. I didn’t even know I knew so many people that would click on something so obviously terrible. Yet there it is, in plain, cold truth.
Appealing to the lowest common denominator obviously works. Once I somehow regain my faith in humanity, I’ll think about possibly taking advantage of this fact.
And no, I’m not going to post this on facebook. Because screw you guys.
Getting the Time Right in Python
&& [ code ] && 9 comments
I hate time. I especially hate dates. There is not a single data type I hate working with more.
I think the problem boils down to the fact that they seem so arbitrary. The Gregorian calendar just doesn’t translate over well to binary systems. Ideally, there would be 100 seconds in every minute, 100 minutes in every hour, 100 hours in every day, etc. But no. We must deal with weird numbers like 60, 24 and 31 (but sometimes 28, or maybe 30) and all the inconsistencies they cause.
</rant>
I’m going to lay out some of the modules and function in Python relevant to working with time.
The time module
Documentation: https://docs.python.org/2/library/time.html
The time module is the most basic module when working with time in python.
time.time() returns the time in seconds since the unix epoch:
{{< highlight python >}} time.time() Out[1]: 1398882554.878436 {{< / highlight >}}
I’ve found that most operations dealing with time usually boil down to converting something into a unix timestamp and then perform operations on them. For example:
{{< highlight python >}} In [1]: a = time.time() In [2]: b = time.time()
The first command was executed before the second, so a’s second value is less than b’s.
In [3]: print a < b True {{< / highlight >}}
time.time() itself is pretty limited. We can’t easily deduce from a unix timestamp the human measurements of time, like minutes hours and days. The timestamp also doesn’t contain any timezone
information.
Oh god, timezones.
Timezones are a bitch. When doing anything with time, they must always be accounted for.
A computer in New York that runs time.time() at the same one as one in California will return
different values. No, it has nothing to do with a New York minute being any faster than a minute in California, it has everything to do with localtime.
Let’s take a look at two more methods, time.localtime() and the terribly named time.gmtime():
{{< highlight python >}}
In [1]: time.gmtime()
Out[1]: time.struct_time(tm_year=2014, tm_mon=4, tm_mday=30, tm_hour=18, tm_min=39, tm_sec=33, tm_wday=2, tm_yday=120, tm_isdst=0)
In [2]: time.localtime() Out[2]: time.struct_time(tm_year=2014, tm_mon=4, tm_mday=30, tm_hour=11, tm_min=39, tm_sec=45, tm_wday=2, tm_yday=120, tm_isdst=1) {{< / highlight >}}
time.localtime() returns a named struct for the localtime, whereas time.gmtime() returns the time in Coordinated Universal Time. Why the method is named gmtime and not utctime I have no idea,
but I can only assume ‘gm’ stands for Greenwich Mean time which should be avoided.
Take a look at tm_hour element.
{{< highlight python >}} In [1]: gmtime = time.gmtime()
In [2]: localtime = time.localtime()
In [3]: print gmtime.tm_hour - localtime.tm_hour 7 {{< / highlight >}}
You can see that the times differ by 7 hours. That’s because my computer in located in Santa Cruz, CA. Which as well as being the best place on earth, is located in the Pacific Time Zone, which is UTC - 8. But wait, why did we get 7 as the time difference?
Because daylight savings time, that’s why. Add another point to time’s suckiness score.
At least we can figure out if we are in daylight savings or not:
{{< highlight python >}} In [1]: time.daylight Out[1]: 1
Looks like we are in daylight saving time! I’m just having the best time ever!
{{< / highlight >}}
We’ll talk about timezones in python more a little later.
Additional Methods
time.mktime(t)
Takes a named struct like the ones returned by time.localtime() and time.gmtime() and converts it to a unix timestamp:
{{< highlight python >}} In [1]: time.mktime(time.gmtime()) Out[1]: 1398921105.0 {{< / highlight >}}
Not terribly useful in that context, but you’ll want to use it in conjunction with:
time.strptime(string[, format])
Takes a string and parses out a time in the format of a named struct, the same format that time.localtime() and time.gmtime() use. Format is built using directives which
can be found here:
{{< highlight python >}} In [1]: today = time.strptime(‘4/30/2014’, “%m/%d/%Y”) In [2]: time.mktime(today) Out[2]: 1398841200.0
{{< / highlight >}}
time.strftime(format[, t])
This method takes the time and prints it in a human readable format. Well, sort of. It formats a String From the Time. (StrFTime) so its up to the programmer if he wants to make it readable or not:
{{< highlight python >}} In [1]: time.strftime(‘%m/%d/%Y’) Out[1]: ‘04/30/2014’
In [2]: time.strftime(“‘Tis the %dth of %B which is the %wrd day of the %Wth week of the year %Y”) Out[2]: “‘Tis the 30th of April which is the 3rd day of the 17th week of the year 2014”
In [3]: time.strftime(“The time is %H:%M”) Out[3]: ‘The time is 13:55’
{{< / highlight >}}
The datetime module
You could do everything you wanted to do with the time module alone. But in most cases, you would
be insane to do so. the datetime module provides some high level functionality for working with dates. From the documentation:
While date and time arithmetic is supported, the focus of the implementation is on efficient attribute extraction for output formatting and manipulation.
Basically, we want to be able to do thing things like “add one week to this date and print the result” without going batshit insane.
One of the main gotchya’s with the datetime module is the concept of naive vs aware time objects.
Aware objects are “aware” of timezone and daylight savings time. So a datetime of 4:00am, 1st of April 2014 that is aware and set to PST, would represent 7:00am, 1st of April 2014 in EST.
“Naive” dates represent absolute values. The same object representing 4:00am, 1st of April, 2014 would still read 4:00am, 1st of April, 2014 in PST and EST.
Let’s check out an example using the pytz module to help with timezones:
{{< highlight python >}} import datetime import pytz
Set the timezones
In [1]: eastern = pytz.timezone(‘US/Eastern’) In [2]: pacific = pytz.timezone(‘US/Pacific’)
Make 2 dates using the same naive datetime, and localize them to the timezone.
In [3]: eastern_dt = eastern.localize(datetime.datetime(2013, 10, 1, 12, 0, 0)) In [4]: pacific_dt = pacific.localize(datetime.datetime(2013, 10, 1, 12, 0, 0))
subtact the time
In [5]: diff = pacific_dt - eastern_dt
In [6]: diff.seconds Out[6]: 10800 # 3 hours {{< / highlight >}}
Basically, working with timezones is a pain. It’s best just not to do it and always store time in UTC, converting to localtime for display purposes only using a method like datetime.datetime.fromtimestamp()
The datetime.date object
the datetime.date object is about as close as you can get to representing a “date” as most people understand them in code:
{{< highlight python >}} In [1]: today = datetime.date.today() In [2]: print today 2014-04-30
In [3]: print today.month 4
In [4]: tomorrow = datetime.date(2014, 5, 1) In [5]: print tomorrow.month 5
{{< / highlight >}}
You can convert the date into the format heavily used by the time module:
{{< highlight python >}} In [1]: first_of_this_month = datetime.date.today().replace(day=1)
In [2]: first_of_this_month Out[3]: datetime.date(2014, 4, 1)
In [4]: first_of_this_month.timetuple() Out[4]: time.struct_time(tm_year=2014, tm_mon=4, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=1, tm_yday=91, tm_isdst=-1)
In [5]: time.mktime(first_of_this_month.timetuple()) Out[5]: 1396335600.0
In [6]: datetime.date.fromtimestamp(1396335600.0) Out[6]: datetime.date(2014, 4, 1)
{{< / highlight >}}
The datetime.date object has other useful methods such as date.isoformat() which prints the date in ISO 8601 format (YYYY-MM-DD) and date.strftime() which functions the same as time.strftime() allowing you to print dates in whatever format you’d like.
The datetime.datetime object
datetime.datetime is the same as datetime.date except it includes time data as well.
{{< highlight python >}} In [1]: datetime.datetime.today() Out[2]: datetime.datetime(2014, 4, 30, 15, 20, 15, 86516) {{< / highlight >}}
Remember to watch out for TZ gotchyas.
The timedelta object
A timedelta object represents a duration - meaning the difference between two times. Thus it helps us set times in the future or past.
Lets try a simple use case. Print the time one week from today:
{{< highlight python >}} In [1]: today = datetime.datetime.today() In [2]: print today 2014-04-30 16:58:02.663769
In [3]: print today + datetime.timedelta(weeks=1) 2014-05-07 16:58:02.663769 {{< / highlight >}}
We can also obtain timedelta objects from performing arithmetic operations on datetime objects:
{{< highlight python >}} In [1]: today = datetime.datetime.today()
In [2]: print today 2014-04-30 17:02:00.378875
In [3]: future = datetime.datetime(2014, 11, 1)
In [4]: print future 2014-11-01 00:00:00
In [5]: print future - today 184 days, 6:57:59.621125
{{< / highlight >}}
Stuff to remember
- It’s a good idea to always store time in UTC. Convert to localtime as late as possible.
- Use the high level libraries as much as possible. You may think you can pull off using
time.time()when in reality, you’re forgetting in your calculations that this month has 31 days instead of 28. The higher level libraries are good at taking these inconsistencies into account. - Stay sane, go outside, hug your mother.