{"cells":[{"metadata":{"trusted":true,"_uuid":"1ce9d10d3467e08aa439e9119bbf43bf5a3fc9bb"},"cell_type":"code","source":"import pandas as pd\npd.options.display.precision = 15","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"bf63db7d4f165e84a260f1dfc42511ed14c98ff0"},"cell_type":"code","source":"train = pd.read_csv('../input/train.csv', dtype={\n    'acoustic_data': 'int16',\n    'time_to_failure': 'float64',\n}, nrows=200000000)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"289b55a10bef64d0d8fb5fbcb1c5167b5e6df2a9"},"cell_type":"code","source":"train[::1000].plot(secondary_y=['time_to_failure'], figsize=(30,5))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ab22f7521cc226eb5a86e56a2ff527a6063d8b89"},"cell_type":"code","source":"train[:50000].plot(secondary_y=['time_to_failure'], figsize=(30,5))","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"9aabd6e32f8ede2ca102e45ab4bf87c563681d98"},"cell_type":"markdown","source":"Errr... wat?"},{"metadata":{"trusted":true,"_uuid":"e19af5efb014c3a8c82b9382b5afe529a308be9b"},"cell_type":"code","source":"train.iloc[:8000].plot(secondary_y=['time_to_failure'], figsize=(5, 30))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"74a21c7ac5917bfc74e828ed1fa3fe5689e4941f"},"cell_type":"code","source":"a, b = train.time_to_failure[4094:4096]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a7fba6beda9f2d6aa3cb3bbd92dca14c33625cb3"},"cell_type":"code","source":"print('Interval between chunks: %.9f\\nInterval between points: %.9f' % (a - b, train.time_to_failure[0] - a))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5264e422181ee00195ef5f95134bff818754edba"},"cell_type":"code","source":"from IPython.display import display, Audio","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"35f9cf9770face5a62351d6ce72154103f860944"},"cell_type":"code","source":"Audio(train.acoustic_data[:150000], rate=2000)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4b32e7d361eadbec21f46cad6b6bb3e855d71e59"},"cell_type":"code","source":"failures = train.index[train.time_to_failure.shift(1) < train.time_to_failure]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"45672dc835cf6814222fdf7773a250931acd90b0"},"cell_type":"code","source":"spike = train[:failures[0]].acoustic_data.abs().argmax()\nd = train[spike - 100000:failures[0]]\nd.plot(figsize=(30, 5), secondary_y=['time_to_failure'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d56db0268faada21caca1b94f291a29136c0d5f4"},"cell_type":"code","source":"display(Audio(d.acoustic_data, rate=4000))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3c0f82d122fb441b1194f713cfc172801e11488f"},"cell_type":"code","source":"import librosa\nimport librosa.display\nX = librosa.stft(d.acoustic_data.astype('float16').values)\nXdb = librosa.amplitude_to_db(abs(X))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f6cf7ace84449d4830e63f855a6ca3cf2480bde4"},"cell_type":"code","source":"from matplotlib import pylab as plt\nplt.figure(figsize=(28, 10))\nlibrosa.display.specshow(Xdb, x_axis='time', y_axis='hz')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1d4e4fd2d98c241ebd7c1cb930c46dbdf3626d61"},"cell_type":"code","source":"import os\ntest = []\nfor i in os.listdir('../input/test'):\n    test.append((i, pd.read_csv('../input/test/' + i, dtype={'acoustic_data': 'int16'})))","execution_count":null,"outputs":[]},{"metadata":{"scrolled":false,"trusted":true,"_uuid":"6122107ab859c77e2c72148d39f7d53c29d9c18e"},"cell_type":"code","source":"for name, i in test:\n    if i.acoustic_data.max() > 1000:\n        display(name)\n        display(Audio(i.acoustic_data, rate=4000))\n        i.plot()\n        plt.show()","execution_count":null,"outputs":[]},{"metadata":{"scrolled":false,"trusted":true,"_uuid":"00799aead8e2ccb796bacfe20be034415d91f0c3"},"cell_type":"code","source":"for i in range(10):\n    display(test[i][0])\n    display(Audio(test[i][1].acoustic_data, rate=4000))\n    test[i][1].plot()\n    plt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"e0537a49408eae63d9747d0dd777386f34a105d7"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}