<commit_before>__author__ = 'nmearl'

from pynamic import photometry, optimizers
import numpy as np


class Optimizer(object):
    def __init__(self, params, photo_data_file='', rv_data_file='', rv_body=0,
                 chain_file=''):
        self.params = params
        self.photo_data = np.loadtxt(photo_data_file,
                                     unpack=True, usecols=(0, 1, 2))
        self.rv_data = np.zeros((3, 0))

        if rv_data_file:
            self.rv_data = np.loadtxt(rv_data_file,
                                      unpack=True, usecols=(0, 1, 2))

        self.rv_body = rv_body
        self.chain = np.zeros([1, 1 + len(self.params.get_all(True))])
        self.maxlnp = -np.inf

        if chain_file:
            self.chain = np.load(chain_file)

    def run(self, method=None, **kwargs):
        if method == 'mcmc':
            optimizers.hammer(self, **kwargs)
        elif method == 'multinest':
            optimizers.multinest(self, **kwargs)
        else:
            optimizers.minimizer(self, method=method, **kwargs)

    def save(self, chain_out_file="chain.txt", photo_out_file="photo_model.txt",
             rv_out_file="rv_model.txt"):
        if False:
            mod_flux, mod_rv = self.model()
            mod_rv = self.filled_rv_model()
            np.savetxt(photo_out_file, mod_flux)
            np.savetxt(rv_out_file, mod_rv)
            np.savetxt(chain_out_file, self.chain)

        np.save("chain", self.chain)

    def model(self, nprocs=1):
        flux_x, rv_x = self.photo_data[0], self.rv_data[0]
        x = np.append(flux_x, rv_x)
        x = np.unique(x[np.argsort(x)])

        flux_inds = np.in1d(x, flux_x, assume_unique=True)
        rv_inds = np.in1d(x, rv_x, assume_unique=True)

        mod_flux, mod_rv = photometry.generate(self.params, x,
                                               self.rv_body, nprocs)<commit_msg>Weird issue with unique time values in model fixed?<commit_after>__author__ = 'nmearl'

from pynamic import photometry, optimizers
import numpy as np


class Optimizer(object):
    def __init__(self, params, photo_data_file='', rv_data_file='', rv_body=0,
                 chain_file=''):
        self.params = params
        self.photo_data = np.loadtxt(photo_data_file,
                                     unpack=True, usecols=(0, 1, 2))
        self.rv_data = np.zeros((3, 0))

        if rv_data_file:
            self.rv_data = np.loadtxt(rv_data_file,
                                      unpack=True, usecols=(0, 1, 2))

        self.rv_body = rv_body
        self.chain = np.zeros([1, 1 + len(self.params.get_all(True))])
        self.maxlnp = -np.inf

        if chain_file:
            self.chain = np.load(chain_file)

    def run(self, method=None, **kwargs):
        if method == 'mcmc':
            optimizers.hammer(self, **kwargs)
        elif method == 'multinest':
            optimizers.multinest(self, **kwargs)
        else:
            optimizers.minimizer(self, method=method, **kwargs)

    def save(self, chain_out_file="chain.txt", photo_out_file="photo_model.txt",
             rv_out_file="rv_model.txt"):
        if False:
            mod_flux, mod_rv = self.model()
            mod_rv = self.filled_rv_model()
            np.savetxt(photo_out_file, mod_flux)
            np.savetxt(rv_out_file, mod_rv)
            np.savetxt(chain_out_file, self.chain)

        np.save("chain", self.chain)

    def model(self, nprocs=1):
        flux_x, rv_x = self.photo_data[0], self.rv_data[0]
        x = np.append(flux_x, rv_x)

        flux_inds = np.in1d(x, flux_x, assume_unique=False)
        rv_inds = np.in1d(x, rv_x, assume_unique=True)

        mod_flux, mod_rv = photometry.generate(self.params, x,
                                               self.rv_body, nprocs)
{'fraction_non_alphanumeric': 0.11950513292971834, 'fraction_numerical': 0.008423269281389839, 'mean_word_length': 2.04, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '312240', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1261, 'n_words': 235}