<commit_before># coding: utf-8

""" Dealing with RR Lyrae photometry/measurements """

from __future__ import division, print_function

__author__ = "adrn <<EMAIL>>"

# Standard library
import os, sys

# Third-party
from astropy.time import Time, TimeDelta
import numpy as np
import astropy.units as u
from astropy.utils.misc import isiterable
from pygaia.errors.spectroscopic import vradErrorSkyAvg
from pygaia.errors.astrometric import properMotionErrorSkyAvg

# Project
from .core import distance_modulus
from .gaia import V_to_G

__all__ = ["M_V", "gaia_rv_error", "gaia_pm_error"]

# Johnson/Cousins (V - I_C) color for RR Lyrae at *minimum*
# Guldenschuh et al. (2005 PASP 117, 721), pg. 725
# (V-I)_min = 0.579 +/- 0.006 mag
V_minus_I = 0.579

def M_V(fe_h, dfe_h=None):
    """ Given an RR Lyrae metallicity, return the V-band absolute magnitude.

        This expression comes from Benedict et al. 2011 (AJ 142, 187),
        equation 14 reads:
            M_v = (0.214 +/- 0.047)([Fe/H] + 1.5) + a_7

        where
            a_7 = 0.45 +/- 0.05

        From that, we take the absolute V-band magnitude to be:
            Mabs = 0.214 * ([Fe/H] + 1.5) + 0.45
            δMabs = sqrt[(0.047*(δ[Fe/H]))**2 + (0.05)**2]

        Parameters
        ----------
        fe_h : numeric or iterable
            Metallicity.
        dfe_h : numeric or iterable
            Uncertainty in the metallicity.

    """

    # V abs mag for RR Lyrae
    Mabs = 0.214*(fe_h + 1.5) + 0.45

    if dfe_h is not None:
        dMabs = np.sqrt((0.047*dfe_h)**2 + (0.05)**2)

        return (Mabs, dMabs)

    return Mabs

def gaia_rv_error(d, fe_h=-1.):
    """ Compute the sky-averaged radial velocity error for an
        RR Lyrae at the given distance.

        Parameters:
        -----------
        d : quantity_like
            The distance as an Astropy Quantity object.
        fe_h : numeric
            The metallicity.
    """

    Vmag = distance_modulus(d) + M_V(fe_h)
    err = vradErrorSkyAvg(Vmag, spt="F0V")*u.km/u.s

    return err

def gaia_pm_error(d, fe_h=-1.):
    """ Compute the sky-averaged proper motion error for an
        RR Lyrae at the given distance.

        Parameters:
        -----------
        d : quantity_like
            The distance as an Astropy Quantity object.
        fe_h : numeric
            The metallicity.
    """

    Vmag = distance_modulus(d) + M_V(fe_h)
    G = V_to_G(Vmag, V_minus_I)
    err = properMotionErrorSkyAvg(G, V_minus_I)
    err = 0.5*(err[0] + err[1])
    return err*u.microarcsecond/u.yr

############################################################
# Below are light curve utilities
#
def sawtooth_fourier(n_max, x):<commit_msg>change names and add parallax<commit_after># coding: utf-8

""" Dealing with RR Lyrae photometry/measurements """

from __future__ import division, print_function

__author__ = "adrn <<EMAIL>>"

# Standard library
import os, sys

# Third-party
from astropy.time import Time, TimeDelta
import numpy as np
import astropy.units as u
from astropy.utils.misc import isiterable
from pygaia.errors.spectroscopic import vradErrorSkyAvg
from pygaia.errors.astrometric import properMotionErrorSkyAvg, parallaxErrorSkyAvg

# Project
from .core import distance_modulus
from .gaia import V_to_G

__all__ = ["M_V", "gaia_rv_error", "gaia_pm_error"]

# Johnson/Cousins (V - I_C) color for RR Lyrae at *minimum*
# Guldenschuh et al. (2005 PASP 117, 721), pg. 725
# (V-I)_min = 0.579 +/- 0.006 mag
V_minus_I = 0.579

def M_V(fe_h, dfe_h=None):
    """ Given an RR Lyrae metallicity, return the V-band absolute magnitude.

        This expression comes from Benedict et al. 2011 (AJ 142, 187),
        equation 14 reads:
            M_v = (0.214 +/- 0.047)([Fe/H] + 1.5) + a_7

        where
            a_7 = 0.45 +/- 0.05

        From that, we take the absolute V-band magnitude to be:
            Mabs = 0.214 * ([Fe/H] + 1.5) + 0.45
            δMabs = sqrt[(0.047*(δ[Fe/H]))**2 + (0.05)**2]

        Parameters
        ----------
        fe_h : numeric or iterable
            Metallicity.
        dfe_h : numeric or iterable
            Uncertainty in the metallicity.

    """

    # V abs mag for RR Lyrae
    Mabs = 0.214*(fe_h + 1.5) + 0.45

    if dfe_h is not None:
        dMabs = np.sqrt((0.047*dfe_h)**2 + (0.05)**2)

        return (Mabs, dMabs)

    return Mabs

def gaia_radial_velocity_error(d, fe_h=-1.):
    """ Compute the sky-averaged radial velocity error for an
        RR Lyrae at the given distance.

        Parameters:
        -----------
        d : quantity_like
            The distance as an Astropy Quantity object.
        fe_h : numeric
            The metallicity.
    """

    Vmag = distance_modulus(d) + M_V(fe_h)
    err = vradErrorSkyAvg(Vmag, spt="F0V")*u.km/u.s

    return err

def gaia_proper_motion_error(d, fe_h=-1.):
    """ Compute the sky-averaged proper motion error for an
        RR Lyrae at the given distance.

        Parameters:
        -----------
        d : quantity_like
            The distance as an Astropy Quantity object.
        fe_h : numeric
            The metallicity.
    """

    Vmag = distance_modulus(d) + M_V(fe_h)
    G = V_to_G(Vmag, V_minus_I)
    err = properMotionErrorSkyAvg(G, V_minus_I)
    err = 0.5*(err[0] + err[1])
    return err*u.microarcsecond/u.yr

def gaia_parallax_error(d, fe_h=-1.):
    """ Compute the sky-averaged parallax motion error for an
        RR Lyrae at the given distance.

        Parameters:
        -----------
        d : quantity_like
            The distance as an Astropy Quantity object.
        fe_h : numeric
            The metallicity.
    """

    Vmag = distance_modulus(d) + M_V(fe_h)
    G = V_to_G(Vmag, V_minus_I)
    err = parallaxErrorSkyAvg(G, V_minus_I)
    return err*u.microarcsecond

############################################################
# Below are light curve utilities
#
def sawtooth_fourier(n_max, x):
{'fraction_non_alphanumeric': 0.1323653553942259, 'fraction_numerical': 0.033597838932973155, 'mean_word_length': 2.331833520809899, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2867081', 'n_tokens_mistral': 2253, 'n_tokens_neox': 1999, 'n_words': 580}