def _get_flight_path(pilot, threshold=0.001, last_update=None): fp = _get_flight_path2(pilot, last_update=last_update) if not fp: return None num_levels = 4 zoom_factor = 4 zoom_levels = [0] zoom_levels.extend([round(-log(32.0 / 45.0 * (threshold * pow(zoom_factor, num_levels - i - 1)), 2)) for i in range(1, num_levels)]) xcsoar_flight = xcsoar.Flight(fp) xcsoar_flight.reduce(num_levels=num_levels, zoom_factor=zoom_factor, threshold=threshold) encoded_flight = xcsoar_flight.encode() points = encoded_flight['locations'] barogram_t = encoded_flight['times'] barogram_h = encoded_flight['altitude'] enl = encoded_flight['enl'] fp_reduced = map(lambda line: FlightPathFix(*line), xcsoar_flight.path()) elevations = xcsoar.encode([fix.elevation if fix.elevation is not None else UNKNOWN_ELEVATION for fix in fp_reduced], method="signed") geoid_height = egm96_height(Location(latitude=fp[0].location['latitude'], longitude=fp[0].location['longitude'])) return dict(points=points, barogram_t=barogram_t, barogram_h=barogram_h, enl=enl, elevations=elevations, geoid=geoid_height)
def _get_flight_path(flight, threshold=0.001, max_points=3000): num_levels = 4 zoom_factor = 4 zoom_levels = [0] zoom_levels.extend([ round(-math.log( 32.0 / 45.0 * (threshold * pow(zoom_factor, num_levels - i - 1)), 2)) for i in range(1, num_levels) ]) xcsoar_flight = xcsoar.Flight( files.filename_to_path(flight.igc_file.filename)) if flight.qnh: xcsoar_flight.setQNH(flight.qnh) begin = flight.takeoff_time - timedelta(seconds=2 * 60) end = flight.landing_time + timedelta(seconds=2 * 60) if begin > end: begin = datetime.min end = datetime.max xcsoar_flight.reduce( begin=begin, end=end, num_levels=num_levels, zoom_factor=zoom_factor, threshold=threshold, max_points=max_points, ) encoded_flight = xcsoar_flight.encode() points = encoded_flight["locations"] barogram_t = encoded_flight["times"] barogram_h = encoded_flight["altitude"] enl = encoded_flight["enl"] elevations_t, elevations_h = _get_elevations(flight) contest_traces = _get_contest_traces(flight) geoid_height = (egm96_height(flight.takeoff_location) if flight.takeoff_location else 0) return dict( points=points, barogram_t=barogram_t, barogram_h=barogram_h, enl=enl, contests=contest_traces, elevations_t=elevations_t, elevations_h=elevations_h, sfid=flight.id, geoid=geoid_height, )
def test_geoid(): # test data from http://earth-info.nga.mil/GandG/wgs84/gravitymod/egm96/egm96.html assert egm96_height(Location(38.6281550, 269.7791550)) == pytest.approx(-31.629, abs=0.25) assert egm96_height(Location(-14.6212170, 305.0211140)) == pytest.approx(-2.966, abs=0.25) assert egm96_height(Location(46.8743190, 102.4487290)) == pytest.approx(-43.572, abs=0.25) assert egm96_height(Location(-23.6174460, 133.8747120)) == pytest.approx(15.868, abs=0.25) assert egm96_height(Location(38.6254730, 359.9995000)) == pytest.approx(50.065, abs=0.5) assert egm96_height(Location(-.4667440, .0023000)) == pytest.approx(17.330, abs=0.25)
def _get_flight_path(flight, threshold=0.001, max_points=3000): num_levels = 4 zoom_factor = 4 zoom_levels = [0] zoom_levels.extend( [ round(-math.log(32.0 / 45.0 * (threshold * pow(zoom_factor, num_levels - i - 1)), 2)) for i in range(1, num_levels) ] ) xcsoar_flight = xcsoar.Flight(files.filename_to_path(flight.igc_file.filename)) if flight.qnh: xcsoar_flight.setQNH(flight.qnh) begin = flight.takeoff_time - timedelta(seconds=2 * 60) end = flight.landing_time + timedelta(seconds=2 * 60) if begin > end: begin = datetime.min end = datetime.max xcsoar_flight.reduce( begin=begin, end=end, num_levels=num_levels, zoom_factor=zoom_factor, threshold=threshold, max_points=max_points ) encoded_flight = xcsoar_flight.encode() points = encoded_flight["locations"] barogram_t = encoded_flight["times"] barogram_h = encoded_flight["altitude"] enl = encoded_flight["enl"] elevations_t, elevations_h = _get_elevations(flight) contest_traces = _get_contest_traces(flight) geoid_height = egm96_height(flight.takeoff_location) if flight.takeoff_location else 0 return dict( points=points, barogram_t=barogram_t, barogram_h=barogram_h, enl=enl, contests=contest_traces, elevations_t=elevations_t, elevations_h=elevations_h, sfid=flight.id, geoid=geoid_height, )
def _get_flight_path(pilot, threshold=0.001, last_update=None): fp = _get_flight_path2(pilot, last_update=last_update) if not fp: return None num_levels = 4 zoom_factor = 4 zoom_levels = [0] zoom_levels.extend([ round(-log( 32.0 / 45.0 * (threshold * pow(zoom_factor, num_levels - i - 1)), 2)) for i in range(1, num_levels) ]) xcsoar_flight = xcsoar.Flight(fp) xcsoar_flight.reduce(num_levels=num_levels, zoom_factor=zoom_factor, threshold=threshold) encoded_flight = xcsoar_flight.encode() points = encoded_flight["locations"] barogram_t = encoded_flight["times"] barogram_h = encoded_flight["altitude"] enl = encoded_flight["enl"] fp_reduced = map(lambda line: FlightPathFix(*line), xcsoar_flight.path()) elevations = xcsoar.encode( [ fix.elevation if fix.elevation is not None else UNKNOWN_ELEVATION for fix in fp_reduced ], method="signed", ) geoid_height = egm96_height( Location(latitude=fp[0].location["latitude"], longitude=fp[0].location["longitude"])) return dict( points=points, barogram_t=barogram_t, barogram_h=barogram_h, enl=enl, elevations=elevations, geoid=geoid_height, )