Ejemplo n.º 1
0
    def _mean_galprop_fraction(self, **kwargs):
        """
        Expectation value of the galprop for galaxies living in the input halos.  

        Parameters 
        ----------
        prim_haloprop : array, optional keyword argument 
            Array of mass-like variable upon which occupation statistics are based. 
            If ``prim_haloprop`` is not passed, then ``halo_table`` keyword argument must be passed. 

        halo_table : object, optional keyword argument 
            Data table storing halo catalog. 
            If ``halo_table`` is not passed, then ``prim_haloprop`` keyword argument must be passed. 

        Returns 
        -------
        mean_galprop_fraction : array_like
            Values of the galprop fraction evaluated at the input primary halo properties. 

        """
        # Retrieve the array storing the mass-like variable
        if 'halo_table' in kwargs.keys():
            prim_haloprop = kwargs['halo_table'][self.prim_haloprop_key]
        elif 'prim_haloprop' in kwargs.keys():
            prim_haloprop = kwargs['prim_haloprop']
        else:
            raise KeyError("Must pass one of the following keyword arguments to mean_occupation:\n"
                "``halo_table`` or  ``prim_haloprop``")

        if self._logparam is True:
            prim_haloprop = np.log10(prim_haloprop)

        # Update self._abcissa, in case the user has changed it
        self._abcissa = getattr(self, self.galprop_key+'_abcissa')

        model_ordinates = [self.param_dict[ordinate_key] for ordinate_key in self._ordinates_keys]
        if self._interpol_method=='polynomial':
            mean_galprop_fraction = model_helpers.polynomial_from_table(
                self._abcissa, model_ordinates, prim_haloprop)
        elif self._interpol_method=='spline':
            spline_function = model_helpers.custom_spline(
                self._abcissa, model_ordinates,
                    k=self._spline_degree)
            mean_galprop_fraction = spline_function(prim_haloprop)
        else:
            raise IOError("Input interpol_method must be 'polynomial' or 'spline'.")

        # Enforce boundary conditions 
        mean_galprop_fraction[mean_galprop_fraction<0]=0
        mean_galprop_fraction[mean_galprop_fraction>1]=1

        return mean_galprop_fraction
        def _setup_spline(self):
        # If using spline interpolation, configure its settings 
        
            scipy_maxdegree = 5
            self.spline_degree ={}
            self.spline_function = {}

            for prof_param_key in self.abcissa_dict.keys():
                self.spline_degree[prof_param_key] = (
                    np.min(
                [scipy_maxdegree, self.input_spline_degree, 
                custom_len(self.abcissa_dict[prof_param_key])-1])
                    )
                self.spline_function[prof_param_key] = model_helpers.custom_spline(
                    self.abcissa_dict[prof_param_key], 
                    self.ordinates_dict[prof_param_key], 
                    k=self.spline_degree[prof_param_key])
Ejemplo n.º 3
0
        def _setup_spline(self):
            # If using spline interpolation, configure its settings

            scipy_maxdegree = 5
            self.spline_degree = {}
            self.spline_function = {}

            for prof_param_key in self.abcissa_dict.keys():
                self.spline_degree[prof_param_key] = (np.min([
                    scipy_maxdegree, self.input_spline_degree,
                    custom_len(self.abcissa_dict[prof_param_key]) - 1
                ]))
                self.spline_function[
                    prof_param_key] = model_helpers.custom_spline(
                        self.abcissa_dict[prof_param_key],
                        self.ordinates_dict[prof_param_key],
                        k=self.spline_degree[prof_param_key])
Ejemplo n.º 4
0
    def _mean_galprop_fraction(self, **kwargs):
        """
        Expectation value of the galprop for galaxies living in the input halos.  

        Parameters 
        ----------
        prim_haloprop : array_like, optional keyword argument
            Array of primary halo property, e.g., `mvir`, 
            at which the galprop fraction is being computed. 
            Functionality is equivalent to using the prim_haloprop keyword argument. 

        halos : table, optional keyword argument
            Astropy Table containing a halo catalog. 
            If the ``halos`` keyword argument is passed, 
            ``self.prim_haloprop_key`` must be a column of the halo catalog. 

        galaxy_table : table, optional keyword argument
            Astropy Table containing a galaxy catalog. 
            If the ``galaxy_table`` keyword argument is passed, 
            ``self.prim_haloprop_key`` must be a column of the galaxy catalog. 

        input_param_dict : dict, optional keyword argument 
            If passed, the model will first update 
            its param_dict with input_param_dict, altering the behavior of the model. 

        Returns 
        -------
        mean_galprop_fraction : array_like
            Values of the galprop fraction evaluated at the input primary halo properties. 

        """
        model_helpers.update_param_dict(self, **kwargs)

        # Retrieve the array storing the mass-like variable
        if 'galaxy_table' in kwargs.keys():
            key = model_defaults.host_haloprop_prefix+self.prim_haloprop_key
            prim_haloprop = kwargs['galaxy_table'][key]
        elif 'halos' in kwargs.keys():
            prim_haloprop = kwargs['halos'][self.prim_haloprop_key]
        elif 'prim_haloprop' in kwargs.keys():
            prim_haloprop = kwargs['prim_haloprop']
        else:
            raise KeyError("Must pass one of the following keyword arguments to mean_occupation:\n"
                "``halos``, ``prim_haloprop``, or ``galaxy_table``")

        if self._logparam is True:
            prim_haloprop = np.log10(prim_haloprop)

        # Update self._abcissa, in case the user has changed it
        self._abcissa = getattr(self, self.galprop_key+'_abcissa')

        model_ordinates = [self.param_dict[ordinate_key] for ordinate_key in self._ordinates_keys]
        if self._interpol_method=='polynomial':
            mean_galprop_fraction = model_helpers.polynomial_from_table(
                self._abcissa, model_ordinates, prim_haloprop)
        elif self._interpol_method=='spline':
            spline_function = model_helpers.custom_spline(
                self._abcissa, model_ordinates,
                    k=self._spline_degree)
            mean_galprop_fraction = spline_function(prim_haloprop)
        else:
            raise IOError("Input interpol_method must be 'polynomial' or 'spline'.")

        # Enforce boundary conditions 
        mean_galprop_fraction[mean_galprop_fraction<0]=0
        mean_galprop_fraction[mean_galprop_fraction>1]=1

        return mean_galprop_fraction
Ejemplo n.º 5
0
    def _mean_galprop_fraction(self, **kwargs):
        """
        Expectation value of the galprop for galaxies living in the input halos.  

        Parameters 
        ----------
        prim_haloprop : array_like, optional keyword argument
            Array of primary halo property, e.g., `mvir`, 
            at which the galprop fraction is being computed. 
            Functionality is equivalent to using the prim_haloprop keyword argument. 

        halos : table, optional keyword argument
            Astropy Table containing a halo catalog. 
            If the ``halos`` keyword argument is passed, 
            ``self.prim_haloprop_key`` must be a column of the halo catalog. 

        galaxy_table : table, optional keyword argument
            Astropy Table containing a galaxy catalog. 
            If the ``galaxy_table`` keyword argument is passed, 
            ``self.prim_haloprop_key`` must be a column of the galaxy catalog. 

        input_param_dict : dict, optional keyword argument 
            If passed, the model will first update 
            its param_dict with input_param_dict, altering the behavior of the model. 

        Returns 
        -------
        mean_galprop_fraction : array_like
            Values of the galprop fraction evaluated at the input primary halo properties. 

        """
        model_helpers.update_param_dict(self, **kwargs)

        # Retrieve the array storing the mass-like variable
        if 'galaxy_table' in kwargs.keys():
            key = model_defaults.host_haloprop_prefix + self.prim_haloprop_key
            prim_haloprop = kwargs['galaxy_table'][key]
        elif 'halos' in kwargs.keys():
            prim_haloprop = kwargs['halos'][self.prim_haloprop_key]
        elif 'prim_haloprop' in kwargs.keys():
            prim_haloprop = kwargs['prim_haloprop']
        else:
            raise KeyError(
                "Must pass one of the following keyword arguments to mean_occupation:\n"
                "``halos``, ``prim_haloprop``, or ``galaxy_table``")

        if self._logparam is True:
            prim_haloprop = np.log10(prim_haloprop)

        # Update self._abcissa, in case the user has changed it
        self._abcissa = getattr(self, self.galprop_key + '_abcissa')

        model_ordinates = [
            self.param_dict[ordinate_key]
            for ordinate_key in self._ordinates_keys
        ]
        if self._interpol_method == 'polynomial':
            mean_galprop_fraction = model_helpers.polynomial_from_table(
                self._abcissa, model_ordinates, prim_haloprop)
        elif self._interpol_method == 'spline':
            spline_function = model_helpers.custom_spline(
                self._abcissa, model_ordinates, k=self._spline_degree)
            mean_galprop_fraction = spline_function(prim_haloprop)
        else:
            raise IOError(
                "Input interpol_method must be 'polynomial' or 'spline'.")

        # Enforce boundary conditions
        mean_galprop_fraction[mean_galprop_fraction < 0] = 0
        mean_galprop_fraction[mean_galprop_fraction > 1] = 1

        return mean_galprop_fraction