Saturday, May 21, 2011

Automated Astrophotography with Python - Introduction

As anyone past the beginner stage of astronomical imaging quickly finds out, an executive software application that controls all aspects of the imaging process becomes a desirable tool. There are various applications available (CCD Commander, ACP, CCD Autopilot) that I highly recommend and that perform very well but that also come with relatively high price tags. (Although the price is typically a fraction of the costs tied up in equipment and other software for the average imager.) However, an alternative to using an application that someone else has created and maintains is to create your own control software that directs the imaging process EXACTLY how you would wish it to be executed. This introductory post is the first in a series of posts that will detail how you can easily create and maintain your own executive application at no cost (other than your time learning and programming in Python).

Python is a agile programming language that is freely available, well supported, and easy to learn for beginners. Python syntax is very easy to read and understand, and the language supports object-oriented programming practices. Python is also an interpreted language which means there is no compilation process. You simply execute the script and it runs! Most importantly, Python supports the COM (Common Object Model) architecture under which most astronomical imaging software exposes their properties and methods to the outside world. This means that Python can seamlessly communicate with and control all major astronomical software applications like CCDSoft, MaxIm DL, the Sky, etc. For more information regarding the question of "Why Python?" click here.

Python can be downloaded from this web page. Simply choose the installer that corresponds with your operating system and follow the prompts. (Although Python is written for Windows, Mac, and Unix platforms, you will need the Windows 32-bit or 64-bit OS installer since virtually all of the major astronomical imaging software packages you'll hook into are Windows-based.) The installer will also install IDLE which is the Python IDE (Integrated Development Environment) which you can use to write, test, and debug your scripts. Click here for a beginner's guide to downloading Python.

NOTE: All scripts presented in this series have been tested using the latest stable version of Python which is 2.7.1 as of the date of this post. The scripts should also work under the latest version of Python 3 but this claim has not been verified. Additionally, in order to have COM support, you must also load the Python Extensions for Windows package that corresponds to the version of Python that you have chosen to use. The latest package (Build 216 as of the date of this post) can be found here.

An on-line search of "Learning Python" or "Python tutorial" will return hundreds of on-line tutorials and PDF documents to help you get started. Another list of learning resources can be found here. One on-line PDF document that I found useful, even though it is somewhat dated, can be found here and the official Python tutorial can be found here.

  • No Cost (other than your time)
  • Great opportunity to learn computer programming if you've never done it before or to learn a new programming language if you're already an experienced programmer
  • COMPLETE control of all aspects of the automated imaging process
  • Fine-tuned to the particular set of software that YOU use for imaging
  • You maintain the waiting for someone else to get around to fixing a bug or implementing an improvement
  • Implement only the features that you want in exactly the way you want them to function

The computer that I use for astronomical imaging is a 6-year old Toshiba laptop running Windows XP Home Edition. My Python script accesses the following imaging applications:
  • MaxIm DL 5 (For Camera Control)
  • The Sky6 (For Mount Control)
  • FocusMax (For Automated Focusing)
  • CCDSoft (For Plate Solving)
My imaging equipment is all portable. Since I don't have a suitable dark location near my home, I perform all image acquisition at a dark site that is approximately 200 miles away. Consequently, I don't have any script examples for dome control, weather monitoring equipment, or any other hardware that you would typically find with a permanently mounted setup. These features can be easily added to your Python script if required.

The following is a very top-level description of my script's operation during acquisition of normal, light frames of astronomical objects. I will be describing in detail how each of these steps is implemented in the course of these posts.
  1. Read in the input text file that specifies the object to image and contains a list of images to take that includes filter, exposure, and number of frames. (An example of an input text file can be downloaded here.) Also, read in other options such as CCD temp, minimum altitude, warm CCD after all images etc. that apply to this set of images.
  2. Find the object in the Sky and wait for object to cross the meridian (since I only image on the west side of the sky). If the object has already crossed the meridian, continue immediately with the next step.
  3. Locate a suitable focus star (from a preselected list of candidate stars) that is close to the object, slew to the star, plate solve, then resync and reslew if needed. Using FocusMax's focus method, auto-focus through the specified filter then check focus using FocusMax's HFD measurement method.
  4. Slew to the object, plate solve, then resync and reslew if needed to reduce the pointing error.
  5. Expose the guide camera, identify a guide star, begin autoguiding, then wait until guide errors fall below a specified threshold.
  6. Begin acquiring images until the specified number of images have been captured or until it is time to perform the periodic focus check (required after 'x' number of images have be captured).
  7. When the periodic focus check is required, slew to the same focus star used in step 3 (with plate solve, resync, and reslew if required) and check focus using FocusMax's HFD measurement method. If the HFD has changed by a specified threshold, repeat FocusMax's focus method. Otherwise, continue directly to the next step.
  8. Slew to the object and plate solve, then resync and reslew if required.
  9. Return to step 6 until all images have been acquired for the current set of images.
  10. For the next set of images return to step 3.
  11. When all image sets have been acquired or when the object drops below the specified altitude, end the script. If required, warm the CCD to ambient temperature and/or slew the mount to a safe position.

The scripts contained in the following posts have been written, debugged, and verified as working by me FOR MY PARTICULAR SETUP only. There are no guarantees that they will work, as is, with anyone else's setup. Therefore, I assume no responsibility for damage to equipment, lost time, or other losses anyone may incur. Furthermore, the scripts are not guaranteed to be without bugs that I haven't found yet. Indeed, they probably DO have bugs that I haven't found yet. The message is: Use the information contained in these posts at your own risk. The scripts in these posts are meant only as a STARTING POINT for your own scripts and are not meant to be used as is.

For some time I had been thinking about writing my own scripts even while using CCD Commander on a regular basis. It wasn't until I ran across the series of three articles in the on-line magazine "AstroPhoto Insight" titled "Automated Imaging on a Budget" by Joe Ulowetz that I found the jump-start that I needed. Specifically, at the end of the article, Joe graciously provided a link to allow a download of the complete Python code that controlled the automation described in his article. By pouring through Joe's code and using it as a starting point, I was eventually able to drop CCD Commander and begin the process of writing, testing, debugging, and, eventually, using my own executive software application.

In the next post, I will begin diving into the Python code. Specifically, I'll introduce and begin describing methods contained in the Camera class. I'll also show how these methods can be easily tested using only the camera simulator built into MaxIm DL.


No comments:

Post a Comment