#!/usr/bin/env python3 """ Compute a statistics table for earth-generation with multiple frequencies. .. _script-earth_graph_frequency_statistics-example: Examples: .. code-block:: bash ./scripts/earth_graph_frequency_statistics.py 300 --step 10 Frequency Great Circle Distance (km) # nodes # edges Computation time (sec) 10 705.365422 1002 3000 0.229929 20 352.682711 4002 12000 0.531473 30 235.121807 9002 27000 0.582267 40 176.341356 16002 48000 0.998187 50 141.073084 25002 75000 1.559254 60 117.560904 36002 108000 2.264499 70 100.766489 49002 147000 3.095882 80 88.170678 64002 192000 6.268704 90 78.373936 81002 243000 5.790993 100 70.536542 100002 300000 6.933162 110 64.124129 121002 363000 9.229682 120 58.780452 144002 432000 10.617164 130 54.258879 169002 507000 16.519117 140 50.383244 196002 588000 15.838989 150 47.024361 225002 675000 21.517596 160 44.085339 256002 768000 24.864843 170 41.492084 289002 867000 30.145898 180 39.186968 324002 972000 28.684602 190 37.124496 361002 1083000 27.561629 200 35.268271 400002 1200000 33.667006 210 33.58883 441002 1323000 34.471024 220 32.062065 484002 1452000 37.554208 230 30.668062 529002 1587000 43.1782 240 29.390226 576002 1728000 46.112764 250 28.214617 625002 1875000 44.472765 260 27.129439 676002 2028000 53.084822 270 26.124645 729002 2187000 60.2798 280 25.191622 784002 2352000 63.117184 290 24.322946 841002 2523000 64.914421 300 23.512181 900002 2700000 68.890113 """ # Standard library from argparse import ArgumentDefaultsHelpFormatter from argparse import ArgumentParser from time import perf_counter # Typing from typing import List from typing import Tuple # Scientific import numpy import pandas # Earth graph calculation from pyrate.plan.graph import create_earth_graph from pyrate.plan.graph import great_circle_distance_distance_for def _main() -> None: """The main function.""" parser = ArgumentParser( description="Compute a statistics table for earth-generation with multiple frequencies.", formatter_class=ArgumentDefaultsHelpFormatter, ) parser.add_argument("max", type=int, help="the maximum frequency to test") parser.add_argument( "--step", type=int, default=10, help="how large the steps while increasing the frequencies should be" ) args = parser.parse_args() pandas.set_option("display.max_columns", None) pandas.set_option("display.max_rows", None) columns = [ ("Frequency", numpy.uint), ("Great Circle Distance (km)", numpy.float64), ("# nodes", numpy.uint), ("# edges", numpy.uint), ("Computation time (sec)", numpy.float64), ] records: List[Tuple] = [] for frequency in range(0, args.max + 1, args.step): if frequency == 0: continue # better steps when starting at zero start = perf_counter() graph = create_earth_graph(frequency) end = perf_counter() records.append( ( frequency, great_circle_distance_distance_for(frequency) / 1000, len(graph), graph.num_edges, end - start, ) ) # re-creating this is inefficient, but it does not matter for small sizes data_frame = pandas.DataFrame.from_records(numpy.array(records, dtype=columns)) string = data_frame.iloc[[-1]].to_string(index=False, justify="right") if len(data_frame) == 1: # only the first time print(string) else: print(string.splitlines()[-1]) if __name__ == "__main__": _main()