<commit_before>import numpy as np

from scipy.interpolate import interp1d
from scipy.integrate import trapz

from astropy import units as u, constants as c, table as t
import astropy.io


l_eff_d = {'r': 6166. * u.AA, 'i': 7480. * u.AA, 'z': 8932. * u.AA}
l_wid_d = {'r': 550. * u.AA, 'i': 1300. * u.AA, 'z': 1000. * u.AA}


def lumdens2bbdlum(lam, Llam, band):
    '''
    Convert a spectral luminosity density to a broadband luminosity

    Convolve source spectrum/a with a filter; specific routine derived
        from MaNGA's ml_mangatosdssimage.pro routine from DRP

    Parameters
    ----------
    lam :
        wavelength array of source spectrum

    Llam :
        Luminosity density, units sim to Lsun/AA

    band :
        chosen band
    '''

    # make sure everything's in the right units
    Llam = Llam.to('erg s-1 AA-1')
    lam = lam.to('AA')
    nu = lam.to('Hz', equivalencies=u.spectral())

    # read in filter table
    band_tab = t.Table.read('filters/{}_SDSS.res'.format(band),
                            names=['lam', 'f'], format='ascii')

    # set up interpolator
    band_interp = interp1d(x=band_tab['lam'].quantity.value,
                           y=band_tab['f'], fill_value=0.,
                           bounds_error=False)

    f = band_interp(lam)

    # convert to Lnu, by multiplying by lam^2/c
    Lnu = (Llam * lam**2. / c.c).to('Lsun Hz-1')

    L = trapz(x=nu.value[::-1], y=f * Lnu.value, axis=-1) * u.Lsun
    Lnu_avg = L / (trapz(x=nu.value[::-1], y=f) * u.Hz)

    l_eff = l_eff_d[band]
    L = Lnu_avg * l_eff.to('Hz', equivalencies=u.spectral())

    return L.to('Lsun')

def color(hdulist, band1='g', band2='r'):
    '''
    Calculate the color of a MaNGA galaxy, based on two bandpasses

    By convention, C_br = b - r
    '''
    img1 = hdulist['{}IMG'.format(band1)].data
    img2 = hdulist['{}IMG'.format(band2)].data
<commit_msg>small doc tweak<commit_after>import numpy as np

from scipy.interpolate import interp1d
from scipy.integrate import trapz

from astropy import units as u, constants as c, table as t
import astropy.io


l_eff_d = {'r': 6166. * u.AA, 'i': 7480. * u.AA, 'z': 8932. * u.AA}
l_wid_d = {'r': 550. * u.AA, 'i': 1300. * u.AA, 'z': 1000. * u.AA}


def lumdens2bbdlum(lam, Llam, band):
    '''
    Convert a spectral luminosity density to a broadband luminosity

    Convolve source spectrum/a with a filter; specific routine derived
        from MaNGA's ml_mangatosdssimage.pro routine from DRP

    Parameters
    ----------
    lam :
        wavelength array of source spectrum

    Llam :
        Luminosity density, units sim to Lsun/AA

    band :
        chosen band
    '''

    # make sure everything's in the right units
    Llam = Llam.to('erg s-1 AA-1')
    lam = lam.to('AA')
    nu = lam.to('Hz', equivalencies=u.spectral())

    # read in filter table
    band_tab = t.Table.read('filters/{}_SDSS.res'.format(band),
                            names=['lam', 'f'], format='ascii')

    # set up interpolator
    band_interp = interp1d(x=band_tab['lam'].quantity.value,
                           y=band_tab['f'], fill_value=0.,
                           bounds_error=False)

    f = band_interp(lam)

    # convert to Lnu, by multiplying by lam^2/c
    Lnu = (Llam * lam**2. / c.c).to('Lsun Hz-1')

    L = trapz(x=nu.value[::-1], y=f * Lnu.value, axis=-1) * u.Lsun
    Lnu_avg = L / (trapz(x=nu.value[::-1], y=f) * u.Hz)

    l_eff = l_eff_d[band]
    L = Lnu_avg * l_eff.to('Hz', equivalencies=u.spectral())

    return L.to('Lsun')

def color(hdulist, band1='g', band2='r'):
    '''
    Calculate the color of a MaNGA galaxy, based on two bandpasses

    By convention, C_br = b - r, i.e., band1 - band2
    '''
    img1 = hdulist['{}IMG'.format(band1)].data
    img2 = hdulist['{}IMG'.format(band2)].data

{'fraction_non_alphanumeric': 0.1495400788436268, 'fraction_numerical': 0.022076215505913273, 'mean_word_length': 2.453720508166969, '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': '3165581', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1374, 'n_words': 367}