<commit_before>import matplotlib.pyplot as plt
# import matplotlib
import numpy as np
from scipy.stats import gaussian_kde
import sys
import re
# from lookup import Lookup
import george
from george import kernels

sys.path.append('/home/joao/Work/OPEN')
from OPEN.classes import params as params_paper
# from OPEN.classes import MyFormatter
colors = ["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71"]

sys.path.append('/home/joao/Work/corner/build/lib')
import corner
reload(corner)
import corner_analytic
reload(corner_analytic)

plt.rc("font", size=14, family="serif", serif="Computer Sans")
plt.rc("text", usetex=True)

def apply_argsort(arr1, arr2, axis=-1):
    """
    Apply arr1.argsort() on arr2, along `axis`.
    """
    # check matching shapes
    assert arr1.shape == arr2.shape, "Shapes don't match!"

    i = list(np.ogrid[[slice(x) for x in arr1.shape]])
    i[axis] = arr1.argsort(axis)
    return arr2[i]

def percentile68_ranges(a):
    lp, median, up = np.percentile(a, [16, 50, 84])
    return (median, up-median, median-lp)


def get_aliases(Preal):
    fs = np.array([0.0027381631, 1.0, 1.0027]) #, 0.018472000025212765])
    return np.array([abs(1 / (1./Preal + i*fs)) for i in range(-6, 6)]).T


class DisplayResults(object):
    def __init__(self, options, data_file=None, posterior_samples_file='posterior_sample.txt'):
        self.options = options

        if data_file is None:
            with open('src/main.cpp') as f:
                c = f.readlines()
            for line in c:
                if 'loadnew' in line and '/*' not in line: l = line
            data_file = re.findall('"(.*?)"', l, re.DOTALL)[0]

        print 'Loading data file %s' % data_file

        # self.data = np.loadtxt('1planet_plus_gp.rv')
        # self.data = np.loadtxt('HD41248_harps_mean_corr.rdb')
        # self.data = np.loadtxt('BT1.txt')
        self.data = np.loadtxt(data_file, skiprows=2)
        mean_vrad = self.data[:, 1].mean()
        self.data[:, 1] = (self.data[:, 1] - mean_vrad)*1e3 + mean_vrad
        self.data[:, 2] *= 1e3

        # self.truth = np.loadtxt('fake_data_like_nuoph.truth')
        # posterior_samples_file = 'resultsCorot7/upto10/posterior_sample.txt'
        self.posterior_sample = np.atleast_2d(np.loadtxt(posterior_samples_file))

        start_parameters = 0
        # (nsamples x 1000)
        self.signals = self.posterior_sample[:, :start_parameters]

        self.extra_sigma = self.posterior_sample[:, start_parameters]

        n_hyperparameters = 4
        for i in range(n_hyperparameters):
            name = 'eta' + str(i+1)
            setattr(self, name, self.posterior_sample[:, start_parameters+1+i])<commit_msg>better discover data_file<commit_after>import matplotlib.pyplot as plt
# import matplotlib
import numpy as np
from scipy.stats import gaussian_kde
import sys
import re
import os
import george
from george import kernels

sys.path.append('/home/joao/Work/OPEN')
from OPEN.classes import params as params_paper
# from OPEN.classes import MyFormatter
colors = ["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71"]

sys.path.append('/home/joao/Work/corner/build/lib')
import corner
reload(corner)
import corner_analytic
reload(corner_analytic)

plt.rc("font", size=14, family="serif", serif="Computer Sans")
plt.rc("text", usetex=True)

def apply_argsort(arr1, arr2, axis=-1):
    """
    Apply arr1.argsort() on arr2, along `axis`.
    """
    # check matching shapes
    assert arr1.shape == arr2.shape, "Shapes don't match!"

    i = list(np.ogrid[[slice(x) for x in arr1.shape]])
    i[axis] = arr1.argsort(axis)
    return arr2[i]

def percentile68_ranges(a):
    lp, median, up = np.percentile(a, [16, 50, 84])
    return (median, up-median, median-lp)


def get_aliases(Preal):
    fs = np.array([0.0027381631, 1.0, 1.0027]) #, 0.018472000025212765])
    return np.array([abs(1 / (1./Preal + i*fs)) for i in range(-6, 6)]).T


class DisplayResults(object):
    def __init__(self, options, data_file=None, posterior_samples_file='posterior_sample.txt'):
        self.options = options

        if data_file is None:
            path_to_this_file = os.path.abspath(__file__)
            top_level = os.path.dirname(os.path.dirname(path_to_this_file))
            print top_level
            with open(os.path.join(top_level, 'src', 'main.cpp')) as f:
                c = f.readlines()
            for line in c:
                if 'loadnew' in line and '/*' not in line: l = line
            data_file = re.findall('"(.*?)"', l, re.DOTALL)[0]

        print 'Loading data file %s' % data_file
        data_file = os.path.join(top_level, data_file)

        # self.data = np.loadtxt('1planet_plus_gp.rv')
        # self.data = np.loadtxt('HD41248_harps_mean_corr.rdb')
        # self.data = np.loadtxt('BT1.txt')
        self.data = np.loadtxt(data_file, skiprows=2)
        mean_vrad = self.data[:, 1].mean()
        self.data[:, 1] = (self.data[:, 1] - mean_vrad)*1e3 + mean_vrad
        self.data[:, 2] *= 1e3

        # self.truth = np.loadtxt('fake_data_like_nuoph.truth')
        # posterior_samples_file = 'resultsCorot7/upto10/posterior_sample.txt'
        self.posterior_sample = np.atleast_2d(np.loadtxt(posterior_samples_file))

        start_parameters = 0
        # (nsamples x 1000)
        self.signals = self.posterior_sample[:, :start_parameters]

        self.extra_sigma = self.posterior_sample[:, start_parameters]

        n_hyperparameters = 4
        for i in range(n_hyperparameters):
            name = 'eta' + str(i+1)
            setattr(self, name, self.posterior_sample[:, start_parameters+1+i])
{'fraction_non_alphanumeric': 0.13988993431563998, 'fraction_numerical': 0.04012071720220131, 'mean_word_length': 3.1154127100073046, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2803632', 'n_tokens_mistral': 2144, 'n_tokens_neox': 1962, 'n_words': 434}