<commit_before>import re

import numpy as np
import pandas as pd

from . import StarModel, get_ichrone
from .priors import PowerLawPrior, FlatLogPrior, FehPrior, FlatPrior, GaussianPrior
from .utils import addmags
from .cluster_utils import calc_lnlike_grid, integrate_over_eeps

class StarCatalog(object):
    """
    """
    def __init__(self, df, bands=None, props=None):
        self.df = df

        self.bands = tuple() if bands is None else tuple(bands)
        self.props = tuple() if props is None else tuple(props)

        for c in self.bands + self.props:
            if not c in self.df.columns:
                raise ValueError('{} not in DataFrame!'.format(c))
            if not '{}_unc'.format(c) in self.df.columns:
                raise ValueError('{0} uncertainty ({0}_unc) not in DataFrame!'.format(c))

    def get_measurement(self, prop, values=False):
        return self.df[prop].values, self.df[prop + '_unc'].values

    def iter_bands(self, **kwargs):
        for b in self.bands:
            yield b, self.get_measurement(b, **kwargs)

    def iter_props(self, **kwargs):
        for p in self.props:
            yield p, self.get_measurement(p, **kwargs)


class StarClusterModel(StarModel):

    param_names = ['age', 'feh', 'distance', 'AV', 'alpha', 'gamma', 'fB']

    def __init__(self, ic, stars, name='',
                 halo_fraction=0.001, max_AV=1., max_distance=50000,
                 use_emcee=False, eep_bounds=None,
                 mass_bounds=None, qlo=0.1, **kwargs):
        self._ic = ic

        if not isinstance(stars, StarCatalog):
            stars = StarCatalog(stars, **kwargs)

        self.stars = stars

        self._priors = {'age': FlatLogPrior(bounds=(6, 10.15)),
                       'feh': FehPrior(halo_fraction=halo_fraction),
                       'AV' : FlatPrior(bounds=(0, max_AV)),
                       'distance' : PowerLawPrior(alpha=2., bounds=(0, max_distance)),
                       'alpha' : FlatPrior(bounds=(-4, -1)),
                       'gamma' : GaussianPrior(0.3, 0.1),
                       'fB' : FlatPrior(0., 0.6)}

        self.use_emcee = use_emcee

        self._eep_bounds = eep_bounds
        self._mass_bounds = mass_bounds
        self.qlo = qlo

        self.name = name

        self._samples = None
        self._directory = '.'

    @property
    def bands(self):
        return self.stars.bands

    @property
    def props(self):
        return self.stars.props<commit_msg>correct flat prior<commit_after>import re

import numpy as np
import pandas as pd

from . import StarModel, get_ichrone
from .priors import PowerLawPrior, FlatLogPrior, FehPrior, FlatPrior, GaussianPrior
from .utils import addmags
from .cluster_utils import calc_lnlike_grid, integrate_over_eeps

class StarCatalog(object):
    """
    """
    def __init__(self, df, bands=None, props=None):
        self.df = df

        self.bands = tuple() if bands is None else tuple(bands)
        self.props = tuple() if props is None else tuple(props)

        for c in self.bands + self.props:
            if not c in self.df.columns:
                raise ValueError('{} not in DataFrame!'.format(c))
            if not '{}_unc'.format(c) in self.df.columns:
                raise ValueError('{0} uncertainty ({0}_unc) not in DataFrame!'.format(c))

    def get_measurement(self, prop, values=False):
        return self.df[prop].values, self.df[prop + '_unc'].values

    def iter_bands(self, **kwargs):
        for b in self.bands:
            yield b, self.get_measurement(b, **kwargs)

    def iter_props(self, **kwargs):
        for p in self.props:
            yield p, self.get_measurement(p, **kwargs)


class StarClusterModel(StarModel):

    param_names = ['age', 'feh', 'distance', 'AV', 'alpha', 'gamma', 'fB']

    def __init__(self, ic, stars, name='',
                 halo_fraction=0.001, max_AV=1., max_distance=50000,
                 use_emcee=False, eep_bounds=None,
                 mass_bounds=None, qlo=0.1, **kwargs):
        self._ic = ic

        if not isinstance(stars, StarCatalog):
            stars = StarCatalog(stars, **kwargs)

        self.stars = stars

        self._priors = {'age': FlatLogPrior(bounds=(6, 10.15)),
                       'feh': FehPrior(halo_fraction=halo_fraction),
                       'AV' : FlatPrior(bounds=(0, max_AV)),
                       'distance' : PowerLawPrior(alpha=2., bounds=(0, max_distance)),
                       'alpha' : FlatPrior(bounds=(-4, -1)),
                       'gamma' : GaussianPrior(0.3, 0.1),
                       'fB' : FlatPrior(bounds=(0., 0.6))}

        self.use_emcee = use_emcee

        self._eep_bounds = eep_bounds
        self._mass_bounds = mass_bounds
        self.qlo = qlo

        self.name = name

        self._samples = None
        self._directory = '.'

    @property
    def bands(self):
        return self.stars.bands

    @property
    def props(self):
        return self.stars.props
{'fraction_non_alphanumeric': 0.12294424388287205, 'fraction_numerical': 0.012434817488969114, 'mean_word_length': 2.2029543994861913, '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': '6052756', 'n_tokens_mistral': 1622, 'n_tokens_neox': 1501, 'n_words': 385}