Example #1
0
def run_spam_precalibration_stage(UVFITS_BASE_DIR, DIR, UVFITS):
    print "Running SPAM pre_calibrate_targets on " + DIR
    os.chdir(DIR)
    print(DIR)
    UVFITS_FILE_NAME = glob.glob(DIR + "/*.UVFITS")
    print(UVFITS_FILE_NAME)
    if UVFITS_FILE_NAME:
        original_stdout = sys.stdout
        original_stderr = sys.stderr
        precal_log = open('precal_stdout.log', 'a+')
        precal_log.write('\n\n******PRECALIBRATION STARTED******\n\n')
        sys.stdout = precal_log
        sys.stderr = precal_log
        PROJECT_CODE = UVFITS_BASE_DIR.split('/')[4]
        print PROJECT_CODE
        if check_haslam_flag(PROJECT_CODE):
            print(PROJECT_CODE + " Flagging apply_tsys=False")
            try:
                spam.pre_calibrate_targets(UVFITS_FILE_NAME,
                                           apply_tsys=False,
                                           keep_channel_one=True)
                set_flag(UVFITS_BASE_DIR, PRECAL_SUCCESS)
            except Exception as e:
                failed_log = open('failed_log.txt', 'a+')
                failed_log.write("Failed Error: " + str(e))
                failed_log.flush()
                set_flag(UVFITS_BASE_DIR, PRECAL_FAILED)
        else:
            print(PROJECT_CODE + " Flagging apply_tsys=True")
            try:
                spam.pre_calibrate_targets(UVFITS_FILE_NAME)
                set_flag(UVFITS_BASE_DIR, PRECAL_SUCCESS)
            except Exception as e:
                failed_log = open('failed_log.txt', 'a+')
                failed_log.write("Failed Error: " + str(e))
                failed_log.flush()
                set_flag(UVFITS_BASE_DIR, PRECAL_FAILED)
        delete_file(UVFITS_FILE_NAME[0])
        PROCCEED_FILE_LIST = glob.glob(DIR + "/*")
        sys.stdout = original_stdout
        sys.stderr = original_stderr
        precal_log.flush()
        if PROCCEED_FILE_LIST:
            for EACH_FILE in PROCCEED_FILE_LIST:
                move_files(EACH_FILE, UVFITS_BASE_DIR + "/PRECALIB")
    else:
        set_flag(UVFITS_BASE_DIR, PRECAL_FAILED)
Example #2
0
def run_precalibrate_targets(filename):
    print("spam.precalibrate_targets")
    # spam.set_aips_userid(11)
    project_code = os.path.dirname(filename)
    copy_uvfits = os.system('cp ' + filename + ' fits/')
    print('cp ' + filename + ' fits/')
    uvfits_file = filename.split('/')[-1]
    try:
        spam.pre_calibrate_targets("fits/" + uvfits_file, keep_channel_one=True)
        rm_tmp = os.system('rm fits/' + uvfits_file)
        print(uvfits_file, project_code)
    except Exception as ex:
        print(ex)
    precalib_dir = project_code + '/PRECALIB'
    if not os.path.exists(precalib_dir):
        print(precalib_dir)
        os.mkdir(precalib_dir)
    mv_datfil = os.system('mv datfil/* fits/')
    mv_fits = os.system('mv fits/* ' + precalib_dir + '/')
Example #3
0
def precalibrator(CURRENT_DIR):
    os.chdir('fits/')
    original_stdout = sys.stdout
    original_stderr = sys.stderr
    l2u_precal_log = open('l2u_precal.log', 'a+')
    l2u_precal_log.write('\n\n\n******PRECALIBRATION STARTED******\n\n\n')
    sys.stdout = l2u_precal_log
    sys.stderr = l2u_precal_log
    uvfits_files = glob.glob('*.UVFITS')
    #print uvfits_files
    final_list = []
    precalibrator_log = open('precalibrator_log.txt', 'a+')
    #os.system('pwd')
    #print('\n\n\nPrinting user ID AIPS\n\n\n')
    #print spam.get_aips_userid()
    if uvfits_files != []:
        try:
            #To get a list of newly added files after precalibration
            spam.pre_calibrate_targets(uvfits_files[0])
            precalibrator_log.write(
                hostname + "\n" + "Successful precalibration of " +
                str(uvfits_files[0]) +
                '\n********************************************************\n')
            precalibrator_log.flush()
            os.remove(str(uvfits_files[0]))
        #print "*****Precalibration of UVFITS DONE*****"
        except Exception, r:
            precalibrator_log.write(
                hostname + "\n" + "Error in precalibration of " +
                str(uvfits_files[0]) + '\n' + str(r) +
                '\n********************************************************\n')
            precalibrator_log.flush()
            failed_files.write(CURRENT_DIR + '/' +
                               str(uvfits_files[0]).replace('.UVFITS', '') +
                               " : Precalibration error\n")
            failed_files.flush()
Example #4
0
import re
import os
import glob
import spam
data_dir = '/data2/archit/kaka1/partialcycle20/'
os.chdir(data_dir)
all_observations = os.listdir(data_dir)
for DIR_NAME in all_observations:
    os.chdir(data_dir + DIR_NAME + '/')
    lta_files = glob.glob('*.lta')
    uvfits_files = glob.glob('*.UVFITS')
    flag_files = glob.glob('*.FLAGS*')
    for i in range(1, len(uvfits_files)):
        spam.pre_calibrate_targets(uvfits_files[i])