<commit_before>
# ############################################################################
# Calculations for flux ratios.
# ############################################################################
import numpy as np
from db_queries import get_temperature


def flux_mag_ratio(mag1, mag2):
    """Calcualte the flux ratio between two magnitudes.

    Using the equation f1/f2 = 10**(-0.4 * (mag1 - mag2)).
    A common approximation is the equation f1/f2 \approx 2.512**(m2 - m1), but is not here.

    Parameters
    ----------
    mag1 float
        Magnitude of first object.
    mag2: float
        Magnitude of second object.

    Returns
    -------
    flux_ratio: float
        flux/contrast ratio between the two magnitudes.

    """
    # return 2.512**(mag2 - mag1)  # Approximation
    return 10**(-0.4 * (mag1 - mag2))


def calculate_flux_ratios(star_params, companion_params):
    """Flux ratios for the different bands."""
    Flux_ratios = dict()
    Flux_ratios["J"] = flux_mag_ratio(star_params["FLUX_J"], companion_params["Mj"])
    Flux_ratios["K"] = flux_mag_ratio(star_params["FLUX_K"], companion_params["Mk"])
    Flux_ratios["H"] = flux_mag_ratio(star_params["FLUX_H"], companion_params["Mh"])
    return Flux_ratios

def calculate_stellar_radius(star_params):
    """Based on R/Rs = (Ts/T)^2(L/Ls)^(1/2) equation.

    Parameters
    ----------
    star_params: votable, dict
        Table of Stellar parameters.

    Returns
    -------
    R_Rs: float
        Esitmated Stellar Radius in solar radii.

    """
    star_name = star_params['name'][0]
    teff_star = get_temperature(star_name, star_params)

    Ts_T = 5800. / teff_star              # Temperature ratio
    Dm = 4.83 - star_params["FLUX_V"]     # Differnce of aboslute magnitude
    L_Ls = 2.51 ** Dm                     # Luminosity ratio
    R_Rs = (Ts_T)**2 * np.sqrt(L_Ls)      # Raidus of Star in Solar Radii

    return R_Rs   # Radius of star in solar radii
<commit_msg>Update flux_ratio calculation, iterate over band given.<commit_after>
# ############################################################################
# Calculations for flux ratios.
# ############################################################################
import numpy as np
from db_queries import get_temperature


def flux_mag_ratio(mag1, mag2):
    """Calcualte the flux ratio between two magnitudes.

    Using the equation f1/f2 = 10**(-0.4 * (mag1 - mag2)).
    A common approximation is the equation f1/f2 \approx 2.512**(m2 - m1), but is not here.

    Parameters
    ----------
    mag1 float
        Magnitude of first object.
    mag2: float
        Magnitude of second object.

    Returns
    -------
    flux_ratio: float
        flux/contrast ratio between the two magnitudes.

    """
    # return 2.512**(mag2 - mag1)  # Approximation
    return 10**(-0.4 * (mag1 - mag2))


def calculate_flux_ratio(star_params, companion_params, bands):
    """Flux ratios for the different bands in bands.

    parameters
    ----------
    star_params: dict
       Stellar parameters with stellar magnitude values like "FLUX_K".
    companion_params: dict
        Companion parameters with magnitude values like "Mk".
    bands: list of str
        Bands to return ratios for.

    Returns
    -------
    flux_ratios: dict
       Flux ratios for each given band.

    """
    flux_ratios = dict()
    for band in bands:
        flux_ratios[band] = flux_mag_ratio(star_params["FLUX_{0!s}".format(band)],
                                           companion_params["M{}".format(band.lower())])

    return flux_ratios


def calculate_stellar_radius(star_params):
    """Based on R/Rs = (Ts/T)^2(L/Ls)^(1/2) equation.

    Parameters
    ----------
    star_params: votable, dict
        Table of Stellar parameters.

    Returns
    -------
    R_Rs: float
        Esitmated Stellar Radius in solar radii.

    """
    star_name = star_params['name'][0]
    teff_star = get_temperature(star_name, star_params)

    Ts_T = 5800. / teff_star              # Temperature ratio
    Dm = 4.83 - star_params["FLUX_V"]     # Differnce of aboslute magnitude
    L_Ls = 2.51 ** Dm                     # Luminosity ratio
    R_Rs = (Ts_T)**2 * np.sqrt(L_Ls)      # Raidus of Star in Solar Radii

    return R_Rs   # Radius of star in solar radii

{'fraction_non_alphanumeric': 0.1789351851851852, 'fraction_numerical': 0.02199074074074074, 'mean_word_length': 2.625, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '336619', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1286, 'n_words': 363}