{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Fast, accurate WGS-ECEF conversions\n\nConvert between earth-positioning coordinate systems.\n\nAn efficient, tested, python-numba implementation.\n\nAlgorithms from [D. Rose (2014) \"Converting between Earth-Centered, Earth Fixed and Geodetic Coordinates\"](danceswithcode.net/engineeringnotes/geodetic_to_ecef/geodetic_to_ecef.html)\n\n\n### Access\n```\nFile > Add utility script > Search Notebooks \"wgs_ecef\" > Add\n```","metadata":{}},{"cell_type":"code","source":"import wgs_ecef\n\nfrom wgs_ecef import wgs_to_ecef, ecef_to_wgs","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-06-05T11:09:18.963434Z","iopub.execute_input":"2021-06-05T11:09:18.963750Z","iopub.status.idle":"2021-06-05T11:09:18.968950Z","shell.execute_reply.started":"2021-06-05T11:09:18.963709Z","shell.execute_reply":"2021-06-05T11:09:18.967738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Demo","metadata":{}},{"cell_type":"code","source":"def demo():\n    # latitude in degrees,\n    # longitude in degrees,\n    # altitude above \"sea level\" in meters\n    lat = 37.4166281\n    lng = -122.0820531\n    alt = -30.69\n    \n    x, y, z = wgs_to_ecef(lat, lng, alt)\n    lat_, lng_, alt_ = ecef_to_wgs(x, y, z)\n    \n    print(\"WGS original\")\n    print(f\"lat={lat}, lng={lng}, alt={alt}\")\n    print()\n    print(\"ECEF\")\n    print(f\"x={x}, y={y}, z={z}\")\n    print()\n    print(\"WGS recovered to high accuracy\")\n    print(f\"lat={lat_}, lng={lng_}, alt={alt_}\")\n\n\ndemo()","metadata":{"execution":{"iopub.status.busy":"2021-06-05T11:09:18.970497Z","iopub.execute_input":"2021-06-05T11:09:18.970784Z","iopub.status.idle":"2021-06-05T11:09:18.986716Z","shell.execute_reply.started":"2021-06-05T11:09:18.970756Z","shell.execute_reply":"2021-06-05T11:09:18.985095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Test\n\nThis does some checks of self-consistency and agreement with a reference implementation.  \nPlease see the source code for details.","metadata":{"execution":{"iopub.status.busy":"2021-06-05T10:12:12.237125Z","iopub.execute_input":"2021-06-05T10:12:12.237625Z","iopub.status.idle":"2021-06-05T10:12:12.242694Z","shell.execute_reply.started":"2021-06-05T10:12:12.237586Z","shell.execute_reply":"2021-06-05T10:12:12.240954Z"}}},{"cell_type":"code","source":"wgs_ecef.check()","metadata":{"execution":{"iopub.status.busy":"2021-06-05T11:09:18.988547Z","iopub.execute_input":"2021-06-05T11:09:18.989001Z","iopub.status.idle":"2021-06-05T11:09:25.051918Z","shell.execute_reply.started":"2021-06-05T11:09:18.988955Z","shell.execute_reply":"2021-06-05T11:09:25.050789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Benchmark","metadata":{}},{"cell_type":"code","source":"def benchmark():\n    n = 10**5\n    bench_we_one, bench_we_vec = wgs_ecef.make_benchmark_wgs_to_ecef(n)\n\n    print(\"WGS to ECEF (vectorized)\")\n    %timeit bench_we_vec(wgs_to_ecef)\n    print(\"WGS to ECEF (python loop)\")\n    %timeit bench_we_one(wgs_to_ecef)\n    print(\"WGS to ECEF (reference implementation)\")\n    %timeit bench_we_one(wgs_ecef.wgs_to_ecef_ref)\n\n    print()\n    bench_ew_one, bench_ew_vec = wgs_ecef.make_benchmark_ecef_to_wgs(n)\n    print(\"ECEF to WGS (vectorized)\")\n    %timeit bench_ew_vec(ecef_to_wgs)\n    print(\"ECEF to WGS (python loop)\")\n    %timeit bench_ew_one(ecef_to_wgs)\n    print(\"ECEF to WGS (reference implementation)\")\n    %timeit bench_ew_one(wgs_ecef.ecef_to_wgs_ref)\n\n\nbenchmark()","metadata":{"execution":{"iopub.status.busy":"2021-06-05T11:09:25.054099Z","iopub.execute_input":"2021-06-05T11:09:25.054463Z","iopub.status.idle":"2021-06-05T11:10:24.022629Z","shell.execute_reply.started":"2021-06-05T11:09:25.054425Z","shell.execute_reply":"2021-06-05T11:10:24.021555Z"},"trusted":true},"execution_count":null,"outputs":[]}]}