def air_density(temp, patm, pw = 0):
    """
    Calculates the density of dry air by means of the universal gas law as a
    function of air temperature and atmospheric pressure.
    
    m / V = [Pw / (Rv * T)] + [Pd / (Rd * T)]
    
    where:
        Pd: Patm - Pw
        Rw: specific gas constant for water vapour [Rw = 461.495 MJ/kg/K]
        Rv: specific gas constant for dry air [Rv = 287.058 MJ/kg/K]
        T: air temperature [K]
        m/V: density of air [kg/m³]
    
    Parameters
    ----------
    temp : float
        Air temperature [K].
    patm : float
        Atmospheric pressure [Pa].
    pw : float
        Vapour pressure [Pa]. Default to 0 Pa (dry air).
    
    Returns
    -------
    float
        Air density [kg/m³].

    """
    rd, rw = 287.058, 461.495 # specific gas constant for dry air and water vapour [J / (kg K)]
    pd = patm - pw
    return (pd / (rd * temp)) + (pw / (rw * temp))