<commit_before>"""Galaxy Cluster Ensemble Calculations.

Cluster mass-richness and mass-concentration scaling relations, and NFW
halo profiles for weak lensing shear and magnification, including the
effects of cluster miscentering offsets.

This framework calculates properties and profiles for every individual
cluster, storing the data in tabular form. This is useful for fitting
measured stacked weak lensing profiles, e.g. when you want to account for
the full redshift, mass, and/or centroid offset distributions, and avoid
fitting a single average mass at a single effective redshift.
"""

from __future__ import absolute_import, division, print_function

import numpy as np
import pandas as pd
from astropy import units
import os

from clusterlensing.nfw import SurfaceMassDensity
from clusterlensing import cofm
from clusterlensing import utils

try:
    from IPython.display import display
    notebook_display = True
except:
    notebook_display = False


class ClusterEnsemble(object):
    """Ensemble of galaxy clusters and their properties.

    The ClusterEnsemble object contains parameters and calculated
    values for every individual cluster in a sample. Initializing with
    a collection of redshifts z will fix the number of clusters
    described by the object. Setting the n200 values will then populate
    the object with the full set of available attributes (except for
    the NFW profiles). The values of z, n200, massrich_norm, and
    massrich_slope can be altered and these changes will propogate to
    the other (dependent) attributes.

    In order to generate the attributes containing the NFW halo
    profiles, sigma_nfw and deltasigma_nfw, pass the desired radial
    bins (and additional optional parameters) to the calc_nfw method.

    Parameters
    ----------
    z : array_like
        Redshifts for each cluster in the sample. Should be 1D.

    Attributes
    ----------
    z
    n200
    m200
    c200
    delta_c
    r200
    rs
    Dang_l
    dataframe
    massrich_norm
    massrich_slope
    describe : str
        Short description of the ClusterEnsemble object.
    number : int
        Number of clusters in the sample.
    sigma_nfw : Quantity
        Surface mass density of every cluster, (1D ndarray) with
        astropy.units of Msun/pc/pc. Generated for each element of rbins
        by running calc_nfw(rbins) method.
    deltasigma_nfw : Quantity
        Differential surface mass density of every cluster, (1D ndarray)
        with astropy.units of Msun/pc/pc. Generated for each element of
        rbins by running calc_nfw(rbins) method.

    Methods
    ----------
    calc_nfw(rbins, offsets=None, use_c=True, epsabs=0.1, epsrel=0.1)
        Generate Sigma and DeltaSigma NFW profiles for each cluster,
        optionally with miscentering offsets included.
    show(notebook=True)
        Display table of cluster information and mass-richness
        scaling relaton in use.
    massrich_parameters()
        Print a string showing the mass-richness scaling relation and
        current values of the normalization and slope.

    Other Parameters
    ----------------
    cosmology : str, optional
        Cosmology to use in calculations, default 'Planck13'. Other choices
        are 'WMAP9', 'WMAP7', and 'WMAP5'.
    cm : str, optional
        Concentration-mass relation to use, default 'DuttonMaccio'. Other
        choices are 'Prada' and 'Duffy'.
    """
    def __init__(self, redshifts, cosmology='Planck13', cm='DuttonMaccio'):
        if type(redshifts) != np.ndarray:
            redshifts = np.array(redshifts)
        if redshifts.ndim != 1:
            raise ValueError("Input redshift array must have 1 dimension.")<commit_msg>fix Docstring<commit_after>"""Galaxy Cluster Ensemble Calculations.

Cluster mass-richness and mass-concentration scaling relations, and NFW
halo profiles for weak lensing shear and magnification, including the
effects of cluster miscentering offsets.

This framework calculates properties and profiles for every individual
cluster, storing the data in tabular form. This is useful for fitting
measured stacked weak lensing profiles, e.g. when you want to account for
the full redshift, mass, and/or centroid offset distributions, and avoid
fitting a single average mass at a single effective redshift.
"""

from __future__ import absolute_import, division, print_function

import numpy as np
import pandas as pd
from astropy import units
import os

from clusterlensing.nfw import SurfaceMassDensity
from clusterlensing import cofm
from clusterlensing import utils

try:
    from IPython.display import display
    notebook_display = True
except:
    notebook_display = False


class ClusterEnsemble(object):
    """Ensemble of galaxy clusters and their properties.

    The ClusterEnsemble object contains parameters and calculated
    values for every individual cluster in a sample. Initializing with
    a collection of redshifts z will fix the number of clusters
    described by the object. Setting the n200 values will then populate
    the object with the full set of available attributes (except for
    the NFW profiles). The values of z, n200, massrich_norm, and
    massrich_slope can be altered and these changes will propogate to
    the other (dependent) attributes.

    In order to generate the attributes containing the NFW halo
    profiles, sigma_nfw and deltasigma_nfw, pass the desired radial
    bins (and additional optional parameters) to the calc_nfw method.

    Parameters
    ----------
    z : array_like
        Redshifts for each cluster in the sample. Should be 1D.

    Attributes
    ----------
    z
    n200
    m200
    c200
    delta_c
    r200
    rs
    Dang_l
    dataframe
    massrich_norm
    massrich_slope
    describe : str
        Short description of the ClusterEnsemble object.
    number : int
        Number of clusters in the sample.
    sigma_nfw : Quantity
        Surface mass density of every cluster, (1D ndarray) with
        astropy.units of Msun/pc/pc. Generated for each element of rbins
        by running calc_nfw(rbins) method.
    deltasigma_nfw : Quantity
        Differential surface mass density of every cluster, (1D ndarray)
        with astropy.units of Msun/pc/pc. Generated for each element of
        rbins by running calc_nfw(rbins) method.

    Methods
    ----------
    calc_nfw(rbins, offsets=None, use_c=True)
        Generate Sigma and DeltaSigma NFW profiles for each cluster,
        optionally with miscentering offsets included.
    show(notebook=True)
        Display table of cluster information and mass-richness
        scaling relaton in use.
    massrich_parameters()
        Print a string showing the mass-richness scaling relation and
        current values of the normalization and slope.

    Other Parameters
    ----------------
    cosmology : str, optional
        Cosmology to use in calculations, default 'Planck13'. Other choices
        are 'WMAP9', 'WMAP7', and 'WMAP5'.
    cm : str, optional
        Concentration-mass relation to use, default 'DuttonMaccio'. Other
        choices are 'Prada' and 'Duffy'.
    """
    def __init__(self, redshifts, cosmology='Planck13', cm='DuttonMaccio'):
        if type(redshifts) != np.ndarray:
            redshifts = np.array(redshifts)
        if redshifts.ndim != 1:
            raise ValueError("Input redshift array must have 1 dimension.")
{'fraction_non_alphanumeric': 0.057219973009446694, 'fraction_numerical': 0.00863697705802969, 'mean_word_length': 3.005945945945946, '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': '6480600', 'n_tokens_mistral': 2035, 'n_tokens_neox': 1900, 'n_words': 850}