Skip to content

models.recovery

machwave.models.recovery

HemisphericalParachute

Bases: Parachute

Source code in machwave/models/recovery/parachutes.py
class HemisphericalParachute(Parachute):
    def __init__(self, diameter) -> None:
        """Initialize a HemisphericalParachute object.

        Args:
            diameter: Parachute diameter [m].
        """
        super().__init__()
        self.diameter = diameter

    @property
    def drag_coefficient(self) -> float:
        """Drag coefficient of the hemispherical parachute."""
        return 0.71

    @property
    def area(self) -> float:
        """Area of the hemispherical parachute [m^2]."""
        return get_circle_area(self.diameter)

area property

Area of the hemispherical parachute [m^2].

drag_coefficient property

Drag coefficient of the hemispherical parachute.

__init__(diameter)

Initialize a HemisphericalParachute object.

Parameters:

Name Type Description Default
diameter

Parachute diameter [m].

required
Source code in machwave/models/recovery/parachutes.py
def __init__(self, diameter) -> None:
    """Initialize a HemisphericalParachute object.

    Args:
        diameter: Parachute diameter [m].
    """
    super().__init__()
    self.diameter = diameter

Parachute

Bases: ABC

Base class for implementing different parachute geometries using the Strategy design pattern.

Subclasses should inherit from Parachute and override its methods to customize the behavior for specific parachute geometries.

Source code in machwave/models/recovery/parachutes.py
class Parachute(ABC):
    """
    Base class for implementing different parachute geometries using the
    Strategy design pattern.

    Subclasses should inherit from Parachute and override its methods to
    customize the behavior for specific parachute geometries.
    """

    def __init__(self) -> None:
        pass

    @property
    @abstractmethod
    def drag_coefficient(self) -> float:
        """
        The drag coefficient of the parachute.
        Subclasses must override this property to provide the appropriate drag
        coefficient value.
        """
        pass

    @property
    @abstractmethod
    def area(self) -> float:
        """
        The area of the parachute.
        Subclasses must override this property to provide the appropriate area
        value.
        """
        pass

area abstractmethod property

The area of the parachute. Subclasses must override this property to provide the appropriate area value.

drag_coefficient abstractmethod property

The drag coefficient of the parachute. Subclasses must override this property to provide the appropriate drag coefficient value.

Recovery

Source code in machwave/models/recovery/base.py
class Recovery:
    def __init__(self) -> None:
        """
        Initializes a Recovery object.
        """
        self.events = []

    def add_event(self, recovery_event: RecoveryEvent) -> None:
        """Add a recovery event to the list of events.

        Args:
            recovery_event: Recovery event to add.
        """
        self.events.append(recovery_event)

    def get_drag_coefficient_and_area(
        self,
        height: np.ndarray,
        time: np.ndarray,
        velocity: np.ndarray,
        propellant_mass: float,
    ) -> tuple[float, float]:
        """Calculate cumulative drag coefficient and area for active events.

        We first filter the self.events list to include only the active
        events based on the provided conditions. Then, we calculate the
        cumulative drag coefficient and area directly from the filtered list
        using list comprehension and the sum function.

        Args:
            height: Array of heights.
            time: Array of time values.
            velocity: Array of velocities.
            propellant_mass: Instant propellant mass.

        Returns:
            Cumulative drag coefficient and area.
        """
        active_events = [
            event
            for event in self.events
            if event.is_active(height, time, velocity, propellant_mass)
        ]

        drag_coefficient = sum(
            event.parachute.drag_coefficient for event in active_events
        )
        area = sum(event.parachute.area for event in active_events)

        return drag_coefficient, area

__init__()

Initializes a Recovery object.

Source code in machwave/models/recovery/base.py
def __init__(self) -> None:
    """
    Initializes a Recovery object.
    """
    self.events = []

add_event(recovery_event)

Add a recovery event to the list of events.

Parameters:

Name Type Description Default
recovery_event RecoveryEvent

Recovery event to add.

required
Source code in machwave/models/recovery/base.py
def add_event(self, recovery_event: RecoveryEvent) -> None:
    """Add a recovery event to the list of events.

    Args:
        recovery_event: Recovery event to add.
    """
    self.events.append(recovery_event)

get_drag_coefficient_and_area(height, time, velocity, propellant_mass)

Calculate cumulative drag coefficient and area for active events.

We first filter the self.events list to include only the active events based on the provided conditions. Then, we calculate the cumulative drag coefficient and area directly from the filtered list using list comprehension and the sum function.

Parameters:

Name Type Description Default
height ndarray

Array of heights.

required
time ndarray

Array of time values.

required
velocity ndarray

Array of velocities.

required
propellant_mass float

Instant propellant mass.

required

Returns:

Type Description
tuple[float, float]

Cumulative drag coefficient and area.

Source code in machwave/models/recovery/base.py
def get_drag_coefficient_and_area(
    self,
    height: np.ndarray,
    time: np.ndarray,
    velocity: np.ndarray,
    propellant_mass: float,
) -> tuple[float, float]:
    """Calculate cumulative drag coefficient and area for active events.

    We first filter the self.events list to include only the active
    events based on the provided conditions. Then, we calculate the
    cumulative drag coefficient and area directly from the filtered list
    using list comprehension and the sum function.

    Args:
        height: Array of heights.
        time: Array of time values.
        velocity: Array of velocities.
        propellant_mass: Instant propellant mass.

    Returns:
        Cumulative drag coefficient and area.
    """
    active_events = [
        event
        for event in self.events
        if event.is_active(height, time, velocity, propellant_mass)
    ]

    drag_coefficient = sum(
        event.parachute.drag_coefficient for event in active_events
    )
    area = sum(event.parachute.area for event in active_events)

    return drag_coefficient, area

RecoveryEvent

Bases: ABC

Source code in machwave/models/recovery/events.py
class RecoveryEvent(ABC):
    def __init__(self, trigger_value: float, parachute: Parachute) -> None:
        """Initialize a RecoveryEvent object.

        Args:
            trigger_value: Trigger value for the event.
            parachute: Parachute associated with the event.
        """
        self.trigger_value = trigger_value
        self.parachute = parachute

    @abstractmethod
    def is_active(
        self,
        height: np.ndarray,
        time: np.ndarray,
        velocity: np.ndarray,
        propellant_mass: np.ndarray,
    ) -> bool:
        """Check if the recovery event is active.

        Args:
            height: Array of heights.
            time: Array of time values.
            velocity: Array of velocities.
            propellant_mass: Array of propellant masses.

        Returns:
            True if the recovery event is active, False otherwise.
        """
        return False

__init__(trigger_value, parachute)

Initialize a RecoveryEvent object.

Parameters:

Name Type Description Default
trigger_value float

Trigger value for the event.

required
parachute Parachute

Parachute associated with the event.

required
Source code in machwave/models/recovery/events.py
def __init__(self, trigger_value: float, parachute: Parachute) -> None:
    """Initialize a RecoveryEvent object.

    Args:
        trigger_value: Trigger value for the event.
        parachute: Parachute associated with the event.
    """
    self.trigger_value = trigger_value
    self.parachute = parachute

is_active(height, time, velocity, propellant_mass) abstractmethod

Check if the recovery event is active.

Parameters:

Name Type Description Default
height ndarray

Array of heights.

required
time ndarray

Array of time values.

required
velocity ndarray

Array of velocities.

required
propellant_mass ndarray

Array of propellant masses.

required

Returns:

Type Description
bool

True if the recovery event is active, False otherwise.

Source code in machwave/models/recovery/events.py
@abstractmethod
def is_active(
    self,
    height: np.ndarray,
    time: np.ndarray,
    velocity: np.ndarray,
    propellant_mass: np.ndarray,
) -> bool:
    """Check if the recovery event is active.

    Args:
        height: Array of heights.
        time: Array of time values.
        velocity: Array of velocities.
        propellant_mass: Array of propellant masses.

    Returns:
        True if the recovery event is active, False otherwise.
    """
    return False

ToroidalParachute

Bases: Parachute

Source code in machwave/models/recovery/parachutes.py
class ToroidalParachute(Parachute):
    def __init__(self, major_radius: float, minor_radius: float) -> None:
        """Initialize a ToroidalParachute object.

        Args:
            major_radius: Major radius of the toroidal parachute [m].
            minor_radius: Minor radius of the toroidal parachute [m].
        """
        super().__init__()
        self.major_radius = major_radius
        self.minor_radius = minor_radius

    @property
    def drag_coefficient(self) -> float:
        """Drag coefficient of the toroidal parachute."""
        return 0.85

    @property
    def area(self) -> float:
        """Area of the toroidal parachute [m^2]."""
        return get_torus_area(self.major_radius, self.minor_radius)

area property

Area of the toroidal parachute [m^2].

drag_coefficient property

Drag coefficient of the toroidal parachute.

__init__(major_radius, minor_radius)

Initialize a ToroidalParachute object.

Parameters:

Name Type Description Default
major_radius float

Major radius of the toroidal parachute [m].

required
minor_radius float

Minor radius of the toroidal parachute [m].

required
Source code in machwave/models/recovery/parachutes.py
def __init__(self, major_radius: float, minor_radius: float) -> None:
    """Initialize a ToroidalParachute object.

    Args:
        major_radius: Major radius of the toroidal parachute [m].
        minor_radius: Minor radius of the toroidal parachute [m].
    """
    super().__init__()
    self.major_radius = major_radius
    self.minor_radius = minor_radius