voyager/models.py
def run(self, vessel: Vessel) -> Vessel:
        """Calculates the trajectory of a vessel object in space over time.

        Trajectories are calculated by estimating the displacement in km from a position in
        (longitude, latitude) coordinates, and converting the displacement back to (longitude, latitude).

        Simulation is stopped when the vessel encounters NaN, indicating land or area outside the simulation region.

        Assumes a spherical Earth.

        Args:
            vessel (Vessel): Vessel object with initial position

        Returns:
            Vessel: A modified vessel object with full trajectory
        """

        # Set random seed
        # Important, otherwise all virtual threads will return the same result
        np.random.seed()

        longitude = vessel.x
        latitude  = vessel.y

        # Constant
        N_SECONDS_IN_DAY = 86400

        # Initialization
        dx = 0
        dy = 0

        target_tol = (self.dt) * self.tolerance # 1/1000 is a good value

        # The type of displacement is handled by the vessel mode of traversal
        displacement = Displacement(vessel, self.dt)

        for t in np.arange(start=0, stop=self.duration, step=self.dt/N_SECONDS_IN_DAY):
            
            # Calculate interpolated velocity at current coordinates
            c, w = self.velocity(t, longitude, latitude)

            # If return is None, we have reached land
            if c is None or w is None:
                break

            # Calculate displacement
            dx, dy = displacement.move(c, w)\
                                 .with_uncertainty(sigma=self.sigma)\
                                 .km()
               
            # print(dx, dy)
            # Calculate new longitude, latitude from displacement
            # Using great circle distances
            longitude, latitude = displacement.to_lonlat(dx, dy, longitude, latitude)

            # Update vessel data
            vessel.update_distance(dx, dy)\
                  .update_position(longitude, latitude)\
                  .update_mean_speed(self.dt)

            # Check progress along route
            is_arrived = vessel.has_arrived(longitude, latitude, target_tol)

            if is_arrived:
                break

        return vessel
Calculates the trajectory of a vessel object in space over time.

        Trajectories are calculated by estimating the displacement in km from a position in
        (longitude, latitude) coordinates, and converting the displacement back to (longitude, latitude).

        Simulation is stopped when the vessel encounters NaN, indicating land or area outside the simulation region.

        Assumes a spherical Earth.

        Args:
            vessel (Vessel): Vessel object with initial position

        Returns:
            Vessel: A modified vessel object with full trajectory
        
Calculates the trajectory of a vessel object in space over time.
Trajectories are calculated by estimating the displacement in km from a position in
(longitude, latitude) coordinates, and converting the displacement back to (longitude, latitude).

Simulation is stopped when the vessel encounters NaN, indicating land or area outside the simulation region.

Assumes a spherical Earth.
Calculates the trajectory of a vessel object in space over time . Trajectories are calculated by estimating the displacement in km from a position in ( longitude latitude ) coordinates and converting the displacement back to ( longitude latitude ) . Simulation is stopped when the vessel encounters NaN indicating land or area outside the simulation region . Assumes a spherical Earth .
def run(self, vessel: Vessel) -> Vessel:
        np.random.seed()
        longitude = vessel.x
        latitude  = vessel.y
        N_SECONDS_IN_DAY = 86400
        dx = 0
        dy = 0
        target_tol = (self.dt) * self.tolerance 
        displacement = Displacement(vessel, self.dt)
        for t in np.arange(start=0, stop=self.duration, step=self.dt/N_SECONDS_IN_DAY):
            c, w = self.velocity(t, longitude, latitude)
            if c is None or w is None:
                break
            dx, dy = displacement.move(c, w)\
                                 .with_uncertainty(sigma=self.sigma)\
                                 .km()
            longitude, latitude = displacement.to_lonlat(dx, dy, longitude, latitude)
            vessel.update_distance(dx, dy)\
                  .update_position(longitude, latitude)\
                  .update_mean_speed(self.dt)
            is_arrived = vessel.has_arrived(longitude, latitude, target_tol)
            if is_arrived:
                break
        return vessel
def run ( self , vessel : Vessel ) -> Vessel : np . random . seed ( ) longitude = vessel . x latitude = vessel . y N_SECONDS_IN_DAY = 86400 dx = 0 dy = 0 target_tol = ( self . dt ) * self . tolerance displacement = Displacement ( vessel , self . dt ) for t in np . arange ( start = 0 , stop = self . duration , step = self . dt / N_SECONDS_IN_DAY ) : c , w = self . velocity ( t , longitude , latitude ) if c is None or w is None : break dx , dy = displacement . move ( c , w ) . with_uncertainty ( sigma = self . sigma ) . km ( ) longitude , latitude = displacement . to_lonlat ( dx , dy , longitude , latitude ) vessel . update_distance ( dx , dy ) . update_position ( longitude , latitude ) . update_mean_speed ( self . dt ) is_arrived = vessel . has_arrived ( longitude , latitude , target_tol ) if is_arrived : break return vessel
Calculates the trajectory of a vessel object in space over time.
Calculates the trajectory of a vessel object in space over time .
"""Calculates the trajectory of a vessel object in space over time.

        Trajectories are calculated by estimating the displacement in km from a position in
        (longitude, latitude) coordinates, and converting the displacement back to (longitude, latitude).

        Simulation is stopped when the vessel encounters NaN, indicating land or area outside the simulation region.

        Assumes a spherical Earth.

        Args:
            vessel (Vessel): Vessel object with initial position

        Returns:
            Vessel: A modified vessel object with full trajectory
        """ # Set random seed # Important, otherwise all virtual threads will return the same result # Constant # Initialization # 1/1000 is a good value # The type of displacement is handled by the vessel mode of traversal # Calculate interpolated velocity at current coordinates # If return is None, we have reached land # Calculate displacement # print(dx, dy) # Calculate new longitude, latitude from displacement # Using great circle distances # Update vessel data # Check progress along route
A modified vessel object with full trajectory
A modified vessel object with full trajectory
Vessel
self
vessel
Vessel
Vessel object with initial position
Vessel object with initial position