Sentinel of the Caprock Observatory
  Astronomical Computer Applications
 

 

 

Many astronomical activities, like image processing, are easier and faster when automated using a computer. On this page, I provide computer applications for various activities that I have written. These can be downloaded and run on your computer.

These applications have been programmed and compiled using PowerBasic. They should run on any PC with the Windows XP, Windows 7, or Windows 8 operating system. All the files are in executable form (.exe) and do not need any Basic compiler or other language-related software to operate on your PC. When downloaded, your antivirus software may flag them and give the usual warnings about potential risks. While I can't say that the programs are real good, I can say that they shouldn't harm your computer. Feel free to use and share these programs. If you post them on other websites, a reference to SOCO would be appreciated.

A note about downloading the files. This website makes use of the built-in capability of most browsers to directly download files to your computer. By right-clicking on the provided link, you'll be presented with a menu of options. Among these options, if you choose "Save As...." or "Save Target As....", you'll be presented with a dialog box in which you can specify the location in your computer to download the file. All the applications available on this webpage are relatively small, so they don't need to be unzipped or otherwise de-compressed.

 


Calculating Stellar Elevation Angle and Atmospheric Transmissivity

 

Several of the image processing procedures described on this website require information on the elevation of stars (or other objects) above the horizon. While this information can be obtained from planetarium software applications like like Cartes du Ciel or Starry Night, it is possible to calculate stellar elevation angle (SEA) directly from time, date, location of the observer, and coordinates of the object. The application presented below will calculate SEA and the azimuth angle (AZM) along the horizon (measured from North) for an astronomical object provided its RA and Declination. The application will also calculate the value of the airmass (X) associated with the elevation angle for use in evaluating atmospheric extinction coefficients (k). For correcting stellar photon fluxes for differences in elevation angle, the application will calculate the atmospheric transmissivity (A) given the appropriate value of the atmospheric extinction coefficient. Calculated values of SEA and AZM produced by this application are typically within 0.2 of a degree of corresponding values produced by other sources, such as Cartes du Ciel. This degree of accuracy is acceptable for the image processing procedures decribed on this website. Details of inputs to the application are presented when you initially run it.

Right-click or option-click on the link immediately below and choose "Save As...." or "Save Target As...." to download the file for this application.

Application for Calculating Stellar Elevation Angle and Atmospheric Transmissivity (ver. 1.1)

I'm indebted to Keith Burnett (keith@xylem.demon.co.uk) for his outline of the computational procedure for calculating astronomical elevation angles (Converting RA and DEC to ALT and AZ). The calculation of atmospheric transmissivity follows the procedures found in "The Handbook of Astronomical Image Processing" by Richard Berry and James Burnell (Willmann-Bell Publishers, Richmond, VA, 2009).

PROGRAM HISTORY:

Version 1.0 April 2015 Initial release.
Version 1.1 May 2015 Includes bug fix for negative declinations.

 


PowerBasic Program for Reading and Writing FITS Image Files

 

Sometimes you'd like to do some specific processing to an image file that might not be included in the commercial image processing software packages that you have access to. Or maybe you want to automate certain steps in the processing procedure rather than perform them manually or in the sequence dictated by a particular software package. In that situation, it would be great to write your own software applications to do that. Years ago in college, I learned how to program in FORTAN (it was about the only language around in those days). More recently, I picked up programming in PowerBasic, which was easy to learn and contains all the functions of a modern programming language. Using PowerBasic, I've been able to write a large number of computer applications, like those found on this webpage.

Of course, to write programs for processing FITS image files, you have to be able to successfully read and write this file format. FITS files have a standardized format that is well-documented. Each image file is basically a combination of an ASCII text header, a string of binary data representing the image, and a tailer of blank ("null") spaces rounding the file out to a standard length. People have written programs in various computer languages (like C++, MATLAB, etc.) to read/write FITS files. Since I am a PowerBasic programmer, I checked the PowerBasic User's Forum to see if anyone had already done this for PowerBasic. After waiting a while and getting no positive responses, I decided to "bite the bullet" and develop one myself.

The listing below shows the results of my effort. If you're a PowerBasic programmer, the format of the program will be obvious to you. It took about a week to write and debug, but it appears to be working quite well now. The main hurdle in writing this program was to understand and accommodate the differences in the order of bytes in multi-byte values between what the FITS standard expects and how modern personal computers (PCs) handle them. Basically, the FITS format expects that the order of bytes in all multi-byte values (integer and real numbers) is "big-endian", which means that the most significant byte in the value comes first. However, modern PCs expect multi-byte values to have their bytes in "little-endian" order, which means that the most significant byte in the value comes last. So, in reading a FITS file, the byte order must first be reversed before you can do anything with the image data. In writing a FITS file, the order of the bytes must be re-reversed to get them back in the proper order for the FITS format. It took some checking around the Internet, and a lot of trial-and-error, but I finally got it worked out.

The program listed below is intended to be a starting point for anyone wanting to develop FITS image processing applications using PowerBasic. It will read two types of FITS image files— files where the image data are stored as 16-bit signed integers, and files where the image data are stored as 32-bit floating point ("real") numbers. There are other types of FITS files, but these are the two most common that amateur astronomers will run across. It will output FITS files with the image data stored as 32-bit floating point ("real") numbers. The program is written for PowerBasic Console Compiler Version 5. I've verified that the FITS files it produces can be successfully read by other applications, including AIP4WinV2, Maxim DL Version 5, and NASA's FITS Liberator Version 3.


#COMPILE EXE "FITS-BASIC.exe"
DEFSNG A-H,O-Z
DEFINT I-N
 
FUNCTION PBMAIN

 
PRINT      " *******************************"
PRINT      " "
PRINT      " PROGRAM FOR READING AND WRITING "
PRINT      " FITS FILES USING POWERBASIC CC "
PRINT      " "
PRINT      " Programmed by Steve Maas "
PRINT      " cat-star.org "
PRINT      " Version 1.0 June 2015 "
PRINT      " "
PRINT      " *******************************"
 
PRINT ""
PRINT "Enter the name of the input FITS file"
PRINT "including path (if not in same directory
PRINT "as program) and file extension (.fit)-"
INPUT FILIN$
PRINT ""
PRINT "Enter a name for the output FITS file"
PRINT "including path (if not in same directory
PRINT "as program) and file extension (.fit)-"
INPUT FILOUT$
 
OPEN "FITS-LOG.txt" FOR OUTPUT AS #2
 
PRINT #2, "INPUT FILE: "; FILIN$
PRINT #2, "OUTPUT FILE: "; FILOUT$
PRINT #2, ""
 
'-------------- READ IMAGE HEADER ---------------------
 
OPEN FILIN$ FOR BINARY AS #1
NHEADSIZE = 0
 
ReadHead:
GET$ #1, 2880, A$
NHEADSIZE = NHEADSIZE + 36
FOR II=1 TO 36
      ICOUNTR = (II-1)*80
      IF MID$(A$,ICOUNTR+1,3) = "END" THEN
           IF NHEADSIZE = 36 THEN
                C$ = A$
           ELSE
                C$ = C$ + A$
           END IF
           PRINT #2, "ORIGINAL FILE HEADER:"
           PRINT #2, C$
           GOTO headfinished
      END IF
NEXT II
IF NHEADSIZE = 36 THEN
      C$ = A$
ELSE
      C$ = C$ + A$
END IF
GOTO ReadHead      'read next 2880-byte block of header
 
headfinished:
 
'Find type of image (from BITPIX in header):
' 8      unsigned 1-byte integer (PB Byte)
' 16      signed 2-byte (16-bit) integer (PB Regular Integer)
' 32      signed 4-byte (32-bit) integet (PB Long Integer)
' -32      4-byte (32-bit) floating point real (PB Regular Real)
' -64      8-byte (64-bit) floating point real (PB Double-precision Real)
FOR II=1 TO NHEADSIZE
      ICOUNTR = (II-1)*80
      IF MID$(C$,ICOUNTR+1,6) = "BITPIX" THEN
           IMGTYPE = VAL( MID$(C$,ICOUNTR+11,20) )
           LOCBITPIX = ICOUNTR+1
           PRINT #2, ""
           PRINT #2, "From FITS image header:"
           PRINT #2, "Image type (BITPIX) = "; IMGTYPE
           GOTO typefinished
      END IF
NEXT II
typefinished:
'Find dimensions of image
FOR II=1 TO NHEADSIZE
      ICOUNTR = (II-1)*80
      IF MID$(C$,ICOUNTR+1,6) = "NAXIS1" THEN
           NCOL = VAL( MID$(C$,ICOUNTR+11,20) )
           NROW = VAL( MID$(C$,ICOUNTR+80+11,20) )
           PRINT #2, ""
           PRINT #2, "Columns in image = ";NCOL, " Rows in image = ";NROW
           GOTO dimfinished
      END IF
NEXT II
dimfinished:
'Find scale factors for image data
FOR II=1 TO NHEADSIZE
      ICOUNTR = (II-1)*80
      IF MID$(C$,ICOUNTR+1,6) = "BSCALE" THEN
           BSCALE = VAL( MID$(C$,ICOUNTR+11,20) )
           LOCBSCALE = ICOUNTR+1
           PRINT #2, ""
           PRINT #2, "Value of BSCALE = ";BSCALE
           GOTO scalefinished
      END IF
NEXT II
scalefinished:
FOR II=1 TO NHEADSIZE
      ICOUNTR = (II-1)*80
      IF MID$(C$,ICOUNTR+1,5) = "BZERO" THEN
           BZERO = VAL( MID$(C$,ICOUNTR+11,20) )
           LOCBZERO = ICOUNTR+1
           PRINT #2, ""
           PRINT #2, "Value of BZERO = ";BZERO
           GOTO zerofinished
      END IF
NEXT II
zerofinished:
'Extract date and time-
FOR II=1 TO NHEADSIZE
      ICOUNTR = (II-1)*80
      IF MID$(C$,ICOUNTR+1,8) = "DATE-OBS" THEN
           DATETIME$ = MID$(C$,ICOUNTR+11,20)
           IYEAR = VAL( MID$(DATETIME$,2,4) )
           IMON = VAL( MID$(DATETIME$,7,2) )
           IDAY = VAL( MID$(DATETIME$,10,2) )
           IHOUR = VAL( MID$(DATETIME$,13,2) )
           IMIN = VAL( MID$(DATETIME$,16,2) )
           ISEC = VAL( MID$(DATETIME$,19,2) )
           PRINT #2, ""
           PRINT #2, "Year, month, day = ";IYEAR; IMON; IDAY
           PRINT #2, "Hour, minutes, seconds = ";IHOUR; IMIN; ISEC
           GOTO datefinished
      END IF
NEXT II
datefinished:
 
'------------- READ IMAGE DATA ---------------------
 
STARTBYTE& = NHEADSIZE*80 + 1
 
IF IMGTYPE = 16 THEN      'start of 16-bit integer (BITPIX = 16) image data input
CLOSE #1
'read (GET) binary data as array of 2-byte strings-
DIM PIXDATASTI(1 TO NROW*NCOL) AS STRING * 2
'read in binary data-
OPEN FILIN$ FOR BINARY AS #5
GET #5, STARTBYTE&, PIXDATASTI() TO COUNT&
PRINT #2, ""
PRINT #2, "Number of 2-byte data strings read from file = "; COUNT&
 
'reverse string bytes and convert to real-
DIM PIXDATAI%(1 TO NROW*NCOL)
FOR IPIX&=1 TO NROW*NCOL
      PIXDATAI%(IPIX&) = CVI(STRREVERSE$(PIXDATASTI(IPIX&)))
NEXT IPIX&
 
'load pixel data into 2-D image array
'note- images in AIP4WinV2 start at (0,0) in upper left corner-
DIM PIXVAL!(0 TO NCOL-1,0 TO NROW-1) 'row = J, col = I
IROW = 0
ICOL = -1
FOR IPIX&=1 TO NROW*NCOL
      ICOL = ICOL + 1
      IF ICOL > NCOL-1 THEN 'start new row
           IROW = IROW + 1
           ICOL = 0
      END IF
      PIXVAL!(ICOL,IROW) = PIXDATAI%(IPIX&)*BSCALE + BZERO
NEXT IPIX&
GOTO FinishedReading
END IF 'end of 16-bit integer (BITPIX = 16) image data input
 
IF IMGTYPE = -32 THEN      'start of 32-bit floating point image data input
CLOSE #1
'read (GET) binary data as array of 4-byte strings-
DIM PIXDATASTR(1 TO NROW*NCOL) AS STRING * 4
'read in binary data-
OPEN FILIN$ FOR BINARY AS #5
GET #5, STARTBYTE&, PIXDATASTR() TO COUNT&
PRINT #2, ""
PRINT #2, "Number of 4-byte data strings read from file = "; COUNT&
 
'reverse string bytes and convert to real-
DIM PIXDATAR!(1 TO NROW*NCOL)
FOR IPIX&=1 TO NROW*NCOL
      PIXDATAR!(IPIX&) = CVS(STRREVERSE$(PIXDATASTR(IPIX&)))
NEXT IPIX&
 
'load pixel data into 2-D image array
'note- images in AIP4WinV2 start at (0,0) in upper left corner-
DIM PIXVAL!(0 TO NCOL-1,0 TO NROW-1)      'row = J, col = I
IROW = 0
ICOL = -1
FOR IPIX&=1 TO NROW*NCOL
      ICOL = ICOL + 1
      IF ICOL > NCOL-1 THEN      'start new row
           IROW = IROW + 1
           ICOL = 0
      END IF
      PIXVAL!(ICOL,IROW) = PIXDATAR!(IPIX&)*BSCALE + BZERO
NEXT IPIX&
GOTO FinishedReading
END IF      'end of 32-bit floating point image data input
 
FinishedReading:
 
'----------------- IMAGE PROCESSING ------------------
 
' In this section you can put code for processing
' the image data.
 
'------------------ WRITE FILE ---------------------
 
'data in output file will be written as 32-bit floating point.
'byte order will be re-reversed to big-endian for FITS.
'Change value of BITPIX in header, and change value of BZERO-
MID$(C$,LOCBITPIX,32) = "BITPIX = -32 /"
MID$(C$,LOCBZERO,32) = "BZERO = 0.00000000000E00 /"
PRINT #2, ""
PRINT #2, "OUTPUT FILE HEADER:"
PRINT #2, C$
 
'determine how much padding is required at end of data to
'make up last 2880-byte block
NUMBYTESNEEDED& = NCOL*NROW*4
RB = NUMBYTESNEEDED& /2880
EXTRABYTES& = 2880*(INT(RB)+1) - NUMBYTESNEEDED&
PRINT #2, ""
PRINT #2, "Number of NUL bytes added to end of data (padding) = "; EXTRABYTES&
'create long NUL string for last data block-
D$ = NUL$(EXTRABYTES&)
 
'create long data array for image values-
IVALUES& = 0
DIM DATAOUT!(1 TO NCOL*NROW)
FOR JJJ=0 TO NROW-1
      FOR III=0 TO NCOL-1
           IVALUES& = IVALUES& + 1
           DATAOUT!(IVALUES&) = PIXVAL!(III,JJJ)
      NEXT III
NEXT JJJ
 
'convert real values to strings, reverse byte
'order in strings, and convert back to reals-
FOR IVALUES&=1 TO NCOL*NROW
      DATAOUT!(IVALUES&) = CVS(STRREVERSE$(MKS$(DATAOUT!(IVALUES&))))
NEXT IVALUES&
 
'write (PUT) new FITS file-
OPEN FILOUT$ FOR BINARY AS #8
PUT$ #8, C$      'write header
PUT #8, STARTBYTE&, DATAOUT!()      'write image data
PUT$ #8, D$      'write padding
CLOSE #8
 
END
 
END FUNCTION

Right-click or option-click on the link immediately below and choose "Save As...." or "Save Target As...." to download a text file (.bas) containing a "clean" (no HTML tags) listing of this program.

Listing of PowerBasic Program for Reading and Writing FITS Image Files (ver. 1.0)

Right-click or option-click on the link immediately below and choose "Save As...." or "Save Target As...." to download an executable version (.exe) of this program.

Executable PowerBasic Program for Reading and Writing FITS Image Files (ver. 1.0)

 

FILE COMPATIBILITY ISSUE:
FITS-BASIC has exhibited a problem in opening certain FITS files created by AIP4WinV2 (particularly dark files and defect maps, but maybe others). In this situation, the program will "hang" and a 0-byte version of the file that was to be opened will be written to the directory. The FITS-BASIC log file will show that the process stopped before the file header was read. Currently, I have no idea why this is happening. But, if you take the suspect file and open it in another application, like Maxim DL, and then save it again, FITS-BASIC will open the new version of the file with no problems. It must be something with how AIP4WinV2 is creating these files. I need to download the latest version of AIP4Win to see if this situation has been corrected. Until then, be aware of this possible problem and it's work-around.

PROGRAM HISTORY:

Version 1.0 June 2015 Initial release.

 


SOCO Image Autoprocessing Module (SIAM)

 

In the Image Processing pages of this website, I have laid out the steps for performing basic image processing functions on FITS astronomical imagery. While procedures like Basic FITS Image Processing Part I are straight-forward, they can be very tedious to perform manually with your image processing software (like AIP4WinV2) for a large number of raw light images. It's not unusual for me to spend 3 to 4 hours processing a set of images. Many of the initial processing steps are just repetitive "mechanical" operations (like subtracting one image from another, or multiplying an image by some factor) that don't require any decision-making. These are the ideal kinds of activities that can be done automatically by a computer. So, in response to this opportunity, I've spent a couple of weeks writing a PowerBasic computer program that can automatically perform all these otherwise tedious and time-consuming functions. This program is called the SOCO Image Autoprocessing Module, or "SIAM".

In its current form, SIAM automatically performs Steps 4, 5, 6 and 7 in the Basic FITS Image Processing Part I procedure. It also tacks on Step 2 from the Basic FITS Image Processing Part III procedure, except that it applies the weight factors to the individual light images rather than the Master Light Images. The results should be the same. After running SIAM, all that is left to do is align the images, stack them, normalize the background brightness, and composite them. It takes SIAM about 4.5 minutes to automatically process 30 raw light images. Besides the set of raw light images, you need to provide a Master Dark Image, a Defect Map, and Master Flat Images appropriate for the optical system and spectral bands processed.

SIAM uses FITS-BASIC (described above) for the input and output of FITS images. It uses my procedure for calculating stellar elevation angle and atmospheric transmissivity (also described above) for calculating the atmospheric effects. For performing defect correction, it uses the approach described in the user's documentation for AIP4WinV2. The rest is just algebra. Much of the information needed in performing the processing functions is taken directly from the image headers. The results of tests I've performed on images processed using SIAM and processed manually show that the resulting pairs of processed images are essentially identical.

 


SuperSIAM

 

As described above, SIAM was an attempt to automate the sequence of image processing functions found on the Image Processing pages of this website. This sequence of processing functions essentially follows the standard steps laid out in sources such as the Handbook of Astronomical Image Processing (Richard Berry and James Burnell, Willman-Bell Publishers, 2009). However, after doing imaging processing for some time, I have devised my own sequence of processing steps that I feel has some advantages over the standard method. So, I took SIAM and completely re-formulated it to incorporate my sequence of image processing functions. I have called this new application SuperSIAM, as it supercedes the previous version.

SuperSIAM incorporates a number of important changes in the philosophy of processing astronomical images. These are outlined below.

SuperSIAM uses dark images, but not in the standard way. Normally, a master dark image (created from a sequence of individual dark images) is subtracted from the light images to remove the contribution due to the thermal noise of the imaging camera. I found that this process can result in negative pixel values being introduced into the image data. Later in the processing sequence when the light images are divided by weight factors (that normally have values less than 1), the positive pixel values are increased while the negative pixel values are driven to be more negative. This increases the overall variance in the image data, which is something you normally don't want. To avoid this problem, some people add a "pedestal" to the image data after subtracting the master dark to keep all the image pixels positive. In SuperSIAM, the thermal noise is left in the imagery to act as a pedestal. It can easily be removed later during contrast stretching of the imagery.

In SuperSIAM, dark images are used for two purposes. The user must supply a minimum of five raw dark images for processing light images. Ideally, these should have been acquired immediately before or after the acquisition of the light images. The first purpose for these dark images is creating a "hot pixel" image. The five raw dark images are processed using a median procedure to indentify hot pixels in the imagery. This hot pixel image is used later in SuperSIAM to remove hot pixels from the light images.

The second purpose for dark images in SuperSIAM is to create a "bias" image. In the dark images, it can be seen that pixels near the left and right edges of the imagery are consistently brighter. This may be due to the conduction of heat to the imaging CCD from these edges. To create a bias image, the individual dark images are first processed to remove all unusually "bright" pixels (hot pixels and cosmic ray hits) using a median procedure. The individual images are then averaged to produce and average dark image. This average image is normalized by the average pixel value for the center portion of the image (not affected by the edge effects). Later in SuperSIAM, the light images are divided by this normalized bias image to remove the edge effect.

SuperSIAM does not use regular flat images to correct the light imagery for brightness artifacts related to the physical characteristics of the imaging system (like vignetting). Rather, SuperSIAM models a flat image based on previously determined parameters for the imaging system and brightness characteristics of the light imagery. The light images are divided by this modeled flat image after application of the bias image. This feature of SuperSIAM means that it is not necessary to acquire flat images. It should be noted that using modeled flat images in SuperSIAM does not remove "dust donuts" from the light imagery. While dust donuts exist in the light imagery, it has been my experience that they make a negligible contribution to the final processed image. So, at this time, they are ignored by SuperSIAM.

SuperSIAM took some effort to develop, but using it greatly reduces the overall effort in acquiring and processing imagery. Specifically, the only imagery needed to be acquired besides the light images are five dark images. In tests, SuperSIAM produces results that are equal to or better than those produced by my earlier processing efforts, including SIAM. Currently, I'm using a version of SuperSIAM that is specific for my imaging system and operations. In the future, I hope to be able to offer a general version that can be downloaded and used by anyone.

 


SOCO Atmospheric Extinction Coefficient Calculator (SOCO-X)

 

In the Image Processing section of this website, I describe the procedures for calculating the values of atmospheric extinction coefficints (k) from imagery acquired of stars. Manually, this is a rather long and drawn-out procedure. To make the effort much easier, I've written a computer program that will do all the calculations for you. This program is the SOCO Atmospheric Extinction Coefficient Calculator, or "SOCO-X". All you need to run it is a set of FITS images of the target star in the red, green and blue spectral bands and some additional information (latitude and longitude of the observing site, and the RA and Declination of the target star). Details of inputs to the application are presented when you initially run it.

Right-click or option-click on the link immediately below and choose "Save As...." or "Save Target As...." to download the executable file for this application.

SOCO Atmospheric Extinction Coefficient Calculator (ver. 1.0)

I'm indebted to Keith Burnett (keith@xylem.demon.co.uk) for his outline of the computational procedure for calculating astronomical elevation angles (Converting RA and DEC to ALT and AZ), which is used in SOCO-X.

PROGRAM HISTORY:

Version 1.0 January 2016 Initial release.

 


Computer applications available from this website are provided "as is" without any warranty for compatibility or accuracy.

 

 

HOMEReturn to SOCO Image Processing Page            HOMEReturn to SOCO Main Page

Questions or comments? Email SOCO@cat-star.org