コード例 #1
0
def connect_dadsops():
    '''
    Connect to the MAST database on HARPO and store lists of all files.

    Parameters: 
        None

    Returns: 
        jitdict : dictionary
            Dictionary where the keys are rootnames of jitter files and the 
            values are the corresponding proposal IDs.
        sciencedict : dictionary
            Dictionary where the keys are rootnames of all COS files and the 
            values are the corresponding proposal IDs.
        ccidict : dictionary
            Dictionary where the keys are rootnames of CCI files and the 
            values are the corresponding proposal IDs.
    '''
    
    # Open the configuration file for the MAST database connection (TSQL).
    config_file = os.path.join(os.environ['HOME'], "configure2.yaml")
    with open(config_file, 'r') as f:
        SETTINGS = yaml.load(f)
    
        # Connect to the database.
        Session, engine = load_connection(SETTINGS['connection_string'])
        engine.execute("use dadsops_rep;")
        # Get all jitter, science (ASN), and CCI datasets.
        jitters = engine.execute("SELECT ads_data_set_name,ads_pep_id "
                                 "FROM archive_data_set_all "
                                 "WHERE ads_instrument='cos' " 
                                 "AND ads_data_set_name LIKE '%J';")
        science = engine.execute("SELECT sci_data_set_name,sci_pep_id "
                                 "FROM science WHERE sci_instrume='cos';")
        cci = engine.execute("SELECT ads_data_set_name,ads_pep_id "
                             "FROM archive_data_set_all "
                             "WHERE ads_archive_class='csi';")
       
        # Store SQLAlchemy results as dictionaries (we need dataset name 
        # and proposal ID).
        jitdict = OrderedDict()
        sciencedict = OrderedDict()
        ccidict = OrderedDict()
        for row in jitters:
# WHY DID THIS HAPPEN, I have to use indices
#            jitdict[row["ads_data_set_name"]] = row["ads_pep_id"]
            jitdict[row[0]] = row[1]
        for row in science:
#            sciencedict[row["sci_data_set_name"]] = row["sci_pep_id"]
            sciencedict[row[0]] = row[1]
        for row in cci:
#            ccidict[row["ads_data_set_name"]] = row["ads_pep_id"]
            ccidict[row[0]] = row[1]

        # Close connection
        engine.dispose()
        return jitdict, sciencedict, ccidict
コード例 #2
0
def connect_cosdb():
    '''
    Connect to the COS database on greendev and store lists of all files.

    Parameters:
        None

    Returns:
        nullrows : list
            All rootnames of files where ASN_ID = NONE.
        asnrows : list
            All ASN_IDs for files where ASN_ID is not NONE.
        smovjitrows : list
            All rootnames of jitter files.
    '''
    
    # Open the configuration file for the COS database connection (MYSQL).
    config_file = os.path.join(os.environ['HOME'], "configure.yaml")
    with open(config_file, 'r') as f:
        SETTINGS = yaml.load(f)
    
        # Connect to the database.
        Session, engine = load_connection(SETTINGS['connection_string'])
        # All entries that ASN_ID = NULL (should be individual jits, acqs)
        null = engine.execute("SELECT rootname FROM headers WHERE asn_id='NONE';")
#        null2 = engine.execute("SELECT rootname FROM headers WHERE asn_id IS NULL;")
        # All entries that have ASN_ID defined (will pull science, jit, acq)
#        jitters = engine.execute("SELECT rootname FROM headers WHERE rootname LIKE '%j';")
        jitters = engine.execute("SELECT rootname FROM files WHERE RIGHT(rootname,1) = 'j';")
        asn = engine.execute("SELECT asn_id FROM headers " 
                             "WHERE asn_id!='NONE';")

        # Store SQLAlchemy results as lists
        nullrows = []
        asnrows = []
        smovjitrows = []
        for row in null:
            nullrows.append(row["rootname"].upper())
        for row in asn:
            asnrows.append(row["asn_id"])
        for row in jitters:
            smovjitrows.append(row["rootname"].upper())
        
        # Close connection
        engine.dispose()
        return nullrows, asnrows, smovjitrows
コード例 #3
0
def main():

    print("Querying the whole headers table...enjoy")

    #-- load the configuration settings from the config file
    config_file = os.path.join(os.environ['HOME'], "configure.yaml")
    with open(config_file, 'r') as f:
        SETTINGS = yaml.load(f)

    #-- setup a connection to the databse
    Session, engine = load_connection(SETTINGS['connection_string'])
    results = engine.execute("SELECT * FROM headers ORDER BY expstart;")
    keys = results.keys()
    file_name = 'all_file'
    csv_generator(results,keys,file_name)

    #-- close connections
    engine.dispose()
コード例 #4
0
def main():

    print("Querying the whole headers table...enjoy")

    #-- load the configuration settings from the config file
    config_file = os.path.join(os.environ['HOME'], "configure.yaml")
    with open(config_file, 'r') as f:
        SETTINGS = yaml.load(f)

    #-- setup a connection to the databse
    Session, engine = load_connection(SETTINGS['connection_string'])
    #results = engine.execute("SELECT * FROM headers ORDER BY expstart;")
    results = engine.execute("SELECT * FROM gain;")
    keys = results.keys()
    file_name = 'gain.csv'
    path = os.getcwd()
    csv_generator(results, keys, path, file_name)

    #-- close connections
    engine.dispose()