<commit_before>import numpy as np

from hyperion.util.constants import pi
from hyperion.util.functions import FreezableClass
from hyperion.densities.bipolar_cavity import BipolarCavity


class PowerLawEnvelope(FreezableClass):

    def __init__(self, mass=None, rmin=None, rmax=None, power=None):
        '''
        Initialize a power-law envelope instance. The required parameters are:

            mass: envelope mass (g)
            rmin: inner radius (cm)
            rmin: output radius (cm)
            power: power-law exponent

        '''

        # Basic envelope parameters
        self.mass = mass
        self.rmin = rmin
        self.rmax = rmax
        self.power = power

        # Cavity
        self.cavity = None

        # Dust
        self.dust = None

        self._freeze()

    def check_all_set(self):

        if self.mass is None:
            raise Exception("mass is not set")
        if self.rmin is None:
            raise Exception("rmin is not set")
        if self.rmax is None:
            raise Exception("rmax is not set")
        if self.power is None:
            raise Exception("power is not set")

    def exists(self):
        return self.mass > 0.

    def density(self, grid):
        '''
        Find the density of a power-law envelope

        Input is the position of the center of the grid cells in spherical
        polar coordinates (r, theta, phi), the volume of the grid cells, and a
        parameter dictionary
        '''

        self.check_all_set()

        alpha = 3. + self.power

        rho_0 = self.mass * alpha / \
            (4. * pi * (self.rmax ** alpha - self.rmin ** alpha))<commit_msg>Check that rmin and rmax are set correctly in power-law envelope<commit_after>import numpy as np

from hyperion.util.constants import pi
from hyperion.util.functions import FreezableClass
from hyperion.densities.bipolar_cavity import BipolarCavity


class PowerLawEnvelope(FreezableClass):

    def __init__(self, mass=None, rmin=None, rmax=None, power=None):
        '''
        Initialize a power-law envelope instance. The required parameters are:

            mass: envelope mass (g)
            rmin: inner radius (cm)
            rmin: output radius (cm)
            power: power-law exponent

        '''

        # Basic envelope parameters
        self.mass = mass
        self.rmin = rmin
        self.rmax = rmax
        self.power = power

        # Cavity
        self.cavity = None

        # Dust
        self.dust = None

        self._freeze()

    def check_all_set(self):

        if self.mass is None:
            raise Exception("mass is not set")
        if self.rmin is None:
            raise Exception("rmin is not set")
        if self.rmax is None:
            raise Exception("rmax is not set")
        if self.power is None:
            raise Exception("power is not set")
            
        if isinstance(self.rmin, OptThinRadius):
            raise Exception("Inner envelope radius needs to be computed first")
        if isinstance(self.rmax, OptThinRadius):
            raise Exception("Outer envelope radius needs to be computed first")

    def exists(self):
        return self.mass > 0.

    def density(self, grid):
        '''
        Find the density of a power-law envelope

        Input is the position of the center of the grid cells in spherical
        polar coordinates (r, theta, phi), the volume of the grid cells, and a
        parameter dictionary
        '''

        self.check_all_set()

        alpha = 3. + self.power

        rho_0 = self.mass * alpha / \
            (4. * pi * (self.rmax ** alpha - self.rmin ** alpha))
{'fraction_non_alphanumeric': 0.08053875755909841, 'fraction_numerical': 0.0021990104452996153, 'mean_word_length': 1.9323126510878323, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '238033', 'n_tokens_mistral': 1028, 'n_tokens_neox': 979, 'n_words': 353}