This repo is still under development. We are also actively looking for users and developers. If this sounds like you, get in touch!

Wind#

Overview#

PyFlyt supports various wind field models, as well as provides the capability for users to define their own wind field models.

Preimplemented Wind Models#

Several popular wind models are provided:

  1. Lorem Ipsum

They can be initialized in the aviary like so:

env = Aviary(..., wind_type="Lorem Ipsum")

Simple Custom Wind Modelling#

For simple, stateless wind models (models that do not have state variables), it is possible to simply define the wind model as a Python method. Then, the wind model can be hooked to the aviary using the register_wind_field_function method. The following is an example:

"""Implements a simple time invariant, stateless wind model."""
import numpy as np

from PyFlyt.core import Aviary


# define the wind field
def simple_wind(time: float, position: np.ndarray):
    """Defines a simple wind updraft model.

    Args:
        time (float): time
        position (np.ndarray): position as an (n, 3) array
    """
    # the xy velocities are 0...
    wind = np.zeros_like(position)

    # and the vertical velocity is dependent on the logarithmic of height
    wind[:, -1] = np.log(position[:, -1])

    return wind


# the starting position and orientations
start_pos = np.array([[0.0, 0.0, 1.0]])
start_orn = np.array([[0.0, 0.0, 0.0]])

# environment setup, attach the windfield
env = Aviary(start_pos=start_pos, start_orn=start_orn, render=True, drone_type="quadx")
env.register_wind_field_function(simple_wind)

# set the flight mode
env.set_mode(7)

# simulate for 1000 steps (1000/120 ~= 8 seconds)
for i in range(1000):
    env.step()

env.disconnect()

More Complex Custom Wind Modelling#

To define custom wind models, refer the the example provided by the WindFieldClass below:

class PyFlyt.core.abstractions.WindFieldClass(np_random: None | RandomState = None)#

Basic WindField class to implement custom wind field models.

Example Usage:
>>> from PyFlyt.core import Aviary
>>> from PyFlyt.core.abstractions import WindFieldClass
>>>
>>> # define the wind field
>>> class MyWindField(WindFieldClass):
>>>     def __init__(self, my_parameter=1.0, np_random: None | np.random.RandomState = None):
>>>         super().__init__(np_random)
>>>         self.strength = my_parameter
>>>
>>>     def __call__(self, time: float, position: np.ndarray):
>>>         # simulate a thermal windfield, where the xy velocities are 0,
>>>         wind = np.zeros_like(position)
>>>
>>>         # but the z velocity varies to the log of height,
>>>         wind[:, -1] = np.log(position[:, -1]) * self.strength
>>>
>>>         # plus some noise,
>>>         wind += self.np_random.randn(*wind.shape)
>>>
>>>         return wind
>>>
>>> # environment setup, attach the windfield, override the parameter `my_parameter` from the default
>>> env = Aviary(..., wind_type=MyWindField, wind_options=dict(my_parameter=1.2))
>>>
>>> # step as usual
>>> ...

Default Attributes#

property PyFlyt.core.abstractions.WindFieldClass.np_random#

dtype - np.random.RandomState

Required Methods#

PyFlyt.core.abstractions.WindFieldClass.__init__(self, np_random: None | RandomState = None)#

Initializes the wind_field.

PyFlyt.core.abstractions.DroneClass.__call__(*args, **kwargs)#

Call self as a function.