<commit_before>'''
Functions to calculate virial properties, integrated properties, etc.
'''

import L500analysis.utils.constants as constants
from L500analysis.utils.utils import *

def calculate_virial_mass(radii_kpc_h=None, M_tot=None,
                          aexp=None, delta=None) :
    
    cutoff_density = _calculate_cutoff_background_density(delta=delta,aexp=aexp)
    pass


def calculate_virial_radius(radii_kpc_h=None, M_tot=None,
                          aexp=None, delta=None) :
    cutoff_density = _calculate_cutoff_background_density(delta=delta,aexp=aexp)

    calculate_enclosed_density( radii_kpc_h=radii_kpc_h,
                                M_tot=None )
    pass

def calculate_enclosed_density() :
    pass

def interpolate_profile() :
    pass


def _calculate_cutoff_background_density(delta=None,aexp=None) :
    '''Calculates cutoff background density in h^2Msun/kpc^3'''
    
    overdensity_type = {'c':calculate_rhoc(aexp=aexp),
                        'm':calculate_rhom(aexp=aexp)}

    if delta=='bryan_norman98' :
        overdensity = calculate_bryan_norman98_overdensity(
            Omz=calculate_Omz(aexp=aexp))

        return overdensity*overdensity_type['c']

    else : 
        overdensity = float(delta[:-1])
        return overdensity*overdensity_type[delta[-1]]
<commit_msg>Added class for calculating integrated halo properties for general overdensity<commit_after>'''
Functions to calculate virial properties, integrated properties, etc.
'''
import numpy as np
import L500analysis.utils.constants as constants
from L500analysis.utils.utils import *
from L500analysis.plotting.profiles.tools.make_profile import make_profile_linear 
from L500analysis.derived_fields.derived_field_tools.self_similar_normalizations \
    import calculate_T_normalization

class CalculateHaloProperties :
    def __init__( self, 
                  physical_radial_profile=None, mass_enclosed_profile=None,
                  delta=None,aexp=None) :
        '''
        Expects physical radial profile in kpc/h and mass enclosed in Msun/h.
        delta should be of form 200c, 200m, etc. OR "bryan_norman98"   
        '''

        self.delta=delta
        self.aexp=aexp
        self._calculate_interpolated_enclosed_density(physical_radial_profile=physical_radial_profile,
                                                      mass_enclosed_profile=mass_enclosed_profile)
        self._calculate_cutoff_density()
        self._get_virial_indices()

    def _calculate_cutoff_density(self) :
        self.cutoff_density = calculate_cutoff_background_density(delta=self.delta, aexp=self.aexp)

    def _calculate_enclosed_density(self,
                                    physical_radial_profile=None,
                                    mass_enclosed_profile=None) :
        self.interpolated_radius = make_profile_linear(x=physical_radial_profile,y=physical_radial_profile)
        self.interpolated_mass_enclosed = make_profile_linear(x=physical_radial_profile,y=mass_enclosed_profile)
        self.interpolated_enclosed_density = interpolated_mass_enclosed / (4./3. * pi * interpolated_radius**3)

    def _get_virial_indices(self) :
        self.virial_indices = np.where(self.interpolated_enclosed_density<self.cutoff_density \
                                           and self.interpolated_enclosed_density>self.cutoff_density)

    def calculate_virial_mass(self) :
        return self.interpolated_mass_enclosed(virial_indices)

    def calculate_virial_radius(self) :
        return self.interpolated_radius(virial_indices)

    def calculate_virial_temperature(self) :
        '''T delta in keV, expects Mvir in Msun/h'''
        return calculate_T_normalization(Mvir=self.calculate_virial_mass(),
                                         aexp=self.aexp,
                                         delta=self.delta)


def calculate_cutoff_background_density(delta=None,aexp=None) :
    '''Calculates cutoff background density in h^2Msun/kpc^3'''
    
    overdensity_type = {'c':calculate_rhoc(aexp=aexp),
                        'm':calculate_rhom(aexp=aexp)}
    
    if delta=='bryan_norman98' :
        overdensity = calculate_bryan_norman98_overdensity(
            Omz=calculate_Omz(aexp=aexp))
        
        return overdensity*overdensity_type['c']
    
    else : 
        overdensity = float(delta[:-1])
        return overdensity*overdensity_type[delta[-1]]

{'fraction_non_alphanumeric': 0.07840471334692953, 'fraction_numerical': 0.010197144799456152, 'mean_word_length': 2.972997299729973, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4669493', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1297, 'n_words': 205}