DEFOT - an IDL package for time-series photometry


DEFOT is a package I have developed in IDL for obtaining light curves of planetary transits from raw fits files. It performs aperture photometry but can also deal with bias and flat-field images, sort and rename fits file based on header keywords, etc. It is optimised for analysing defocussed photometry but can be used for in-focus observations too.

Please do not link to this page, or send the link to anybody without asking me first.

The code is not intended to be publicly available, as its programming style is sub-optimal and I only have limited time available to provide support. But my collaborators are welcome to use the code at their own risk. I use DEFOT a lot and it works well for me, but I am also happy to receive bug reports.

Installing the code

DEFOT is in standard IDL but relies on some external packages. I use it on a laptop currently running kubuntu and IDL version 8.1. Here are all the files you should need to use DEFOT. Simply save them to a directory which is in your IDL_PATH environment variable. I recommend putting them in their own directory so it is easier to find them at a later date.

Files which can be downloaded here:

  1. defotpro2.pro   This text file contains the main code library and is frequently updated.
  2. defotlc.pro   This text file contains the code for calculating the final light curves and is frequently updated.
  3. defot.pro   Unlike all other files, this one is intended to be kept in the directory you are working in, so one example exists for each dataset you are working with. defot.pro is where all the input parameters for a dataset are kept, making it easy to retrace or revise previous work.
  4. jkt_strsub.pro   This text file is a small function I wrote to replace strings with other strings.
  5. madpoly.pro   This text file is a small procedure written by Pierre Maxted to fit polynomials to data containing many outliers.
  6. defotpro.pro   This text file is the old version of the code. I no longer use or support this code, but include it here for reference.

Files which must be downloaded from external sources. Modifications to these files are outside my control, so in principle could affect DEFOT in the future.

  1. ASTROLIB   NASA's IDL ASTROLIB library. This is absolutely crucial to DEFOT. Check the readme file for installation instructions.
  2. MPFIT   Craig Markward's MPFIT suite for fitting functions in IDL. Very easy to install.
  3. time conversion routines from Jason Eastman (see his paper). Check the readme file for installation instructions. Check that your list of leap seconds is up to date.
  4. barycen.pro (and file_exist.pro)   Routine from Tübingen for calculating the barycentric correction.
  5. getcolor.pro   A widely-available routine for generating plotting colours in many desktop environments.
  6. imdisp.pro   A widely-available routine for plotting images in an IDL window.

Running the code

Once you have installed all the required procedures mentioned above, you can start using DEFOT.

Copy the defot.pro file into the directory where your fits files are. You could put your fits files elsewhere (I usually keep them in multiple sub-directories) and give DEFOT their file path.

Modify the parameters in defot.pro so they match the values you want to use for your fits files.

Enter the IDL command-line environment. This is usually done by typing   idl   on the terminal command line.

Type   .r defot   and follow the prompts. Further input may be by keyboard or mouse depending on what you want to do.

There is an alternative way of running "lc" on an output file from "ap": on the IDL command line type   defotlc, 'name_of_ap_file'   and follow the instructions on the screen.

 


Code options

DEFOT has several tasks it can perform, each requiring some input parameters. If these are not present then you will be prompted to type them in. A few optional parameters are set to reasonable defaults if they are not defined in the input file.

"sf": sort fits files

Required input parameters: SORTFRAMES, HEADFMT, EXTENSION, REFIMG

This sorts fits files into directories depending on a header keyword. Some possible keywords are given for the reference image to help the user make their choice. The resulting directories will be named after the value of the header keyword and put into the directory sortfits_defot.

"re": rename fits files

Required input parameters: RENAMEFRAMES, REPLACE_IN, REPLACE_OUT

This renames a set of files by replacing given strings in their names with substitute strings. I originally wrote it so I could shorten some very long file names constructed according to the ESO standard. The files started off called something like DFOSC_FASU.2008-09-28T02:42:30.000.fits and ended up called something like 2008-09-28T02-42-30.fits.

"di": display multiple fits files sequentially

Required input parameters: DISPFRAMES, HEADFMT, EXTENSION

Optional input parameters: WINDOWSIZE, HISTMINV, HISTPOWER

This displays a set of fits images using the imdisp procedure. Press [enter] to advance from one to the next.

"pc": do interactive aperture photometry on one fits file

Required input parameters: PCFRAME, OBSERVATORY, HEADFMT, EXTENSION, PADU, READNOISE

Optional input parameters: MAXCOUNTS, WINDOWSIZE, HISTMINV, HISTPOWER

This allows the user to perform aperture photometry on a single fits file. The stars and apertures are defined interactively.

"mb": create a master bias image

Required input parameters: BIASFRAMES, HEADFMT, MASTERBIAS, EXTENSION

Optional input parameters: WINDOWSIZE, HISTMINV, HISTPOWER

This reads in and displays a set of bias images for the user to inspect. The user specifies which to include and which to reject. The ones to include are then combined into a single master bias image by median-combining.

"mf": create a master flat-field image

Required input parameters: FLATFRAMES, HEADFMT, EXTENSION, MASTERBIAS

Optional input parameters: WINDOWSIZE, HISTMINV, HISTPOWER

This reads in and displays a set of flat-field images for the user to inspect. The user specifies which to include and which to reject. The ones to include are then combined into a single master flat-field image by scaling them to unit median flux and then median-combining. This is a good way of using flat-fields with different illumination levels, whilst robustly rejecting transient feature (e.g. stars in twilight flat-fields).

"fb": apply bias and flat-field calibration to a set of fits files

Required input parameters: SCIFRAMES, HEADFMT, EXTENSION, MASTERBIAS, MASTERFLAT, XINTERVAL, YINTERVAL

Optional input parameters: WINDOWSIZE, HISTMINV, HISTPOWER

This calibrates a set of fits images by subtracting the master bias image and then dividing by the master flat-field image. The calibrated images are outputted into a new directory. If performing aperture photometry with "ap" you do not need to perform the "fb" task first.

"su": set up apertures for photometry

Required input parameters: SCIFRAMES, HEADFMT, EXTENSION, MASTERBIAS, MASTERFLAT, REFIMG, PSTAMP, CLOSEUP

Output parameters: APERX, APERY, APERSIZE

Optional input parameters: WINDOWSIZE, HISTMINV, HISTPOWER

This interactively sets up the apertures for photometry, using a reference image. First the stars of interest are indicated by clicking on them with the mouse. Then the aperture sizes are specified by hand, whilst being plotted around the first star for visual inspection and adjustment.

"ap": perform aperture photometry

Required input parameters: SCIFRAMES, HEADFMT, EXTENSION, MASTERBIAS, MASTERFLAT, REFIMG, APERX, APERY, APERSIZE, OBSERVATORY, APOUTFILE, SHOW, TRACK, XTRACK, YTRACK, XINTERVAL, YINTERVAL, PADU, READNOISE

Optional input parameters: MAXCOUNTS, WINDOWSIZE, HISTMINV, HISTPOWER, right ascension and declination

This is the big one. It performs aperture photometry on a set of fits images. If MASTERBIAS and/or MASTERFLAT are specified it debiases and/or flat-fields the images first. The science images can be smaller than the master bias and flat-field images - in this case you will need to specify XINTERVAL and YINTERVAL. Several options for tracking the image motion are implemented. You can use "n" for no tracking, or "c" for centroiding each aperture, or "x" for cross-correlating each image against the reference image. I almost always use "x".

"lc": construct light curves

Required input parameters: APOUTFILE

Optional input parameters: WINDOWSIZE

This is another important one, and uses only the photometry file from "ap". It can plot the results and auxiliary properties, create differential-magnitude light curves, and detrend datasets containing transits etc. You can run this procedure directly from the IDL command line by typing   defotlc, 'name_of_ap_file'   instead of accessing it from DEFOT.

 


List of parameters

"float" means floating-point number and can be single or double precision. I always work in double precision.

The parameters are defined using standard IDL syntax. You can therefore use expressions or even call subroutines to define them. One option I use a lot is to have most parameters defined at the top of defot.pro and then have multiple blocks of the important parameters below, each corresponding to a different dataset. To work with a specific dataset I simply comment out the blocks of parameters for the other ones. This allows me to keep multiple similar datasets together and analyse them all with the same defot.pro file.

Parameter Type Explanation
SORTFRAMES
RENAMEFRAMES
DISPFRAMES
BIASFRAMES
FLATFRAMES
SCIFRAMES
string These input parameters specify the file names to use for the different DEFOT options. Each parameter is actually a string which can be executed at runtime to find the files to use. You can therefore use IDL commands such as findfile and file_find or alternatively specify an array of filenames directly. Examples:
SCIFRAMES = "findfile('WASP26/*.fits')"
SCIFRAMES = "['WASP26/000001.fits','WASP26/000002.fits','WASP26/000003.fits']"
HEADFMT string This is the type of header format to use. These are manually defined inside defotpro2 but new ones can be created quite easily. These header formats are defined:
dk dk2 efosc loiano busca 123ccd2 grond
EXTENSION integer Some fits files contain multiple images as separate extensions. You can specify which image to use from each file with this parameter. If you have simple fits files with only one image each, use:
EXTENSION = 0
REPLACE_IN
REPLACE_OUT
string arrays These specify one or more sets of strings to be replaced in fits files names. REPLACE_IN givens the string(s) to be replaced and REPLACE_OUT gives the replacement string(s). Example of use:
REPLACE_IN = ['DFOSC_FASU.2',':','.000.fits']
REPLACE_OUT = ['2','-','.fit']
would change "DFOSC_FASU.2008-09-28T02:42:30.000.fits" to "2008-09-28T02-42-30.fits".
REFIMG string or integer or float Which of the images to use as the reference image. There are three options to specify this image. (1) A string will be interpreted as the filename of the reference image. (2) A number greater than 1 means the actual number of the image in the list of images. (3) A number between 0 and 1 means the fractional position within the list of images, e.g. 0.5 would correspond to the image at the midpoint of the list.
OBSERVATORY string The name of observatory the images were obtained from. The name must be one of those included in the ASTROLIB/OBSERVATORY procedure. Examples:
eso ca lapalma
MASTERBIAS
MASTERFLAT
strings The file names of the master bias and flat-field images.
PADU
READNOISE
floats The CCD gain (in photons per ADU) and readout noise (in electrons).
XINTERVAL
YINTERVAL
arrays of two floats If the master bias and flat-field images are larger than the science images then they need to be trimmed before use. This could happen if the science images are only a rectangular window covering part of the CCD. XINTERVAL and YINTERVAL give the array indices to use to trim the calibration images. If any of the four number is below zero then no trimming will be performed. In future I might modify DEFOT to get these values from the header automatically.
APERX
APERY
float arrays of same length These are the x and y pixel coordinates of the centres of the apertures for photometry.
APERSIZE array of 3 floats The sizes of the apertures to use. The three numbers give the radii, in pixels, of the target aperture, the inner sky aperture, and the outer sky aperture.
PSTAMP string How close-up images are displayed in "su". The two options are "h" for histeq and "c" for contour plots.
CLOSEUP integer The close-up images will be squares with each side of length CLOSEUP pixels.
SHOW integer Which images to plot on screen whilst doing aperture photometry. 1 means every image, 2 means every second image, etc.
TRACK string Telescope tracking errors induce small pointing changes between images which must be tracked to keep the apertures centred on the stars. Several options for tracking the image motion are implemented. You can use "n" for no tracking, or "c" for centroiding each aperture, or "x" for cross-correlating each image against the reference image. I almost always use "x".
XTRACK
YTRACK
array of 1 or 2 integers If you choose TRACK = 'x' then you need to specify which part of the image to use for cross-correlation. This allows you to avoid parts of the image with bad pixels which could affect the cross-correlation results. To specify part of an image give arrays of two integers which are the lower and upper pixel numbers of the part of the image to use. You could alternatively give an array of one integer N, in which case all pixels within distance N of the outside edge of the image will be ignored.
APOUTFILE string Name of the photometry output file which is produced by "ap" and used by "lc".
RADEG
DECDEG
 
RACHAR
DECCHAR
 
RADECCHAR
float
float
 
string
string
 
string
It is a good idea to specify the right ascension and declination of your target star exactly, to ensure that the barycentric correction is precise. Option 1: use RADEG and DECDEG to specify the RA and Dec in decimal degrees. Option 2: use RACHAR and DECCHAR to give three numbers each, corresponding to RA in hours, minutes, seconds, and Dec in degrees, arcminutes and arcseconds. The numbers can be separated by spaces, colons, commas or underscores. Option 3: use RADECCHAR to give one string containing both RACHAR and DECCHAR. Option 4: if none of these parameters are given, DEFOT will take the sky position from the fits file headers. This could affect your timestamps by several seconds or more, depending on how close your target star is to the centre of the images. Examples:
RADEG = 4.6029167d0 & DECDEG = -0.2673056
RACHAR = '00 18 24.70' & DECCHAR = '-00 16 02.3'
RADECCHAR = '00:18:24.70 -00:16:02.3'
MAXCOUNTS array of two long integers An array giving the minimum and maximum counts per pixel. Values outside these limits will be treated as bad. If MAXCOUNTS is not specified it is set to [0L,65000L].
WINDOWSIZE array of 2 integers Size of the IDL display window in pixels. If it not given then you will get the usual IDL window of default size.
HISTMINV
HISTPOWER
floats These govern how your images are displayed using hist_equal and imdisp. Set the minimum value in hist_equal to be HISTMINV in units where the median of the image equals 1.0. Set the power to raise the hist_equal image to using HISTPOWER. These default to 0.995d0 and 4.0d0, respectively, if not given.

 


Additional notes

 


Last modified: 2013/10/01           John Southworth   (Keele University, UK)