R language utility functions with astronomical application


The R language is a straightforward and powerful language for manipulating, analyzing, and displaying data.   It is free software with releases for Unix, Windows, and Mac operating systems.   The language is in active open-source development by the R Development Core Team of the R Foundation for Statistical Computing, Vienna, Austria, as a language and environment for statistical computing.   More information is available at http://www.R-project.org.

For the code below, comments and bug reports are always welcome; a contact link is at the bottom of the page.  The latest versions of the packages are here; current or earlier versions are on CRAN.

Time and position functions

Functions for time (sidereal time, Julian day, modified Julian day), position (elevation, azimuth, angular distance, B1950-J2000 precession and vice versa), and calibration (convolution of a disk and Gaussian, flux from a uniform thermal disk). 

Observational cosmology functions

Functions to compute distances, comoving volumes, lookback time, and luminosities (mostly but not entirely geared toward molecular line observations) in a flat cosmology. 

FITS file utilities

Functions in FITSio read multi-dimensional arrays (images and image cubes) and bintables, and write a multi-dimensional array (image or image cube) data.  The function contains sub-functions that can read, edit, and parse headers and read image and binatbles independently.  For usage and examples see the comments at the top of the file.  Within these extension types, the only known incompleteness is the absence of bit, complex and array descriptor data types for bintables.  
FITS is the Flexible Image Transport System, a common file format in astronomy.  Further information, including format specifications and example files, is available at http://fits.gsfc.nasa.gov/ and http://www.cv.nrao.edu/fits/, among other places.

Binning (akin to smoothing but for independent bins, not binning for e.g. histograms)

Binning in this application is averaging adjacent elements in a vector, for instance binning a spectrum to increase the signal to noise ratio at the cost of spectral resolution.  As an example, for a sequence of numbers {1 5 3 8 9 2}, binning by three would produce the two values {3, 6.33}, the means of (1+5+3)/3 = 3 and (8+9+2)/3 = 6.33.

bin.r is a straightforward but inefficient (it uses a for loop) binning routine that is useful for simple vectors.  For usage see the comments at the top of the file.

binmat.r generates a matrix that, with a matrix multiplication, bins vectors or multiple vectors stored in matrices.  This is efficient for binning large numbers of vectors.  binmat2.r does the same but leaves the size of the original matrix unchanged by repeating elements within the bins.  For usage see the comments at the top of the file.

Miscellaneous functions

ha_freq.r generates the frequencies of H-alpha recombination lines.
ruze.r gives the Ruze efficiency factor as a function of rms surface error and frequency.
clipIm.r enhances image contrast by clipping the amplitudes of an image (array).
svdinv.r  performs an SVD matrix inversion for ill-conditioned or non-square matrices.



Code on this page was developed for analyzing instrumental data from the Zpectrometer, an ultrawideband spectrometer for high-redshift galaxy searches with the U.S. National Radio Astronomy Observatory's 100 meter diameter Robert C. Byrd Green Bank Telescope.   The Zpectrometer was supported by National Science Foundation grant AST-0503946.

Questions or comments?  Please contact Andrew Harris.