<commit_before>from __future__ import print_function, division

import numpy as np
import pandas as pd
from scipy.optimize import minimize
import os, os.path

from astropy import constants as const
G = const.G.cgs.value
M_sun = const.M_sun.cgs.value
R_sun = const.R_sun.cgs.value
DAY = 86400


import emcee

try:
    import triangle
except ImportError:
    triangle=None

from transit.transit import InvalidParameterError
    
from .utils import lc_eval

class TransitModel(object):
    def __init__(self, lc, width=2, continuum_method='constant',
                 rhostar=None, dilution=None):
        self.lc = lc
        self.width = width
        self.continuum_method = continuum_method

        self.rhostar = rhostar
        self.dilution = dilution

        self._bestfit = None
        self._samples = None


    def continuum(self, p, t):
        """ Out-of-transit 'continuum' model.

        :param p:
            List of parameters.  For now all that is implemented
            is a constant.

        param t:
            Times at which to evaluate model.
        
        """
        p = np.atleast_1d(p)
        
        return p[0]*np.ones_like(t)
        
    def evaluate(self, p):
        """Evaluates light curve model at light curve times<commit_msg>added prior properties for rhostar, dilution<commit_after>from __future__ import print_function, division

import numpy as np
import pandas as pd
from scipy.optimize import minimize
import os, os.path

from scipy.stats import norm
from scipy.stats import gaussian_kde

from astropy import constants as const
G = const.G.cgs.value
M_sun = const.M_sun.cgs.value
R_sun = const.R_sun.cgs.value
DAY = 86400


import emcee

try:
    import triangle
except ImportError:
    triangle=None

from transit.transit import InvalidParameterError
    
from .utils import lc_eval

class TransitModel(object):
    """Model of one or more transiting planets around a particular star
    
    :param lc:
        LightCurve object

    :param width:
        The number of durations around a transit calculated to evaluate
        model.  Model is evaluated between ``tc - width*duration`` and
        ``tc + width*duration``, where ``tc`` is the transit center time.

    :param rhostar:
        Stellar density.  May be passed as a two-element tuple/list, 
        in which case it will be interpreted as a normal distribution
        with (mu, sigma); or it may be passed as an array, in which
        case it will be interpreted as posterior samples.

    :param dilution:
        The fraction of light in the photometric aperture that does 
        not come from the star being transited.  Will be interpreted
        the same way as ``rhostar``, either as a normal distribution
        or as posterior samples.

    """
    def __init__(self, lc, width=2, continuum_method='constant',
                 rhostar=None, dilution=None):
        self.lc = lc
        self.width = width
        self.continuum_method = continuum_method

        self.rhostar = rhostar
        self._rhostar_priorfn = None

        self.dilution = dilution
        self._dilution_proirfn = None

        self._bestfit = None
        self._samples = None


    def continuum(self, p, t):
        """ Out-of-transit 'continuum' model.

        :param p:
            List of parameters.  For now all that is implemented
            is a constant.

        param t:
            Times at which to evaluate model.
        
        """
        p = np.atleast_1d(p)
        
        return p[0]*np.ones_like(t)
        

    def _property_priorfn(self, prop):
        p = getattr(self,prop)
        if len(p)==2:
            dist = norm(*p)
            return dist.pdf
        else:
            return gaussian_kde(p)

    @property
    def rhostar_prior(self):
        if self._rhostar_priorfn is None:
            self._rhostar_priorfn = self._property_priorfn('rhostar')

        return self._rhostar_priorfn
            
    @property
    def dilution_prior(self):
        if self._dilution_priorfn is None:
            self._dilution_priorfn = self._dilution_priorfn('dilution')

        return self._dilution_priorfn
            

    def evaluate(self, p):
        """Evaluates light curve model at light curve times
{'fraction_non_alphanumeric': 0.06969625618083353, 'fraction_numerical': 0.004002825523899223, 'mean_word_length': 2.2551724137931033, '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': '1265340', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1204, 'n_words': 409}