Esempio n. 1
0
formats = tmp[1]
record = np.dtype({'names':names,'formats':formats})

data = []

for ifile, fname in enumerate(filename_lst):
    t1 = time.time()
    data1 = []
    infile = open(fname)
    for row in infile:
        if row[0] == '#':
            continue
        kic    = int(row[0:8])
        ra     = np.float64(row[9:19])
        dec    = np.float64(row[19:29])
        pmra   = _str_to_float(row[30:38], np.NaN)
        pmde   = _str_to_float(row[39:47], np.NaN)
        plx    = _str_to_float(row[48:56], np.NaN)
        umag   = _str_to_float(row[57:63], np.NaN)
        gmag   = _str_to_float(row[63:70], np.NaN)
        rmag   = _str_to_float(row[70:77], np.NaN)
        imag   = _str_to_float(row[77:84], np.NaN)
        zmag   = _str_to_float(row[84:91], np.NaN)
        grmag  = _str_to_float(row[92:98], np.NaN)
        d51mag = _str_to_float(row[99:105], np.NaN)
        #magJ   = _str_to_float(row[106:112], np.NaN)
        #magH   = _str_to_float(row[112:119], np.NaN)
        #magK   = _str_to_float(row[119:126], np.NaN)
        kepmag = _str_to_float(row[127:133], np.NaN)
        flag_g = int(row[209])
        flag_v = int(row[211])
Esempio n. 2
0
tmp = list(zip(*types))
record = np.dtype({'names':tmp[0],'formats':tmp[1]})

fill_item = np.array(
                (0, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN,
                    np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN),
                dtype=record)

data = {}

infile = open(inputfile)
for row in infile:
    hip     = int(row[0:6])
    radeg   = float(row[15:28])/math.pi*180.
    dedeg   = float(row[29:42])/math.pi*180.
    plx     = _str_to_float(row[43:50], np.NaN)
    e_plx   = _str_to_float(row[83:89], np.NaN)
    pmRA    = _str_to_float(row[51:59], np.NaN)
    pmDE    = _str_to_float(row[60:68], np.NaN)
    e_pmRA  = _str_to_float(row[90:96], np.NaN)
    e_pmDE  = _str_to_float(row[97:103], np.NaN)
    Hpmag   = _str_to_float(row[129:136], np.NaN)
    e_Hpmag = _str_to_float(row[137:143], np.NaN)
    Hpscat  = _str_to_float(row[144:149], np.NaN)
    BV      = _str_to_float(row[152:158], np.NaN)
    e_BV    = _str_to_float(row[159:164], np.NaN)
    VI      = _str_to_float(row[165:171], np.NaN)

    if not np.isnan(pmRA):
        pm_ra = pmRA*1e-3/3600. # convert pm_RA  from mas/yr to degree/yr
        #radeg += (2000.0-1991.25)*pm_ra/math.cos(dedeg/180.*math.pi)
Esempio n. 3
0
def main():
    path = os.path.join(os.getenv('ASTRO_DATA'), 'catalog/I/259/')
    
    # load duplicate list
    dup_tyc_lst = []
    infile1 = open('duplicate.txt')
    for row in infile1:
        g = row.split('|')[0].split()
        tyc1 = int(g[0])
        tyc2 = int(g[1])
        tyc3 = int(g[2])
        dup_tyc_lst.append((tyc1,tyc2,tyc3))
    infile1.close()
    
    types = [
            ('TYC',      np.int32),
            ('RAdeg',    np.float64),
            ('DEdeg',    np.float64),
            ('e_RA',     np.int16),
            ('e_DE',     np.int16),
            ('epoch_RA', np.float32),
            ('epoch_DE', np.float32),
            ('q_RA',     np.float32),
            ('q_DE',     np.float32),
            ('pmRA',     np.float32),
            ('pmDE',     np.float32),
            ('e_pmRA',   np.float32),
            ('e_pmDE',   np.float32),
            ('q_pmRA',   np.float32),
            ('q_pmDE',   np.float32),
            ('Num',      np.int16),
            ('BTmag',    np.float32),
            ('e_BTmag',  np.float32),
            ('VTmag',    np.float32),
            ('e_VTmag',  np.float32),
            ('prox',     np.float32),
            ]
    tmp = list(zip(*types))
    record = np.dtype({'names':tmp[0],'formats':tmp[1]})
    
    fn_lst = ['tyc2.dat.%02d'%i for i in range(20)]
    data = []
    for fn in fn_lst:
        print(fn)
        infile = open(os.path.join(path, fn))
        for row in infile:
            tyc1   = int(row[0:4])
            tyc2   = int(row[5:10])
            tyc3   = int(row[11])
            tyc = np.int32((tyc1<<18) + (tyc2<<4) + (tyc3<<1))
    
            radeg    = _str_to_float(row[15:27], np.NaN)
            dedeg    = _str_to_float(row[28:40], np.NaN)
            pmRA     = _str_to_float(row[41:48], np.NaN)
            pmDE     = _str_to_float(row[49:56], np.NaN)
            e_ra     = _str_to_int(row[57:60], -1)
            e_de     = _str_to_int(row[61:64], -1)
            e_pmRA   = _str_to_float(row[65:69], np.NaN)
            e_pmDE   = _str_to_float(row[70:74], np.NaN)
            epoch_ra = _str_to_float(row[75:82], np.NaN)
            epoch_de = _str_to_float(row[83:90], np.NaN)
            num      = _str_to_int(row[91:93], -1)
            q_RA     = _str_to_float(row[94:97], np.NaN)
            q_DE     = _str_to_float(row[98:101], np.NaN)
            q_pmRA   = _str_to_float(row[102:105], np.NaN)
            q_pmDE   = _str_to_float(row[106:109], np.NaN)
            BTmag    = _str_to_float(row[110:116], np.NaN)
            e_BTmag  = _str_to_float(row[117:122], np.NaN)
            VTmag    = _str_to_float(row[123:129], np.NaN)
            e_VTmag  = _str_to_float(row[130:135], np.NaN)
            prox     = _str_to_float(row[136:139], np.NaN)*0.1
    
            item = (tyc, radeg, dedeg, e_ra, e_de, epoch_ra, epoch_de, q_RA, q_DE,
                    pmRA, pmDE, e_pmRA, e_pmDE, q_pmRA, q_pmDE, num,
                    BTmag, e_BTmag, VTmag, e_VTmag, prox)
            data.append(item)
        infile.close()
    
    
    for fn in ['suppl_1.dat', 'suppl_2.dat']:
        infile = open(os.path.join(path, fn))
        for row in infile:
            tyc1   = int(row[0:4])
            tyc2   = int(row[5:10])
            tyc3   = int(row[11])
    
            if (tyc1,tyc2,tyc3) in dup_tyc_lst:
                m = 1
            else:
                m = 0
    
            tyc = np.int32((tyc1<<18) + (tyc2<<4) + (tyc3<<1) + m)
    
            radeg    = _str_to_float(row[15:27], np.NaN)
            dedeg    = _str_to_float(row[28:40], np.NaN)
            pmRA     = _str_to_float(row[41:48], np.NaN)
            pmDE     = _str_to_float(row[49:56], np.NaN)
            e_ra     = _str_to_int(row[57:60], -1)
            e_de     = _str_to_int(row[61:64], -1)
            e_pmRA   = _str_to_float(row[65:69], np.NaN)
            e_pmDE   = _str_to_float(row[70:74], np.NaN)
            epoch_ra = _str_to_float(row[75:82], np.NaN)
            epoch_de = _str_to_float(row[83:90], np.NaN)
            num      = _str_to_int(row[91:93], -1)
            q_RA     = _str_to_float(row[94:97], np.NaN)
            q_DE     = _str_to_float(row[98:101], np.NaN)
            q_pmRA   = _str_to_float(row[102:105], np.NaN)
            q_pmDE   = _str_to_float(row[106:109], np.NaN)
            BTmag    = _str_to_float(row[110:116], np.NaN)
            e_BTmag  = _str_to_float(row[117:122], np.NaN)
            VTmag    = _str_to_float(row[123:129], np.NaN)
            e_VTmag  = _str_to_float(row[130:135], np.NaN)
            prox     = _str_to_float(row[136:139], np.NaN)*0.1
    
            item = (tyc, radeg, dedeg, e_ra, e_de, epoch_ra, epoch_de, q_RA, q_DE,
                    pmRA, pmDE, e_pmRA, e_pmDE, q_pmRA, q_pmDE, num,
                    BTmag, e_BTmag, VTmag, e_VTmag, prox)
            data.append(item)
        infile.close()

    fill_item = (0, np.NaN, np.NaN, 0, 0, np.NaN, np.NaN, np.NaN, np.NaN,
                np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, -1,
                np.NaN, np.NaN, np.NaN, np.NaN, np.NaN)
    
    data = np.array(data, dtype=record)
    data = np.sort(data, order='TYC')
    # add an empty item in the beginning
    data = np.insert(data, 0, np.array(fill_item, dtype=record))
    
    pri_hdu = fits.PrimaryHDU()
    tbl_hdu = fits.BinTableHDU(data)
    hdu_lst = fits.HDUList([pri_hdu,tbl_hdu])
    outputfile = 'TYC2.fits'
    if os.path.exists(outputfile):
        os.remove(outputfile)
    hdu_lst.writeto(outputfile)
    
    data = fits.getdata(outputfile)
    tyc_lst = data['TYC']
    diff = np.diff(tyc_lst)
    mask = diff==0
    for i, m in enumerate(mask):
        if m:
            print(data[i]['TYC'], data[i]['Note'], data[i+1]['TYC'],data[i+1]['Note'])
Esempio n. 4
0
def main():
    path = os.path.join(os.getenv('ASTRO_DATA'), 'catalog/I/239/')

    types = [
        ('TYC', np.int32),
        ('RAdeg', np.float64),
        ('DEdeg', np.float64),
        ('e_RA', np.float32),
        ('e_DE', np.float32),
        ('pmRA', np.float32),
        ('pmDE', np.float32),
        ('e_pmRA', np.float32),
        ('e_pmDE', np.float32),
        ('Plx', np.float32),
        ('e_Plx', np.float32),
        ('Nastro', np.int16),
        ('Vmag', np.float32),
        ('r_Vmag', 'S1'),
        ('BTmag', np.float32),
        ('e_BTmag', np.float32),
        ('VTmag', np.float32),
        ('e_VTmag', np.float32),
        ('r_BTmag', 'S1'),
        ('B-V', np.float32),
        ('e_B-V', np.float32),
        ('Nphoto', np.int16),
        ('VTscat', np.float32),
        ('VTmax', np.float32),
        ('VTmin', np.float32),
        ('VarFlag', 'S1'),
        ('MultFlag', 'S1'),
    ]
    tmp = list(zip(*types))
    record = np.dtype({'names': tmp[0], 'formats': tmp[1]})

    fill_item = (
        0,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,  # ra, de, e_ra, e_de
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,  # pm
        np.NaN,
        np.NaN,
        -1,  # plx, Nastro
        np.NaN,
        '',
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        '',  # vmag ~ r_BTmag
        np.NaN,
        np.NaN,
        -1,
        np.NaN,
        np.NaN,
        np.NaN,
        '',
        '')

    data = []

    fn = 'tyc_main.dat'
    infile = open(os.path.join(path, fn))
    for row in infile:
        if row[0] != 'T':
            print('Warning: Not Tycho star')
        g = row[2:14].split()
        tyc1 = int(g[0])
        tyc2 = int(g[1])
        tyc3 = int(g[2])
        tyc = np.int32((tyc1 << 18) + (tyc2 << 4) + (tyc3 << 1))

        radeg = _str_to_float(row[51:63], np.NaN)
        dedeg = _str_to_float(row[64:76], np.NaN)
        vmag = _str_to_float(row[41:46], np.NaN)
        r_vmag = row[49].strip()
        plx = _str_to_float(row[79:86], np.NaN)
        pm_ra = _str_to_float(row[87:95], np.NaN)
        pm_de = _str_to_float(row[96:104], np.NaN)
        e_ra = _str_to_float(row[105:111], np.NaN)
        e_de = _str_to_float(row[112:118], np.NaN)
        e_plx = _str_to_float(row[119:125], np.NaN)
        e_pmra = _str_to_float(row[126:132], np.NaN)
        e_pmde = _str_to_float(row[133:139], np.NaN)
        nastro = _str_to_int(row[200:203], 0)
        btmag = _str_to_float(row[217:223], np.NaN)
        e_btmag = _str_to_float(row[224:229], np.NaN)
        vtmag = _str_to_float(row[230:236], np.NaN)
        e_vtmag = _str_to_float(row[237:242], np.NaN)
        r_btmag = row[243].strip()
        bv = _str_to_float(row[245:251], np.NaN)
        e_bv = _str_to_float(row[252:257], np.NaN)
        nphoto = _str_to_int(row[269:272], 0)
        vtscat = _str_to_float(row[273:278], np.NaN)
        vtmax = _str_to_float(row[279:284], np.NaN)
        vtmin = _str_to_float(row[285:290], np.NaN)
        varflag = row[293].strip()
        multflag = row[295].strip()

        item = (tyc, radeg, dedeg, e_ra, e_de, pm_ra, pm_de, e_pmra, e_pmde,
                plx, e_plx, nastro, vmag, r_vmag, btmag, e_btmag, vtmag,
                e_vtmag, r_btmag, bv, e_bv, nphoto, vtscat, vtmax, vtmin,
                varflag, multflag)
        data.append(item)
    infile.close()

    data = np.array(data, dtype=record)
    data = np.sort(data, order='TYC')
    # add an empty item in the beginning
    data = np.insert(data, 0, np.array(fill_item, dtype=record))

    pri_hdu = fits.PrimaryHDU()
    tbl_hdu = fits.BinTableHDU(data)
    hdu_lst = fits.HDUList([pri_hdu, tbl_hdu])
    outputfile = 'TYC.fits'
    if os.path.exists(outputfile):
        os.remove(outputfile)
    hdu_lst.writeto(outputfile)

    data = fits.getdata(outputfile)
    tyc_lst = data['TYC']
    diff = np.diff(tyc_lst)
    mask = diff == 0
    for i, m in enumerate(mask):
        if m:
            print(data[i]['TYC'], data[i + 1]['TYC'])
Esempio n. 5
0
def main():
    inputfile = os.path.join(os.getenv('ASTRO_DATA'), 'catalog/I/131A/sao.dat')

    types = [
            ('SAO',      np.int32),
            ('RAdeg',    np.float64),
            ('DEdeg',    np.float64),
            ('pmRA',     np.float32),
            ('pmDE',     np.float32),
            ('e_pmRA',   np.float32),
            ('e_pmDE',   np.float32),
            ('Vmag',     np.float32),
            ('Pmag',     np.float32),
            ('SpType',   'S3'),
            ('r_Vmag',   np.int16),
            ('r_Pmag',   np.int16),
            ('r_Num',    np.int16),
            ('r_pm',     np.int16),
            ('r_SpType', np.int16),
            ('RAdeg2000', np.float64),
            ('DEdeg2000', np.float64),
            ('pmRA2000',  np.float32),
            ('pmDE2000',  np.float32),
            ]

    tmp = list(zip(*types))
    record = np.dtype({'names': tmp[0], 'formats': tmp[1]})

    data = []
    infile = open(inputfile)
    for row in infile:
        sao = int(row[0:6])
        radeg = (int(row[7:9]) + int(row[9:11])/60. + float(row[11:17])/3600.)*15.
        dedeg = int(row[42:44]) + int(row[44:46])/60. + float(row[46:51])/3600.
        if row[41]=='-':
            dedeg = -dedeg

        pmra   = _str_to_float(row[17:24], np.NaN)*1000.
        e_pmra = _str_to_float(row[24:26], np.NaN)
        pmde   = _str_to_float(row[51:57], np.NaN)*1000.
        e_pmde = _str_to_float(row[57:59], np.NaN)
        pmag   = _str_to_float(row[76:80], np.NaN)
        vmag   = _str_to_float(row[80:84], np.NaN)
        sptype = row[84:87].strip()
        r_vmag = int(row[87:89])
        r_num  = int(row[89:91])
        r_pmag = int(row[91])
        r_pm   = int(row[92])
        r_sptype = int(row[93])
        ra2000 = (int(row[150:152]) + int(row[152:154])/60. + float(row[154:160])/3600.)*15.
        pmra2000 = _str_to_float(row[160:167], np.NaN)*1000.
        de2000 = int(row[168:170]) + int(row[170:172])/60. + float(row[172:177])/3600.
        pmde2000 = _str_to_float(row[177:183], np.NaN)*1000.
        if row[167]=='-':
            de2000 = -de2000

        item = (sao, radeg, dedeg, pmra, pmde, e_pmra, e_pmde,
                vmag, pmag, sptype, r_vmag, r_pmag, r_num, r_pm, r_sptype,
                ra2000, de2000, pmra2000, pmde2000)

        data.append(item)

    data = np.array(data, dtype=record)

    pri_hdu = fits.PrimaryHDU()
    tbl_hdu = fits.BinTableHDU(data)
    hdu_lst = fits.HDUList([pri_hdu, tbl_hdu])

    outname = 'SAO.fits'
    if os.path.exists(outname):
        os.remove(outname)
    hdu_lst.writeto(outname)
Esempio n. 6
0
data = {}

infile = open(inputfile)
for row in infile:
    hip = int(row[8:14])
    rah = int(row[17:19])
    ram = int(row[20:22])
    ras = float(row[23:28])
    radeg = (rah + ram/60. + ras/3600.)*15.
    ded = abs(int(row[30:32]))
    dem = int(row[33:35])
    des = float(row[36:40])
    dedeg = ded + dem/60. + des/3600.
    if row[29]=='-':
        dedeg = -dedeg
    vmag     = _str_to_float(row[41:46], np.NaN)
    plx      = _str_to_float(row[79:86], np.NaN)
    e_plx    = _str_to_float(row[119:125], np.NaN)
    pmRA     = _str_to_float(row[87:95], np.NaN)
    pmDE     = _str_to_float(row[96:104], np.NaN)
    e_pmRA   = _str_to_float(row[126:132], np.NaN)
    e_pmDE   = _str_to_float(row[133:139], np.NaN)
    BTmag    = _str_to_float(row[217:223], np.NaN)
    VTmag    = _str_to_float(row[230:236], np.NaN)
    e_BTmag  = _str_to_float(row[224:229], np.NaN)
    e_VTmag  = _str_to_float(row[237:242], np.NaN)
    BV       = _str_to_float(row[245:251], np.NaN)
    e_BV     = _str_to_float(row[252:257], np.NaN)
    r_BV     = row[258].strip()
    VI       = _str_to_float(row[260:264], np.NaN)
    e_VI     = _str_to_float(row[265:269], np.NaN)
Esempio n. 7
0
def main():
    path = os.path.join(os.getenv('ASTRO_DATA'), 'catalog/I/259/')

    # load duplicate list
    dup_tyc_lst = []
    infile1 = open('duplicate.txt')
    for row in infile1:
        g = row.split('|')[0].split()
        tyc1 = int(g[0])
        tyc2 = int(g[1])
        tyc3 = int(g[2])
        dup_tyc_lst.append((tyc1, tyc2, tyc3))
    infile1.close()

    types = [
        ('TYC', np.int32),
        ('RAdeg', np.float64),
        ('DEdeg', np.float64),
        ('e_RA', np.int16),
        ('e_DE', np.int16),
        ('epoch_RA', np.float32),
        ('epoch_DE', np.float32),
        ('q_RA', np.float32),
        ('q_DE', np.float32),
        ('pmRA', np.float32),
        ('pmDE', np.float32),
        ('e_pmRA', np.float32),
        ('e_pmDE', np.float32),
        ('q_pmRA', np.float32),
        ('q_pmDE', np.float32),
        ('Num', np.int16),
        ('BTmag', np.float32),
        ('e_BTmag', np.float32),
        ('VTmag', np.float32),
        ('e_VTmag', np.float32),
        ('prox', np.float32),
    ]
    tmp = list(zip(*types))
    record = np.dtype({'names': tmp[0], 'formats': tmp[1]})

    fn_lst = ['tyc2.dat.%02d' % i for i in range(20)]
    data = []
    for fn in fn_lst:
        print(fn)
        infile = open(os.path.join(path, fn))
        for row in infile:
            tyc1 = int(row[0:4])
            tyc2 = int(row[5:10])
            tyc3 = int(row[11])
            tyc = np.int32((tyc1 << 18) + (tyc2 << 4) + (tyc3 << 1))

            radeg = _str_to_float(row[15:27], np.NaN)
            dedeg = _str_to_float(row[28:40], np.NaN)
            pmRA = _str_to_float(row[41:48], np.NaN)
            pmDE = _str_to_float(row[49:56], np.NaN)
            e_ra = _str_to_int(row[57:60], -1)
            e_de = _str_to_int(row[61:64], -1)
            e_pmRA = _str_to_float(row[65:69], np.NaN)
            e_pmDE = _str_to_float(row[70:74], np.NaN)
            epoch_ra = _str_to_float(row[75:82], np.NaN)
            epoch_de = _str_to_float(row[83:90], np.NaN)
            num = _str_to_int(row[91:93], -1)
            q_RA = _str_to_float(row[94:97], np.NaN)
            q_DE = _str_to_float(row[98:101], np.NaN)
            q_pmRA = _str_to_float(row[102:105], np.NaN)
            q_pmDE = _str_to_float(row[106:109], np.NaN)
            BTmag = _str_to_float(row[110:116], np.NaN)
            e_BTmag = _str_to_float(row[117:122], np.NaN)
            VTmag = _str_to_float(row[123:129], np.NaN)
            e_VTmag = _str_to_float(row[130:135], np.NaN)
            prox = _str_to_float(row[136:139], np.NaN) * 0.1

            item = (tyc, radeg, dedeg, e_ra, e_de, epoch_ra, epoch_de, q_RA,
                    q_DE, pmRA, pmDE, e_pmRA, e_pmDE, q_pmRA, q_pmDE, num,
                    BTmag, e_BTmag, VTmag, e_VTmag, prox)
            data.append(item)
        infile.close()

    for fn in ['suppl_1.dat', 'suppl_2.dat']:
        infile = open(os.path.join(path, fn))
        for row in infile:
            tyc1 = int(row[0:4])
            tyc2 = int(row[5:10])
            tyc3 = int(row[11])

            if (tyc1, tyc2, tyc3) in dup_tyc_lst:
                m = 1
            else:
                m = 0

            tyc = np.int32((tyc1 << 18) + (tyc2 << 4) + (tyc3 << 1) + m)

            radeg = _str_to_float(row[15:27], np.NaN)
            dedeg = _str_to_float(row[28:40], np.NaN)
            pmRA = _str_to_float(row[41:48], np.NaN)
            pmDE = _str_to_float(row[49:56], np.NaN)
            e_ra = _str_to_int(row[57:60], -1)
            e_de = _str_to_int(row[61:64], -1)
            e_pmRA = _str_to_float(row[65:69], np.NaN)
            e_pmDE = _str_to_float(row[70:74], np.NaN)
            epoch_ra = _str_to_float(row[75:82], np.NaN)
            epoch_de = _str_to_float(row[83:90], np.NaN)
            num = _str_to_int(row[91:93], -1)
            q_RA = _str_to_float(row[94:97], np.NaN)
            q_DE = _str_to_float(row[98:101], np.NaN)
            q_pmRA = _str_to_float(row[102:105], np.NaN)
            q_pmDE = _str_to_float(row[106:109], np.NaN)
            BTmag = _str_to_float(row[110:116], np.NaN)
            e_BTmag = _str_to_float(row[117:122], np.NaN)
            VTmag = _str_to_float(row[123:129], np.NaN)
            e_VTmag = _str_to_float(row[130:135], np.NaN)
            prox = _str_to_float(row[136:139], np.NaN) * 0.1

            item = (tyc, radeg, dedeg, e_ra, e_de, epoch_ra, epoch_de, q_RA,
                    q_DE, pmRA, pmDE, e_pmRA, e_pmDE, q_pmRA, q_pmDE, num,
                    BTmag, e_BTmag, VTmag, e_VTmag, prox)
            data.append(item)
        infile.close()

    fill_item = (0, np.NaN, np.NaN, 0, 0, np.NaN, np.NaN, np.NaN, np.NaN,
                 np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, -1, np.NaN,
                 np.NaN, np.NaN, np.NaN, np.NaN)

    data = np.array(data, dtype=record)
    data = np.sort(data, order='TYC')
    # add an empty item in the beginning
    data = np.insert(data, 0, np.array(fill_item, dtype=record))

    pri_hdu = fits.PrimaryHDU()
    tbl_hdu = fits.BinTableHDU(data)
    hdu_lst = fits.HDUList([pri_hdu, tbl_hdu])
    outputfile = 'TYC2.fits'
    if os.path.exists(outputfile):
        os.remove(outputfile)
    hdu_lst.writeto(outputfile)

    data = fits.getdata(outputfile)
    tyc_lst = data['TYC']
    diff = np.diff(tyc_lst)
    mask = diff == 0
    for i, m in enumerate(mask):
        if m:
            print(data[i]['TYC'], data[i]['Note'], data[i + 1]['TYC'],
                  data[i + 1]['Note'])
Esempio n. 8
0
formats = tmp[1]
record = np.dtype({'names': names, 'formats': formats})

data = []

for ifile, fname in enumerate(filename_lst):
    t1 = time.time()
    data1 = []
    infile = open(fname)
    for row in infile:
        if row[0] == '#':
            continue
        kic = int(row[0:8])
        ra = np.float64(row[9:19])
        dec = np.float64(row[19:29])
        pmra = _str_to_float(row[30:38], np.NaN)
        pmde = _str_to_float(row[39:47], np.NaN)
        plx = _str_to_float(row[48:56], np.NaN)
        umag = _str_to_float(row[57:63], np.NaN)
        gmag = _str_to_float(row[63:70], np.NaN)
        rmag = _str_to_float(row[70:77], np.NaN)
        imag = _str_to_float(row[77:84], np.NaN)
        zmag = _str_to_float(row[84:91], np.NaN)
        grmag = _str_to_float(row[92:98], np.NaN)
        d51mag = _str_to_float(row[99:105], np.NaN)
        #magJ   = _str_to_float(row[106:112], np.NaN)
        #magH   = _str_to_float(row[112:119], np.NaN)
        #magK   = _str_to_float(row[119:126], np.NaN)
        kepmag = _str_to_float(row[127:133], np.NaN)
        flag_g = int(row[209])
        flag_v = int(row[211])
Esempio n. 9
0
tmp = list(zip(*types))
record = np.dtype({'names': tmp[0], 'formats': tmp[1]})

fill_item = np.array(
    (0, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN,
     np.NaN, np.NaN, np.NaN, np.NaN, np.NaN),
    dtype=record)

data = {}

infile = open(inputfile)
for row in infile:
    hip = int(row[0:6])
    radeg = float(row[15:28]) / math.pi * 180.
    dedeg = float(row[29:42]) / math.pi * 180.
    plx = _str_to_float(row[43:50], np.NaN)
    e_plx = _str_to_float(row[83:89], np.NaN)
    pmRA = _str_to_float(row[51:59], np.NaN)
    pmDE = _str_to_float(row[60:68], np.NaN)
    e_pmRA = _str_to_float(row[90:96], np.NaN)
    e_pmDE = _str_to_float(row[97:103], np.NaN)
    Hpmag = _str_to_float(row[129:136], np.NaN)
    e_Hpmag = _str_to_float(row[137:143], np.NaN)
    Hpscat = _str_to_float(row[144:149], np.NaN)
    BV = _str_to_float(row[152:158], np.NaN)
    e_BV = _str_to_float(row[159:164], np.NaN)
    VI = _str_to_float(row[165:171], np.NaN)

    if not np.isnan(pmRA):
        pm_ra = pmRA * 1e-3 / 3600.  # convert pm_RA  from mas/yr to degree/yr
        #radeg += (2000.0-1991.25)*pm_ra/math.cos(dedeg/180.*math.pi)
Esempio n. 10
0
def main():

    astrodata = os.getenv('ASTRO_DATA')

    types = [
            ('EPIC',     np.int32),
            ('Objtype',  'S8'),
            ('Kepflag',  'S3'),
            ('RAdeg',    np.float64),
            ('DEdeg',    np.float64),
            ('pmRA',     np.float32),
            ('pmDE',     np.float32),
            ('e_pmRA',   np.float32),
            ('e_pmDE',   np.float32),
            ('Plx',      np.float32),
            ('e_Plx',    np.float32),
            ('Bmag',     np.float32),
            ('e_Bmag',   np.float32),
            ('Vmag',     np.float32),
            ('e_Vmag',   np.float32),
            ('umag',     np.float32),
            ('e_umag',   np.float32),
            ('gmag',     np.float32),
            ('e_gmag',   np.float32),
            ('rmag',     np.float32),
            ('e_rmag',   np.float32),
            ('imag',     np.float32),
            ('e_imag',   np.float32),
            ('zmag',     np.float32),
            ('e_zmag',   np.float32),
            ('Jmag',     np.float32),
            ('e_Jmag',   np.float32),
            ('Hmag',     np.float32),
            ('e_Hmag',   np.float32),
            ('Kmag',     np.float32),
            ('e_Kmag',   np.float32),
            ('W1mag',    np.float32),
            ('e_W1mag',  np.float32),
            ('W2mag',    np.float32),
            ('e_W2mag',  np.float32),
            ('W3mag',    np.float32),
            ('e_W3mag',  np.float32),
            ('W4mag',    np.float32),
            ('e_W4mag',  np.float32),
            ('kepmag',   np.float32),
            ('Teff',     np.int16),
            ('ue_Teff',  np.int16),
            ('le_Teff',  np.int16),
            ('logg',     np.float32),
            ('ue_logg',  np.float32),
            ('le_logg',  np.float32),
            ('FeH',      np.float32),
            ('ue_FeH',   np.float32),
            ('le_FeH',   np.float32),
            ('Rad',      np.float32),
            ('ue_Rad',   np.float32),
            ('le_Rad',   np.float32),
            ('Mass',     np.float32),
            ('ue_Mass',  np.float32),
            ('le_Mass',  np.float32),
            ('rho',      np.float32),
            ('ue_rho',   np.float32),
            ('le_rho',   np.float32),
            ('Lum',      np.float32),
            ('ue_Lum',   np.float32),
            ('le_Lum',   np.float32),
            ('Dist',     np.float32),
            ('ue_Dist',  np.float32),
            ('le_Dist',  np.float32),
            ('E(B-V)',   np.float32),
            ('ue_E(B-V)',np.float32),
            ('le_E(B-V)',np.float32),
            ]
    
    tmp = list(zip(*types))
    record = np.dtype({'names':tmp[0],'formats':tmp[1]})
    
    fill_item = (0, '', '',
                np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN,
                #ra      dec      pmra    pmdec e_pmra, e_pmdec   plx,   e_plx
                np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN,
                #Bmag             Vmag             umag            gmag
                np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN,
                #rmag             imag              zmag
                np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN,
                # Jmag            Hmag              Kmag
                np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN,
                # w1              w2            w3              w4
                np.NaN,
                # kpmag
                -1, -1, -1, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN,
                # Teff      logg                    FeH
                np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN,
                # Rad                    Mass                   rho
                np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN,
                # Lum                   dist                    EBV
                )

    epic_ranges = {
            1: (201000001, 210000000),
            2: (210000001, 220000000),
            3: (220000001, 230000000),
            4: (230000001, 240000000),
            5: (240000001, 250000000),
            6: (250000001, 251809654),
            }

    for i in range(1,7):
        count = 0
        data = []

        fn = 'epic_%d_19Dec2017.txt'%i
        print(fn)
        filename = os.path.join(astrodata, 'catalog/others/EPIC/%s'%fn)
    
        prev_epic = 0
        infile = open(filename)
        infile.readline()
        _epic = epic_ranges[i][0]
        for row in infile:
            g       = row.split('|')
            epic    = int(g[0])
            objtype = g[6].strip()
            kepflag = g[7].strip()
            ra      = float(g[9])
            dec     = float(g[10])
            pmra    = _str_to_float(g[11], np.NaN)
            e_pmra  = _str_to_float(g[12], np.NaN)
            pmde    = _str_to_float(g[13], np.NaN)
            e_pmde  = _str_to_float(g[14], np.NaN)
            plx     = _str_to_float(g[15], np.NaN)
            e_plx   = _str_to_float(g[16], np.NaN)
            bmag    = _str_to_float(g[17], np.NaN)
            ebmag   = _str_to_float(g[18], np.NaN)
            vmag    = _str_to_float(g[19], np.NaN)
            evmag   = _str_to_float(g[20], np.NaN)
            umag    = _str_to_float(g[21], np.NaN)
            eumag   = _str_to_float(g[22], np.NaN)
            gmag    = _str_to_float(g[23], np.NaN)
            egmag   = _str_to_float(g[24], np.NaN)
            rmag    = _str_to_float(g[25], np.NaN)
            ermag   = _str_to_float(g[26], np.NaN)
            imag    = _str_to_float(g[27], np.NaN)
            eimag   = _str_to_float(g[28], np.NaN)
            zmag    = _str_to_float(g[29], np.NaN)
            ezmag   = _str_to_float(g[30], np.NaN)
            jmag    = _str_to_float(g[31], np.NaN)
            ejmag   = _str_to_float(g[32], np.NaN)
            hmag    = _str_to_float(g[33], np.NaN)
            ehmag   = _str_to_float(g[34], np.NaN)
            kmag    = _str_to_float(g[35], np.NaN)
            ekmag   = _str_to_float(g[36], np.NaN)
            w1mag   = _str_to_float(g[37], np.NaN)
            ew1mag  = _str_to_float(g[38], np.NaN)
            w2mag   = _str_to_float(g[39], np.NaN)
            ew2mag  = _str_to_float(g[40], np.NaN)
            w3mag   = _str_to_float(g[41], np.NaN)
            ew3mag  = _str_to_float(g[42], np.NaN)
            w4mag   = _str_to_float(g[43], np.NaN)
            ew4mag  = _str_to_float(g[44], np.NaN)
            kepmag  = _str_to_float(g[45], np.NaN)
            teff    = _str_to_int(g[46], -1)
            ue_teff = _str_to_int(g[47], -1)
            le_teff = _str_to_int(g[48], -1)
            logg    = _str_to_float(g[49], np.NaN)
            ue_logg = _str_to_float(g[50], np.NaN)
            le_logg = _str_to_float(g[51], np.NaN)
            feh     = _str_to_float(g[52], np.NaN)
            ue_feh  = _str_to_float(g[53], np.NaN)
            le_feh  = _str_to_float(g[54], np.NaN)
            rad     = _str_to_float(g[55], np.NaN)
            ue_rad  = _str_to_float(g[56], np.NaN)
            le_rad  = _str_to_float(g[57], np.NaN)
            mass    = _str_to_float(g[58], np.NaN)
            ue_mass = _str_to_float(g[59], np.NaN)
            le_mass = _str_to_float(g[60], np.NaN)
            rho     = _str_to_float(g[61], np.NaN)
            ue_rho  = _str_to_float(g[62], np.NaN)
            le_rho  = _str_to_float(g[63], np.NaN)
            lum     = _str_to_float(g[64], np.NaN)
            ue_lum  = _str_to_float(g[65], np.NaN)
            le_lum  = _str_to_float(g[66], np.NaN)
            dist    = _str_to_float(g[67], np.NaN)
            ue_dist = _str_to_float(g[68], np.NaN)
            le_dist = _str_to_float(g[69], np.NaN)
            ebv     = _str_to_float(g[70], np.NaN)
            ue_ebv  = _str_to_float(g[71], np.NaN)
            le_ebv  = _str_to_float(g[72], np.NaN)
            
            item = (epic, objtype, kepflag,
                    ra, dec, pmra, pmde, e_pmra, e_pmde, plx, e_plx,
                    bmag, ebmag, vmag, evmag, umag, eumag, gmag, egmag, rmag, ermag,
                    imag, eimag, zmag, ezmag, jmag, ejmag, hmag, ejmag, kmag, ekmag,
                    w1mag, ew1mag, w2mag, ew2mag, w3mag, ew3mag, w4mag, ew4mag, kepmag,
                    teff, ue_teff, le_teff, logg, ue_logg, le_logg,
                    feh,  ue_feh,  le_feh,  rad,  ue_rad,  le_rad,
                    mass, ue_mass, le_mass, rho,  ue_rho,  le_rho,
                    lum,  ue_lum,  le_lum,  dist, ue_dist, le_dist,
                    ebv,  ue_ebv,  le_ebv,
                    )

            if epic > _epic:
                for j in range(epic - _epic):
                    data.append(fill_item)
                    _epic += 1
            data.append(item)

            _epic += 1

            count += 1
            if count % 1000000==0: print(count)

        infile.close()

        print('Data reading finished')
        data = np.array(data, dtype=record)
        print('Begin file writing')

        pri_hdu = fits.PrimaryHDU()
        tbl_hdu = fits.BinTableHDU(data)
        hdu_lst = fits.HDUList([pri_hdu,tbl_hdu])
        outputfile = 'EPIC_%d.fits'%i
        if os.path.exists(outputfile):
            os.remove(outputfile)
        hdu_lst.writeto(outputfile)
Esempio n. 11
0
def main():
    inputfile = os.path.join(os.getenv('ASTRO_DATA'), 'catalog/V/50/catalog')

    types = [
            ('HR',      np.int16),
            ('RAdeg',   np.float64),
            ('DEdeg',   np.float64),
            ('pmRA',    np.float32),
            ('pmDE',    np.float32),
            ('Plx',     np.float32),
            ('n_Plx',   'S1'),
            ('Vmag',    np.float32),
            ('n_Vmag',  'S1'),
            ('u_Vmag',  'S1'),
            ('B-V',     np.float32),
            ('u_B-V',   'S1'),
            ('U-B',     np.float32),
            ('u_U-B',   'S1'),
            ('R-I',     np.float32),
            ('n_R-I',   'S1'),
            ('SpType',  'S20'),
            ('n_SpType','S1'),
            ('RadVel',  np.float32),
            ('n_RadVel','S4'),
            ('l_RotVel','S1'),
            ('RotVel',  np.float32),
            ('u_RotVel','S1'),
            ('Dmag',    np.float32),
            ('Sep',     np.float32),
            ('MultID',  'S4'),
            ('MultCnt', np.int16),
        ]

    tmp = list(zip(*types))
    record = np.dtype({'names': tmp[0], 'formats': tmp[1]})

    data = []
    infile = open(inputfile)
    for row in infile:
        hr = int(row[0:4])
        try:
            ra = (int(row[75:77]) + int(row[77:79])/60. + float(row[79:83])/3600.)*15.
        except:
            ra = np.NaN
        try:
            de = int(row[84:86]) + int(row[86:88])/60. + float(row[88:90])/3600.
        except:
            de = np.NaN
        if row[83]=='-':
            de = -de
        vmag = _str_to_float(row[102:107], np.NaN)
        n_vmag = row[107].strip()
        u_vmag = row[108].strip()
        bv   = _str_to_float(row[109:114], np.NaN)
        u_bv = row[114].strip()
        ub   = _str_to_float(row[115:120], np.NaN)
        u_ub = row[120].strip()
        ri   = _str_to_float(row[121:126], np.NaN)
        u_ri = row[126].strip()
        sptype = row[127:147].strip()
        n_sptype = row[147].strip()
        pmra = _str_to_float(row[148:154], np.NaN)*1000
        pmde = _str_to_float(row[154:160], np.NaN)*1000
        n_plx = row[160].strip()
        plx = _str_to_float(row[161:166], np.NaN)
        radv = _str_to_float(row[166:170], np.NaN)
        if len(row)>=174:
            n_radv = row[170:174].strip()
        else:
            n_radv = ''
        if len(row)>=176:
            l_rotv = row[174:176].strip()
        else:
            l_rotv = ''
        if len(row)>=179:
            rotv = _str_to_float(row[176:179], np.NaN)
        else:
            rotv = np.NaN
        if len(row)>=180:
            u_rotv = row[179].strip()
        else:
            u_rotv = ''
        if len(row)>=180:
            dmag = _str_to_float(row[180:184], np.NaN)
            sep  = _str_to_float(row[184:190], np.NaN)
            multid = row[190:194].strip()
            multcnt = _str_to_int(row[194:196], -1)
        else:
            dmag = np.NaN
            sep  = np.NaN
            multid = ''
            multcnt = -1

        item = (hr, ra, de, pmra, pmde, plx, n_plx, 
                vmag, n_vmag, u_vmag, bv, u_bv, ub, u_ub, ri, u_ri,
                sptype, n_sptype, radv, n_radv, l_rotv, rotv, u_rotv,
                dmag, sep, multid, multcnt)
        data.append(item)
    data = np.array(data, dtype=record)

    pri_hdu = fits.PrimaryHDU()
    tbl_hdu = fits.BinTableHDU(data)
    hdu_lst = fits.HDUList([pri_hdu, tbl_hdu])

    outname = 'BSC.fits'
    if os.path.exists(outname):
        os.remove(outname)
    hdu_lst.writeto(outname)
Esempio n. 12
0
def main():

    astrodata = os.getenv('ASTRO_DATA')

    types = [
        ('EPIC', np.int32),
        ('Objtype', 'S8'),
        ('Kepflag', 'S3'),
        ('RAdeg', np.float64),
        ('DEdeg', np.float64),
        ('pmRA', np.float32),
        ('pmDE', np.float32),
        ('e_pmRA', np.float32),
        ('e_pmDE', np.float32),
        ('Plx', np.float32),
        ('e_Plx', np.float32),
        ('Bmag', np.float32),
        ('e_Bmag', np.float32),
        ('Vmag', np.float32),
        ('e_Vmag', np.float32),
        ('umag', np.float32),
        ('e_umag', np.float32),
        ('gmag', np.float32),
        ('e_gmag', np.float32),
        ('rmag', np.float32),
        ('e_rmag', np.float32),
        ('imag', np.float32),
        ('e_imag', np.float32),
        ('zmag', np.float32),
        ('e_zmag', np.float32),
        ('Jmag', np.float32),
        ('e_Jmag', np.float32),
        ('Hmag', np.float32),
        ('e_Hmag', np.float32),
        ('Kmag', np.float32),
        ('e_Kmag', np.float32),
        ('W1mag', np.float32),
        ('e_W1mag', np.float32),
        ('W2mag', np.float32),
        ('e_W2mag', np.float32),
        ('W3mag', np.float32),
        ('e_W3mag', np.float32),
        ('W4mag', np.float32),
        ('e_W4mag', np.float32),
        ('kepmag', np.float32),
        ('Teff', np.int16),
        ('ue_Teff', np.int16),
        ('le_Teff', np.int16),
        ('logg', np.float32),
        ('ue_logg', np.float32),
        ('le_logg', np.float32),
        ('FeH', np.float32),
        ('ue_FeH', np.float32),
        ('le_FeH', np.float32),
        ('Rad', np.float32),
        ('ue_Rad', np.float32),
        ('le_Rad', np.float32),
        ('Mass', np.float32),
        ('ue_Mass', np.float32),
        ('le_Mass', np.float32),
        ('rho', np.float32),
        ('ue_rho', np.float32),
        ('le_rho', np.float32),
        ('Lum', np.float32),
        ('ue_Lum', np.float32),
        ('le_Lum', np.float32),
        ('Dist', np.float32),
        ('ue_Dist', np.float32),
        ('le_Dist', np.float32),
        ('E(B-V)', np.float32),
        ('ue_E(B-V)', np.float32),
        ('le_E(B-V)', np.float32),
    ]

    tmp = list(zip(*types))
    record = np.dtype({'names': tmp[0], 'formats': tmp[1]})

    fill_item = (
        0,
        '',
        '',
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        #ra      dec      pmra    pmdec e_pmra, e_pmdec   plx,   e_plx
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        #Bmag             Vmag             umag            gmag
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        #rmag             imag              zmag
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        # Jmag            Hmag              Kmag
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        # w1              w2            w3              w4
        np.NaN,
        # kpmag
        -1,
        -1,
        -1,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        # Teff      logg                    FeH
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        # Rad                    Mass                   rho
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        np.NaN,
        # Lum                   dist                    EBV
    )

    epic_ranges = {
        1: (201000001, 210000000),
        2: (210000001, 220000000),
        3: (220000001, 230000000),
        4: (230000001, 240000000),
        5: (240000001, 250000000),
        6: (250000001, 251809654),
    }

    for i in range(1, 7):
        count = 0
        data = []

        fn = 'epic_%d_19Dec2017.txt' % i
        print(fn)
        filename = os.path.join(astrodata, 'catalog/others/EPIC/%s' % fn)

        prev_epic = 0
        infile = open(filename)
        infile.readline()
        _epic = epic_ranges[i][0]
        for row in infile:
            g = row.split('|')
            epic = int(g[0])
            objtype = g[6].strip()
            kepflag = g[7].strip()
            ra = float(g[9])
            dec = float(g[10])
            pmra = _str_to_float(g[11], np.NaN)
            e_pmra = _str_to_float(g[12], np.NaN)
            pmde = _str_to_float(g[13], np.NaN)
            e_pmde = _str_to_float(g[14], np.NaN)
            plx = _str_to_float(g[15], np.NaN)
            e_plx = _str_to_float(g[16], np.NaN)
            bmag = _str_to_float(g[17], np.NaN)
            ebmag = _str_to_float(g[18], np.NaN)
            vmag = _str_to_float(g[19], np.NaN)
            evmag = _str_to_float(g[20], np.NaN)
            umag = _str_to_float(g[21], np.NaN)
            eumag = _str_to_float(g[22], np.NaN)
            gmag = _str_to_float(g[23], np.NaN)
            egmag = _str_to_float(g[24], np.NaN)
            rmag = _str_to_float(g[25], np.NaN)
            ermag = _str_to_float(g[26], np.NaN)
            imag = _str_to_float(g[27], np.NaN)
            eimag = _str_to_float(g[28], np.NaN)
            zmag = _str_to_float(g[29], np.NaN)
            ezmag = _str_to_float(g[30], np.NaN)
            jmag = _str_to_float(g[31], np.NaN)
            ejmag = _str_to_float(g[32], np.NaN)
            hmag = _str_to_float(g[33], np.NaN)
            ehmag = _str_to_float(g[34], np.NaN)
            kmag = _str_to_float(g[35], np.NaN)
            ekmag = _str_to_float(g[36], np.NaN)
            w1mag = _str_to_float(g[37], np.NaN)
            ew1mag = _str_to_float(g[38], np.NaN)
            w2mag = _str_to_float(g[39], np.NaN)
            ew2mag = _str_to_float(g[40], np.NaN)
            w3mag = _str_to_float(g[41], np.NaN)
            ew3mag = _str_to_float(g[42], np.NaN)
            w4mag = _str_to_float(g[43], np.NaN)
            ew4mag = _str_to_float(g[44], np.NaN)
            kepmag = _str_to_float(g[45], np.NaN)
            teff = _str_to_int(g[46], -1)
            ue_teff = _str_to_int(g[47], -1)
            le_teff = _str_to_int(g[48], -1)
            logg = _str_to_float(g[49], np.NaN)
            ue_logg = _str_to_float(g[50], np.NaN)
            le_logg = _str_to_float(g[51], np.NaN)
            feh = _str_to_float(g[52], np.NaN)
            ue_feh = _str_to_float(g[53], np.NaN)
            le_feh = _str_to_float(g[54], np.NaN)
            rad = _str_to_float(g[55], np.NaN)
            ue_rad = _str_to_float(g[56], np.NaN)
            le_rad = _str_to_float(g[57], np.NaN)
            mass = _str_to_float(g[58], np.NaN)
            ue_mass = _str_to_float(g[59], np.NaN)
            le_mass = _str_to_float(g[60], np.NaN)
            rho = _str_to_float(g[61], np.NaN)
            ue_rho = _str_to_float(g[62], np.NaN)
            le_rho = _str_to_float(g[63], np.NaN)
            lum = _str_to_float(g[64], np.NaN)
            ue_lum = _str_to_float(g[65], np.NaN)
            le_lum = _str_to_float(g[66], np.NaN)
            dist = _str_to_float(g[67], np.NaN)
            ue_dist = _str_to_float(g[68], np.NaN)
            le_dist = _str_to_float(g[69], np.NaN)
            ebv = _str_to_float(g[70], np.NaN)
            ue_ebv = _str_to_float(g[71], np.NaN)
            le_ebv = _str_to_float(g[72], np.NaN)

            item = (
                epic,
                objtype,
                kepflag,
                ra,
                dec,
                pmra,
                pmde,
                e_pmra,
                e_pmde,
                plx,
                e_plx,
                bmag,
                ebmag,
                vmag,
                evmag,
                umag,
                eumag,
                gmag,
                egmag,
                rmag,
                ermag,
                imag,
                eimag,
                zmag,
                ezmag,
                jmag,
                ejmag,
                hmag,
                ejmag,
                kmag,
                ekmag,
                w1mag,
                ew1mag,
                w2mag,
                ew2mag,
                w3mag,
                ew3mag,
                w4mag,
                ew4mag,
                kepmag,
                teff,
                ue_teff,
                le_teff,
                logg,
                ue_logg,
                le_logg,
                feh,
                ue_feh,
                le_feh,
                rad,
                ue_rad,
                le_rad,
                mass,
                ue_mass,
                le_mass,
                rho,
                ue_rho,
                le_rho,
                lum,
                ue_lum,
                le_lum,
                dist,
                ue_dist,
                le_dist,
                ebv,
                ue_ebv,
                le_ebv,
            )

            if epic > _epic:
                for j in range(epic - _epic):
                    data.append(fill_item)
                    _epic += 1
            data.append(item)

            _epic += 1

            count += 1
            if count % 1000000 == 0: print(count)

        infile.close()

        print('Data reading finished')
        data = np.array(data, dtype=record)
        print('Begin file writing')

        pri_hdu = fits.PrimaryHDU()
        tbl_hdu = fits.BinTableHDU(data)
        hdu_lst = fits.HDUList([pri_hdu, tbl_hdu])
        outputfile = 'EPIC_%d.fits' % i
        if os.path.exists(outputfile):
            os.remove(outputfile)
        hdu_lst.writeto(outputfile)
Esempio n. 13
0
def main():
    path = os.path.join(os.getenv('ASTRO_DATA'), 'catalog/I/239/')
    
    types = [
            ('TYC',      np.int32),
            ('RAdeg',    np.float64),
            ('DEdeg',    np.float64),
            ('e_RA',     np.float32),
            ('e_DE',     np.float32),
            ('pmRA',     np.float32),
            ('pmDE',     np.float32),
            ('e_pmRA',   np.float32),
            ('e_pmDE',   np.float32),
            ('Plx',      np.float32),
            ('e_Plx',    np.float32),
            ('Nastro',   np.int16),
            ('Vmag',     np.float32),
            ('r_Vmag',   'S1'),
            ('BTmag',    np.float32),
            ('e_BTmag',  np.float32),
            ('VTmag',    np.float32),
            ('e_VTmag',  np.float32),
            ('r_BTmag',  'S1'),
            ('B-V',      np.float32),
            ('e_B-V',    np.float32),
            ('Nphoto',   np.int16),
            ('VTscat',   np.float32),
            ('VTmax',    np.float32),
            ('VTmin',    np.float32),
            ('VarFlag',  'S1'),
            ('MultFlag', 'S1'),
            ]
    tmp = list(zip(*types))
    record = np.dtype({'names':tmp[0],'formats':tmp[1]})

    fill_item = (0, np.NaN, np.NaN, np.NaN, np.NaN, # ra, de, e_ra, e_de
                 np.NaN, np.NaN, np.NaN, np.NaN, # pm
                 np.NaN, np.NaN, -1, # plx, Nastro
                 np.NaN, '', np.NaN, np.NaN, np.NaN, np.NaN, '', # vmag ~ r_BTmag
                 np.NaN, np.NaN, -1, np.NaN, np.NaN, np.NaN, '', ''
                 )
    
    data = []

    fn = 'tyc_main.dat'
    infile = open(os.path.join(path, fn))
    for row in infile:
        if row[0]!='T':
            print('Warning: Not Tycho star')
        g = row[2:14].split()
        tyc1   = int(g[0])
        tyc2   = int(g[1])
        tyc3   = int(g[2])
        tyc = np.int32((tyc1<<18) + (tyc2<<4) + (tyc3<<1))
    
        radeg    = _str_to_float(row[51:63], np.NaN)
        dedeg    = _str_to_float(row[64:76], np.NaN)
        vmag     = _str_to_float(row[41:46], np.NaN)
        r_vmag   = row[49].strip()
        plx      = _str_to_float(row[79:86], np.NaN)
        pm_ra    = _str_to_float(row[87:95], np.NaN)
        pm_de    = _str_to_float(row[96:104], np.NaN)
        e_ra     = _str_to_float(row[105:111], np.NaN)
        e_de     = _str_to_float(row[112:118], np.NaN)
        e_plx    = _str_to_float(row[119:125], np.NaN)
        e_pmra   = _str_to_float(row[126:132], np.NaN)
        e_pmde   = _str_to_float(row[133:139], np.NaN)
        nastro   = _str_to_int(row[200:203], 0)
        btmag    = _str_to_float(row[217:223], np.NaN)
        e_btmag  = _str_to_float(row[224:229], np.NaN)
        vtmag    = _str_to_float(row[230:236], np.NaN)
        e_vtmag  = _str_to_float(row[237:242], np.NaN)
        r_btmag  = row[243].strip()
        bv       = _str_to_float(row[245:251], np.NaN)
        e_bv     = _str_to_float(row[252:257], np.NaN)
        nphoto   = _str_to_int(row[269:272], 0)
        vtscat   = _str_to_float(row[273:278], np.NaN)
        vtmax    = _str_to_float(row[279:284], np.NaN)
        vtmin    = _str_to_float(row[285:290], np.NaN)
        varflag  = row[293].strip()
        multflag = row[295].strip()

        item = (tyc, radeg, dedeg, e_ra, e_de, pm_ra, pm_de, e_pmra, e_pmde,
                plx, e_plx, nastro, 
                vmag, r_vmag, btmag, e_btmag, vtmag, e_vtmag, r_btmag,
                bv, e_bv, nphoto, vtscat, vtmax, vtmin, varflag, multflag)
        data.append(item)
    infile.close()
    
    data = np.array(data, dtype=record)
    data = np.sort(data, order='TYC')
    # add an empty item in the beginning
    data = np.insert(data, 0, np.array(fill_item, dtype=record))
    
    pri_hdu = fits.PrimaryHDU()
    tbl_hdu = fits.BinTableHDU(data)
    hdu_lst = fits.HDUList([pri_hdu,tbl_hdu])
    outputfile = 'TYC.fits'
    if os.path.exists(outputfile):
        os.remove(outputfile)
    hdu_lst.writeto(outputfile)
    
    data = fits.getdata(outputfile)
    tyc_lst = data['TYC']
    diff = np.diff(tyc_lst)
    mask = diff==0
    for i, m in enumerate(mask):
        if m:
            print(data[i]['TYC'], data[i+1]['TYC'])