trafficgen.encounter module
Functions to generate encounters consisting of one own ship and one to many target ships. The generated encounters may be of type head-on, overtaking give-way and stand-on and crossing give-way and stand-on.
- trafficgen.encounter.assign_beta(encounter_type: EncounterType, settings: EncounterSettings) float [source]
Assign random (uniform) relative bearing beta between own ship and target ship depending on type of encounter.
- Params:
encounter_type: Type of encounter
settings: Encounter settings
- Return type:
* Relative bearing between own ship and target ship seen from own ship [rad]
- trafficgen.encounter.assign_beta_from_list(beta_limit: List[float]) float [source]
Assign random (uniform) relative bearing beta between own ship and target ship depending between the limits given by beta_limit.
- Params:
beta_limit: Limits for beta
- Return type:
* Relative bearing between own ship and target ship seen from own ship [rad]
- trafficgen.encounter.assign_future_position_to_target_ship(own_ship_position_future: Position, lat_lon0: Position, max_meeting_distance: float) Position [source]
Randomly assign future position of target ship. If drawing a circle with radius max_meeting_distance around future position of own ship, future position of target ship shall be somewhere inside this circle.
- Params:
- own_ship_position_future: Dict, own ship position at a given time in the
future, {north, east}
lat_lon0: Reference point, latitudinal [rad] and longitudinal [rad]
- max_meeting_distance: Maximum distance between own ship and target ship at
a given time in the future [m]
- Returns:
future_position_target_ship
- Return type:
Future position of target ship {north, east} [m]
- trafficgen.encounter.assign_sog_to_target_ship(encounter_type: EncounterType, own_ship_sog: float, min_target_ship_sog: float, relative_sog_setting: EncounterRelativeSpeed)[source]
Assign random (uniform) sog to target ship depending on type of encounter.
- Params:
encounter_type: Type of encounter
own_ship_sog: Own ship sog [m/s]
min_target_ship_sog: Minimum target ship sog [m/s]
relative_sog_setting: Relative sog setting dependent on encounter [-]
- Returns:
* target_ship_sog
- Return type:
Target ship sog [m/s]
- trafficgen.encounter.assign_vector_time(vector_time_range: List[float])[source]
Assign random (uniform) vector time.
- Params:
vector_range: Minimum and maximum value for vector time
- Returns:
* vector_time
- Return type:
Vector time [min]
- trafficgen.encounter.calculate_min_vector_length_target_ship(own_ship_position: Position, own_ship_cog: float, target_ship_position_future: Position, desired_beta: float, lat_lon0: Position) float [source]
Calculate minimum vector length (target ship sog x vector). This will ensure that ship sog is high enough to find proper situation.
- Params:
own_ship_position: Own ship initial position, latitudinal [rad] and longitudinal [rad]
own_ship_cog: Own ship initial cog
target_ship_position_future: Target ship future position
desired_beta: Desired relative bearing between
lat_lon0: Reference point, latitudinal [rad] and longitudinal [rad]
- Returns:
* min_vector_length
- Return type:
Minimum vector length (target ship sog x vector)
- trafficgen.encounter.calculate_relative_bearing(position_own_ship: Position, heading_own_ship: float, position_target_ship: Position, heading_target_ship: float, lat_lon0: Position) Tuple[float, float] [source]
Calculate relative bearing between own ship and target ship, both seen from own ship and seen from target ship.
- Params:
position_own_ship: Own ship position {latitude, longitude} [rad]
heading_own_ship: Own ship heading [rad]
position_target_ship: Target ship position {latitude, longitude} [rad]
heading_target_ship: Target ship heading [rad]
lat_lon0: Reference point, latitudinal [rad] and longitudinal [rad]
- Returns:
* beta (relative bearing between own ship and target ship seen from own ship [rad])
* alpha (relative bearing between target ship and own ship seen from target ship [rad])
- trafficgen.encounter.calculate_ship_cog(pos_0: Position, pos_1: Position, lat_lon0: Position) float [source]
Calculate ship cog between two waypoints.
- Params:
waypoint_0: Dict, waypoint {latitude, longitude} [rad]
waypoint_1: Dict, waypoint {latitude, longitude} [rad]
- Returns:
* cog
- Return type:
Ship cog [rad]
- trafficgen.encounter.check_encounter_evolvement(own_ship: OwnShip, own_ship_cog: float, own_ship_position_future: Position, lat_lon0: Position, target_ship_sog: float, target_ship_cog: float, target_ship_position_future: Position, desired_encounter_type: EncounterType, settings: EncounterSettings) bool [source]
Check encounter evolvement. The generated encounter should be the same type of encounter (head-on, crossing, give-way) also some time before the encounter is started.
- Params:
own_ship: Own ship information such as initial position, sog and cog
target_ship: Target ship information such as initial position, sog and cog
desired_encounter_type: Desired type of encounter to be generated
settings: Encounter settings
- Return type:
* returns True if encounter ok, False if encounter not ok
- trafficgen.encounter.decide_target_ship(target_ships_static: List[ShipStatic]) ShipStatic [source]
Randomly pick a target ship from a list of target ships.
- Params:
target_ships: list of target ships with static information
- Return type:
* The target ship, info of type, size etc.
- trafficgen.encounter.define_own_ship(desired_traffic_situation: SituationInput, own_ship_static: ShipStatic, encounter_settings: EncounterSettings, lat_lon0: Position) OwnShip [source]
Define own ship based on information in desired traffic situation.
- Params:
desired_traffic_situation: Information about type of traffic situation to generate
own_ship_static: Static information of own ship.
encounter_settings: Necessary setting for the encounter
lat_lon0: Reference position [deg]
- Returns:
* own_ship
- Return type:
Own ship
- trafficgen.encounter.determine_colreg(alpha: float, beta: float, theta13_criteria: float, theta14_criteria: float, theta15_criteria: float, theta15: List[float]) EncounterType [source]
Determine the colreg type based on alpha, relative bearing between target ship and own ship seen from target ship, and beta, relative bearing between own ship and target ship seen from own ship.
- Params:
alpha: relative bearing between target ship and own ship seen from target ship
beta: relative bearing between own ship and target ship seen from own ship
theta13_criteria: Tolerance for “coming up with” relative bearing
theta14_criteria: Tolerance for “reciprocal or nearly reciprocal cogs”, “when in any doubt… assume… [head-on]”
theta15_criteria: Crossing aspect limit, used for classifying a crossing encounter
- theta15: 22.5 deg aft of the beam, used for classifying a crossing and an overtaking
encounter
- Return type:
* encounter classification
- trafficgen.encounter.find_start_position_target_ship(own_ship_position: Position, lat_lon0: Position, own_ship_cog: float, target_ship_position_future: Position, target_ship_vector_length: float, desired_beta: float, desired_encounter_type: EncounterType, settings: EncounterSettings) Tuple[Position, bool] [source]
Find start position of target ship using desired beta and vector length.
- Params:
own_ship_position: Own ship initial position, sog and cog
own_ship_cog: Own ship initial cog
target_ship_position_future: Target ship future position
target_ship_vector_length: vector length (target ship sog x vector)
desired_beta: Desired bearing between own ship and target ship seen from own ship
desired_encounter_type: Desired type of encounter to be generated
settings: Encounter settings
- Returns:
* start_position_target_ship (Dict, initial position of target ship {north, east} [m])
* start_position_found (0=position not found, 1=position found)
- trafficgen.encounter.generate_encounter(desired_encounter_type: EncounterType, own_ship: OwnShip, target_ships_static: List[ShipStatic], encounter_number: int, beta_default: List[float] | float | None, relative_sog_default: float | None, vector_time_default: float | None, settings: EncounterSettings) Tuple[TargetShip, bool] [source]
Generate an encounter.
- Params:
desired_encounter_type: Desired encounter to be generated
own_ship: Dict, information about own ship that will encounter a target ship
target_ships_static: List of target ships including static information that may be used in an encounter
encounter_number: Integer, used to naming the target ships. target_ship_1,2 etc.
beta_default: User defined beta. If not set, this is None.
- relative_sog_default: User defined relative sog between own ship and
target ship. If not set, this is None.
vector_time_default: User defined vector time. If not set, this is None.
settings: Encounter settings
- Returns:
* target_ship (target ship information, such as initial position, sog and cog)
* encounter_found (True=encounter found, False=encounter not found)