""" Write an AIPS script for the reduction of a given idfile The whole reduction process is 1) run write_aips_script.py to generate the aips file 2) run aips file to load and calibrate the data and save list of scans 3) parse the list of scans to get times and generate commands to drive the saving of the total power text files 4) run parse_listr_scans.py to parse scan list and generate code to save total power text files 5) run plot_total_power_scans.py to generate total power plots 6) run whatever is needed to load data on RFI website As can be seen the whole process is really involved. Part of the complexity is due to the fact that AIPS cannot be easily scripted. I should plan to convert this to ParselTongue at some point. I will talk to Huib about this. wmax, nov 8, 2014 """ import os import sys import imp # load script configuration parameters from PWD # this will ensure that only the configredrfi.py file on current directory is # loaded PWD = os.environ['PWD'] try: configredrfi = imp.load_source('configredrfi', os.path.join(PWD, 'configredrfi.py')) from configredrfi import * except IOError: error_message = """No configredrfi.py file was found in %s use 'redrfi --help' for help\n""" % (PWD) sys.exit(error_message) #------------------------------------------------------------------------------- def write_script(fitsfilename, aips_filename, aips_id='2768', aips_ehexid='24w', input_folder='/home/inti/Documents/usno-sband-tests-2014-08/ts035a/data/', output_folder='/home/inti/Documents/usno-sband-tests-2014-08/ts035a/calibration/output/'): """ Write an AIPS script to load, calibrate total power data and save a list of scans wmax, nov 14, 2014 """ fitld = """%s * Starts with user ID to run it from the command line *------------------------------------------------------------------------------ * Load the data on the fits file *------------------------------------------------------------------------------ default 'fitld' task 'fitld' clint 0.1 datain 'INPUT:%s digicor 1 outname '%s'; outclass 'uvdata' timerang 0 bchan 0; echan 0; bif 0; eif 0 opcode '' antname 'vlba', 'gb', 'ar' inp go wait recat wait """ % (str(aips_id), fitsfile_name, aips_filename) # It doesn't work well when I add this step vlbafix = """ *------------------------------------------------------------------------------ * Add NX table needed to make a list of scans *------------------------------------------------------------------------------ default 'indxr' task 'indxr' inname '%s'; inclass 'uvdata' cparm 0,0,0.1,1 inp go wait """ % (aips_filename) listr = """ *------------------------------------------------------------------------------ * Save the scan list to a text file *------------------------------------------------------------------------------ default 'listr' task 'listr' inname '%s'; inclass 'uvdata' optype 'scan' dparm 0 docrt 0 outprint 'OUTPUT:%s_listr_scan.txt inp go wait """ % (aips_filename, aips_filename) accor = """ *------------------------------------------------------------------------------ * Calibrate data - a priori calibration *------------------------------------------------------------------------------ * Digital sampler bias correction * creates SN = 1 default 'accor' task 'accor' inname '%s'; inclass 'uvdata' timerang 0 solint 2 inp go wait * Apply SN table to CL table * creates CL = 2 default 'clcal' task 'clcal' inname '%s'; inclass 'uvdata' timerang 0 opcode 'calp' interpol '2pt' samptype '' bparm 0 smotype '' snver 1 invers 1 gainver 1 gainuse 2 refant 9 inp go wait """ % (aips_filename, aips_filename) aips_script = """ """ aips_script += fitld aips_script += vlbafix aips_script += listr aips_script += accor # Save AIPS script to text file output_filename = ('%sr.%s' % (aips_filename, aips_ehexid)).upper() fileObj = open(output_filename, 'w') fileObj.writelines(aips_script) fileObj.close() # Notify the user of the script name print 'Creating the AIPS run file "%s"\n' % (output_filename) return output_filename #------------------------------------------------------------------------------- # Run #------------------------------------------------------------------------------- for name_prefix in name_prefixes: # Name of the idifits file to load fitsfile_name = '%s.idifits' % (name_prefix) # Name of the file in AIPS aips_filename = name_prefix # Write the AIPS run file output_filename = write_script(fitsfile_name, aips_filename, aips_id=aips_id, aips_ehexid=aips_ehexid, input_folder=aips_input, output_folder=aips_output) # Run the AIPS script from the command line # Define input and output AIPS folder os.putenv('INPUT', aips_input) os.putenv('OUTPUT', aips_output) aips_command = 'aips notv pr=1 > %s-aipslog.txt < %s' % (output_filename, output_filename) os.system(aips_command)