<commit_before>"""Definitions for the `Redshift` class."""
import numpy as np
from astropy import units as un
from astropy.cosmology import Planck15 as cosmo
from astropy.cosmology import z_at_value

from mosfit.modules.parameters.parameter import Parameter


# Important: Only define one ``Module`` class per file.


class Redshift(Parameter):
    """Redshift parameter that depends on luminosity distance."""

    def __init__(self, **kwargs):
        """Initialize module."""
        super(Redshift, self).__init__(**kwargs)

        self._warned_small = False

    def process(self, **kwargs):
        """Process module."""
        if (self._name in kwargs or self._min_value is None or
                self._max_value is None):
            # If this parameter is not free and is already set, then skip
            if self._name in kwargs:
                return {}

            self._lum_dist = kwargs.get(self.key('lumdist'), None)
            if not self._value and self._lum_dist:
                if self._lum_dist < 1.0:
                    if not self._warned_small:
                        self._printer.message(
                            'small_lumdist', [
                                str(np.around(
                                    self._lum_dist * 1.0e6, decimals=2))],
                            warning=True)
                    self._warned_small = True
                    value = 0.0
                else:
                    value = z_at_value(cosmo.luminosity_distance,
                                       self._lum_dist * un.Mpc)
            elif self._value:
                value = self._value
            else:
                raise ValueError('Redshift has no value!')
        else:
            value = self.value(kwargs['fraction'])

        return {self._name: value}<commit_msg>BUG: should compare redshift value to `None`<commit_after>"""Definitions for the `Redshift` class."""
import numpy as np
from astropy import units as un
from astropy.cosmology import Planck15 as cosmo
from astropy.cosmology import z_at_value

from mosfit.modules.parameters.parameter import Parameter


# Important: Only define one ``Module`` class per file.


class Redshift(Parameter):
    """Redshift parameter that depends on luminosity distance."""

    def __init__(self, **kwargs):
        """Initialize module."""
        super(Redshift, self).__init__(**kwargs)

        self._warned_small = False

    def process(self, **kwargs):
        """Process module."""
        if (self._name in kwargs or self._min_value is None or
                self._max_value is None):
            # If this parameter is not free and is already set, then skip
            if self._name in kwargs:
                return {}

            self._lum_dist = kwargs.get(self.key('lumdist'), None)
            if self._value is None and self._lum_dist:
                if self._lum_dist < 1.0:
                    if not self._warned_small:
                        self._printer.message(
                            'small_lumdist', [
                                str(np.around(
                                    self._lum_dist * 1.0e6, decimals=2))],
                            warning=True)
                    self._warned_small = True
                    value = 0.0
                else:
                    value = z_at_value(cosmo.luminosity_distance,
                                       self._lum_dist * un.Mpc)
            else:
                value = self._value
        else:
            value = self.value(kwargs['fraction'])

        return {self._name: value}
{'fraction_non_alphanumeric': 0.08756274400446179, 'fraction_numerical': 0.005577244841048522, 'mean_word_length': 1.5731707317073171, 'pattern_counts': {'":': 0, '<': 5, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4136403', 'n_tokens_mistral': 964, 'n_tokens_neox': 905, 'n_words': 269}