GBT_RFI_pipeline/process_new_RFI_files.py
def analyze_file(file_to_process,output_directory):
    """
    param: file_to_process:: if the data has passed all checks up to this point, it is a dictionary containing metadata needed to process the RFI file.
    """
    if file_to_process['list_of_scans'] == []:
        raise(EmptyScans)
    # The parameters for running the process are different if the receiver is ka (26_40) so it needs to be called separately
    # Unfortunately IDL does not have an easy way to access module data, so we have to actually navigate to the appropriate directory
    path = str(pathlib.Path(__file__).parent.absolute())+'/'
    temp_path = tempfile.gettempdir()+'/'
    temp_file = open(temp_path+"temp_file.pro","w+")
    temp_file.write('.compile '+path+'scalUtils_wilsonedit.pro\n')
    temp_file.write('.compile '+path+'rfiDisplay_wilsonedit.pro\n')
    temp_file.write('.compile '+path+'process_file\n')
    temp_file.write('offline,  \''+str(file_to_process["filename"])+'\' \n')
    temp_file.write('process_file, '+str(file_to_process["list_of_scans"])+', fdnum='+str(file_to_process["number_of_feeds"])+'-1, ymax='+str(file_to_process["ymax"])+', ifmax = '+str(file_to_process["number_of_IFs"])+'-1, nzoom = 0, output_file=\''+output_directory+'\', temp_path=\''+temp_path+'\', /blnkChans, /makefile')
    if file_to_process['frontend'] == 'Rcvr26_40':
        temp_file.write(', /ka\n')
    else:
        temp_file.write('\n')
    temp_file.write('exit')
    temp_file.close()
    # Create a subprocess that calls the idl script that can process the file. 
    process = subprocess.Popen(['gbtidl', temp_path+'temp_file.pro'])
    # Wait 5 minutes (300 seconds) and if the file does not finish processing, kill it. It has entered an infinite loop
    # Since this process uses gettp, an official GBTIDL module, which does not return errors when it enters an infinite loop, this is the best we can do.
    try:
        print('Running in process', process.pid)
        process.wait(timeout=300)
        # Prints the status of whether or not the subprocess occured to a file. Because of the difficulties of output communications between the IDL subprocess
        # And the python process, it was best to communicate this status through a file
        subprocess_success = open(temp_path+"stat.txt","r").read().strip('\n')
        if subprocess_success == "bad_data":
            raise(BadIDLProcess)
    except subprocess.TimeoutExpired:
        print('Timed out - killing', process.pid)
        process.kill()
        raise(TimeoutError)

    # After we're done with getting the status, go ahead and remove the stat and temporary idl file
    def remove_file(temp_path,filename):
        if os.path.exists(temp_path+filename):
            os.remove(temp_path+filename)
    remove_file(temp_path,'stat.txt')
    remove_file(temp_path,'temp_file.pro')

    param: file_to_process:: if the data has passed all checks up to this point, it is a dictionary containing metadata needed to process the RFI file.
    
: if the data has passed all checks up to this point, it is a dictionary containing metadata needed to process the RFI file.
: if the data has passed all checks up to this point it is a dictionary containing metadata needed to process the RFI file .
def analyze_file(file_to_process,output_directory):
    if file_to_process['list_of_scans'] == []:
        raise(EmptyScans)
    path = str(pathlib.Path(__file__).parent.absolute())+'/'
    temp_path = tempfile.gettempdir()+'/'
    temp_file = open(temp_path+"temp_file.pro","w+")
    temp_file.write('.compile '+path+'scalUtils_wilsonedit.pro\n')
    temp_file.write('.compile '+path+'rfiDisplay_wilsonedit.pro\n')
    temp_file.write('.compile '+path+'process_file\n')
    temp_file.write('offline,  \''+str(file_to_process["filename"])+'\' \n')
    temp_file.write('process_file, '+str(file_to_process["list_of_scans"])+', fdnum='+str(file_to_process["number_of_feeds"])+'-1, ymax='+str(file_to_process["ymax"])+', ifmax = '+str(file_to_process["number_of_IFs"])+'-1, nzoom = 0, output_file=\''+output_directory+'\', temp_path=\''+temp_path+'\', /blnkChans, /makefile')
    if file_to_process['frontend'] == 'Rcvr26_40':
        temp_file.write(', /ka\n')
    else:
        temp_file.write('\n')
    temp_file.write('exit')
    temp_file.close()
    process = subprocess.Popen(['gbtidl', temp_path+'temp_file.pro'])
    try:
        print('Running in process', process.pid)
        process.wait(timeout=300)
        subprocess_success = open(temp_path+"stat.txt","r").read().strip('\n')
        if subprocess_success == "bad_data":
            raise(BadIDLProcess)
    except subprocess.TimeoutExpired:
        print('Timed out - killing', process.pid)
        process.kill()
        raise(TimeoutError)
    def remove_file(temp_path,filename):
        if os.path.exists(temp_path+filename):
            os.remove(temp_path+filename)
    remove_file(temp_path,'stat.txt')
    remove_file(temp_path,'temp_file.pro')
def analyze_file ( file_to_process , output_directory ) : if file_to_process [ 'list_of_scans' ] == [ ] : raise ( EmptyScans ) path = str ( pathlib . Path ( __file__ ) . parent . absolute ( ) ) + '/' temp_path = tempfile . gettempdir ( ) + '/' temp_file = open ( temp_path + "temp_file.pro" , "w+" ) temp_file . write ( '.compile ' + path + 'scalUtils_wilsonedit.pro\n' ) temp_file . write ( '.compile ' + path + 'rfiDisplay_wilsonedit.pro\n' ) temp_file . write ( '.compile ' + path + 'process_file\n' ) temp_file . write ( 'offline,  \'' + str ( file_to_process [ "filename" ] ) + '\' \n' ) temp_file . write ( 'process_file, ' + str ( file_to_process [ "list_of_scans" ] ) + ', fdnum=' + str ( file_to_process [ "number_of_feeds" ] ) + '-1, ymax=' + str ( file_to_process [ "ymax" ] ) + ', ifmax = ' + str ( file_to_process [ "number_of_IFs" ] ) + '-1, nzoom = 0, output_file=\'' + output_directory + '\', temp_path=\'' + temp_path + '\', /blnkChans, /makefile' ) if file_to_process [ 'frontend' ] == 'Rcvr26_40' : temp_file . write ( ', /ka\n' ) else : temp_file . write ( '\n' ) temp_file . write ( 'exit' ) temp_file . close ( ) process = subprocess . Popen ( [ 'gbtidl' , temp_path + 'temp_file.pro' ] ) try : print ( 'Running in process' , process . pid ) process . wait ( timeout = 300 ) subprocess_success = open ( temp_path + "stat.txt" , "r" ) . read ( ) . strip ( '\n' ) if subprocess_success == "bad_data" : raise ( BadIDLProcess ) except subprocess . TimeoutExpired : print ( 'Timed out - killing' , process . pid ) process . kill ( ) raise ( TimeoutError ) def remove_file ( temp_path , filename ) : if os . path . exists ( temp_path + filename ) : os . remove ( temp_path + filename ) remove_file ( temp_path , 'stat.txt' ) remove_file ( temp_path , 'temp_file.pro' )
param: file_to_process:: if the data has passed all checks up to this point, it is a dictionary containing metadata needed to process the RFI file.
param : file_to_process :: if the data has passed all checks up to this point it is a dictionary containing metadata needed to process the RFI file .
"""
    param: file_to_process:: if the data has passed all checks up to this point, it is a dictionary containing metadata needed to process the RFI file.
    """ # The parameters for running the process are different if the receiver is ka (26_40) so it needs to be called separately # Unfortunately IDL does not have an easy way to access module data, so we have to actually navigate to the appropriate directory # Create a subprocess that calls the idl script that can process the file.  # Wait 5 minutes (300 seconds) and if the file does not finish processing, kill it. It has entered an infinite loop # Since this process uses gettp, an official GBTIDL module, which does not return errors when it enters an infinite loop, this is the best we can do. # Prints the status of whether or not the subprocess occured to a file. Because of the difficulties of output communications between the IDL subprocess # And the python process, it was best to communicate this status through a file # After we're done with getting the status, go ahead and remove the stat and temporary idl file
file_to_process
output_directory