示例#1
0
    for typedesc in dtype.descr:
        name = typedesc[0]
        type = typedesc[1]
        if (type[0] == '<') or (type[0] == '>'):
            type = type[1:]
        if len(typedesc) > 2:
            type = '{}'.format(typedesc[2][0]) + type
            #tdescr += (typedesc[2],)
            # bit of a hack, but doesn't work with the more complicated format
            # specification and FITS binary tables don't support multidimensional
            # arrays as columns.
        tdescr = (name, type)
        columns.append(tdescr)

    pool = pool2.Pool()
    db = DB(db)
    with db.transaction():
        if not db.table_exists(table):
            table = db.create_table(table, table_def)
        else:
            table = db.table(table)
        for fn, num in pool.imap_unordered(filenames, import_file,
                                           (table, ra, dec, is_radians)):
            print 'Imported file {:s} containing {:d} entries.'.format(fn, num)


def main():
    parser = argparse.ArgumentParser(description='Import FITS files to LSD')
    parser.add_argument('--db', '-d', default=os.environ['LSD_DB'])
    parser.add_argument('--ra', default='ra', help='Column in FITS file to rename "ra"')
    parser.add_argument('--dec', default='dec', help='Column in FITS file to rename "dec"')
示例#2
0
#!/usr/bin/env python

from lsd import DB


def row_counter_kernel(qresult):
    for rows in qresult:
        yield len(rows)


db = DB('db')
query = db.query("SELECT obj_id FROM ps1_obj, sdss")

total = 0
for subtotal in query.execute([row_counter_kernel]):
    total += subtotal

print "The total number of rows returned by the query '%s' is %d" % (query,
                                                                     total)
示例#3
0
import os


def mapper(qresult, bins):
    for rows in qresult:
        counts, _ = np.histogram(rows['dec'], bins)
        for (bin, count) in zip(bins, counts):
            if count != 0:
                yield (bin, count)


def reducer(kv):
    bin, counts = kv
    yield (bin, sum(counts))


db = DB(os.environ['LSD_DB'])
query = db.query("SELECT dec FROM sdss")

ddec = 10.
bins = np.arange(-90, 90.0001, ddec)

hist = {}
for (bin, count) in query.execute([(mapper, bins), reducer]):
    hist[bin + ddec / 2] = count

for binctr in sorted(hist.keys()):
    print "%+05.1f %10d" % (binctr, hist[binctr])

print "Total number of objects:", sum(hist.values())