Exemplo n.º 1
0
Arquivo: mgls.py Projeto: rosich/mgls
            """
            TABLE_DATA = []
            TABLE_DATA.append(
                ['Data set', 'slope', 'intercept', 'r', 'p-value'])
            for s in range(Globals.n_sets):
                TABLE_DATA.append([
                    str(Globals.dataset_names[s]),
                    str(round(lt_params[s][0], 7)),
                    str(round(lt_params[s][1], 5)),
                    str(round(lt_params[s][2], 5)),
                    str(lt_params[s][3])
                ])

            TABLE_DATA = tuple(TABLE_DATA)
            table_instance = SingleTable(TABLE_DATA, "Linear trend fit")
            table_instance.justify_column = 'right'
            print ""
            print(table_instance.table)

        except:
            #if terminaltables is not installed
            for s in range(Globals.n_sets):
                print ""
                print_message(
                    '\t/' + str(s) + " Data set:" +
                    str(Globals.dataset_names[s]), 3, 32)
                print "\tslope:", lt_params[s][0]
                print "\tintercept:", lt_params[s][1]
                print "\tr:", lt_params[s][2]
                print "\tp-value:", lt_params[s][3]
Exemplo n.º 2
0
def load_multiset_data():
    """
    """
    #multiset 
    Globals.n_sets = 0
    print_message("\nReading multiset data\n", index=4, color=34)
    #count data files passed as CLI arguments
    Globals.times, Globals.rvs, Globals.rv_errs = [],[],[]
    Globals.dataset_names, DATA = [], []
    Globals.mean_err = []
    
    try:
        from terminaltables import AsciiTable, DoubleTable, SingleTable
        ttable = True
    except:
        ttable = False
    
    s = 0
    for arg in sys.argv[1:]:
        if arg[0] != '-':
            #read data
            try:
                in_data = mgls_io.read_file(arg, ' ')
                if not ttable: print_message("\t" + str(s) + "/ Read data file " + arg, index=3, color=32)
            except IOError:
                print_message("\tData file could not be read", 5, 31)
                sys.exit()       
            
            #assign data vectors
            time, rv, rv_err = mgls_io.get_data_vectors(in_data, Globals.col)
            if Globals.km2m:
                rv *= 1000.0
                rv_err *= 1000.0
            Globals.dataset_names.append( str(s) + '/ ' + arg.split('/')[-1]) #file name. Not full path
            Globals.times.append(time)
            mean_rv = np.mean(rv)
            mean_rv_err = np.mean(rv_err)
            Globals.mean_err.append(mean_rv_err)
            Globals.rvs.append(rv)
            Globals.rv_errs.append(rv_err)
            inv_sigma2 = 1.0/(rv_err**2)
            logL_0 = -0.5*(np.sum(((rv-mean_rv)**2)*inv_sigma2 + np.log(2.0*np.pi) + np.log(1.0/inv_sigma2)) ) 
            Globals.n_sets += 1
            
            #print info
            summ = 0.0
            separation = []
            
            for i in range(len(time)-1):
                summ += time[i+1] - time[i]
                separation.append(time[i+1] - time[i])
            
            if ttable:
                DATA.append([len(time), time[-1] - time[0], summ/len(time), logL_0])
                
            else:
                if not Globals.inhibit_msg:
                    print "\t-----------------Summary of data--------------------"
                    print "\tData points:", len(time)
                    print "\tTime span:", time[-1] - time[0]
                    print "\tMean sep.", summ/len(time)
                    print "\tlogL null model (data, no jitter):", logL_0
                    print "\t----------------------------------------------------"
            #count dataset
            s += 1
       
    #print ttable (if appliable)
    if ttable:
        TABLE_DATA = []
        TABLE_DATA.append(['Data set name (full path not shown)', 'Data points', 'Timespan', 'Mean sep.', 'logL (data)'])
        for s in range(Globals.n_sets):
            TABLE_DATA.append([str(Globals.dataset_names[s]), str(DATA[s][0]), str(round(DATA[s][1],5)), str(round(DATA[s][2],5)), str(round(DATA[s][3],5))])
        
        TABLE_DATA = tuple(TABLE_DATA)
        table_instance = SingleTable(TABLE_DATA, "Dataset summary")
        table_instance.justify_column = 'right'
        print(table_instance.table)
    
    
    Globals.len_sets = [len(Globals.times[i]) for i in range(len(Globals.times))]
            
    Globals.times_seq, Globals.rvs_seq, Globals.rv_errs_seq = [], [], []
    for i in range(len(Globals.times)):
        Globals.times_seq.extend(Globals.times[i])
        Globals.rvs_seq.extend(Globals.rvs[i])
        Globals.rv_errs_seq.extend(Globals.rv_errs[i])

    Globals.times_seq = np.array(Globals.times_seq)
    Globals.rvs_seq = np.array(Globals.rvs_seq)
    Globals.rv_errs_seq = np.array(Globals.rv_errs_seq)