Exemple #1
0
def xymatch(outfile, filenames, tol=2):
    import math
    import MOPfiles
    import sys
    output = {}
    files = []
    for filename in filenames:
        this_file = MOPfiles.read(filename)
        ## match files based on the 'X' and 'Y' column.
        ## if those don't exist then skip this file
        if not this_file['data'].has_key('X') or not this_file['data'].has_key(
                'Y'):
            continue
        if not output.has_key('data'):
            output = this_file
            continue
        delete_list = []
        for keyword in this_file['header']:
            if not keyword in output['header']:
                output['header'][keyword] = this_file['header'][keyword]
        for col in this_file['data'].keys():
            if not output['data'].has_key(col):
                output['order'].append(col)
                output['data'][col] = []
                output['order'].append(col)
                output['format'].append(this_file['format'][col])
                ### pad previously values with empties..
                for i in range(len(output['data']['X'])):
                    output['data'][col].append(None)
        for i in xrange(len(output['data']['X'])):
            x1 = float(output['data']['X'][i])
            y1 = float(output['data']['Y'][i])
            matched = False
            for j in xrange(len(this_file['data']['X'])):
                x2 = float(this_file['data']['X'][j])
                y2 = float(this_file['data']['Y'][j])
                if (((x1 - x2)**2 + (y1 - y2)**2) < tol**2):
                    for col in this_file['data'].keys():
                        if output['data'][col][i] is None:
                            output['data'][col][i] = this_file['data'][col][j]
                    matched = True
                    break
            if not matched:
                delete_list.append(i)

        delete_list.sort()
        delete_list.reverse()
        for i in delete_list:
            for col in output['data'].keys():
                del output['data'][col][i]

    MOPfiles.write(outname, output)
Exemple #2
0
def xymatch(outfile, filenames, tol=2):
    import math
    import MOPfiles
    import sys
    output={}
    files=[]
    for filename in filenames:
        this_file=MOPfiles.read(filename)
        ## match files based on the 'X' and 'Y' column.
        ## if those don't exist then skip this file
        if not this_file['data'].has_key('X') or not this_file['data'].has_key('Y'):
            continue
        if not output.has_key('data'):
            output=this_file
            continue
        delete_list=[]
        for keyword in this_file['header']:
            if not keyword in output['header']:
                output['header'][keyword]=this_file['header'][keyword]
        for col in this_file['data'].keys():
            if not output['data'].has_key(col):
                output['order'].append(col)
                output['data'][col]=[]
                output['order'].append(col)
                output['format'].append(this_file['format'][col])
                ### pad previously values with empties.. 
                for i in range(len(output['data']['X'])):
                    output['data'][col].append(None)
        for i in xrange(len(output['data']['X'])):
            x1=float(output['data']['X'][i])
            y1=float(output['data']['Y'][i])
            matched=False
            for j in xrange(len(this_file['data']['X'])):
                x2=float(this_file['data']['X'][j])
                y2=float(this_file['data']['Y'][j])
                if ( ((x1-x2)**2+(y1-y2)**2) < tol**2):
                    for col in this_file['data'].keys():
                        if output['data'][col][i] is None:
                            output['data'][col][i]=this_file['data'][col][j]
                    matched=True
                    break
            if not matched:
                delete_list.append(i)

        delete_list.sort()
        delete_list.reverse()
        for i in delete_list:
            for col in output['data'].keys():
                del output['data'][col][i]


    MOPfiles.write(outname,output)
Exemple #3
0
def objIngest(obj_file):
    import sys, os, math, re

    import pyfits

    import MOPfiles

    obj = MOPfiles.read(obj_file)
    """
    The SQL description of the source table
    +-------------+---------+------+-----+---------+----------------+
    | Field       | Type    | Null | Key | Default | Extra          |
    +-------------+---------+------+-----+---------+----------------+
    | sourceID    | int(11) |      | PRI | NULL    | auto_increment |
    | x_pix       | float   | YES  | MUL | NULL    |                |
    | y_pix       | float   | YES  |     | NULL    |                |
    | iso_flux    | float   | YES  |     | NULL    |                |
    | iso_err     | float   | YES  |     | NULL    |                |
    | aper_flux   | float   | YES  |     | NULL    |                |
    | aper_err    | float   | YES  |     | NULL    |                |
    | iso_area    | float   | YES  |     | NULL    |                |
    | kron_radius | float   | YES  | MUL | NULL    |                |
    | elongation  | float   | YES  |     | NULL    |                |
    | cxx         | float   | YES  |     | NULL    |                |
    | cyy         | float   | YES  |     | NULL    |                |
    | cxy         | float   | YES  |     | NULL    |                |
    | max_flux    | float   | YES  |     | NULL    |                |
    | max_int     | float   | YES  |     | NULL    |                |
    | mag_dao     | float   | YES  | MUL | NULL    |                |
    | merr_dao    | float   | YES  |     | NULL    |                |
    | sky_cts     | float   | YES  |     | NULL    |                |
    | chi2        | float   | YES  |     | NULL    |                |
    | npix        | float   | YES  |     | NULL    |                |
    | sharp       | float   | YES  |     | NULL    |                |
    | ra_deg      | float   | YES  | MUL | NULL    |                |
    | dec_deg     | float   | YES  |     | NULL    |                |
    +-------------+---------+------+-----+---------+----------------+
    """
    """
    Columns in the SOURCE table...
    ##           X          Y   FLUX_ISO FLUXERR_ISO  FLUX_APER FLUXERR_APER ISOAREA_IMAGE KRON_RADIUS ELONGATION  CXX_IMAGE  CYY_IMAGE  CXY_IMAGE   FLUX_MAX         ID    MAX_INT       FLUX       MERR        SKY       ELON        X^2      N_PIX        MAG      SHARP       SIZE

    """

    ### The mapping
    obj['hdu2sql'] = {
        'MAX_INT': 'peak',
        'FLUX': 'flux',
        'MAG': 'mag',
        'MERR': 'merr',
        'SKY': 'sky',
        'ELON': 'elongation',
        'X^2': 'chi2',
        'N_PIX': 'npix',
        'SHARP': 'sharpness',
        'Y': 'yPix',
        'X': 'xPix',
        'SIZE': 'size',
        'RA': 'raDeg',
        'DEC': 'decDeg',
    }

    MOPfiles.store(obj)

    return
Exemple #4
0
def objIngest(obj_file):
    import sys,os,math,re
    
    import pyfits
    
    import MOPfiles

    obj=MOPfiles.read(obj_file)

    """
    The SQL description of the source table
    +-------------+---------+------+-----+---------+----------------+
    | Field       | Type    | Null | Key | Default | Extra          |
    +-------------+---------+------+-----+---------+----------------+
    | sourceID    | int(11) |      | PRI | NULL    | auto_increment |
    | x_pix       | float   | YES  | MUL | NULL    |                |
    | y_pix       | float   | YES  |     | NULL    |                |
    | iso_flux    | float   | YES  |     | NULL    |                |
    | iso_err     | float   | YES  |     | NULL    |                |
    | aper_flux   | float   | YES  |     | NULL    |                |
    | aper_err    | float   | YES  |     | NULL    |                |
    | iso_area    | float   | YES  |     | NULL    |                |
    | kron_radius | float   | YES  | MUL | NULL    |                |
    | elongation  | float   | YES  |     | NULL    |                |
    | cxx         | float   | YES  |     | NULL    |                |
    | cyy         | float   | YES  |     | NULL    |                |
    | cxy         | float   | YES  |     | NULL    |                |
    | max_flux    | float   | YES  |     | NULL    |                |
    | max_int     | float   | YES  |     | NULL    |                |
    | mag_dao     | float   | YES  | MUL | NULL    |                |
    | merr_dao    | float   | YES  |     | NULL    |                |
    | sky_cts     | float   | YES  |     | NULL    |                |
    | chi2        | float   | YES  |     | NULL    |                |
    | npix        | float   | YES  |     | NULL    |                |
    | sharp       | float   | YES  |     | NULL    |                |
    | ra_deg      | float   | YES  | MUL | NULL    |                |
    | dec_deg     | float   | YES  |     | NULL    |                |
    +-------------+---------+------+-----+---------+----------------+
    """


    """
    Columns in the SOURCE table...
    ##           X          Y   FLUX_ISO FLUXERR_ISO  FLUX_APER FLUXERR_APER ISOAREA_IMAGE KRON_RADIUS ELONGATION  CXX_IMAGE  CYY_IMAGE  CXY_IMAGE   FLUX_MAX         ID    MAX_INT       FLUX       MERR        SKY       ELON        X^2      N_PIX        MAG      SHARP       SIZE

    """

    ### The mapping 
    obj['hdu2sql']={'MAX_INT': 'peak',
                    'FLUX': 'flux',
		    'MAG': 'mag',
		    'MERR': 'merr',
                    'SKY': 'sky',
                    'ELON': 'elongation',
                    'X^2': 'chi2',
                    'N_PIX': 'npix',
                    'SHARP': 'sharpness',
                    'Y': 'yPix',
                    'X': 'xPix',
                    'SIZE': 'size',
                    'RA': 'raDeg',
                    'DEC': 'decDeg',
                    }


    MOPfiles.store(obj)

    return