Exemple #1
0
pathdata = pathbase + 'data/'
pathimag = pathbase + 'imag/'

path = pathdata + 'asassn_2021-01-21-21_49_54.csv'
arry = pd.read_csv(path, sep=',', low_memory=False)

# write the RA and DEC to a new file
numbtarg = len(arry['RAJ2000'])
arryoutp = np.empty((numbtarg, 2))
arryoutp[:, 0] = arry['RAJ2000'].values
arryoutp[:, 1] = arry['DEJ2000'].values

print(arry.columns)
for name in arry.columns:
    print(name)
    summgene(arry[name].values)
    print('')

path = pathdata + 'asassn_coor.csv'
print('Writing to %s...' % path)
#np.savetxt(path, arryoutp, delimiter=',')

# read WTVT output
path = pathdata + 'wtv-asassn_coor.csv'
arrytess = np.loadtxt(path, skiprows=62, delimiter=',')
listrasc = arrytess[:, 0]
listdecl = arrytess[:, 1]
boolobsd = arrytess[:, 2:]

# start at Sector 40 with index 39
boolobsdtotl = boolobsd[:, 39:].any(1)
Exemple #2
0
import astropy

from astropy.io import fits

## read PCAT path environment variable
pathbase = os.environ['TROIA_DATA_PATH'] + '/'
pathdata = pathbase + 'data/'
pathimag = pathbase + 'imag/'

# read Gaia IDs with high radial velocity errors from Saul
dictcatl = retr_dictcatlrvel()

print('listnamesaul')
print(listnamesaul)
print('rascradv')
summgene(rascradv)
print('declradv')
summgene(declradv)
print('stdvradv')
summgene(stdvradv)
print

# get Gaia RVs
path = pathdata + 'GaiaSource.csv'
liststrgextn = fnmatch.filter(os.listdir(pathdata), 'GaiaSource_[0-9]*.csv')
listobjtarch = []
for strgextn in liststrgextn:
    path = pathdata + strgextn
    print('Reading from %s...' % path)
    for line in open(path):
        listcols = line[:-1].split(',')
Exemple #3
0
        if k < numbrele:
            numbtran = np.random.random_integers(15)
            indxtran = np.arange(numbbins / 2 - numbtran / 2,
                                 numbbins / 2 + numbtran / 2 + 1)
            deptthis[k] = dept * (1. + np.random.rand())
            flux[k, indxtran] -= deptthis[k]
            s2nr[k] = deptthis[k] / fact[k] * np.sqrt(indxtran.size)
    labltrue[indxrele] = 1.
    gdat.inptraww, gdat.outp, gdat.peri = exopmain.retr_datamock(numbplan=gdat.numbrele, \
                                                numbnois=gdat.numbirre, numbtime=gdat.numbtime, dept=gdat.dept, nois=gdat.nois, boolflbn=True)
else:
    meanphas, flux, labltrue, legdoutp, tici, itoi = exopmain.retr_datatess(
        False)
    indxbadd = np.where(~np.isfinite(flux))[0]
    print 'indxbadd'
    summgene(indxbadd)
    print 'flux'
    summgene(flux)
    flux[indxbadd] = np.random.randn(indxbadd.size)

    print 'meanphas'
    summgene(meanphas)
    print 'flux'
    summgene(flux)
    #imp = Imputer(strategy="mean", axis=0)
    #flux = 0wiimp.fit_transformflux))

indxdataplot = np.arange(numbdataplot)

# do clustering
listobjt = []
Exemple #4
0
print('Reading from %s...' % path)
data = np.loadtxt(path, skiprows=45, delimiter=',')
rasc = data[:, 0]
decl = data[:, 1]
boolsect = data[:, 2:]
# determine visible targets
indxoldd = np.where(np.sum(boolsect[:, 26:], 1) > 0)[0]

indxneww = []
for k in indxoldd:
    if len(indxneww) == 0 or (np.sqrt((rasc[k] - rasc[np.array(indxneww)])**2 + (decl[k] - decl[np.array(indxneww)])**2) > 2.).all():
        indxneww.append(k)
indxneww = np.array(indxneww)
indx = np.array(indxneww)
print('indxneww')
summgene(indxneww)
print('indxoldd')
summgene(indxoldd)
print('data')
summgene(data)
print('indx')
summgene(indx)

# read TIC xmat
path = pathdata + 'datafull.csv'
print('Reading from %s...' % path)
datafull = np.loadtxt(path, delimiter=',', skiprows=1)
 

# write the output
pathsave = pathdata + 'outp.csv'
Exemple #5
0
def cnfg_TOI270():

    timeobsdinit = 2458387.0927381925

    # perform allesfitter run
    boolalle = False

    # relevant transit times
    liststrgplan = ['b', 'c', 'd']
    numbplan = len(liststrgplan)
    indxplan = np.arange(numbplan, dtype=int)
    timetranwind = [[] for j in indxplan]
    timetranwind[0] = [np.array([])]
    timetranwind[1] = np.array([
                                  2458797.034958, \
                                  2458802.695130, \
                                  2458808.355302, \
                                  2458830.995990, \
                                  2458836.656162, \
                                  2458842.316334, \
                                  2458847.976506, \
                                  2458887.597710, \
                                  2458893.257882, \
                                  2458898.918054, \
                                  2458904.578226, \
                                  2458921.558742, \
                                  2458927.218914, \
                                  2458938.539258, \
                                  2458944.199430, \
                                  2458955.519774, \
                                  2458961.179946, \
                                  2458966.840118, \
                                  2458972.500290, \
                                  2458978.160462, \
                                  2458983.820634, \
                                  2459006.461322, \
                                  2459012.121494, \
                                  2459017.781666, \
                                  2459023.441838, \
                                  2459057.402870, \
                                  2459063.063042, \
                                  2459068.723214, \
                                  2459074.383386, \
                                  2459080.043558, \
                                 ])
    timetranwind[2] = np.array([
                                  2458799.362400, \
                                  2458890.403520, \
                                  2458901.783660, \
                                  2458924.543940, \
                                  2458935.924080, \
                                  2458958.684360, \
                                  2458970.064500, \
                                  2458981.444640, \
                                  2459004.204920, \
                                  2459015.585060, \
                                  2459026.965200, \
                                  2459061.105620, \
                                  2459072.485760, \
                                 ])

    import pickle
    pathdata = os.environ['TTVR_DATA_PATH'] + '/data/'
    path = pathdata + 'measured_allesfit_all_ttv.pickle'
    objtfile = open(path, 'rb')
    datapickttvr = pickle.load(objtfile)
    indxtranobsd = [[] for j in indxplan]
    timetranlineproj = [[] for j in indxplan]
    timetranobsd = [[] for j in indxplan]
    stdvtimetranobsd = [[] for j in indxplan]
    for j in indxplan:
        #meanperiline[j] = datapickttvr[liststrgplan[j]]['lin_period']
        timetranobsd[j] = datapickttvr[liststrgplan[j]]['transit_time']
        stdvtimetranobsd[j] = datapickttvr[liststrgplan[j]]['transit_time_err']
        if j == 1:
            timetranobsd[j] = np.concatenate(
                (timetranobsd[j],
                 np.array([2458780.0690228315, 2458797.054231985])))
            stdvtimetranobsd[j] = np.concatenate(
                (stdvtimetranobsd[j],
                 np.array([0.0011934256181120872, 0.0006028260104358196])))
        if j == 2:
            timetranobsd[j] = np.concatenate(
                (timetranobsd[j], np.array([2458799.350335964])))
            stdvtimetranobsd[j] = np.concatenate(
                (stdvtimetranobsd[j], np.array([0.001056972425431013])))
        timetranobsd[j] -= timeobsdinit

    # setttings
    ## modeling
    # get data
    meanepocline = np.array([1461.01464, 1463.08481, 1469.33834]) + 2457000
    meanperiline = np.array([3.360080, 5.660172, 11.38014])

    numbparaplan = 7
    numbconf = 2
    indxconf = np.arange(numbconf)
    minmpara = [[] for k in indxconf]
    maxmpara = [[] for k in indxconf]
    meanpara = [[] for k in indxconf]
    stdvpara = [[] for k in indxconf]

    for k in indxconf:
        if k == 0:
            numbparaplanconf = 2
        else:
            numbparaplanconf = 7
        numbparaconf = numbparaplanconf * numbplan
        minmpara[k] = np.empty(numbparaconf)
        maxmpara[k] = np.empty(numbparaconf)
        meanpara[k] = np.empty(numbparaconf)
        stdvpara[k] = np.empty(numbparaconf)
        if k == 0:
            meanpara[k][indxplan] = np.array(
                [timetranobsd[j][0] for j in indxplan])
            stdvpara[k][indxplan] = 1e-2

            print('indxplan+numbplan:')
            print(indxplan + numbplan)
            print('stdvpara[k]')
            summgene(stdvpara[k])
            print('meanpara[k]')
            summgene(meanpara[k])
            print('meanperiline')
            print(meanperiline)
            meanpara[k][indxplan + numbplan] = meanperiline
            stdvpara[k][indxplan + numbplan] = meanperiline * 1e-2

        else:
            meanpara[k][indxplan + numbplan * 0] = np.array([2.47, 5.46, 2.55
                                                             ]) * 0.00000300245
            stdvpara[k][indxplan + numbplan * 0] = np.array(
                [0.75, 1.30, 0.91]) * 0.00000300245 * 1e-2

            meanpara[k][indxplan + numbplan * 1] = meanperiline
            stdvpara[k][indxplan + numbplan *
                        1] = meanpara[k][indxplan + numbplan * 1] * 1e-2

            meanpara[k][indxplan + numbplan * 2] = np.array([0., 0.,
                                                             0.])  # ecce
            stdvpara[k][indxplan + numbplan *
                        2] = meanpara[k][indxplan + numbplan * 2] * 1e-2

            meanpara[k][indxplan + numbplan * 3] = np.array(
                [88.65, 89.53, 89.69])  # incl
            stdvpara[k][indxplan + numbplan *
                        3] = meanpara[k][indxplan + numbplan * 3] * 1e-2

            meanpara[k][indxplan + numbplan * 4] = np.array(
                [0., 0., 0.])  # ascending long
            stdvpara[k][indxplan + numbplan *
                        4] = meanpara[k][indxplan + numbplan * 4] * 1e-2

            meanpara[k][indxplan + numbplan * 5] = np.array(
                [0., 0., 0.])  # arg periapsis
            stdvpara[k][indxplan + numbplan *
                        5] = meanpara[k][indxplan + numbplan * 5] * 1e-2

            meanpara[k][indxplan + numbplan * 6] = np.array(
                [89.99999, 296.7324, 8.25829165761])  # mean anomaly
            stdvpara[k][indxplan + numbplan *
                        6] = meanpara[k][indxplan + numbplan * 6] * 1e-2

        minmpara[k] = meanpara[k] - stdvpara[k] * 5.
        maxmpara[k] = meanpara[k] + stdvpara[k] * 5.

    indxtranobsd = [[] for j in indxplan]
    for j in indxplan:
        indxtranobsd[j] = np.round(timetranobsd[j] /
                                   meanperiline[j]).astype(int)

    offs = [17, 10, 5]
    epoc = [2458444.2140459623, 2458446.104473652, 2458446.5783906463]
    peri = [3.360062366764236, 5.660172076246358, 11.38028139190828]
    liststrginst = [
        'TESS', 'Trappist-South_z_2', 'LCO-SAAO-1m0_ip', 'Trappist-South_z_1',
        'LCO_ip', 'LCO-SSO-1m0_ip_1', 'mko-cdk700_g', 'Myers_B'
    ]
    pathtmpt = pathdata
    if boolalle:
        exec_alle_ttvr(pathdata, pathtmpt, epoc, peri, offs, liststrginst)

    init( \
         timetranobsd, \
         stdvtimetranobsd, \
         minmpara, \
         maxmpara, \
         meanpara, \
         stdvpara, \
        )
Exemple #6
0
def init(
         # data
         timetranobsd, \
         stdvtimetranobsd, \

         # model


         minmpara, \
         maxmpara, \
         meanpara, \
         stdvpara, \

         timeobsdinit=None, \
        
         ## TTV model tyye: 'nbod', 'line' or 'sinu'


         listmodltype = ['line', 'nbod'], \
         # strings for the list of planets

         liststrgplan=None, \
         
         ## if eccentricity is included


         maxmecce = 0.1, \

        ):

    # construct global object
    gdat = tdpy.util.gdatstrt()

    # copy unnamed inputs to the global object
    #for attr, valu in locals().iter():
    for attr, valu in locals().items():
        if '__' not in attr and attr != 'gdat':
            setattr(gdat, attr, valu)

    # paths
    gdat.pathbase = os.environ['TTVR_DATA_PATH'] + '/'
    gdat.pathdata = gdat.pathbase + 'data/'
    gdat.pathimag = gdat.pathbase + 'imag/'

    gdat.numbplan = len(gdat.meanpara)
    gdat.indxplan = np.arange(gdat.numbplan)

    gdat.facttime = 24. * 60.

    # setup
    gdat.diagmode = True

    if gdat.liststrgplan is None:
        gdat.liststrgplan = ['b', 'c', 'd'][:gdat.numbplan]

    gdat.inittimefastttvr = 0
    gdat.delttimefastttvr = 0.03
    gdat.numbstepfastttvr = 700

    # The function ttvfast.ttvfast returns a dictionary containing positions and rv. The positions entry is a tuple of:
    # a list of integer indices for which values correspond to which planet,
    # a list of integers defining the epoch,
    # a list of times,
    # a list of rsky values, and
    # a list of vsky values.

    gdat.numbtranoffs = [22, 13, 7]
    #for j in gdat.indxplan:
    #    gdat.timetranlineproj[j] = gdat.meanepocline[j] + (gdat.indxtranobsd[j] - gdat.numbtranoffs[j]) * gdat.meanperiline[j] - gdat.timeobsdinit

    numbsampwalk = 15000
    numbsampburnwalk = 5000
    numbsampburnwalkseco = 5000

    # number of total data points
    numbdata = 0
    for j in gdat.indxplan:
        numbdata += gdat.timetranobsd[j].size

    for y, gdat.modltype in enumerate(gdat.listmodltype):

        listlablpara = []
        if gdat.modltype == 'line':
            listlistlablpara = [['E', ' [day]'], ['P', ' [day]']]
        if gdat.modltype == 'sinu':
            # temp
            listlistlablpara = [['E', ' [day]'], ['P', ' [day]']]
        if gdat.modltype == 'nbod':
            listlistlablpara = [['M', ' [$M_{\odot}$]'], ['P', ' [day]'], ['\epsilon', ''], ['i', ' [deg]'], ['\Omega', ' [deg]'], \
                                                                                                ['\omega', ' [deg]'], ['A', ' [deg]']]
        gdat.numbparaplan = len(listlistlablpara)
        for strgfrst, strgseco in listlistlablpara:
            for j in gdat.indxplan:
                listlablpara.append('$%s_%s$%s' %
                                    (strgfrst, gdat.liststrgplan[j], strgseco))
        numbpara = len(listlablpara)
        indxpara = np.arange(numbpara)
        numbdoff = numbdata - numbpara

        # impose priors
        gdat.indxparaplan = np.arange(gdat.numbparaplan)
        numbbins = 20

        gdat.numbpara = gdat.numbplan * gdat.numbparaplan
        gdat.indxpara = np.arange(gdat.numbpara)
        numbwalk = 2 * numbpara
        indxwalk = np.arange(numbwalk)

        #gdat.initindxtranmodl, gdat.inittimetranmodl, \
        #        gdat.initindxtranmodlproj, gdat.inittimetranmodlproj = retr_modl_full(gdat.meanparainit, gdat, modltype)
        #listvarb = [[gdat.initindxtranmodl], [gdat.inittimetranmodl], [gdat.initindxtranmodlproj], [gdat.inittimetranmodlproj]]

        listscalpara = ['self' for k in gdat.indxpara]
        print('gdat.minmpara')
        summgene(gdat.minmpara)
        print('listlablpara')
        print(listlablpara)
        parapost = tdpy.mcmc.samp(gdat, gdat.pathimag, numbsampwalk, numbsampburnwalk, numbsampburnwalkseco, retr_llik, \
                            listlablpara, listscalpara, gdat.minmpara[y], gdat.maxmpara[y], gdat.meanpara[y], gdat.stdvpara[y], numbdata)

        objtsave = objtsamp

        for j in gdat.indxplan:
            if j == 0:
                continue
            timetranwind[j] -= gdat.timeobsdinit

        gdat.parapost = objtsave.flatchain
        gdat.indxsampfeww = indxsamp[::100]
        gdat.numbsampfeww = gdat.indxsampfeww.size
        gdat.sampindxtranmodl = [[] for i in gdat.indxsampfeww]
        gdat.samptimetranmodl = [[] for i in gdat.indxsampfeww]
        gdat.sampindxtranmodlproj = [[] for i in gdat.indxsampfeww]
        gdat.samptimetranmodlproj = [[] for i in gdat.indxsampfeww]
        sizearry = np.empty((gdat.numbsampfeww, gdat.numbplan), dtype=int)
        listtemptemp = [[[] for i in gdat.indxsampfeww] for j in gdat.indxplan]
        for ii, i in enumerate(gdat.indxsampfeww):
            gdat.sampindxtranmodl[ii], gdat.samptimetranmodl[ii], gdat.sampindxtranmodlproj[ii], gdat.samptimetranmodlproj[ii] = \
                                                                                                        retr_modl(gdat.parapost[i, :], gdat)
            for j in gdat.indxplan:
                listtemptemp[j][ii] = gdat.samptimetranmodl[ii][j]
                sizearry[ii, j] = gdat.samptimetranmodl[ii][j].size
        minmsizearry = np.amin(sizearry, 0)
        gdat.stdvtime = [[] for j in gdat.indxplan]
        gdat.indxtranstdv = [[] for j in gdat.indxplan]
        for j in gdat.indxplan:
            listtemp = np.empty((gdat.numbsampfeww, minmsizearry[j]))
            for ii, i in enumerate(gdat.indxsampfeww):
                listtemp[ii, :] = listtemptemp[j][ii][:minmsizearry[j]]
            gdat.stdvtime[j] = np.std(listtemp, 0) * gdat.facttime
            gdat.indxtranstdv[j] = np.arange(
                minmsizearry[j])  #gdat.sampindxtranmodl[i][j][minmsizearry[j]]

        listvarb = [
            gdat.sampindxtranmodl, gdat.samptimetranmodl,
            gdat.sampindxtranmodlproj, gdat.samptimetranmodlproj
        ]
        plot_ttvr(gdat, gdat.modltype, listvarb)

        numbsampfeww = gdat.indxsampfeww.size

        for j in gdat.indxplan:
            # temp
            if j == 0:
                continue
            numbtranwind = timetranwind[j].size
            timetranwindpred = np.empty((numbtranwind, numbsampfeww))
            for k, timetran in enumerate(timetranwind[j]):
                for i in range(numbsampfeww):
                    indx = np.argmin(
                        np.abs(gdat.samptimetranmodl[i][j] - timetran))
                    timetranwindpred[k, i] = gdat.samptimetranmodl[i][j][indx]

                print('%f %f %g %g' % (gdat.timeobsdinit + timetranwind[j][k], gdat.timeobsdinit + np.mean(timetranwindpred[k, :]), \
                                                                                        np.std(timetranwindpred[k, :]) * gdat.facttime, \
                                                                                        (np.mean(timetranwindpred[k, :]) - timetran) * gdat.facttime))

        if numbsamp != numbsampwalk * numbwalk:
            raise Exception('')

        listsamp = objtsave.flatchain
        listllik = objtsave.flatlnprobability

        listlpos = objtsave.lnprobability
        chi2 = -2. * listlpos

        listsampproc = np.empty((gdat.numbsampfeww, gdat.numbplan))
        for j in gdat.indxplan:
            for ii, i in enumerate(gdat.indxsampfeww):
                listsampproc[ii, j] = gdat.samptimetranmodl[ii][j][40]
            listsampproc[:, j] -= np.mean(listsampproc[:, j])
            listsampproc[:, j] *= gdat.facttime
            listlablpara.append('T_{p,%s}' % gdat.liststrgplan[j])

        print('Minimum chi2: ')
        print(np.amin(chi2))
        print('Minimum chi2 per dof: ')
        print(np.amin(chi2) / numbdoff)
        print('Maximum aposterior: ')
        print(np.amax(listlpos))
Exemple #7
0
def plot(gdat, indxstar, indxpara=None, strgtype='evol'):
    
    if indxstar.size == 1:
        strg = gdat.liststrgstar[indxstar[0]] + '_'
    else:
        strg = ''
    
    print('strgtype')
    print(strgtype)
    
    listticklabl = []
    if strgtype == 'epocevol':
        chanlist = [[[] for m in gdat.indxstar] for i in gdat.indxruns]
        xpos = np.array(gdat.listyear)
        for i in gdat.indxruns:
            for m in indxstar:
                chanlist[i][m] = [gdat.timejwst[k][i][m] for k in gdat.indxyear]
        for k in gdat.indxyear:
            listticklabl.append('%s' % str(gdat.listyear[k]))
    else:
        chanlist = []
        numbxdat = gdat.numbruns * indxstar.size
        xpos = 0.6 * (np.arange(numbxdat) + 1.)

        for i in gdat.indxruns:
            for m in indxstar:
                if strgtype == 'jwstcomp':
                    chanlist.append(gdat.timejwst[1][i][m])
                if strgtype == 'paracomp':
                    for k in indxpara:
                        chanlist.append((gdat.listobjtalle[i][m].posterior_params[gdat.liststrgparaconc[k]] - \
                            np.mean(gdat.listobjtalle[i][m].posterior_params[gdat.liststrgparaconc[k]])) * 24. * 60.)
                    
                if strgtype == 'paracomp' or strgtype == 'jwstcomp':
                    ticklabl = '%s, %s' % (gdat.liststrgstar[m], gdat.liststrgruns[i])
                    listticklabl.append(ticklabl)
                else:
                    ticklabl = '%s, %s' % (gdat.liststrgstar[m], gdat.liststrgruns[i])
                    listticklabl.append(ticklabl)
                
        if xpos.size != len(listticklabl):
            raise Exception('')
        
    print('xpos')
    summgene(xpos)
    print('chanlist')
    print(chanlist)
    figr, axis = plt.subplots(figsize=(5, 4))
    if strgtype != 'epocevol':
        axis.violinplot(chanlist, xpos, showmedians=True, showextrema=False)
    else:
        for i in gdat.indxruns:
            for m in indxstar:
                axis.violinplot(chanlist[i][m], xpos, showmedians=True, showextrema=False)

    axis.set_xticks(xpos)
    if strgtype == 'jwstcomp':
        axis.set_ylabel('Transit time residual in 2023 [min]')
        strgbase = strgtype

    if strgtype == 'paracomp':
        if gdat.liststrgparaconc[indxpara] == 'b_period':
            axis.set_ylabel('P [min]')
        else:
            labl = gdat.listlablparaconc[indxpara[0]]
            axis.set_ylabel(labl)
        strgbase = '%04d' % indxpara
    
    if strgtype == 'epocevol':
        axis.set_xlabel('Year')
        axis.set_ylabel('Transit time residual [min]')
        strgbase = strgtype
    
    path = gdat.pathimag + 'viol_%s.%s' % (strgbase, gdat.strgplotextn)
    axis.set_xticklabels(listticklabl)
    plt.tight_layout()
    print('Writing to %s...' % path)
    print()
    figr.savefig(path)
    plt.close()