Module skytools.unit_conversion

This module computes unit conversion and color correction factors for CMB observations based on Planck 2013 IX: HFI Spectral Response. This is meant to be a python equivalent to the Planck UC_CC IDL codes.

Functions

def C12O16_KRJkms_to_KCMB(nus_in_GHz, transmission=None, threshold=0.0001)
Expand source code
def C12O16_KRJkms_to_KCMB(nus_in_GHz, transmission=None, threshold=1e-4):
    """
    Computes conversion factor from K_RJ km/s to K_CMB for C12O16 line emission.

    Parameters
    ----------
    nus_in_GHz: float or np.ndarray
        If single float value is provided, assumed to be delta transmission.
        If np.ndarray is provided without transmission, assume tophat transmission.

    transmission: np.ndarray, default=None
        Must be the same size as nus_in_GHz. Need not be normalized to one. Assume HFI/LFI definition
        of transmission, assuming \\(\\lambda^2\\) factor is multipled and the transmission is in units of
        MJy/sr. If your bandpass is in \\(K_b\\) unit then the \\(\\lambda^2\\) factor is missing.

    threshold: float, default=1e-4
        Threshold value for filtering transmission data.

    Returns
    -------
    float or np.ndarray
        A float or array value that is the conversion factor from K_RJ km/s to K_CMB for C12O16.
    """

    if (not isinstance(nus_in_GHz, (list, np.ndarray))) and (nus_in_GHz in c12o16_lines):
        return el.B_prime_nu_T(nus_in_GHz) / el.Brj_prime_nu_T(c12o16_lines[c12o16_lines == nus_in_GHz])

    if isinstance(transmission, (list,np.ndarray)):
        if len(transmission) != len(nus_in_GHz):
            raise Exception("ERROR: transmission and frequency arrays are not of same size.")

    else:

        transmission = np.ones(nus_in_GHz.shape) 
    
    nus_in_GHz   = nus_in_GHz[transmission > threshold]
    transmission = transmission[transmission > threshold] 
    
    nu_lo = np.min(nus_in_GHz)
    nu_hi = np.max(nus_in_GHz)

    weights = transmission / np.trapezoid(transmission, x=nus_in_GHz * con.giga)
    
    
    co12o16_in_band = c12o16_lines[(c12o16_lines > nu_lo) & (c12o16_lines < nu_hi)]
    weights_co12016 = np.interp(co12o16_in_band * con.giga, nus_in_GHz * con.giga, weights)
    
    band_integ_c12o16 = weights_co12016 * (co12o16_in_band * con.giga / con.c) * el.Brj_prime_nu_T(co12o16_in_band)
    
    band_integrated_CMB = np.trapezoid(weights * el.B_prime_nu_T(nus_in_GHz), x=nus_in_GHz * con.giga)

    return (band_integ_c12o16 / band_integrated_CMB) 

Computes conversion factor from K_RJ km/s to K_CMB for C12O16 line emission.

Parameters

nus_in_GHz : float or np.ndarray
If single float value is provided, assumed to be delta transmission. If np.ndarray is provided without transmission, assume tophat transmission.
transmission : np.ndarray, default=None
Must be the same size as nus_in_GHz. Need not be normalized to one. Assume HFI/LFI definition of transmission, assuming \lambda^2 factor is multipled and the transmission is in units of MJy/sr. If your bandpass is in K_b unit then the \lambda^2 factor is missing.
threshold : float, default=1e-4
Threshold value for filtering transmission data.

Returns

float or np.ndarray
A float or array value that is the conversion factor from K_RJ km/s to K_CMB for C12O16.
def C13O16_KRJkms_to_KCMB(nus_in_GHz, transmission=None, threshold=0.0001)
Expand source code
def C13O16_KRJkms_to_KCMB(nus_in_GHz, transmission=None, threshold=1e-4):
    """
    Computes conversion factor from K_RJ km/s to K_CMB for C13O16 line emission.

    Parameters
    ----------
    nus_in_GHz: float or np.ndarray
        If single float value is provided, assumed to be delta transmission.
        If np.ndarray is provided without transmission, assume tophat transmission.

    transmission: np.ndarray, default=None
        Must be the same size as nus_in_GHz. Need not be normalized to one. Assume HFI/LFI definition
        of transmission, assuming \\(\\lambda^2\\) factor is multipled and the transmission is in units of
        MJy/sr. If your bandpass is in \\(K_b\\) unit then the \\(\\lambda^2\\) factor is missing.

    threshold: float, default=1e-4
        Threshold value for filtering transmission data.

    Returns
    -------
    float or np.ndarray
        A float or array value that is the conversion factor from K_RJ km/s to K_CMB for C13O16.
    """

    if (not isinstance(nus_in_GHz, (list, np.ndarray))) and (nus_in_GHz in c13o16_lines):
        return el.B_prime_nu_T(nus_in_GHz) / el.Brj_prime_nu_T(c13o16_lines[c13o16_lines == nus_in_GHz])

    if isinstance(transmission, (list,np.ndarray)):
        if len(transmission) != len(nus_in_GHz):
            raise Exception("ERROR: transmission and frequency arrays are not of same size.")

    else:

        transmission = np.ones(nus_in_GHz.shape) 
    
    nus_in_GHz   = nus_in_GHz[transmission > threshold]
    transmission = transmission[transmission > threshold] 
    
    nu_lo = np.min(nus_in_GHz)
    nu_hi = np.max(nus_in_GHz)
    
    weights = transmission / np.trapezoid(transmission, x=nus_in_GHz * con.giga)
    
    co13o16_in_band = c13o16_lines[(c13o16_lines > nu_lo) & (c13o16_lines < nu_hi)]
    weights_co13016 = np.interp(co13o16_in_band * con.giga, nus_in_GHz * con.giga, weights)
    
    band_integ_c13o16 = weights_co13016 * (co13o16_in_band * con.giga / con.c) * el.Brj_prime_nu_T(co13o16_in_band)
    
    band_integrated_CMB = np.trapezoid(weights * el.B_prime_nu_T(nus_in_GHz), x=nus_in_GHz * con.giga)

    return (band_integ_c13o16 / band_integrated_CMB) 

Computes conversion factor from K_RJ km/s to K_CMB for C13O16 line emission.

Parameters

nus_in_GHz : float or np.ndarray
If single float value is provided, assumed to be delta transmission. If np.ndarray is provided without transmission, assume tophat transmission.
transmission : np.ndarray, default=None
Must be the same size as nus_in_GHz. Need not be normalized to one. Assume HFI/LFI definition of transmission, assuming \lambda^2 factor is multipled and the transmission is in units of MJy/sr. If your bandpass is in K_b unit then the \lambda^2 factor is missing.
threshold : float, default=1e-4
Threshold value for filtering transmission data.

Returns

float or np.ndarray
A float or array value that is the conversion factor from K_RJ km/s to K_CMB for C13O16.
def KCMB_to_MJysr(nus_in_GHz, nuc_in_GHz=None, transmission=None)
Expand source code
def KCMB_to_MJysr(nus_in_GHz, nuc_in_GHz=None, transmission=None):
    """
    Gives conversion factor from K_CMB to MJy/sr.
    MJy/sr assumes nu^-1 (IRAS) reference spectrum following Planck. 

    Parameters
    ----------
    nus_in_GHz: float or np.ndarray
        If single float value is provided, assumed to be delta transmission.
        If np.ndarray is provided without transmission, assume tophat transmission.

    nuc_in_GHz: float, default=None
        If nus_in_GHz is a single number, then nuc_in_GHz is ignored, and is assumed to be the same.
        If nus_in_GHz is a np.ndarray, and nuc_in_GHz is not provided, we assume transmission weighted 
        average of nus_in_GHz.
    transmission: np.ndarray, default=None
        Must be the same size as nus_in_GHz. Need not be normalized to one. Assume HFI/LFI definition
        of transmission, assuming \\(\\lambda^2\\) factor is multipled and the transmission is in units of
        MJy/sr. If your bandpass is in \\(K_b\\) unit then the \\(\\lambda^2\\) factor is missing.

    Returns
    -------
    float
        A float value to convert K_CMB to MJy/sr.
    """
    if not isinstance(nus_in_GHz, (list, np.ndarray)):
        return el.B_prime_nu_T(nus_in_GHz) * 1.e20      # 1.e20 factor converts W/m2/Hz to MJy.

    if isinstance(transmission, (list,np.ndarray)):
        if len(transmission) != len(nus_in_GHz):
            raise Exception("ERROR: transmission and frequency arrays are not of same size.")

    else:

        transmission = np.ones(nus_in_GHz.shape) 

    weights = transmission / np.trapezoid(transmission, x=nus_in_GHz * con.giga)

    if nuc_in_GHz == None:
        nuc_in_GHz = np.trapezoid(nus_in_GHz*weights, x=nus_in_GHz * con.giga)

    band_integrated_CMB = np.trapezoid(weights*el.B_prime_nu_T(nus_in_GHz), x=nus_in_GHz * con.giga)
    band_integrated_nucbynu = np.trapezoid(weights*(nuc_in_GHz / nus_in_GHz), x=nus_in_GHz * con.giga)

    return (band_integrated_CMB / band_integrated_nucbynu) * 1.e20  # 1.e20 factor converts W/m2/Hz to MJy.

Gives conversion factor from K_CMB to MJy/sr. MJy/sr assumes nu^-1 (IRAS) reference spectrum following Planck.

Parameters

nus_in_GHz : float or np.ndarray
If single float value is provided, assumed to be delta transmission. If np.ndarray is provided without transmission, assume tophat transmission.
nuc_in_GHz : float, default=None
If nus_in_GHz is a single number, then nuc_in_GHz is ignored, and is assumed to be the same. If nus_in_GHz is a np.ndarray, and nuc_in_GHz is not provided, we assume transmission weighted average of nus_in_GHz.
transmission : np.ndarray, default=None
Must be the same size as nus_in_GHz. Need not be normalized to one. Assume HFI/LFI definition of transmission, assuming \lambda^2 factor is multipled and the transmission is in units of MJy/sr. If your bandpass is in K_b unit then the \lambda^2 factor is missing.

Returns

float
A float value to convert K_CMB to MJy/sr.
def KCMB_to_ySZ(nus_in_GHz, transmission=None)
Expand source code
def KCMB_to_ySZ(nus_in_GHz, transmission=None):
    """
    Computes conversion factor from K_CMB to y SZ (Compton parameter). 

    Parameters
    ----------
    nus_in_GHz: float or np.ndarray
        If single float value is provided, assumed to be delta transmission.
        If np.ndarray is provided without transmission, assume tophat transmission.

    transmission: np.ndarray, default=None
        Must be the same size as nus_in_GHz. Need not be normalized to one. Assume HFI/LFI definition
        of transmission, assuming \\(\\lambda^2\\) factor is multipled and the transmission is in units of
        MJy/sr. If your bandpass is in \\(K_b\\) unit then the \\(\\lambda^2\\) factor is missing.

    Returns
    -------
    float
        A float value that is the conversion factor from K_CMB to y SZ.
    """

    if not isinstance(nus_in_GHz, (list, np.ndarray)):
        return el.B_prime_nu_T(nus_in_GHz) / el.ysz_spectral_law(nus_in_GHz)     # 1.e20 factor converts W/m2/Hz to MJy.

    if isinstance(transmission, (list,np.ndarray)):
        if len(transmission) != len(nus_in_GHz):
            raise Exception("ERROR: transmission and frequency arrays are not of same size.")

    else:

        transmission = np.ones(nus_in_GHz.shape) 

    weights = transmission / np.trapezoid(transmission, x=nus_in_GHz * con.giga)

    band_integrated_CMB = np.trapezoid(weights*el.B_prime_nu_T(nus_in_GHz), x=nus_in_GHz * con.giga)
    band_integrated_ysz = np.trapezoid(weights*el.ysz_spectral_law(nus_in_GHz), x=nus_in_GHz * con.giga)

# Referenece: Eq 33 from Planck 2013 XI HFI spectral response  
    return band_integrated_CMB/band_integrated_ysz  # returns in K_CMB^(-1) 

Computes conversion factor from K_CMB to y SZ (Compton parameter).

Parameters

nus_in_GHz : float or np.ndarray
If single float value is provided, assumed to be delta transmission. If np.ndarray is provided without transmission, assume tophat transmission.
transmission : np.ndarray, default=None
Must be the same size as nus_in_GHz. Need not be normalized to one. Assume HFI/LFI definition of transmission, assuming \lambda^2 factor is multipled and the transmission is in units of MJy/sr. If your bandpass is in K_b unit then the \lambda^2 factor is missing.

Returns

float
A float value that is the conversion factor from K_CMB to y SZ.
def MJysr_to_Kb(nuc_in_GHz)
Expand source code
def MJysr_to_Kb(nuc_in_GHz):
    """
    Gives conversion factor from MJy/sr to brightness temperature Kb (K_RJ).

    Parameters
    ----------
    nuc_in_GHz: float
        A float denoting the central frequency of the band. No bandpass information needed.
    
    Notes
    -----
    No bandpass is required only central frequency is assumed.

    Returns
    -------
    float
        A float value to convert MJy/sr to Kb.
    """

    return con.c**2. / 2. / (nuc_in_GHz * con.giga)**2. / con.k / 1.e20    # 1e20 is conversion factor from SI unit of emissivity to MJy 1e-6 x 1e26 = 1e20

Gives conversion factor from MJy/sr to brightness temperature Kb (K_RJ).

Parameters

nuc_in_GHz : float
A float denoting the central frequency of the band. No bandpass information needed.

Notes

No bandpass is required only central frequency is assumed.

Returns

float
A float value to convert MJy/sr to Kb.