<commit_before># coding: utf-8
"""ISA functions. Implementation based on:

.. [1] U.S. Standard Atmosphere, 1976, U.S. Government Printing Office,
        Washington, D.C., 1976
.. [2] https://en.wikipedia.org/wiki/U.S._Standard_Atmosphere
"""

from math import exp

# Constants
R_a = 287.05287  # J/(Kg·K)
g0 = 9.80665  # m/s^2

# From: https://en.wikipedia.org/wiki/U.S._Standard_Atmosphere
#
#               Geopotential
#               altitude     Static       Standard     Temperature
#    Subscript  above MSL    Pressure     Temperature  Lapse Rate
#    -------------------------------------------------------------
#               (m)	       (pascals)    (K)         (K/m)
#
#    0	   0	             101325	    288.15	     -0.0065
#    1	   11000	       22632.1	    216.65	      0
#    2	   20000	       5474.89	    216.65	      0.001
#    3	   32000	       868.019	    228.65	      0.0028
#    4	   47000	       110.906	    270.65	      0
#    5	   51000	       66.9389	    270.65	     -0.0028
#    6	   71000	       3.95642	    214.65	     -0.002

h0 = (0, 11000, 20000, 32000, 47000, 51000, 71000, 84500)  # m
T0_layers = (288.15, 216.65, 216.65, 228.65, 270.65, 270.65, 214.65)  # K
p0_layers = (101325.0, 22632.1, 5474.89, 868.019, 110.906, 66.9389, 3.95642)  # Pa
alpha_layers = (-0.0065, 0, 0.001, 0.0028, 0, -0.0028, -0.002)  # K / m


def atm(h):
    """ISA 1976 Standard atmosphere temperature, pressure and density.

    Parameters
    ----------
    h : float
        Geopotential altitude (m).

    Returns
    -------
    T : float
        Temperature (K).
    p : float
        Pressure (Pa).
    rho : float
        Density (kg/m³)

    Raises
    ------
    ValueError
        If the value of the altitude is outside the defined layers.

    References
    ----------
    .. [1] U.S. Standard Atmosphere, 1976, U.S. Government Printing Office,
        Washington, D.C., 1976
    .. [2] https://en.wikipedia.org/wiki/U.S._Standard_Atmosphere

    """

    if h < 0.0:
        raise ValueError("Altitude cannot be less than 0 m.")

    elif h0[0] <= h < h0[1]:  # Troposphere
        T0 = T0_layers[0]<commit_msg>Moved table with reference values to module docstring and added a notes section and the available altitude range in the  function.<commit_after># coding: utf-8
"""ISA functions. Implementation based on:

.. [1] U.S. Standard Atmosphere, 1976, U.S. Government Printing Office,
        Washington, D.C., 1976

 From: https://en.wikipedia.org/wiki/U.S._Standard_Atmosphere

               Geopotential
               altitude     Static       Standard     Temperature
    Subscript  above MSL    Pressure     Temperature  Lapse Rate
    -------------------------------------------------------------
                (m)	       (pascals)     (K)         (K/m)

    0	           0	       101325	    288.15	     -0.0065
    1	          11000	       22632.1	    216.65	      0
    2	          20000	       5474.89	    216.65	      0.001
    3	          32000	       868.019	    228.65	      0.0028
    4	          47000	       110.906	    270.65	      0
    5	          51000	       66.9389	    270.65	     -0.0028
    6	          71000	       3.95642	    214.65	     -0.002

"""

from math import exp

# Constants
R_a = 287.05287  # J/(Kg·K)
g0 = 9.80665  # m/s^2

# Layer constants
h0 = (0, 11000, 20000, 32000, 47000, 51000, 71000, 84500)  # m
T0_layers = (288.15, 216.65, 216.65, 228.65, 270.65, 270.65, 214.65)  # K
p0_layers = (101325.0, 22632.1, 5474.89, 868.019, 110.906, 66.9389, 3.95642)  # Pa
alpha_layers = (-0.0065, 0, 0.001, 0.0028, 0, -0.0028, -0.002)  # K / m


def atm(h):
    """ISA 1976 Standard atmosphere temperature, pressure and density.

    Parameters
    ----------
    h : float
        Geopotential altitude (m). h values must range from 0 to 84500 m.

    Returns
    -------
    T : float
        Temperature (K).
    p : float
        Pressure (Pa).
    rho : float
        Density (kg/m³)

    Raises
    ------
    ValueError
        If the value of the altitude is outside the defined layers.

    Notes
    -----
    Check layers and reference values in [2].

    References
    ----------
    .. [1] U.S. Standard Atmosphere, 1976, U.S. Government Printing Office,
        Washington, D.C., 1976
    .. [2] https://en.wikipedia.org/wiki/U.S._Standard_Atmosphere

    """

    if h < 0.0:
        raise ValueError("Altitude cannot be less than 0 m.")

    elif h0[0] <= h < h0[1]:  # Troposphere
        T0 = T0_layers[0]
{'fraction_non_alphanumeric': 0.1496098104793757, 'fraction_numerical': 0.14983277591973243, 'mean_word_length': 1.4513661202185792, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 5, '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': '638988', 'n_tokens_mistral': 2022, 'n_tokens_neox': 1560, 'n_words': 436}