Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# np.nanargmax seems bugged with timestamps
argmax = np.where(diff == max_)[0][0]
yield from _split(data.iloc[:argmax], value, unit)
yield from _split(data.iloc[argmax:], value, unit) # noqa
else:
yield data
# flake B008
attrgetter_duration = attrgetter("duration")
# flake B006
default_angle_features = ["track", "heading"]
class Position(PointMixin, pd.core.series.Series):
def plot(
self, ax: Axes, text_kw=None, shift=None, **kwargs
) -> List[Artist]: # coverage: ignore
visualdict = dict(s=300)
if hasattr(self, "track"):
visualdict["marker"] = rotate_marker(aircraft_marker, self.track)
if "s" not in text_kw and hasattr(self, "callsign"):
text_kw["s"] = self.callsign
return super().plot(ax, text_kw, shift, **{**visualdict, **kwargs})
class Flight(HBoxMixin, GeographyMixin, ShapelyMixin, NavigationFeatures):
"""Flight is the most basic class associated to a trajectory.
def point(self) -> PointMixin:
p = PointMixin()
p.longitude, p.latitude = list(self.centroid.coords)[0]
return p
icao: str
latitude: float
longitude: float
name: str
class AirportPoint(PointMixin):
def plot(
self, ax: Axes, text_kw=None, shift=None, **kwargs
) -> List[Artist]: # coverage: ignore
return super().plot(
ax, text_kw, shift, **{**{"marker": atc_tower, "s": 400}, **kwargs}
)
class Airport(HBoxMixin, AirportNamedTuple, PointMixin, ShapelyMixin):
def __repr__(self) -> str:
short_name = (
self.name.replace("International", "")
.replace("Airport", "")
.strip()
)
return f"{self.icao}/{self.iata}: {short_name}"
def _repr_html_(self) -> str:
title = f"<b>{self.name.strip()}</b> ({self.country}) "
title += f"<code>{self.icao}/{self.iata}</code>"
no_wrap_div = '<div style="white-space: nowrap">{}</div>'
return title + no_wrap_div.format(self._repr_svg_())
def __getattr__(self, name) -> Dict[str, Any]:
if not name.startswith("osm_"):
def __init__(self, json):
for _, value in json.items():
self.shape = Polygon(
[(lon, lat) for (deg, lat, lon) in value[0]["ranges"]]
)
self.point = PointMixin()
self.point.latitude, self.point.longitude = value[0][
"sensorPosition"
]
self.point.name = value[0]["serial"]
import warnings
from functools import lru_cache
from typing import Any, Dict, List, Optional, Union, cast
from cartopy.crs import PlateCarree
from cartopy.mpl.geoaxes import GeoAxesSubplot
from matplotlib.artist import Artist
from shapely.geometry import LineString
from shapely.ops import linemerge
from ..drawing import markers
from .mixins import PointMixin, ShapelyMixin
from .structure import Airport, Navaid, Route
class _Point(PointMixin):
def __init__(self, lat: float, lon: float, name: str):
super().__init__()
self.latitude = lat
self.longitude = lon
self.name = name
def __repr__(self):
return f"{self.name} ({self.latitude:.4}, {self.longitude:.4})"
class _ElementaryBlock:
pattern: str
def __init__(self, *args) -> None:
self.elt = args
type: str
latitude: float
longitude: float
altitude: float
frequency: Optional[float]
magnetic_variation: Optional[float]
description: Optional[str]
def __getstate__(self):
return self.__dict__
def __setstate__(self, d):
self.__dict__.update(d)
class Navaid(NavaidTuple, PointMixin):
def __getattr__(self, name):
if name == "lat":
return self.latitude
if name == "lon":
return self.longitude
if name == "alt":
return self.altitude
def __repr__(self):
if self.type not in {"DME", "NDB", "TACAN", "VOR"}:
return (
f"{self.name} ({self.type}): {self.latitude} {self.longitude}"
)
else:
return (
f"{self.name} ({self.type}): {self.latitude} {self.longitude}"
def map_add_layer(_map, elt, **kwargs):
if any(
isinstance(elt, c) for c in (Flight, FlightPlan, Airspace, PointMixin)
):
layer = elt.leaflet(**kwargs)
_old_add_layer(_map, layer)
return layer
return _old_add_layer(_map, elt)
from ... import cache_expiration
from ...core.geodesy import bearing, destination
from ...core.mixins import HBoxMixin, PointMixin, ShapelyMixin
__github_url = "https://raw.githubusercontent.com/"
base_url = __github_url + "ProfHoekstra/bluesky/master/data/navdata"
class ThresholdTuple(NamedTuple):
latitude: float
longitude: float
bearing: float
name: str
class Threshold(ThresholdTuple, PointMixin):
def __repr__(self):
return f"Runway {self.name}: {self.latlon}"
RunwaysType = Dict[str, List[Tuple[Threshold, Threshold]]]
class RunwayAirport(HBoxMixin, ShapelyMixin):
def __init__(self, runways: List[Tuple[Threshold, Threshold]]):
self._runways = runways
@property
def data(self) -> pd.DataFrame:
return pd.DataFrame.from_records(
self.list, columns=["latitude", "longitude", "bearing", "name"]
)
- otherwise, the same Flight is returned enriched with a new
column (by default, named "distance") with the distance of each
point of the trajectory to the geometrical element.
.. warning::
- An Airspace is (currently) considered as its flattened
representation
- Computing a distance to a polygon is quite slow at the moment.
Consider a strict resampling (e.g. one point per minute, "1T")
before calling the method.
"""
if isinstance(other, PointMixin):
size = len(self)
return self.assign(
**{
column_name: geo.distance(
self.data.latitude.values,
self.data.longitude.values,
other.latitude * np.ones(size),
other.longitude * np.ones(size),
)
/ 1852 # in nautical miles
}
)
from .airspace import Airspace # noqa: F811
if isinstance(other, Airspace):
request.cache_expiration = cache_expiration
class AirportNamedTuple(NamedTuple):
altitude: float
country: str
iata: str
icao: str
latitude: float
longitude: float
name: str
class AirportPoint(PointMixin):
def plot(
self, ax: Axes, text_kw=None, shift=None, **kwargs
) -> List[Artist]: # coverage: ignore
return super().plot(
ax, text_kw, shift, **{**{"marker": atc_tower, "s": 400}, **kwargs}
)
class Airport(HBoxMixin, AirportNamedTuple, PointMixin, ShapelyMixin):
def __repr__(self) -> str:
short_name = (
self.name.replace("International", "")
.replace("Airport", "")
.strip()
)
return f"{self.icao}/{self.iata}: {short_name}"