Skip to content

Software platform

Dominic Ford edited this page Dec 22, 2018 · 5 revisions

The Pi Gazing software platform

All the software we use to control our Pi Gazing observatories is all freely available in this GitHub repository under an open-source license (The Gnu General Public License V3).

The software platform is designed to run as autonomously as possible. Once it is set up, all you need to do is to connect your observatory to a 12V power supply and to the internet, and it will be able to make useful observations.

The software is able to determine the location of the camera and the time of day using GPS. It is able to calculate the times of local sunrise and sunset, and from this, it knows when it should observe, and when to switch the camera off. Over time, it is even able to work out exactly which direction the camera is pointing, by monitoring which stars can be seen at which times.

You don't need to understand the details of how our software works to use Pi Gazing. You can find step-by-step instructions on this Wiki for setting up our software on a Raspberry Pi. The sections below give a brief overview of what the software does, but feel free to skip over them.

System requirements

The Pi Gazing software platform is a mixture of C code and Python, and is designed to run in Linux-like environments. It is not possible to run it under Windows. We provide step-by-step instructions for setting it up on a Raspberry Pi computer, and it also runs well on any Linux PC.

The software requires 1 GB of RAM, and is close to the processing-power limits of a Raspberry Pi 2 Model B. It will not run on older less-powerful models of Raspberry Pi.

The software typically generates 200-300 MB of observations each night. It also requires 1 GB of temporary files. If you are using a Raspberry Pi, we recommend storing observations on a SD card with between 16 and 64 GB capacity, as these are cheaply available.

Flow diagram

Pi Gazing software operation

The diagram above show the workflow of a Pi Gazing observatory. The first priority when an observatory is switched on is to determine its time and location. Ideally this is done using a USB GPS dongle. If none is available, then a default latitude and longitude is read from a local configuration file, and if an internet connection is available, it may be possible to determine the time using Network Time Protocol (NTP).

What the camera does next depends whether it is day time or night time. Sunrise and sunset times are calculated for the observatory's current location, and each day it will start observing 30 minutes after sunset, and finish observing 30 minutes before sunrise.

Night-time operation

During the hours of darkness, the software turns the camera on and analyses the video received from it in real time. This includes averaging the frames over 30-second periods to generate low-noise still photographs, and monitoring the video stream for bright moving objects.

The code used to do this is heavily optimised, as it has to process video frames which arrive at a rate of 25 per second. A quad-core Raspberry Pi 2 Model B will typically run with 80% of its RAM being used, and a similar proportion of its CPU.

Day-time operation

At dawn, the camera switches into a different mode of operation and performs a series of house-keeping operations. These commonly take several hours to complete.

Converting files to standard formats

The first of these is to convert its observations from the previous night into standard file formats. We make Pi Gazing images available in PNG format, and videos available as MP4 files (encoded using H264). However, the encoding of these files takes time which is not available during the night time. Instead, the observations are stored in a raw format.

At dawn, the software goes through all of the previous night's observations, converting these raw files into PNG and MP4 format. On a Raspberry Pi, this is done using the hardware H264 encoder (OpenMAX), but fallback code is included to use libx264 when the code finds itself running on other hardware platforms.

Database administration

Pi Gazing stores all of its observations in a MySQL database.

The next task that the software does is to register all of the previous night's observations into the database.

The database comprises a list of "observations", each of which may be a still photographs or a moving object, or some other event. Each of these may have a number of files associated with them. Both the observation records, and each individual file, may have arbitrary metadata fields associated with them. These might include, for example, the position of the object that trigger the camera's motion sensor, and an estimate of the sky clarity.

Upload of observations to remote servers

Once the database is updated, the software may automatically upload all of its observations to a remote server, if it has been configured to do so.

You are unlikely to want to browse your Pi Gazing observations on the same Raspberry Pi that you are using the make them, because the Pi will spend much of its time heavily-loaded, running the observing software. This makes it advantageous to upload your observations to a remote server, where you can host the Pi Gazing web interface and browse them at your leisure.

This structure also means that you can potentially have several cameras automatically upload observations to a single server, where they can be browsed together. It is the system we use to collate all the observations from the Pi Gazing network onto the Pi Gazing website.

Determine the camera's orientation

If time permits, the observatory will attempt to work out precisely which direction its camera is pointing in.

It does this by taking a selection of the clearest images taken over the previous night, and passing them to a piece of software called astrometry.net, which uses pattern recognition to identify any star patterns that are visible.

By using the known time of each image, and the stars that are visible at known positions in each image, the software is able to calculate its field of view, azimuth (the bearing the camera is pointing in -- north being 0 degrees, east being 90 degrees, south 180 degrees, etc), and altitude (degrees above the horizontal).

This is only possible in very clear conditions when there are plenty of stars visible, and so will fail on around 80% of days. However, assuming the camera remains in a fixed orientation for a long time, this does not matter as the alignment is assumed to have remained unchanged when a new determination isn't possible.

Clone this wiki locally