# This Python module lists the scan numbers and observed object names from # all of the files under /home/gbtdata for the specified project ID and # device. The default device is the spectral processor. The default # output is stdout, but the output may be directed to a file named in the # third argument. # To run from the Python prompt: # >>> import list_scans # >>> list_scans.list_scans('AGBT02A_069_01') # or # >>> from list_scans import * # >>> list_scans('AGBT02A_069_01') import os, string from fitsio import cfitsio def list_scans ( project, device='SpectralProcessor', out_file='' ) : # assemble the directory path name and get a list of file names path = '/home/gbtdata/' + project + '/' + device ls = os.listdir(path) if len(ls) < 1 : return file_num = 0 # if file output has been requested, open the file if out_file != '' : fd = open(out_file, 'w') # step through every file in the list for fn in ls : sfn = string.split(fn, '.') # if it's not a FITS file, skip it if sfn[-1] == 'fits' : file_num += 1 fpn = path + '/' + fn # open the file to the cfitsio access module for reading status, fits = cfitsio.fits_open_file(fpn, cfitsio.READONLY) # retrieve the SCAN and OBJECT keyword values in the main header status, scan, comment = cfitsio.fits_read_key_lng(fits, 'SCAN') status, object, comment = cfitsio.fits_read_key_str(fits, 'OBJECT') # if it's a spectral pocessor FITS file, skip to the second and # fourth HDU's, and pick up the number of receivers and number # of records (integrations) in the data table if device == 'SpectralProcessor' : q, qq = cfitsio.fits_movabs_hdu(fits, 2) status, num_rcvrs, comment = \ cfitsio.fits_read_key_str(fits, 'NAXIS2') q, qq = cfitsio.fits_movabs_hdu(fits, 4) status, num_records, comment = \ cfitsio.fits_read_key_str(fits, 'NAXIS2') # assemble the output string line = ('Scan ' + str(scan) + ' ' + object + ' - ' + str(num_rcvrs) + ' receivers ' + str(num_records) + ' records') else : line = 'Scan ' + str(scan) + object # print or write the output line if out_file == '' : print line else : fd.write(line + '\n') # close the cfitsio access for this file cfitsio.fits_close_file(fits) # and repeat until no more files # Tell how many FITS files and files of all sort were found in this # directory print file_num, 'FITS files in this directory' print 'Total number of files:', len(ls) # if necessary, close the output file if out_file != '' : fd.close() return # To test uncover one of the list_scans calls below and, from the Python # prompt, execute either # import list_scans # or # reload(list_scans) # list_scans('AGBT02A_069_01') # list_scans('AGBT02A_069_01', 'Antenna') # list_scans('AGBT02A_069_01', out_file='testlist')