Upgrading Wheezy to Jessie: Nginx and PHP5-fpm

&& [ code ] && 1 comments

I just upgraded this VPS from Debian Wheezy to Jessie. The upgrade went pretty flawless, excpet some minor issues with postgres and the new bad systemd smell.

However, if you are running NGINX + PHP5-fpm, you may want to read the news that gets displayed during the upgrade:

nginx shipped a modified `fastcgi_params`, which declared `SCRIPT_FILENAME`
fastcgi_param. This line has now been removed. From now on we are also
shipping fastcgi.conf from the upstream repository, which includes a sane
`SCRIPT_FILENAME` parameter value.

So, if you are using fastcgi_params, you can try switching to fastcgi.conf
or manually set the relevant params.

After the upgrade, I was getting blank responses from nginx for all php scripts. No errors in nginx or fpm logs. After re-reading the news above, the following fix worked for me:

In /etc/nginx/sites-available/* change

include fastcgi_params

to

include fastcgi.conf

Hope this helps anyone in need.

100 Observations Logged on AstroChallenge!

&& [ featured, astrochallenge, astronomy, code ] && 0 comments

2015-04-13-100-observations-logged-on-astrochallenge.markdown

I created AstroChallenge to scratch my own itch: to have a place to keep an observation journal for astronomy and to share it with the rest of the community. In that I believe I’ve succeeded, check out my profile and journal.

Since then the word has gotten out and other astronomers have been logging their own observations. Now, only 2 weeks after making AstroChallenge public, over 100 observations have been logged! I want to thank everyone who has helped me make AstroChallenge awesome by providing great feedback and ideas.

It’s been a fun project so far and I look forward to seeing where it goes from here. Most of all, I wish everyone clear skies! Keep looking up.

Feynman on "Computer Disease"

&& [ other ] && 0 comments

2015-03-26-feynman-on-computer-disease.markdown

The following is a excerpt from the book I am currently reading by Richard Feynman, Surely You Must be Joking, Mr. Feynman! that I found amusing.

Well, Mr. Frankel, who started this program, began to suffer from the computer disease that anybody who works with computers now knows about. It’s a very serious disease and it interferes completely with the work. The trouble with computers is you play with them. They are so wonderful. You have these switches–if it’s an even number you do this, if it’s an odd number you do that–and pretty soon you can do more and more elaborate things if you are clever enough, on one machine.

After a while the whole system broke down. Frankel wasn’t paying any attention; he wasn’t supervising anybody. The system was going very, very slowly–while he was sitting in a room figuring out how to make one tabulator automatically print arc-tangent X, and then it would start and it would print columns and then bitsi, bitsi, bitsi and calculate the arc-tangent automatically by integrating as it went along and make a whole table in one operation.

Absolutely useless. We had tables of arc-tangents. But if you’ve ever worked with computers, you understand the disease–the delight in being able to see how much you can do. But he got the disease for the first time, the poor fellow who invented the thing.

Still suffering to this day!

Reviving fchart to Create Beautiful Astronomical Finder Charts

&& [ astronomy, code, astrochallenge ] && 0 comments

I’ve spent a good deal of time in the last few days searching for a good library to draw star charts (finder charts) that I could use to integrate with AstroChallenge. While there are plenty of utilities to create star maps, they mostly consist of desktop software or websites that are not open source.

2015-02-25-creating-finder-charts-for-astronomy-using-fchart.markdown

Eventually I found fchart which resembled was I was looking for. A set of python scripts with minimal dependencies that would output star maps! This I could use.

I extracted the package downloaded from Michiel Brentjens’ website and hit go… nothing. Then I realized the file’s last modified date: 2005. Uh-oh. It depended on numarray, a package long ago replaced by numpy.

But the source was clean, so I decided to see if I couldn’t upgrade it to work in numpy and python2.7. Indeed, after a few find/replaces and some method renaming, the code ran! However, there was another problem. The tyc2.bin file from fchart website seemed to be corrupt - I couldn’t get any stars to draw. So I headed over to http://cdsarc.u-strasbg.fr/viz-bin/Cat?I/259 and grabbed a fresh copy of the tyco2 star database, concatenated the archives and created a new tyc2.bin file using the tyc2_to_binary script.

Now everything appears to be working. The image above is an example of a chart generated for the Andromeda Galaxy. I emailed Michiel to let him know about my modifications and that I’ve hosted the code on github. The repo also contains the new tyc2.bin file that contains the star catalog - so the installation should run out of the box without issues.

This is a great example of why open source software works. Not only can the software be useful to a wider audience now, but I plan on adding my own improvements and functionality.

Get fchart

Michiel Brentjens’ website

GraniteMaps: Soquel Demonstaion Forest/Nisene Marks released!

&& [ granitemaps, code, cartography ] && 0 comments

2015-02-23-granitemaps:-soquel-demonstaion-forest---nisene-marks-released!.markdown

After much ado, the latest map from GraniteMaps is now available. This map covers 2 distinct areas; The first is Soquel Demonstration Forest, well known in the mountain biking community as having miles of challenging, technical singletrack. The other is the Forest of Nisene Marks which shares a ridge with Demo and provides trail users of all types some of the most pristine redwood forest trails available in California.

This new map is much improved over the last version for Santa Cruz by having a brand new base layer. This is a custom topographic map I designed myself (detailed in this post) which combines OpenStreetMap and SRTM data to create a concise, easy to read map. I hope you enjoy it.

Thanks everyone for your kind words and support! The reception I received for the Santa Cruz map was fantastic, far exceeding anything I could have imagined while creating it!

www.granitemaps.com

Using Django and PyEphem to Determine the Location of White Fuzzies

&& [ AstroChallenge, astronomy, code ] && 0 comments

I’ve been working on new project recently called AstroChallenge. While the details of what exactly AstroChallenge is will have to come later, rest assured, it has to do with Astronomy.

2015-02-19-using-pyephem-to-determine-the-location-of-white-fuzzies.markdown

One of the bits of information I’m interested in is whether a particular celestial object is visible in the sky or not. Given an observer’s latitude, longitude and elevation and an object’s right ascension and declination it becomes a straightforward calculation.

However, there are libraries written by smarter people than I and it would be a good idea to use them. So instead if spending my time carefully coding maths, I can simply:

$pip install pyephem

and

import ephem

into my project.

Now the work is done for me. Isn’t the modern age great?

PyEphem is a great python library for performing calculations on all sorts of celestial objects including planets, moons, comets, asteroids, stars and deep space objects. Once you input your observation date, time and location some of the interesting functions you can run include:

  • Next transit

  • Altitude, Azimuth

  • Distance from Earth, Sun, other bodies

  • Current Constellation

  • Phase, day, month and year

And so on. When you set up an observer, you can even supply dates in the path so you can, for example, find the positions of the moons of Jupiter on February 15, 1564.

Since AstroChallenge is a webapp written in Django we have data models for things like deep space objects on which we can place handy methods to get information from pyephem:

(fields truncated for readability) {{< highlight python >}} class DeepSpaceObject(models.Model): ra_hours = models.IntegerField() ra_minutes = models.FloatField() dec_sign = models.CharField(max_length=1, choices=((‘+’, ‘+’), (‘-‘, ‘-‘)), default=”+”) dec_deg = models.IntegerField() dec_min = models.FloatField()

@property
def fixed_body(self):
    """ Return a FixedBody object which PyEphem uses to perform calculations """
    object = ephem.FixedBody()
    object._ra = "{0}:{1}".format(self.ra_hours, self.ra_minutes)
    object._dec = "{0}{1}:{2}".format(self.dec_sign, self.dec_deg, self.dec_min)
    return object

def observation_info(self, observer):
    """ Given an observer, perform the calculations we are interested in and return them as a dictionary """
    p_object = self.fixed_body
    p_object.compute(observer)
    up = True if ephem.degrees(p_object.alt) > 0 else False
    return {
        'alt': str(p_object.alt),
        'az': str(p_object.az),
        'up': up,
        'neverup': p_object.neverup,
        'rise': timezone.make_aware(observer.next_rising(p_object).datetime(), pytz.UTC) if p_object.rise_time else None,
        'set': timezone.make_aware(observer.next_setting(p_object).datetime(), pytz.UTC) if p_object.set_time else None
    }

{{< / highlight >}}

Some things to note:

  • An object is “visible” if it’s Altitude is greater than 0, meaning it is above the horizon. If it still light out, or you live in a light polluted area, you’re probably still out of luck, though,

  • PyEphem’s Observer.next_rising/setting methods may return None, that means an object either never rises (as can be determined using Body.neverup) or never sets.

The Observer data can be provided using a simple method on a UserProfile model:

{{< highlight python >}} class UserProfile(models.Model): user = models.OneToOneField(User, editable=False) timezone = TimeZoneField(default=”UTC”) lat = models.FloatField(“latitude”, default=0.0) lng = models.FloatField(“longitude”, default=0.0) elevation = models.IntegerField(default=0)

@property
def observer(self):
    observer = ephem.Observer()
    observer.lat, observer.lon, observer.elevation = str(self.lat), str(self.lng), self.elevation
    return observer

@property
def sunset(self):
    sun = ephem.Sun()
    sun.compute(self.observer)
    return timezone.make_aware(self.observer.next_setting(sun).datetime(), pytz.UTC)

{{< / highlight >}}

Notice the observer property just returns an observer, so we can now supply it in our views to a Celestial object and get the information we need. Another handy property, sunset uses the observer property to compute the time at which the sun will be setting for this user. PyEphem rocks.

How Greece Came to Belong to the Greeks

&& [ greece ] && 0 comments

I met Amalia at the Thessaloniki Pythess (Python) meetup (at which I gave one awkward english presentation) which had migrated to a lounge under the Archaeological Museum of Thessaloniki. I thought the museum looked pretty cool, so I decided I would go the next day. I propositioned the group to see if anyone else was interested in joining me, Amalia was the only one brave enough to to say so.

2015-01-23-how-greece-came-to-belong-to-the-greeks.markdown

We spent a few good hours at the museum and various other historical points of interest around the city. While walking down some buzzing, narrow street Amalia told me a great story about how it is that Greeks came to find themselves in Greece:

After God had created the earth, he told the people that he would be at his office the next day from 7am to 5pm and that they should come by so He could assign a place for them to live. The next morning God came to his office to unlock the door and found the English already waiting for him.

God said to the English: “Since you are so early, I am giving you the best pick of land. It is a large island and you can do with it what you please.”

After God made the final arrangements he escorted the English out of his office and there He found the Germans, right on time.

To the Germans He said: “Since you are first in line, I am giving you a large piece of land. There you will have plenty of space for your industry and farming.”

And so God spent the rest of the day allocating land to the people of the earth. At last 5pm rolled around, and as God was locking his office door the Gypsies arrived.

To God they pleaded: “Please God, give us some land. You won’t believe what happened on the way here. The bus was late, Mother was sick, and there were all sorts of complications. Please, have pity on us.”

God replied to Gypsies: “I have given away all the land. I am sorry you are late but there is nothing I can do for you. From now on you will be the children of the earth. You will not have a land to call home but you will be of the world.”

Satisfied with this answer the Gypsies left God in peace. As God began his walk home, he was approached by the Greeks:

“God, wait! We are here for our land! We are sorry we are late but it’s not our fault!”

God, annoyed, replied: “I am sorry, I have given away all the land, there is none left for you.”

The Greeks would have none of it:

“But please! All these things kept us from being on time. We wanted to come earlier, but we were hungry, so we had to stop to get something to eat. And then one of the sheep got away so we had to bring it back, not to mention all the traffic!”

God, now getting angry, replied: “I am sorry. But you are late and there is nothing I can do for you. You will have no land.”

The Greeks continued, loudly, franticly gesturing with their hands: “But PLEASE! We have these pains, it keeps us from getting up early in the morning. Oh! And this weather! We could barely walk in this wind, how were we supposed to get here on time? Not to mention we wanted to do the laundry, so we could have clean clothes and–“

“Fine!” God exclaimed, exasperated but defeated. “There is one piece of land left, it is the best land in all the world and I was saving it for myself. But I will give it to you if you would please just SHUT UP!”

And so the Greeks were given the land of Greece.

An unexpected visit to Istanbul

&& [ Greece ] && 0 comments

Here I am in Istanbul (not Constantinople) the city on the Bosporus, the ribbon of land separating Europe from Asia and the Black sea from the Sea of Marmara and thus the Aegean to the East. As my plane glided downward and spiraled towards the glittering city I thought about the Golden Fleece and if it had seen a similar view on it’s journey from Greece to Turkey 3 thousand years ago.

2015-01-18-an-unexpected-visit-to-istanbul.markdown

I had hoped to connect to my flight to Thessaloniki immediately, but Turkey wanted me to stay. Late flight, missed connection, security, visas, immigration (twice) and eventually a cramped ride in an airport shuttle to some hotel somewhere in Istanbul, an unsettling 45 minutes from the airport.

So here I am typing this out at 01:00, too nervous to sleep (for fear of missing another flight) but with nothing else really to do.

Travel has gotten faster in the modern age, but I wonder if it hasn’t lost some of it’s humanity. Dysentery sucks, but if the travelers of a few hundred years ago looked upon the conditions of airline travelers today, the lines, the turnstiles and the cramped conditions they might just liken us to cattle.

Hopefully I will see Greece tomorrow.

Creating nice looking topo maps for use in GraniteMaps

&& [ cartography, code, granitemaps ] && 0 comments

The goal of GraniteMaps is to provide accurate and educational maps for people participating in outdoor activities, so a large part of the project is creating maps that are pleasing to the eye.

The map displayed in granitemaps is actually two layers: the “base map” and the trail layer. The base map is is responsible for displaying the details of the map’s area such as land boundaries, rivers/lakes, major roads and elevation. The trail layer is an overlay of the actual trails and points of interest.

Currently GraniteMaps uses The National Map provided by the USGS for the base layer. It’s a good public domain map that includes major roads, hillshading, contour lines and place names. It does have it’s issues, however:

  1. The map is rendered without anti-aliasing which means fonts look jagged. The rest of the render just looks dated, like 90’s jpeg compression was used.
  2. Many of the minor roads are rendered it too low a resolution. This means that many of the “lesser used” roads, i.e the roads we care about in GraniteMaps, are rendered without enough data points. This causes roads to cut across contour lines, have harsh angles, and in general just not appear where they are supposed to.
  3. Not customizable. The map is provided in JPG format which you can use in slippy maps, but what you see is what you get.

For these reasons (especially #2) I concluded that The National Map would not be satisfactory for use in GraniteMaps’ next map.

The solution is to create a custom base layer for use in GraniteMaps. After a few days of getting familiarized with the GIS landscape, I set to work on creating a nice looking map using MapBox’s TileMill. A good starting point was the osm-bright project which pulls openstreetmap data from your local PostGIS database to create a fully featured street map. Elevation data is a must have, so after following this great article by Steve Bennett I loaded some data from the Shuttle Radar Topography Mission into the map to provide contours and hillshading. After that is was a matter of tweaking the CartoCSS rules to get the desired look right. The preliminary result:

2015-01-11-creating-nice-looking-topo-maps-for-use-in--granitemaps.markdown

The rendering isn’t perfect, but it’s a good start and already superior to The National Map. In case anyone else is interested in creating their own topo map in a similar fashion, the style files are available on github!

Keep enjoying these beautiful winter months out on the trail!

Hello World! In AngularJS

&& [ code ] && 0 comments

My coworker recently complained to me how hard it was to find a simple “Hello World” program in AngularJS. I did a google search and found that indeed, all the simplest examples still asked the user to set up a bunch of boilerplate, file structure, etc.

Here is the simplest Hello World in AngularJS I could come up with, and it still shows 2 way binding:

{{< highlight html >}}

Hello Angular!

Hello, {{world}}!

{{< / highlight >}}