{"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":"## Input data","metadata":{}},{"cell_type":"code","source":"!ls '/kaggle/input/google-smartphone-decimeter-challenge'","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Contents of a single phone directory","metadata":{}},{"cell_type":"code","source":"!ls /kaggle/input/google-smartphone-decimeter-challenge/train/2020-05-14-US-MTV-1/Pixel4/","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Reader class for easy data reading","metadata":{}},{"cell_type":"code","source":"import os\nfrom os.path import join\nimport pandas as pd\n\nclass DataReader:\n    def __init__(self):\n        self.input_path='/kaggle/input/google-smartphone-decimeter-challenge'\n        self.train_df = self.read_train_csv()\n        \n    def read_train_csv(self):\n        return pd.read_csv(join(self.input_path, 'baseline_locations_train.csv'))\n        \n    def read_supplemental_gnss_logs(self, phone_path):\n        \"\"\" Read supplemental gnss logs from these file formats .20o/.21o/.nmea\"\"\"\n        # TODO convert it to CSV using this script\n        # https://stackoverflow.com/questions/65394166/how-to-read-an-nmea-file-with-python\n        curr_path = join(self.input_path, phone_path, 'supplemental')\n        for dirname, _, filenames in os.walk(curr_path):\n            for filename in filenames:\n#                 print(os.path.join(dirname, filename))\n                with open(join(curr_path, filename)) as f:\n                    file_content = f.read()\n                    print(file_content)\n                    \n        \n    def read_gnss_logs(self, path, phone_name):\n        with open(join(path, phone_name + '_GnssLog.txt')) as f:\n            file_content = f.read()\n            return file_content\n    \n    def read_one_phone_data(self, phone_path):\n        curr_path = join(self.input_path, phone_path)\n        phone_name = curr_path.split('/')[-1]\n        ground_truth_df = pd.read_csv(join(curr_path, 'ground_truth.csv'))\n        derived_df = pd.read_csv(join(curr_path, phone_name + '_derived.csv'))\n        gnss_logs = self.read_gnss_logs(curr_path, phone_name)\n        # supp_logs = self.read_supplemental_gnss_logs(curr_path)\n        \n        return ground_truth_df, derived_df, gnss_logs\n    \n    def read_all_phone_data(self, phone_path):\n        pass\n#         curr_path = join(self.input_path, phone_path)\n#         ground_truth = pd.read_csv(join(curr_path, 'ground_truth.csv'))\n#         return ground_truth\n\n    def create_submission_file(self):\n        pass\n    ","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = DataReader()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Shape of train_df :\", data.train_df.shape)\ndata.train_df.head(3)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.train_df.describe()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas_profiling as pp\npp.ProfileReport(data.train_df)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ground_truth_df, derived_df, gnss_logs = data.read_one_phone_data('train/2020-05-14-US-MTV-1/Pixel4')\nground_truth_df.head(2)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ground_truth_df.describe()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"derived_df.describe()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls /kaggle/input/google-smartphone-decimeter-challenge/test/2020-05-15-US-MTV-1/Pixel4","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"derived_test = pd.read_csv('/kaggle/input/google-smartphone-decimeter-challenge/test/2020-05-15-US-MTV-1/Pixel4/Pixel4_derived.csv')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"derived_test.columns","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# correctedPrM = rawPrM + satClkBiasM - isrbM - ionoDelayM - tropoDelayM.","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Plot ground truth and Approximated ground truth together","metadata":{}},{"cell_type":"code","source":"output_df = pd.merge(data.train_df, ground_truth_df, on=['collectionName', 'phoneName', 'millisSinceGpsEpoch'])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from mpl_toolkits.basemap import Basemap\nimport matplotlib.pyplot as plt\n\nplt.figure(figsize=(10,10))\ndelta = 0\nm = Basemap(projection = 'merc', llcrnrlat=output_df.latDeg_x.min() - delta,\\\n    urcrnrlat=output_df.latDeg_x.max() + delta, llcrnrlon=output_df.lngDeg_x.min() - delta,\\\n    urcrnrlon=output_df.lngDeg_x.max() + delta,lat_ts=40,resolution='l')\n\nlat = output_df.latDeg_x.tolist()\nlon = output_df.lngDeg_x.tolist()\n\nx, y = m(lon, lat)\nm.plot(x, y, 'o-', markersize=1, linewidth=1) \nlat2 = [x+0.005 for x in output_df.latDeg_y]\nlon2 = [x+0.005 for x in output_df.lngDeg_y]\nx2, y2 = m(lon2, lat2)\nm.plot(x2, y2, 'o-', markersize=1, linewidth=1) \n\nm.drawcoastlines()\nm.fillcontinents(color='yellow')\nm.drawmapboundary(fill_color='white')\nm.drawstates(color='black')\nm.drawcountries(color='black')\nplt.title(\"Route of a single phone\")\nplt.show() ","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Model","metadata":{}},{"cell_type":"code","source":"# TODO build a model","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Submission","metadata":{}},{"cell_type":"code","source":"submission_file = pd.read_csv(join(data.input_path, 'sample_submission.csv'))\nsubmission_file.to_csv('submission.csv', index= False)","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}