def test_clip_point() -> None: records = [ { "timestamp": pd.Timestamp("2019-07-02 15:02:30+0000", tz="UTC"), "longitude": -1.3508333333333333, "latitude": 46.5, "altitude": 36000, "callsign": "WZZ1066", "flight_id": "231619151", "icao24": "471f52", }, { "timestamp": pd.Timestamp("2019-07-02 15:04:42+0000", tz="UTC"), "longitude": -1.00055555, "latitude": 46.664444450000005, "altitude": 36000, "callsign": "WZZ1066", "flight_id": "231619151", "icao24": "471f52", }, { "timestamp": pd.Timestamp("2019-07-02 15:15:52+0000", tz="UTC"), "longitude": 0.5097222166666667, "latitude": 47.71388888333333, "altitude": 36000, "callsign": "WZZ1066", "flight_id": "231619151", "icao24": "471f52", }, ] flight = Flight(pd.DataFrame.from_records(records)) assert flight.clip(eurofirs["LFBB"]) is None
def all(self) -> Optional["Flight"]: from traffic.core import Flight # noqa: F811 t = sum(flight for flight in self) if t == 0: return None return Flight(t.data) # type: ignore
def on_filter(self, max_alt: int, max_time: datetime) -> None: assert self._traffic is not None west, east, south, north = self.map_plot.ax.get_extent( crs=PlateCarree()) self._tview = self._traffic.before(max_time).sort_values("timestamp") if self._tview is None: return filtered = Traffic.from_flights( Flight(f.data.ffill().bfill()) for f in self._tview) if "altitude" in filtered.data.columns: filtered = filtered.query( f"altitude != altitude or altitude <= {max_alt}") if "latitude" in self._tview.data.columns: filtered = filtered.query("latitude != latitude or " f"({west} <= longitude <= {east} and " f"{south} <= latitude <= {north})") self.identifier_select.clear() text = self.identifier_input.text() # cast is necessary because of the @lru_cache on callsigns which hides # the type annotation for callsign in sorted(cast(Set[str], filtered.callsigns)): if re.match(text, callsign, flags=re.IGNORECASE): self.identifier_select.addItem(callsign) callsigns = cast(Set[str], filtered.callsigns) self.map_plot.default_plot(self._tview[callsigns]) self.set_float_columns()
def test_resample_unwrapped() -> None: # https://github.com/xoolive/traffic/issues/41 df = pd.DataFrame.from_records( [ (pd.Timestamp("2019-01-01 12:00:00Z"), 345), (pd.Timestamp("2019-01-01 12:00:30Z"), 355), (pd.Timestamp("2019-01-01 12:01:00Z"), 5), (pd.Timestamp("2019-01-01 12:01:30Z"), 15), ], columns=["timestamp", "track"], ) resampled = Flight(df).resample("1s") assert resampled.query("50 < track < 300") is None resampled_10 = Flight(df).resample(10) assert len(resampled_10) == 10
def all(self) -> Optional["Flight"]: """Returns the concatenation of elements in the FlightIterator. >>> flight.aligned_on_ils("LFBO").all() This is equivalent to: >>> flight.all(lambda f: f.aligned_on_ils("LFBO")) """ from traffic.core import Flight # noqa: F811 t = sum(flight.assign(index_=i) for i, flight in enumerate(self)) if t == 0: return None return Flight(t.data) # type: ignore
def __call__( self, fun: Callable[..., "LazyTraffic"], *args, **kwargs, ) -> Optional["Flight"]: from traffic.core import Flight, Traffic # noqa: F811 in_ = Traffic.from_flights( segment.assign(index_=i) for i, segment in enumerate(self)) if in_ is None: return None out_ = fun(in_, *args, **kwargs).eval() if out_ is None: return None return Flight(out_.data)
def high_altitude(flight: Flight) -> bool: return flight.min("altitude") > 35000
def export_flight(flight: Flight) -> Iterator[Dict[str, Any]]: start = format_ts(flight.start) stop = format_ts(flight.stop) availability = f"{start}/{stop}" color = [ random.randint(0, 255), random.randint(0, 255), random.randint(0, 255), 150, ] yield { "id": flight.callsign, "availability": availability, "position": { "epoch": start, "cartographicDegrees": list(itertools.chain(*flight.coords4d(delta_t=True))), }, "path": { "material": { "polylineOutline": { "color": { "rgba": color }, "outlineColor": { "rgba": color }, "outlineWidth": _CZML_Params.path_outline_width, } }, "width": _CZML_Params.path_width, "leadTime": _CZML_Params.path_lead_time, "trailTime": _CZML_Params.path_trail_time, "resolution": _CZML_Params.path_resolution, }, } yield { "id": flight.callsign, "availability": availability, "position": { "epoch": start, "cartographicDegrees": list(itertools.chain(*flight.coords4d(delta_t=True))), }, "point": { "color": { "rgba": [255, 255, 255, 200] # white center instead of color }, "outlineColor": { "rgba": color }, "outlineWidth": _CZML_Params.point_outline_width, "pixelSize": _CZML_Params.point_pixel_size, "heightReference": _CZML_Params.point_height_reference, }, }