<commit_before>'''Analytic routines for debris disks.'''

import numpy as np

from . import photometry
from . import filter
from . import utils

class BB_Disk(object):
    '''A blackbody disk class.
        
    Takes multiple temperatures, the purpose being for use to show
    disk properties in paramter spaces such as fractional luminosity
    vs. temperature.
    
    Parameters
    ----------
    lstar : float
        Stellar luminosity in Solar units.
    tstar : float
        Stellar effective temperature in Kelvin.
    distance : float
        Stellar distance in parsec.
    wavelengths : 1-D array, optional
        Vector of wavelengths.
    temperatures : 1-D array, optional
        Vector of temperatures.

    .. todo: distance not actually needed for calibration limited, fix.

    .. todo: don't use a for loop over temperatures,
             fix utils.bnu_wav_micron instead.
    '''

    def __init__(self,wavelengths=None,temperatures=None,
                 lstar=None,tstar=None,distance=None):
        '''Initialise, default T=100K, Omega=1.0'''
        
        if wavelengths is None:
            self.wavelengths = 10**np.linspace(-1,4,1000)
        else:
            self.wavelengths = wavelengths
        
        if temperatures is None:
            self.temperatures = 10**np.linspace(1,3,1000)
        else:
            self.temperatures = temperatures

        self.lstar = lstar
        self.tstar = tstar
        self.distance = distance


    def blackbody_radii(self):
        '''Return the blackbody radii.'''
        
        return (278.3/self.temperatures)**2 * self.lstar**0.5


    def radiance(self):
        '''Return radiance, in W / m^2 / sr.'''
        
        return 5.67e-8 * self.temperatures**4 / np.pi


    def f_limits(self,lim_waves,flux_limits=None,r_limits=None,
                 stellar_flux=None,fwhm=None,lstar_1pc=None):
        '''Return fractional luminosity limits.
            
        This routine implements Wyatt (2008) equations 8 and 11.
        
        Parameters
        ----------
        lim_waves : numpy.ndarray
            Array of wavelengths at which limits apply.
        flux_limits : numpy.ndarray, optional
            Array of flux limits.
        r_limits : numpy.ndarray, optional
            Array of calibration limits (F_disk/F_star).
        stellar_flux : numpy.ndarray, optional
            Array of stellar fluxes at lim_waves.
        fwhm : numpy.ndarray, optional
            Array of spatial resolutions at lim_waves, affects flux
            limited observations if disk is resolved.
        lstar_1pc : float
            L_star at 1pc, used for flux limits when distance unknown.

        One of flux_limits or r_limits must be given. If both, they must
        have the same length, and correspond to the wavelengths given.
        Likewise for stellar_flux and fwhm.
        '''

        if flux_limits is not None and r_limits is not None:
            if len(flux_limits) != len(r_limits):
                raise RuntimeError(
                       'flux_limits must be same length as r_limits')

        # sensitivity limit
        if flux_limits is not None:
            
            slims = np.zeros((len(self.temperatures),len(flux_limits)))

            for i,temp in enumerate(self.temperatures):

                if self.distance is not None:
                    slims[i,:] = 3.4e9 * flux_limits * self.distance**2 / \
                                self.blackbody_radii()[i]**2 / \
                                utils.bnu_wav_micron(lim_waves,temp)
                else:
                    # distance independent calculation, 2487305. is
                    # pc^2/Lsun, haven't tracked down the 4 yet
                    ldisk_1pc = 4 * 5.6704e-8 * flux_limits * 2487305. * \
                        temp**4 / utils.bnu_wav_micron(lim_waves,temp)
                    slims[i,:] = ldisk_1pc / lstar_1pc

                # apply correction for resolved disks
                if fwhm is not None:
                    fwhm_fact = 2 * self.blackbody_radii()[i] / self.distance / fwhm
                    resolved = fwhm_fact > 1.0
                    slims[i,resolved] *= fwhm_fact[resolved]

        
        # calibration limit, use actual stellar flux if given<commit_msg>avoid error with no distance<commit_after>'''Analytic routines for debris disks.'''

import numpy as np

from . import photometry
from . import filter
from . import utils

class BB_Disk(object):
    '''A blackbody disk class.
        
    Takes multiple temperatures, the purpose being for use to show
    disk properties in paramter spaces such as fractional luminosity
    vs. temperature.
    
    Parameters
    ----------
    lstar : float
        Stellar luminosity in Solar units.
    tstar : float
        Stellar effective temperature in Kelvin.
    distance : float
        Stellar distance in parsec.
    wavelengths : 1-D array, optional
        Vector of wavelengths.
    temperatures : 1-D array, optional
        Vector of temperatures.

    .. todo: distance not actually needed for calibration limited, fix.

    .. todo: don't use a for loop over temperatures,
             fix utils.bnu_wav_micron instead.
    '''

    def __init__(self,wavelengths=None,temperatures=None,
                 lstar=None,tstar=None,distance=None):
        '''Initialise, default T=100K, Omega=1.0'''
        
        if wavelengths is None:
            self.wavelengths = 10**np.linspace(-1,4,1000)
        else:
            self.wavelengths = wavelengths
        
        if temperatures is None:
            self.temperatures = 10**np.linspace(1,3,1000)
        else:
            self.temperatures = temperatures

        self.lstar = lstar
        self.tstar = tstar
        self.distance = distance


    def blackbody_radii(self):
        '''Return the blackbody radii.'''
        
        return (278.3/self.temperatures)**2 * self.lstar**0.5


    def radiance(self):
        '''Return radiance, in W / m^2 / sr.'''
        
        return 5.67e-8 * self.temperatures**4 / np.pi


    def f_limits(self,lim_waves,flux_limits=None,r_limits=None,
                 stellar_flux=None,fwhm=None,lstar_1pc=None):
        '''Return fractional luminosity limits.
            
        This routine implements Wyatt (2008) equations 8 and 11.
        
        Parameters
        ----------
        lim_waves : numpy.ndarray
            Array of wavelengths at which limits apply.
        flux_limits : numpy.ndarray, optional
            Array of flux limits.
        r_limits : numpy.ndarray, optional
            Array of calibration limits (F_disk/F_star).
        stellar_flux : numpy.ndarray, optional
            Array of stellar fluxes at lim_waves.
        fwhm : numpy.ndarray, optional
            Array of spatial resolutions at lim_waves, affects flux
            limited observations if disk is resolved.
        lstar_1pc : float
            L_star at 1pc, used for flux limits when distance unknown.

        One of flux_limits or r_limits must be given. If both, they must
        have the same length, and correspond to the wavelengths given.
        Likewise for stellar_flux and fwhm.
        '''

        if flux_limits is not None and r_limits is not None:
            if len(flux_limits) != len(r_limits):
                raise RuntimeError(
                       'flux_limits must be same length as r_limits')

        # sensitivity limit
        if flux_limits is not None:
            
            slims = np.zeros((len(self.temperatures),len(flux_limits)))

            for i,temp in enumerate(self.temperatures):

                if self.distance is not None:
                    slims[i,:] = 3.4e9 * flux_limits * self.distance**2 / \
                                self.blackbody_radii()[i]**2 / \
                                utils.bnu_wav_micron(lim_waves,temp)
                else:
                    # distance independent calculation, 2487305. is
                    # pc^2/Lsun, haven't tracked down the 4 yet
                    ldisk_1pc = 4 * 5.6704e-8 * flux_limits * 2487305. * \
                        temp**4 / utils.bnu_wav_micron(lim_waves,temp)
                    slims[i,:] = ldisk_1pc / lstar_1pc

                # apply correction for resolved disks
                if self.distance is not None and fwhm is not None:
                    fwhm_fact = 2 * self.blackbody_radii()[i] / self.distance / fwhm
                    resolved = fwhm_fact > 1.0
                    slims[i,resolved] *= fwhm_fact[resolved]

        
        # calibration limit, use actual stellar flux if given
{'fraction_non_alphanumeric': 0.07940187782543179, 'fraction_numerical': 0.018778254317839343, 'mean_word_length': 1.76096, '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': '7082850', 'n_tokens_mistral': 2551, 'n_tokens_neox': 2317, 'n_words': 718}