With the gracious permission of Jon Olson (WT5L), I'm republished his excellent python scripts here in the hope that they will prove useful to our community and that some members will be able to extend them.
Here is the first script in the series than will follow in the coming weeks... Those of you that can't wait can go to Jon's blog at the following URL: http://wt5l.blogspot...label/Scripting
Yes, I'm going to be deliberately holding back the other scripts since I know how overwhelming it can be to see or realise that the total program is more than 1000 lines. Don't panic we will be going though it slowly at our own pace learning the concepts that we need as we go. Also, fell free to ask questions...
Automated Astrophotography with Python - Part 1a
GETTING THINGS TO WORK
The very first step in this process is to verify that Python and Python Extension for Windows are properly communicating with a suitable Windows application. In this case, we will use MaxIm DL and its built-in camera simulator.
THE cCAMERA CLASS
The first piece of code that we will look at is the 'cCamera' class. The Python code for 'cCamera' is shown below. (Note: Docstrings have been removed from this listing for brevity and readability purposes.)
ERROR = True
NOERROR = False
## Class: cCamera
print "Connecting to MaxIm DL..."
self.__CAMERA = win32com.client.Dispatch("MaxIm.CCDCamera")
self.__CAMERA.DisableAutoShutdown = True
self.__CAMERA.LinkEnabled = True
print "... cannot connect to camera"
print "--> Is camera hardware attached?"
print "--> Is some other application already using camera hardware?"
raise EnvironmentError, 'Halting program'
if not self.__CAMERA.LinkEnabled:
print "... camera link DID NOT TURN ON; CANNOT CONTINUE"
raise EnvironmentError, 'Halting program'
print "Exposing light frame..."
while not self.__CAMERA.ImageReady:
print "Light frame exposure and download complete!"
print "Camera set to full-frame mode"
tup = (1,2,3)
if binmode in tup:
self.__CAMERA.BinX = binmode
self.__CAMERA.BinY = binmode
print "Camera binning set to %dx%d" % (binmode,binmode)
print "ERROR: Invalid binning specified"
## END OF 'cCamera' Class
The first two lines of the listing are 'import' statements that identify and allow use of the 'time' and 'win32com.client' library objects in the script. The listing for the 'cCamera' class follows the 'import' statements and consists of four methods. The '__init__' method is the constructor method for 'cCamera' and is executed whenever an instance of the cCamera object is created. This method creates a '__CAMERA' object that is an instance of MaxIm DL's 'CCDCamera' object. The '__CAMERA' object then can be used to access all the properties and methods found in the scripting section of MaxIm DL's help file (for CCDCamera object). This method also uses 'try' and 'except' statements to determine if a link has been successfully established to the program. If MaxIm DL has not already been loaded and connection to the camera established manually, the script will load MaxIm DL and make the camera connection automatically.
Next in the listing is the 'exposeLight' method that takes as arguments a length of exposure (float) and an integer that specifies the filter to use for the exposure (zero-based). This method uses MaxIm DL's 'Expose' method to start the exposure and polls the 'ImageReady' parameter to determine when the exposure and image download have completed (indicated when 'ImageReady' goes True).
The third method of 'cCamera' calls the MaxIm DL method 'SetFullFrame' and the last method sets the 'BinX' and 'BinY' properties. For more details regarding 'SetFullFrame()', 'BinX', and 'BinY' refer to MaxIm DL help under 'Scripting' and under 'CCDCamera' methods or properties.
cCAMERA UNIT TEST
The listing given below is inserted onto the end of the source listing and allows unit testing the 'cCamera' class. The first step is to create an instance of the 'cCamera' object called 'testCamera'. In turn, the 'setFullFrame' and 'setBinning' methods of 'testCamera' are called to set MaxIm to full-frame mode and to set binning to 1x1. If 'setBinning' finished without error, the 'exposeLight' method is called and initiates a 12.5 second exposure through the simulator's blue filter (slot 2).
if __name__ == "__main__":
# Create an instance of the cCamera class
testCamera = cCamera()
# Setup MaxIm DL to take a full frame image
# Setup binning for 2x2
if not testCamera.setBinning(2):
# Expose filter slot 2 (Blue) for 12.5 seconds
print "Image not taken due to previous error"
RUNNING THE SCRIPT
Follow the steps below to execute the script described in this post:
Start MaxIm DL and open the Camera Control window. Under 'Setup Camera' for Camera 1, choose 'Simulator' and under 'Setup Filter' for Camera 1 choose 'Simulator' also. For Camera 2, choose 'Simulator' and under 'Setup Filter' for Camera 2 leave unselected.
Change focus to the IDLE window containing your script listing, click the 'Run' menu item and pull down to 'Run Module', or simply press the F5 key.
If everything is working correctly, you should see MaxIm DL kick off a 12.5 second exposure through the blue filter and eventually display an image from the simulated camera. You can inspect the FITS header to verify the binning, exposure, and filter for this image.
Modify the parameters in the unit test section of the listing to take exposures of different lengths, through different filters, using different binnings to verify that all work as expected.
Good luck with it, play around with it and get ready for next week went we will go further.