pyFitsidi is a python module that creates FITS IDI files.
Download from Github.pyFitsidi is a collection of functions that create headers and data units that conform to the FITS-IDI convention. It was written primarily to convert data from a CASPER correlator into a format that can be imported into data reduction packages such as AIPS++ and CASA.
The Northern Cross, Medicina, Italy. Photo by G. Foster.
The FITS Interferometry Data Interchange Convention (“FITS-IDI”) is a set of conventions layered upon the standard FITS format to assist in the interchange of data recorded by interferometric telescopes, particularly at radio frequencies and very long baselines.
FITS IDI is a registered convention in the NASA/IAU FITS working group registry, meaning it is defined and documented to “a minimum level of completeness and clarity”. FITS IDI files can be read by AIPS, AIPS++ and CASA (although I have only tested with CASA). They are used by the VLBA (Very Long Baseline Array) and JIVE (Joint Institute for VLBI in Europe), among others.
There are a few alternative formats to FITS IDI, such as Miriad FITS files, UVFITS files, and Measurement Sets (MS). Miriad is getting a little long in the tooth, UVFITS is not very well documented, and Measurement Sets are a bit of a pain to create – plus, a MS isn’t a FITS file, so it can’t be read by FITS readers.
Much more info on the FITS IDI convention can be found on its official page. If you’re not familiar with FITS files, you might also want to look at the actual FITS definition. Finally, there are useful FITS resources at the NASA FITS website.
The actual reading/writing of FITS files is done by the PyFITS package. You’ll also need numpy for array handling and lxml for parsing config XML files.
In the file createMedicinaFITS.py, we make use of pyEphem for astronomical calculations, and pyTables for HDF5 file I/O. Yo
A simple example of how to use pyFitsidi.py can be found in the createFitsIDI.py:
>>> """
... createFitsIDI.py
... =============
...
... Creates a basic FITS IDI file, with headers created from an XML configuration file.
...
... Created by Danny Price on 2011-04-20.
... Copyright (c) 2011 The University of Oxford. All rights reserved.
...
... """
...
... # Required modules
... import sys, os
... import pyfits as pf, numpy as np
...
... # import modules from this package
... from pyFitsidi import *
...
... def main():
... """
... Generate a blank FITS IDI file.
... """
...
... # What are the filenames for our datasets?
... fitsfile = 'blank.fits'
... config = 'config/config.xml'
...
... # Make a new blank FITS HDU
... print('Creating Primary HDU')
... print('------------------------------------\n')
... hdu = make_primary(config)
... print hdu.header.ascardlist()
...
... # Go through and generate required tables
... print('\nCreating ARRAY_GEOMETRY')
... print('------------------------------------')
... tbl_array_geometry = make_array_geometry(config=config, num_rows=32)
... print tbl_array_geometry.header.ascardlist()
...
... print('\nCreating FREQUENCY')
... print('------------------------------------')
... tbl_frequency = make_frequency(config=config, num_rows=1)
... print tbl_frequency.header.ascardlist()
...
... print('\nCreating SOURCE')
... print('------------------------------------')
... tbl_source = make_source(config=config, num_rows=1)
... print tbl_source.header.ascardlist()
...
... print('\nCreating ANTENNA')
... print('------------------------------------')
... tbl_antenna = make_antenna(config=config, num_rows=32)
... print tbl_antenna.header.ascardlist()
...
... print('\nCreating UV_DATA')
... print('------------------------------------')
... # Number of rows req. depends on num. time dumps and num. of baselines
... # Once you have data, it would be worth setting these dimensions automatically
... # For now, we're hard-wiring in 1 time dump, 528 baselines (32 element array)
... (t_len, bl_len) = (1,528)
... tbl_uv_data = make_uv_data(config=config, num_rows=t_len*bl_len)
... print tbl_antenna.header.ascardlist()
...
... print('\nCreating HDU list')
... print('------------------------------------')
... hdulist = pf.HDUList(
... [hdu,
... tbl_array_geometry,
... tbl_frequency,
... tbl_antenna,
... tbl_source,
... tbl_uv_data
... ])
...
... print('\nVerifying integrity...')
... hdulist.verify()
...
... if(os.path.isfile(fitsfile)):
... print('Removing existing file %s...')%fitsfile
... os.remove(fitsfile)
... print('Writing to file %s...')%fitsfile
... hdulist.writeto(fitsfile)
...
... print('Done.')
...
...
... if __name__ == '__main__':
... main()
A more complicated example is shown in createMedicinaFITS.py. In this file, a complete FITS IDI file is generated from an XML config file and a HDF5 data file. While the XML and HDF5 data are specific to the Medicina BEST-2 telescope, this file could be adapted as required.
In createMedicinaFITS.py, only the mandatory binary tables are created: array_geometry, antenna, frequency, source and uv_data.
Created by Danny Price on 2011-04-28. Copyright (c) 2011 The University of Oxford. All rights reserved.
This file is a collection of modules for creating blank FITS IDI files. It consists mainly of pretty basic functions to create blank tables.
The FITS handling is all done by pyFits, and blank arrays are created with numpy. So you’ll need to have both of these installed on your machine. In addition, the config xml file is read with lxml, so install that too.
Here is a quick rundown of the tables that this script can make. Not all these tables are mandatory, so I’ve starred the ones which are the most important to understand and to get into your dataset.
These tables are new from the FITS IDI update, and are all optional:
Creates a vanilla ANTENNA table HDU
Parameters : | config: string :
num_rows: int :
|
---|
Notes
CASA didn’t like importing POLCALA and POLCALB, so they are currently commented out.
Table is built with the following columns:
Creates a vanilla ARRAY_GEOMETRY table HDU.
One row is required for each antenna in the array (num_rows)
Parameters : | config: string :
num_rows: int :
|
---|
Notes
Table is built with the following columns:
Creates a vanilla BANDPASS table HDU
Parameters : | config: string :
num_rows: int :
|
---|
Notes
Table is built with the following columns:
Makes baseline table The BASELINE table contains baseline-dependent multiplicative and additive corrections.
This table is currently not supported (on the todo list)
Make calibration table
From the FITS IDI documentation: This chapter is included for documentation and discussion purposes only. So far as this author is aware, no software has been implemented to either write or read the CALIBRATION table. Therefore, the description provided in this section should be regarded as tentative. In fact, it is not at all clear what the intentions were in the case of some of the columns specified for this table.
This table is currently not supported (on the very bottom of the todo list)
Creates a vanilla FLAG table HDU
Parameters : | config: string :
num_rows: int :
|
---|
Notes
This table is optional.
Table is built with the following columns:
Creates a vanilla FREQUENCY table HDU
Parameters : | config: string :
num_rows: int :
|
---|
Notes
Table is built with the following columns:
Creates a vanilla GAIN_CURVE table HDU
Parameters : | config: string :
num_rows: int :
|
---|
Notes
This is an optional table (we will not include it). Todo: Add switch to allow dual polarisation.
Table is built with the following columns:
Creates a vanilla INTERFEROMETER_MODEL table HDU.
Parameters : | config: string :
num_rows: int :
|
---|
Notes
This table is optional, and is not included in Medicina FITS IDI
Table is built with the following columns:
Make model comps table
The MODEL COMPS table is one of those reserved for use by the VLBA. As such, I can’t see anyone in CASPER needing it any time soon.
Again, this table is currently not supported (on the todo list)
Creates a vanilla PHASE-CAL table HDU
Parameters : | config: string :
num_rows: int :
|
---|
Notes
This is an optional table (we will not include it)
Table is built with the following columns:
Creates the primary header data unit (HDU).
This function generates header keywords from the file headers/primary.tpl
Parameters : | config: string :
|
---|
Creates a vanilla SOURCE table HDU
Parameters : | config: string :
num_rows: int :
|
---|
Notes
Table is built with the following columns:
Creates a vanilla SYSTEM_TEMPERATURE table HDU
Parameters : | config: string :
num_rows: int :
|
---|
Notes
This is an optional table. Todo: add dual pol support.
Table is built with the following columns:
Creates a vanilla UV_DATA table HDU
Parameters : | config: string :
num_rows: int :
|
---|
Notes
Table is built with the following columns:
Makes weather table The WEATHER table contains meteorological data for the antennæ and times used in the FITS-IDI file.
This table is currently not supported (on the todo list)
Finds tagname, in elementTree x, parses and returns dictionary of values This is a helper function, and is not usually called directly.
Notes
This function uses eval() to evaluate the text string inside a child tag. As such, exercise caution! todo: block off certain modules to eval()
Some useful functions for converting in between Right Ascension (hours,mins,secs) and Declination (degrees,mins,secs) to degrees and radians. These functions are all named in the same format: a2b(), where a is the original data, and b is the new data format.
All of this type of basic stuff can be done with pyEphem or similar, but I wanted something super simple.
Created by Danny Price on 2011-05-01. Copyright (c) 2011 The University of Oxford. All rights reserved.
Converts degrees, minutes seconds into degrees i.e. a floating point number in range (0,360)
Parameters : | deg: int :
min: int :
sec: float :
|
---|
Converts degrees, minutes seconds into radians i.e. a floating point number in range (0,2pi)
Parameters : | deg: int :
min: int :
sec: float :
|
---|
Convert number in degrees to declination degs, arcmins, arcsecs Returns in list (hours,mins,secs)
Parameters : | degrees: float :
|
---|
Converts from degrees to radians. This is just a numpy call...
Parameters : | degrees: float :
|
---|
Convert number in degrees to right ascension HH,MM,SS.SS Returns in list (hours,mins,secs)
Parameters : | degrees: float :
|
---|
Convert number in radians to declination degs, arcmins, arcsecs Returns in list (hours,mins,secs)
Parameters : | radians: float :
|
---|
Converts from radians to degrees. This is just a numpy call...
Parameters : | radians: float :
|
---|
Convert number in radians to right ascension H,M,SS.SS Returns tuple (hours,mins,secs)
Parameters : | radians: float :
|
---|
Converts list (hours,minutes,seconds) to degrees Value returned in range (0,360)
Parameters : | h: int :
h: int :
s: float :
|
---|
Converts list (hours,minutes,seconds) to radians Value returned in range (0,2pi)
Parameters : | h: int :
h: int :
s: float :
|
---|