Skip to content

models.atmosphere

machwave.models.atmosphere

Atmosphere

Bases: ABC

Abstract class that represents an atmospheric model.

Source code in machwave/models/atmosphere/base.py
class Atmosphere(ABC):
    """Abstract class that represents an atmospheric model."""

    SEA_LEVEL_PRESSURE: float = 101325.0  # Pa
    SEA_LEVEL_DENSITY: float = 1.225  # kg/m³
    SEA_LEVEL_TEMPERATURE: float = 288.15  # K
    SEA_LEVEL_SONIC_VELOCITY: float = 340.29  # m/s
    SEA_LEVEL_VISCOSITY: float = 1.7894e-5  # Pa·s
    SEA_LEVEL_GRAVITY: float = 9.80665  # m/s²

    @abstractmethod
    def get_density(self, y_amsl: float) -> float:
        """
        Get the air density at the given altitude above mean sea level (AMSL).

        Args:
            y_amsl: Altitude above mean sea level in meters.

        Returns:
            Air density in kg/m^3.
        """

    @abstractmethod
    def get_gravity(self, y_amsl: float) -> float:
        """
        Get the acceleration due to gravity at the given altitude above mean
        sea level (AMSL).

        Args:
            y_amsl: Altitude above mean sea level in meters.

        Returns:
            Acceleration due to gravity in m/s^2.
        """

    @abstractmethod
    def get_pressure(self, y_amsl: float) -> float:
        """
        Get the air pressure at the given altitude above mean sea level (AMSL).

        Args:
            y_amsl: Altitude above mean sea level in meters.

        Returns:
            Air pressure in Pascal (Pa).
        """

    @abstractmethod
    def get_sonic_velocity(self, y_amsl: float) -> float:
        """
        Get the speed of sound in air at the given altitude above mean sea
        level (AMSL).

        Args:
            y_amsl: Altitude above mean sea level in meters.

        Returns:
            Speed of sound in m/s.
        """

    @abstractmethod
    def get_wind_velocity(self, y_amsl: float) -> tuple[float, float]:
        """
        Get the wind velocity components at the given altitude above mean
        sea level (AMSL).

        Args:
            y_amsl: Altitude above mean sea level in meters.

        Returns:
            Wind velocity components (Northward, Eastward) in m/s.
        """

    @abstractmethod
    def get_viscosity(self, y_amsl: float) -> float:
        """
        Get the dynamic viscosity of air at the given altitude above mean sea
        level (AMSL).

        Args:
            y_amsl: Altitude above mean sea level in meters.

        Returns:
            Dynamic viscosity of air in Pascal-second (Pa-s).
        """

get_density(y_amsl) abstractmethod

Get the air density at the given altitude above mean sea level (AMSL).

Parameters:

Name Type Description Default
y_amsl float

Altitude above mean sea level in meters.

required

Returns:

Type Description
float

Air density in kg/m^3.

Source code in machwave/models/atmosphere/base.py
@abstractmethod
def get_density(self, y_amsl: float) -> float:
    """
    Get the air density at the given altitude above mean sea level (AMSL).

    Args:
        y_amsl: Altitude above mean sea level in meters.

    Returns:
        Air density in kg/m^3.
    """

get_gravity(y_amsl) abstractmethod

Get the acceleration due to gravity at the given altitude above mean sea level (AMSL).

Parameters:

Name Type Description Default
y_amsl float

Altitude above mean sea level in meters.

required

Returns:

Type Description
float

Acceleration due to gravity in m/s^2.

Source code in machwave/models/atmosphere/base.py
@abstractmethod
def get_gravity(self, y_amsl: float) -> float:
    """
    Get the acceleration due to gravity at the given altitude above mean
    sea level (AMSL).

    Args:
        y_amsl: Altitude above mean sea level in meters.

    Returns:
        Acceleration due to gravity in m/s^2.
    """

get_pressure(y_amsl) abstractmethod

Get the air pressure at the given altitude above mean sea level (AMSL).

Parameters:

Name Type Description Default
y_amsl float

Altitude above mean sea level in meters.

required

Returns:

Type Description
float

Air pressure in Pascal (Pa).

Source code in machwave/models/atmosphere/base.py
@abstractmethod
def get_pressure(self, y_amsl: float) -> float:
    """
    Get the air pressure at the given altitude above mean sea level (AMSL).

    Args:
        y_amsl: Altitude above mean sea level in meters.

    Returns:
        Air pressure in Pascal (Pa).
    """

get_sonic_velocity(y_amsl) abstractmethod

Get the speed of sound in air at the given altitude above mean sea level (AMSL).

Parameters:

Name Type Description Default
y_amsl float

Altitude above mean sea level in meters.

required

Returns:

Type Description
float

Speed of sound in m/s.

Source code in machwave/models/atmosphere/base.py
@abstractmethod
def get_sonic_velocity(self, y_amsl: float) -> float:
    """
    Get the speed of sound in air at the given altitude above mean sea
    level (AMSL).

    Args:
        y_amsl: Altitude above mean sea level in meters.

    Returns:
        Speed of sound in m/s.
    """

get_viscosity(y_amsl) abstractmethod

Get the dynamic viscosity of air at the given altitude above mean sea level (AMSL).

Parameters:

Name Type Description Default
y_amsl float

Altitude above mean sea level in meters.

required

Returns:

Type Description
float

Dynamic viscosity of air in Pascal-second (Pa-s).

Source code in machwave/models/atmosphere/base.py
@abstractmethod
def get_viscosity(self, y_amsl: float) -> float:
    """
    Get the dynamic viscosity of air at the given altitude above mean sea
    level (AMSL).

    Args:
        y_amsl: Altitude above mean sea level in meters.

    Returns:
        Dynamic viscosity of air in Pascal-second (Pa-s).
    """

get_wind_velocity(y_amsl) abstractmethod

Get the wind velocity components at the given altitude above mean sea level (AMSL).

Parameters:

Name Type Description Default
y_amsl float

Altitude above mean sea level in meters.

required

Returns:

Type Description
tuple[float, float]

Wind velocity components (Northward, Eastward) in m/s.

Source code in machwave/models/atmosphere/base.py
@abstractmethod
def get_wind_velocity(self, y_amsl: float) -> tuple[float, float]:
    """
    Get the wind velocity components at the given altitude above mean
    sea level (AMSL).

    Args:
        y_amsl: Altitude above mean sea level in meters.

    Returns:
        Wind velocity components (Northward, Eastward) in m/s.
    """

Atmosphere1976

Bases: Atmosphere

Atmospheric model based on the 1976 Standard Atmosphere. This model uses the fluids library to calculate the properties of the atmosphere.

Source code in machwave/models/atmosphere/atm_1976.py
class Atmosphere1976(Atmosphere):
    """
    Atmospheric model based on the 1976 Standard Atmosphere. This model uses
    the fluids library to calculate the properties of the atmosphere.
    """

    def get_density(self, y_amsl: float) -> float:
        return ATMOSPHERE_1976(y_amsl).rho  # type: ignore

    def get_gravity(self, y_amsl: float) -> float:
        return ATMOSPHERE_1976.gravity(y_amsl)

    def get_pressure(self, y_amsl: float) -> float:
        return self.SEA_LEVEL_PRESSURE + ATMOSPHERE_1976.pressure_integral(
            self.SEA_LEVEL_TEMPERATURE, self.SEA_LEVEL_PRESSURE, y_amsl
        )

    def get_sonic_velocity(self, y_amsl: float) -> float:
        return ATMOSPHERE_1976.sonic_velocity(y_amsl)

    def get_wind_velocity(self, y_amsl: float) -> tuple[float, float]:
        """
        7 m/s wind velocity in both x and y directions.
        """
        return (7, 7)

    def get_viscosity(self, y_amsl: float) -> float:
        return ATMOSPHERE_1976.viscosity(y_amsl)

get_wind_velocity(y_amsl)

7 m/s wind velocity in both x and y directions.

Source code in machwave/models/atmosphere/atm_1976.py
def get_wind_velocity(self, y_amsl: float) -> tuple[float, float]:
    """
    7 m/s wind velocity in both x and y directions.
    """
    return (7, 7)

Atmosphere1976WindPowerLaw

Bases: Atmosphere1976

Atmospheric model based on the 1976 Standard Atmosphere, using a power-law model for wind velocity variation with altitude.

Source code in machwave/models/atmosphere/atm_1976.py
class Atmosphere1976WindPowerLaw(Atmosphere1976):
    """
    Atmospheric model based on the 1976 Standard Atmosphere, using a power-law
    model for wind velocity variation with altitude.
    """

    def __init__(self, v_ref: float, z_ref: float, alpha: float, direction_deg: float):
        """
        Initialize the atmosphere model with power-law wind parameters.

        Args:
            v_ref: Wind speed at the reference height (in m/s).
            z_ref: Reference height (in meters) where the wind speed is known.
            alpha: Wind shear exponent.
            direction_deg: Wind direction in degrees (0° is North, 90° is East).
        """
        super().__init__()

        if z_ref == 0:
            raise ValueError("Please provide a non-zero reference height 'z_ref'.")

        self.v_ref = v_ref
        self.z_ref = z_ref
        self.alpha = alpha
        self.direction_deg = direction_deg

    def get_wind_velocity(self, y_amsl: float) -> tuple[float, float]:
        """
        Get the wind velocity components at the given altitude above mean sea level (AMSL)
        using the power law.

        Args:
            y_amsl: Altitude above mean sea level in meters.

        Returns:
            Wind velocity components (Northward, Eastward) in m/s.
        """
        if y_amsl <= 0:
            y_amsl = self.z_ref

        wind_speed = self.v_ref * (y_amsl / self.z_ref) ** self.alpha

        direction_rad = np.radians(self.direction_deg)

        v_northward = wind_speed * np.cos(direction_rad)
        v_eastward = wind_speed * np.sin(direction_rad)

        return v_northward, v_eastward

__init__(v_ref, z_ref, alpha, direction_deg)

Initialize the atmosphere model with power-law wind parameters.

Parameters:

Name Type Description Default
v_ref float

Wind speed at the reference height (in m/s).

required
z_ref float

Reference height (in meters) where the wind speed is known.

required
alpha float

Wind shear exponent.

required
direction_deg float

Wind direction in degrees (0° is North, 90° is East).

required
Source code in machwave/models/atmosphere/atm_1976.py
def __init__(self, v_ref: float, z_ref: float, alpha: float, direction_deg: float):
    """
    Initialize the atmosphere model with power-law wind parameters.

    Args:
        v_ref: Wind speed at the reference height (in m/s).
        z_ref: Reference height (in meters) where the wind speed is known.
        alpha: Wind shear exponent.
        direction_deg: Wind direction in degrees (0° is North, 90° is East).
    """
    super().__init__()

    if z_ref == 0:
        raise ValueError("Please provide a non-zero reference height 'z_ref'.")

    self.v_ref = v_ref
    self.z_ref = z_ref
    self.alpha = alpha
    self.direction_deg = direction_deg

get_wind_velocity(y_amsl)

Get the wind velocity components at the given altitude above mean sea level (AMSL) using the power law.

Parameters:

Name Type Description Default
y_amsl float

Altitude above mean sea level in meters.

required

Returns:

Type Description
tuple[float, float]

Wind velocity components (Northward, Eastward) in m/s.

Source code in machwave/models/atmosphere/atm_1976.py
def get_wind_velocity(self, y_amsl: float) -> tuple[float, float]:
    """
    Get the wind velocity components at the given altitude above mean sea level (AMSL)
    using the power law.

    Args:
        y_amsl: Altitude above mean sea level in meters.

    Returns:
        Wind velocity components (Northward, Eastward) in m/s.
    """
    if y_amsl <= 0:
        y_amsl = self.z_ref

    wind_speed = self.v_ref * (y_amsl / self.z_ref) ** self.alpha

    direction_rad = np.radians(self.direction_deg)

    v_northward = wind_speed * np.cos(direction_rad)
    v_eastward = wind_speed * np.sin(direction_rad)

    return v_northward, v_eastward