Pattern¶
Pattern is the reusable container that sits
between the flight-pattern generators and campaign/planning workflows.
Pattern generators such as
racetrack()andspiral()returnPatterninstances.Line-based patterns store ordered
FlightLineobjects.Waypoint-based patterns store ordered
Waypointobjects.compute_flight_plan()acceptsPatternobjects directly and expands them into their underlying elements.Campaignassigns stablepattern_idandline_idvalues when a pattern is added to a campaign.
Pattern class¶
- class Pattern[source]¶
Bases:
objectA named, parameterized pattern within a campaign.
- Variables:
pattern_id – Stable identifier assigned by the owning Campaign. Empty string for patterns not yet added to a campaign.
kind – Generator kind (“rosette”, “racetrack”, “polygon”, “sawtooth”, “spiral”).
name – Human-readable name.
params – Generator parameters as a plain-JSON-compatible dict (lengths/altitudes in meters). Sufficient to regenerate.
lines – Ordered mapping of line_id -> FlightLine for line-based patterns. Empty for waypoint-based patterns.
waypoints – Ordered list of Waypoints for continuous patterns. Empty for line-based patterns.
- lines: dict[str, FlightLine]¶
- elements()[source]¶
Return the ordered flight lines or waypoints for this pattern.
- Return type:
list[FlightLine] |list[Waypoint]
- property entry_waypoint: Waypoint¶
Waypoint where this pattern’s traversal begins.
For line-based patterns, this is the start of the first leg (
self.lines[first_line_id].waypoint1). For waypoint-based patterns, this is the first element ofself.waypoints.Used by the flight-line optimizer to compute transit-in cost when scheduling this pattern in a sortie.
- Raises:
HyPlanValueError – If the pattern has no elements (empty
linesand emptywaypoints).
- property exit_waypoint: Waypoint¶
Waypoint where this pattern’s traversal ends.
For line-based patterns, this is the end of the last leg (
self.lines[last_line_id].waypoint2). For waypoint-based patterns, this is the last element ofself.waypoints.Used by the flight-line optimizer to compute transit-out cost when scheduling this pattern in a sortie.
- Raises:
HyPlanValueError – If the pattern has no elements (empty
linesand emptywaypoints).
- replace_line(line_id, line)[source]¶
Replace a line in place, preserving its ID and pattern membership.
- Return type:
- Parameters:
line_id (str)
line (FlightLine)
- to_geojson()[source]¶
Return a GeoJSON FeatureCollection of this pattern’s elements.
Line-based patterns yield one LineString feature per leg (with
line_idandpattern_idin properties). Waypoint-based patterns yield one Point feature per waypoint plus one LineString for the connecting track.
- regenerate(**overrides)[source]¶
Return a new Pattern by re-invoking the generator with params.
Keyword overrides are merged into
paramsfor the regeneration call. Overrides may use either the stored params spelling (radius_m=50_000) or the generator-style name with pint-aware units (radius=50 * ureg.km); unknown keys raiseHyPlanValueError. The returned Pattern is not yet added to a campaign; useCampaign.replace_pattern()to swap it in.
- translate(offset_north, offset_east)[source]¶
Return a new Pattern shifted by the given N/E offsets.
Every contained
FlightLineandWaypointis moved by the same geodetic N/E offset (delegating to each element’s existingoffset_north_eastmethod). The pattern’s storedcenter_lat/center_lonparams are updated to match so a subsequentregenerate()produces the same geometry.- Parameters:
- Return type:
- Returns:
A new Pattern at the translated position. The original is unchanged.
- move_to(latitude, longitude)[source]¶
Return a new Pattern re-anchored at the given centre.
For built-in generator patterns (those whose
paramscarrycenter_lat/center_lon), the new pattern is produced byregenerate()at the new centre — exact, regardless of displacement size. For ad-hoc patterns, computes the geodetic N/E delta from the pattern centroid to(latitude, longitude)and delegates totranslate().
- rotate(angle_deg, around=None)[source]¶
Return a new Pattern rotated by
angle_deg(compass CW).Each element is rotated about
around(the pattern’s centre by default). Headings on every containedWaypointandFlightLineare shifted by the same angle.params["heading"]is also shifted if present, so a subsequentregenerate()produces matching geometry.
- classmethod from_relative(anchor, *, bearing, distance, generator, **generator_kwargs)[source]¶
Build a pattern centred at a geodesic offset from an anchor.
Combines
Waypoint.relative_to()with a pattern generator: computes the offset point fromanchoralongbearingfordistance, then callsgeneratorwith that point as thecenterkeyword. All other kwargs are forwarded to the generator unchanged.- Parameters:
anchor (
Waypoint|tuple[float,float]) – AWaypointor(latitude, longitude)tuple.bearing (
float) – Initial true bearing fromanchor(compass deg).distance (
Quantity) – Geodesic distance as a pintQuantitywith length units (matchesWaypoint.relative_to(), which rejects bare numbers).generator (
Callable[...,Pattern]) – A pattern generator fromhyplan.flight_patterns(e.g.racetrack,rosette,polygon,sawtooth,spiral).**generator_kwargs (
Any) – Forwarded togenerator(e.g.heading,altitude,leg_length,n_legs).
- Return type:
- Returns:
The Pattern produced by
generator(center=offset, ...).
Example
>>> from hyplan.units import ureg >>> from hyplan.flight_patterns import racetrack >>> from hyplan.waypoint import Waypoint >>> from hyplan.pattern import Pattern >>> edw = Waypoint(34.92, -117.87, heading=0, name="EDW") >>> pattern = Pattern.from_relative( ... edw, ... bearing=90, ... distance=200 * ureg.nautical_mile, # 200 nmi east ... generator=racetrack, ... heading=0, ... altitude=35_000 * ureg.foot, ... leg_length=10 * ureg.nautical_mile, ... n_legs=5, ... )