{"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":"## Overview\n\nThis notebook visualizes that some data in \"../input/smartphone-decimeter-2022/train/2020-08-03-US-MTV-2/GooglePixel5/device_gnss.csv\" is not smooth.\n\nThe root of \"ground_truth.csv\" is smooth, but certain period of \"device_gnss.csv\" does not appear to be smooth.\nTo be precise, two consecutive positions within a certain period show the same position.\n\nI don't think I have enough words to describe it, so please take a look at the figure.\n\nI have shared this question in the discussion.\n\nThank you.","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"markdown","source":"### Import lib","metadata":{}},{"cell_type":"code","source":"import numpy\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport plotly.express as px","metadata":{"_kg_hide-input":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Visualize util\n\nI referred to this notebook : [📱 Smartphone Competition 2022 [Twitch Stream]](https://www.kaggle.com/code/robikscube/smartphone-competition-2022-twitch-stream)","metadata":{}},{"cell_type":"code","source":"def visualize_traffic(\n    df,\n    lat_col=\"LatitudeDegrees\",\n    lon_col=\"LongitudeDegrees\",\n    center=None,\n    color_col=\"phone\",\n    label_col=\"tripId\",\n    zoom=9,\n    opacity=1,\n):\n    if center is None:\n        center = {\n            \"lat\": df[lat_col].mean(),\n            \"lon\": df[lon_col].mean(),\n        }\n    fig = px.scatter_mapbox(\n        df,\n        # Here, plotly gets, (x,y) coordinates\n        lat=lat_col,\n        lon=lon_col,\n        # Here, plotly detects color of series\n        color=color_col,\n        labels=label_col,\n        zoom=zoom,\n        center=center,\n        height=600,\n        width=800,\n        opacity=0.5,\n    )\n    fig.update_layout(mapbox_style=\"stamen-terrain\")\n    fig.update_layout(margin={\"r\": 0, \"t\": 0, \"l\": 0, \"b\": 0})\n    fig.update_layout(title_text=\"GPS trafic\")\n    fig.show()","metadata":{"_kg_hide-input":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Specify the display period","metadata":{}},{"cell_type":"code","source":"st = 1596501799434\net = 1596501818434\ntime_width = 1000\n\nn_labels = int((et-st)/time_width + 1)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Visualize Ground truth\n\nIt is hard to see without hovering the mouse. Sorry.","metadata":{}},{"cell_type":"code","source":"gt_df = pd.read_csv(\"../input/smartphone-decimeter-2022/train/2020-08-03-US-MTV-2/GooglePixel5/ground_truth.csv\")\nspecific_time_gt_df = gt_df[(gt_df[\"UnixTimeMillis\"] >= st) & (gt_df[\"UnixTimeMillis\"] <= et)]\nvisualize_traffic(\n    specific_time_gt_df,\n    lat_col=\"LatitudeDegrees\",\n    lon_col=\"LongitudeDegrees\",\n    color_col=\"UnixTimeMillis\",\n    zoom=15,\n)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Visualize device_gnss.csv","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv(\"../input/smartphone-decimeter-2022/train/2020-08-03-US-MTV-2/GooglePixel5/device_gnss.csv\")\ncmap = [numpy.random.rand(3,) for _ in range(n_labels)]\nfig, axes = plt.subplots(nrows=1, ncols=3, figsize=(25,8))\nfor ax_id, col in enumerate([\"WlsPositionXEcefMeters\", \"WlsPositionYEcefMeters\", \"WlsPositionZEcefMeters\"]):\n    axes[ax_id].set_title(col)\n    for idx, utcTime in enumerate(range(st, et, time_width)):\n        specific_time_df = df[df[\"utcTimeMillis\"]==utcTime]\n        axes[ax_id].scatter(specific_time_df.index, specific_time_df.WlsPositionYEcefMeters, s=10, c=cmap[idx])\nplt.legend(range(st, et, time_width))\nplt.show()","metadata":{},"execution_count":null,"outputs":[]}]}