コード例 #1
0
def combine_catalogs(header, cats, columns, data_start, destination, conversion_factor=1):
    # Combines a list of catalogs (cats) row by row and adds the given header
    # at the top of the file, writes the resulting catalog to (destination)
    # RA and DEC MUST be the first two columns, flux and fluxerr MUST be the
    # next two columns. (There should be 4 columns)
    # Change conversion factor to multiple flux and fluxerr by that value. Useful when
    # converting between Jy and uJy
    jtools.check_paths(cats)
    num_entries = 0  # default value in case something goes wrong.
    table = []
    ra_col = columns[0]
    dec_col = columns[1]
    flux_col = columns[2]
    fluxerr_col = columns[3]
    num_params = len(columns) - 2  # We subtract 2 because of the RA/DEC columns we've already accounted for
    for (n, c) in enumerate(cats):
        if n == 0:
            data = param_get(c, [ra_col, dec_col], data_start)
            num_entries = len(data[0])
            for i in range(num_entries):
                table.append([i+1, data[0][i], data[1][i]])
        data = param_get(c, columns[2:], data_start)
        for i in range(num_entries):
            temp = []
            for j in range(num_params):
                temp.append(data[j][i])
            for t in temp:
                table[i].append(t)
            #table[i].append(float(data[0][i])*conversion_factor)
            #table[i].append(float(data[1][i])*conversion_factor)
    jtools.write_table(table, header, destination)
    return
コード例 #2
0
def fits_add(file_paths, destination, header_index=0, conversion_factor=1.0):
    # Adds a list of fits files together, uses the header of file_paths[header_index]
    # and multiplies by the conversion factor if you are converting units
    jtools.check_paths(file_paths)
    d_list = []
    for f in file_paths:
        hdu = pyfits.open(f)
        d_list.append(hdu[0].data)
        hdu.close()
    hfits = pyfits.open(file_paths[header_index])
    h = hfits[0].header
    hfits.close()
    data_sum = sum(d_list) * conversion_factor / len(file_paths)
    pyfits.writeto(destination, data_sum, header=h, clobber=1)
    return