Skip to content
Gijs Molenaar edited this page Feb 13, 2014 · 5 revisions

There are currently 3 nodes that handle FITS files. i.e.,

  • FITSImage

  • FITSReader

  • FITSWriter For "closing the loop" there are 2 Nodes. i.e.,

  • FITSDataMux

  • FITSSpigot

FITSImage

This node is used to read in a sky image (extended source) in terms of fluxes (IQUV) and the phase center RA,DEC. The initrec of this node requires two parameters,

  • filename : The name of the file to read

  • cutoff : A value within 0 and 1, to represent the cutoff flux ratio to reduce the size of the image. For example, a cutoff of 0.2 will imply that only the rectangular area containing 20% of the total pixels with highest flux (including the peak) will be selected Note: this node could only be used with a real sky image with 4 coordinate axes l,m,Stokes and Freq. If your image does not have all 4 axes, you can add a degenerate axes to your image using AIPS++ images tool (adddegaxes).

  • mode: 1 or 2, if mode=1, a Sixpack (RA,Dec,I,Q,U,V) is returned. if mode=2, only a single VellSet is returned.

FITSWriter

This node is used to save a Result to a FITS file. The (first) VellSet and the Cells will be saved in the FITS file. Each Vell and the Cells is written out as a separate FITS HDU (Header and Data Unit).The initrec of this node requires one parameter,

  • filename : The name of the file to write to. If this file already exists, the node will fail. However, you can prepend a ! to your filename so that it will be overwritten by default. For example, instead of giving myfile.fits, you can give !myfile.fits so that the file will be overwritten the next time you run this node. Usually a MeqTrees node is not aware of any particular relationship between the individual Vells that it contains, So the FITSWriter also does not know of any relationship between the Vells (and their corresponding HDUs). For example, a Stokes IQUV 'image' read in by the FITSImage node as a single HDU, would be split up into a number of separate HDUs if it was then written out by the FITSWriter. If you want to then relate the contents of the individual HDUs in the output FITS file in some way, you must use an external software program to do so. For example. Here is a small python script which reads in the contents of a FITS file generated from a MeqTrees LMN node and plots L vs M with matplotlib.
#!/usr/bin/env python

# a python script to read in L,M and N from a FITS file
# and plot L vs M

import sys
import numpy
import pyfits
#import matplotlib
import matplotlib.pyplot as plt

def main( argv ):
  # get arguments
  fits_file = argv[1]
  hdulist = pyfits.open(fits_file)
  l =  hdulist[0].data
  m =  hdulist[1].data
  n =  hdulist[2].data
  plt.plot(m, l,'bo')
  plt.xlabel('M')
  plt.ylabel('L')

  cells = hdulist[3].data
  print 'cells ', cells

  plt.title('FPA track in Az-El telescope reference frame')
  plt.grid(True)
  plt.savefig('fpa_track.png')
  plt.show()
#=============================
# argv[1] FITS file with L,M,N track
if __name__ == "__main__":
  main(sys.argv)

FITSReader

This node is used to read in a FITS file and convert the values to a Result that include one VellSet and Cells. The initrec of this node requires one parameter,

  • filename : The name of the file to read. Note that if you need to create a FITS file that can be read from this node, the easiest thing to do is to use the program ~/Timba/WH/contrib/SBY/tools/convert.c . This can read in a text file and write a FITS file. The file should have the following format:
========================= File format 
no_of_axes 
axis1_length (0 if no dependence) 
axis2_length 
... 
axisN_length 
axis1[0] 
axis1[1] 
... 
axis1[axis1_length-1] 
axis2[0] 
.. 
.. 
axisN[axisN_length-1] 
data[0] 
data[1] 
data[2] 
.. 
.. 
.. 
============================ End file format 

Note: if there is no dependence on any axis, just put 0 as the axis length. After the axis length, put grid points for each non-zero length axes. Finally, put the data cube as a vector (Fortran - column major format). 

FITSDataMux

This node is what VisDataMux node is for a MS to a FITS image. It must have a FITSSpigot as a step child. Here is how you use it:

def _define_forest (ns):
   ns.mux<<Meq.FITSDataMux()
   ns.s<<Meq.FITSSpigot()
   ns.other_nodes<<......
   ns.mux.add_children(ns.other_nodes)
   ns.mux.add_stepchildren(ns.s)

and then when you run it,

def _test_forest (mqs, parent):
 inrec = dmi.record();
 inrec.filename= "foo.fits";
 inrec.cutoff=1.0;
 req = meq.request();
 req.input  = inrec;
 b = mqs.execute('mux',req,wait=True);

After your tree is run, this node will write the result of its first child back to the FITS file. So the first child should return a sixpack. If you do not want to modify your image, you can just return the original values read from the image.

FITSSpigot

Used in conjunction with the FITSDataMux, this is the node that reads in the FITS file and returns a sixpack.

Clone this wiki locally