<commit_before>"""
Classes and functions for priors.
"""

from astropy.io import fits
import os
import numpy as np

class Priors():
    """Class to store all different redshift priors.

    Args:
        filename (str): the path to the redshift prior file

    """
    def __init__(self, filename):

        print('DEBUG: Using priors')
        print('DEBUG: read {}'.format(filename))

        h = fits.open(os.path.expandvars(filename), memmap=False)

        targetid = h['PRIORS'].data['TARGETID']
        z = h['PRIORS'].data['Z']
        sigma = h['PRIORS'].data['SIGMA']
        self._param = { targetid[i]:{'Z':z[i], 'SIGMA':sigma[i]} for i in range(z.size) }

        h.close()

        self._type = 'gaussian'
        self._func = getattr(self,self._type)

        return
    def eval(self, targetid, z):
        try:
            z0 = self._param[targetid]['Z']
            s0 = self._param[targetid]['SIGMA']
            return self._func(z,z0,s0)
        except KeyError:
            print('DEBUG: targetid {} not in priors'.format(targetid))
            return 0.

    def gaussian(self,z,z0,s0):
        return ((z-z0)/s0)**2
    def lorentzien(self,z,z0,s0):
        return -np.log(1.+((z-z0)/s0)**2)<commit_msg>Codacy recomendations<commit_after>"""
Classes and functions for priors.
"""

from astropy.io import fits
import os
import numpy as np

class Priors():
    """Class to store all different redshift priors.

    Args:
        filename (str): the path to the redshift prior file

    """
    def __init__(self, filename):

        print('DEBUG: Using priors')
        print('DEBUG: read {}'.format(filename))

        h = fits.open(os.path.expandvars(filename), memmap=False)

        targetid = h['PRIORS'].data['TARGETID']
        z = h['PRIORS'].data['Z']
        sigma = h['PRIORS'].data['SIGMA']
        self._param = { targetid[i]:{'Z':z[i], 'SIGMA':sigma[i]} for i in range(z.size) }

        h.close()

        self._type = 'gaussian'
        self._func = getattr(self,self._type)

        return
    def eval(self, targetid, z):
        try:
            z0 = self._param[targetid]['Z']
            s0 = self._param[targetid]['SIGMA']
            return self._func(z,z0,s0)
        except KeyError:
            print('DEBUG: targetid {} not in priors'.format(targetid))
            return 0.

    @staticmethod
    def gaussian(z,z0,s0):
        return ((z-z0)/s0)**2
    @staticmethod
    def lorentzien(z,z0,s0):
        return -np.log(1.+((z-z0)/s0)**2)
{'fraction_non_alphanumeric': 0.15514469453376206, 'fraction_numerical': 0.012861736334405145, 'mean_word_length': 2.3817934782608696, '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': '7109273', 'n_tokens_mistral': 841, 'n_tokens_neox': 814, 'n_words': 190}