Ejemplo n.º 1
0
def make_db_table(sname='final'):
    # table for GZ2 site database
    f = data_path + 'gz2sample_%s_abs_regions_counts_wvt.fits' % sname
    p = pyfits.open(f)
    d = p['data'].data
    n = len(d)
    oldcols = p['data'].columns
    cols = []
    for c in oldcols:
        name = c.name.upper()
        if name in [
                'OBJID', 'RA', 'DEC', 'PETROR90_R', 'REGION',
                'REDSHIFT_SIMPLE_BIN', 'WVT_BIN'
        ]:
            name = name.replace('PETROR90_R', 'SIZE')
            name = name.replace('_SIMPLE', '')
            name = name.replace('WVT_', 'MAGSIZE_')
            cols.append(
                pyfits.Column(name=name,
                              format=c.format,
                              array=d.field(c.name)))
    #cols.append(pyfits.Column(name='CLASSCOUNT', format='I',
    #                               array=N.zeros(n)))
    #cols.append(pyfits.Column(name='COMPCOUNT', format='I',
    #                               array=N.zeros(n)))
    tbhdu = pyfits.new_table(cols)
    tbhdu.name = 'data'
    outfile = data_path + 'gz2sample_%s_db.fits' % sname
    file_exists = os.path.isfile(outfile)
    if file_exists:
        os.remove(outfile)
    tbhdu.writeto(outfile)
    csvfile = outfile.replace('.fits', '.csv')
    fits2csv(outfile, csvfile)
    os.system('gzip %s &' % csvfile)
Ejemplo n.º 2
0
def make_abs_cas_table(sname='final'):
    # table for GZ2 site database
    f = data_path+'gz2sample_%s_wvt.fits'%sname
    p = pyfits.open(f)
    d = p[1].data
    n = len(d)
    oldcols = p[1].columns
    cols = []
    select = notNaN(d.PETROR50_R_KPC)
    d = d[select]
    for c in oldcols:
	name = c.name.upper()
        if name in ['OBJID', 'PETROR50_R_KPC',
                    'PETROMAG_MU', 'PETROMAG_MG',
                    'PETROMAG_MR', 'PETROMAG_MI', 'PETROMAG_MZ',
                    'PETROMAGERR_MU', 'PETROMAGERR_MG',
                    'PETROMAGERR_MR', 'PETROMAGERR_MI', 'PETROMAGERR_MZ']:
            cols.append(pyfits.Column(name=name, format=c.format,
                                      array=d.field(c.name)))
    #cols.append(pyfits.Column(name='CLASSCOUNT', format='I',
    #                               array=N.zeros(n)))
    #cols.append(pyfits.Column(name='COMPCOUNT', format='I',
    #                               array=N.zeros(n)))
    tbhdu=pyfits.new_table(cols)
    tbhdu.name = 'data'
    outfile = data_path+'gz2sample_%s_abs_for_cas.fits'%sname
    file_exists = os.path.isfile(outfile)
    if file_exists:
	os.remove(outfile)
    tbhdu.writeto(outfile)
    csvfile = outfile.replace('.fits', '.csv')
    fits2csv(outfile, csvfile)
    os.remove(outfile)
Ejemplo n.º 3
0
def make_db_table(sname='final'):
    # table for GZ2 site database
    f = data_path+'gz2sample_%s_abs_regions_counts_wvt.fits'%sname
    p = pyfits.open(f)
    d = p['data'].data
    n = len(d)
    oldcols = p['data'].columns
    cols = []
    for c in oldcols:
	name = c.name.upper()
        if name in ['OBJID', 'RA', 'DEC', 'PETROR90_R', 'REGION',
                    'REDSHIFT_SIMPLE_BIN', 'WVT_BIN']:
            name = name.replace('PETROR90_R', 'SIZE')
            name = name.replace('_SIMPLE', '')
            name = name.replace('WVT_', 'MAGSIZE_')
            cols.append(pyfits.Column(name=name, format=c.format,
                                      array=d.field(c.name)))
    #cols.append(pyfits.Column(name='CLASSCOUNT', format='I',
    #                               array=N.zeros(n)))
    #cols.append(pyfits.Column(name='COMPCOUNT', format='I',
    #                               array=N.zeros(n)))
    tbhdu=pyfits.new_table(cols)
    tbhdu.name = 'data'
    outfile = data_path+'gz2sample_%s_db.fits'%sname
    file_exists = os.path.isfile(outfile)
    if file_exists:
	os.remove(outfile)
    tbhdu.writeto(outfile)
    csvfile = outfile.replace('.fits', '.csv')
    fits2csv(outfile, csvfile)
    os.system('gzip %s &'%csvfile)
Ejemplo n.º 4
0
def concatenate_gz2_tables():
    files = [data_path+'gz2sample_final_dr7_wvt.fits',
             data_path+'gz2sample_final_stripe82_coadd_abs_regions_counts_wvt.fits']
    tables = [[pyfits.open(f)[1]] for f in files]
    outfile = data_path+'gz2sample_final_wvt.fits'
    concatenate_fits_tables(tables, outfile, uniquecol='objid')
    csvfile = csvfile.replace('.fits', '.csv')
    fits2csv(outfile, csvfile)
Ejemplo n.º 5
0
def concatenate_gz2_tables():
    files = [
        data_path + 'gz2sample_final_dr7_wvt.fits', data_path +
        'gz2sample_final_stripe82_coadd_abs_regions_counts_wvt.fits'
    ]
    tables = [[pyfits.open(f)[1]] for f in files]
    outfile = data_path + 'gz2sample_final_wvt.fits'
    concatenate_fits_tables(tables, outfile, uniquecol='objid')
    csvfile = csvfile.replace('.fits', '.csv')
    fits2csv(outfile, csvfile)
Ejemplo n.º 6
0
def make_abs_cas_table(sname='final'):
    # table for GZ2 site database
    f = data_path + 'gz2sample_%s_wvt.fits' % sname
    p = pyfits.open(f)
    d = p[1].data
    n = len(d)
    oldcols = p[1].columns
    cols = []
    select = notNaN(d.PETROR50_R_KPC)
    d = d[select]
    for c in oldcols:
        name = c.name.upper()
        if name in [
                'OBJID', 'PETROR50_R_KPC', 'PETROMAG_MU', 'PETROMAG_MG',
                'PETROMAG_MR', 'PETROMAG_MI', 'PETROMAG_MZ', 'PETROMAGERR_MU',
                'PETROMAGERR_MG', 'PETROMAGERR_MR', 'PETROMAGERR_MI',
                'PETROMAGERR_MZ'
        ]:
            cols.append(
                pyfits.Column(name=name,
                              format=c.format,
                              array=d.field(c.name)))
    #cols.append(pyfits.Column(name='CLASSCOUNT', format='I',
    #                               array=N.zeros(n)))
    #cols.append(pyfits.Column(name='COMPCOUNT', format='I',
    #                               array=N.zeros(n)))
    tbhdu = pyfits.new_table(cols)
    tbhdu.name = 'data'
    outfile = data_path + 'gz2sample_%s_abs_for_cas.fits' % sname
    file_exists = os.path.isfile(outfile)
    if file_exists:
        os.remove(outfile)
    tbhdu.writeto(outfile)
    csvfile = outfile.replace('.fits', '.csv')
    fits2csv(outfile, csvfile)
    os.remove(outfile)