{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"papermill":{"default_parameters":{},"duration":77.1155,"end_time":"2023-03-17T15:24:29.405610","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2023-03-17T15:23:12.290110","version":"2.4.0"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":70203,"databundleVersionId":8068726,"sourceType":"competition"}],"dockerImageVersionId":30683,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# <h><center><b>🐧BIRDCIEF 🐤 2024🐧</b></center></h>\n\n<img src='https://c4.wallpaperflare.com/wallpaper/64/863/704/bird-song-wallpaper-preview.jpg'>\n\n\n# <center><b>Explore Audio data - Happy learning🐧</b></center>","metadata":{"papermill":{"duration":0.010889,"end_time":"2023-03-17T15:23:22.096629","exception":false,"start_time":"2023-03-17T15:23:22.085740","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"# ***Identify insight of data (EDA) & Visualize geomap***\n\n### **1. Geopandas**\n### **2. Plotly**\n### **3. folium**\n\n### **4. Audio data basic terms and preprocessing**","metadata":{"papermill":{"duration":0.008753,"end_time":"2023-03-17T15:23:22.133032","exception":false,"start_time":"2023-03-17T15:23:22.124279","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"# **1. Import Necessary Library**","metadata":{"papermill":{"duration":0.008578,"end_time":"2023-03-17T15:23:22.168949","exception":false,"start_time":"2023-03-17T15:23:22.160371","status":"completed"},"tags":[]}},{"cell_type":"code","source":"!pip install plotly\n!pip install geopandas","metadata":{"_kg_hide-input":false,"_kg_hide-output":true,"papermill":{"duration":20.680571,"end_time":"2023-03-17T15:23:42.858826","exception":false,"start_time":"2023-03-17T15:23:22.178255","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:13:24.962053Z","iopub.execute_input":"2024-04-09T16:13:24.962475Z","iopub.status.idle":"2024-04-09T16:13:51.958691Z","shell.execute_reply.started":"2024-04-09T16:13:24.962444Z","shell.execute_reply":"2024-04-09T16:13:51.957657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import math\nimport os\nimport numpy as np\nimport pandas as pd\n\n#Mapping\nimport geopandas as gpd\nimport folium\nfrom folium import Marker\nfrom folium.plugins import HeatMap\nfrom folium.plugins import MarkerCluster\n\n#plotting \nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport plotly.express as px\n\n\n#Audio\n\nimport librosa\nimport librosa.display as ld\nfrom IPython.display import Audio","metadata":{"papermill":{"duration":4.696575,"end_time":"2023-03-17T15:23:47.564552","exception":false,"start_time":"2023-03-17T15:23:42.867977","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:14:21.503048Z","iopub.execute_input":"2024-04-09T16:14:21.503422Z","iopub.status.idle":"2024-04-09T16:14:26.914375Z","shell.execute_reply.started":"2024-04-09T16:14:21.503391Z","shell.execute_reply":"2024-04-09T16:14:26.913431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls /kaggle/input/birdclef-2024","metadata":{"papermill":{"duration":1.01439,"end_time":"2023-03-17T15:23:48.587707","exception":false,"start_time":"2023-03-17T15:23:47.573317","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:14:36.347285Z","iopub.execute_input":"2024-04-09T16:14:36.347843Z","iopub.status.idle":"2024-04-09T16:14:37.345037Z","shell.execute_reply.started":"2024-04-09T16:14:36.347813Z","shell.execute_reply":"2024-04-09T16:14:37.344075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **EDA and identify insight of data**","metadata":{"papermill":{"duration":0.009155,"end_time":"2023-03-17T15:23:48.605890","exception":false,"start_time":"2023-03-17T15:23:48.596735","status":"completed"},"tags":[]}},{"cell_type":"code","source":"train_meta = pd.read_csv('/kaggle/input/birdclef-2024/train_metadata.csv')\nprint(\"Identify null values\",train_meta.isnull().sum())\nprint(\"Train_meta_shape:\",train_meta.shape)","metadata":{"papermill":{"duration":0.131754,"end_time":"2023-03-17T15:23:48.746155","exception":false,"start_time":"2023-03-17T15:23:48.614401","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:14:52.067912Z","iopub.execute_input":"2024-04-09T16:14:52.068660Z","iopub.status.idle":"2024-04-09T16:14:52.315025Z","shell.execute_reply.started":"2024-04-09T16:14:52.068623Z","shell.execute_reply":"2024-04-09T16:14:52.313882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f'Number of different species: {train_meta.primary_label.nunique()}')\nprint(f\"Number of species > 100 audio records: {sum(train_meta['common_name'].value_counts()<100)}\")\npercentage_low = 133/397*100\npercentage_low = \"{:.2f}\".format(percentage_low)\nprint(f\"At least {percentage_low}% of the records are infrequent\")","metadata":{"papermill":{"duration":0.034974,"end_time":"2023-03-17T15:23:48.790881","exception":false,"start_time":"2023-03-17T15:23:48.755907","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:14:58.313931Z","iopub.execute_input":"2024-04-09T16:14:58.314272Z","iopub.status.idle":"2024-04-09T16:14:58.342872Z","shell.execute_reply.started":"2024-04-09T16:14:58.314247Z","shell.execute_reply":"2024-04-09T16:14:58.342100Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## **Maximum and minimum of longitude and latitude**","metadata":{"papermill":{"duration":0.008955,"end_time":"2023-03-17T15:23:48.809817","exception":false,"start_time":"2023-03-17T15:23:48.800862","status":"completed"},"tags":[]}},{"cell_type":"code","source":"print(f\"Minimum longitude: {train_meta['longitude'].min()}\")\nprint(f\"Maximum longitude: {train_meta['longitude'].max()}\")\nprint(f\"Minimum latitude: {train_meta['latitude'].min()}\")\nprint(f\"Maximum latitude: {train_meta['latitude'].max()}\")","metadata":{"papermill":{"duration":0.022364,"end_time":"2023-03-17T15:23:48.841261","exception":false,"start_time":"2023-03-17T15:23:48.818897","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:15:06.547521Z","iopub.execute_input":"2024-04-09T16:15:06.547901Z","iopub.status.idle":"2024-04-09T16:15:06.555671Z","shell.execute_reply.started":"2024-04-09T16:15:06.547873Z","shell.execute_reply":"2024-04-09T16:15:06.554713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## **Identify the location of birds comes using birds longitude and latitude**","metadata":{"papermill":{"duration":0.009395,"end_time":"2023-03-17T15:23:48.860412","exception":false,"start_time":"2023-03-17T15:23:48.851017","status":"completed"},"tags":[]}},{"cell_type":"code","source":"\ndf = train_meta.iloc[:, [0,3,4,8,9]]\ngdf = gpd.GeoDataFrame(\n    df, geometry=gpd.points_from_xy(df.longitude, df.latitude))\ngdf_1 = gdf[(gdf.latitude<35) & (gdf.longitude>-30)]\ngdf_2 = gdf[(gdf.latitude<10) & (gdf.longitude<-20)]\ngdf_3 = gdf[(gdf.latitude>=35) & (gdf.longitude>=-40)]\ngdf_4 = gdf[(gdf.latitude>=10) & (gdf.longitude<=-40)]\nworld = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))\nax = world.plot(color='white', edgecolor='black')\n# We can now plot our ``GeoDataFrame``.\ngdf_1.plot(ax=ax, markersize=1)\ngdf_2.plot(ax=ax, markersize=1)\ngdf_3.plot(ax=ax, markersize=1)\ngdf_4.plot(ax=ax, markersize=1)\nplt.show()\n\n","metadata":{"papermill":{"duration":2.936191,"end_time":"2023-03-17T15:23:51.805786","exception":false,"start_time":"2023-03-17T15:23:48.869595","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:15:11.571532Z","iopub.execute_input":"2024-04-09T16:15:11.572244Z","iopub.status.idle":"2024-04-09T16:15:16.150746Z","shell.execute_reply.started":"2024-04-09T16:15:11.572211Z","shell.execute_reply":"2024-04-09T16:15:16.149801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## **Identify which location large amount of birds here**","metadata":{"papermill":{"duration":0.009966,"end_time":"2023-03-17T15:23:51.826464","exception":false,"start_time":"2023-03-17T15:23:51.816498","status":"completed"},"tags":[]}},{"cell_type":"code","source":"total = np.sum([len(gdf_1), len(gdf_2), len(gdf_3), len(gdf_4)])\n# print(total)\n# assert total == len(train_meta.index)\nprint('The number of records for each quadrant of the earth: \\n' +\n       f'     -> {[len(gdf_1), len(gdf_3), len(gdf_2), len(gdf_4)]}\\n' +\n       f'     -> {[\"Af\", \"EU\", \"SA\", \"NA\"]}')","metadata":{"papermill":{"duration":0.020482,"end_time":"2023-03-17T15:23:51.857094","exception":false,"start_time":"2023-03-17T15:23:51.836612","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:15:20.677026Z","iopub.execute_input":"2024-04-09T16:15:20.677440Z","iopub.status.idle":"2024-04-09T16:15:20.683374Z","shell.execute_reply.started":"2024-04-09T16:15:20.677408Z","shell.execute_reply":"2024-04-09T16:15:20.682383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## **Answer: Most of the bird crowds going to  AF and EU**","metadata":{"papermill":{"duration":0.010196,"end_time":"2023-03-17T15:23:51.878479","exception":false,"start_time":"2023-03-17T15:23:51.868283","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"# **Explore more and verify the my result of most and least birds going in AF and EU**","metadata":{"papermill":{"duration":0.009568,"end_time":"2023-03-17T15:23:51.898266","exception":false,"start_time":"2023-03-17T15:23:51.888698","status":"completed"},"tags":[]}},{"cell_type":"code","source":"#Rating \nsns.violinplot(data=train_meta, x=\"rating\")","metadata":{"papermill":{"duration":0.295378,"end_time":"2023-03-17T15:23:52.203755","exception":false,"start_time":"2023-03-17T15:23:51.908377","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:15:32.993288Z","iopub.execute_input":"2024-04-09T16:15:32.993775Z","iopub.status.idle":"2024-04-09T16:15:33.305696Z","shell.execute_reply.started":"2024-04-09T16:15:32.993740Z","shell.execute_reply":"2024-04-09T16:15:33.304777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Rating of audio data\nplt.figure(figsize=(16,8))\nsns.countplot(x=train_meta.rating,data=train_meta)\nplt.title('Record Rating of Birds sound')","metadata":{"papermill":{"duration":0.342565,"end_time":"2023-03-17T15:23:52.558033","exception":false,"start_time":"2023-03-17T15:23:52.215468","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:15:38.836926Z","iopub.execute_input":"2024-04-09T16:15:38.837549Z","iopub.status.idle":"2024-04-09T16:15:39.266647Z","shell.execute_reply.started":"2024-04-09T16:15:38.837511Z","shell.execute_reply":"2024-04-09T16:15:39.265744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **In the analysis 4 is top rating of birds sound record**","metadata":{"papermill":{"duration":0.011629,"end_time":"2023-03-17T15:23:52.582660","exception":false,"start_time":"2023-03-17T15:23:52.571031","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"# **- Higes and least recoded 20birds in the recording**","metadata":{"papermill":{"duration":0.014873,"end_time":"2023-03-17T15:23:52.609032","exception":false,"start_time":"2023-03-17T15:23:52.594159","status":"completed"},"tags":[]}},{"cell_type":"code","source":"highest_recorded=train_meta['common_name'].value_counts().sort_values(ascending=False)[:20]\nleast_recorded=train_meta['common_name'].value_counts().sort_values()[:20]\n\nplt.subplots(2,1,figsize=(16,16))\n\nplt.subplot(2,1,1)\nplt.bar(x=highest_recorded.index,height=highest_recorded.values)\nplt.xticks(rotation=45)\nplt.ylabel('Count')\nplt.title('Most Recorded birds')\n\nplt.subplot(2,1,2)\nplt.bar(x=least_recorded.index,height=least_recorded.values)\nplt.xticks(rotation=45)\nplt.ylabel('Count')\nplt.title('Least Recorded birds')\n\nplt.tight_layout()\nplt.show()\n","metadata":{"papermill":{"duration":1.078357,"end_time":"2023-03-17T15:23:53.710871","exception":false,"start_time":"2023-03-17T15:23:52.632514","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:15:48.041591Z","iopub.execute_input":"2024-04-09T16:15:48.041937Z","iopub.status.idle":"2024-04-09T16:15:48.893790Z","shell.execute_reply.started":"2024-04-09T16:15:48.041910Z","shell.execute_reply":"2024-04-09T16:15:48.892799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Just Explore plotly in general location through birds name**","metadata":{"papermill":{"duration":0.016004,"end_time":"2023-03-17T15:23:53.745159","exception":false,"start_time":"2023-03-17T15:23:53.729155","status":"completed"},"tags":[]}},{"cell_type":"code","source":"fig = px.density_mapbox(train_meta, lat='latitude',lon='longitude',hover_name='primary_label',radius=1,\n                       center=dict(lat=0,lon=180),zoom=1.5,\n                       mapbox_style=\"stamen-terrain\")\nfig.show()","metadata":{"papermill":{"duration":1.563538,"end_time":"2023-03-17T15:23:55.323786","exception":false,"start_time":"2023-03-17T15:23:53.760248","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:15:57.966894Z","iopub.execute_input":"2024-04-09T16:15:57.967807Z","iopub.status.idle":"2024-04-09T16:16:00.257808Z","shell.execute_reply.started":"2024-04-09T16:15:57.967769Z","shell.execute_reply":"2024-04-09T16:16:00.256918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **Recording location of birds using folium - Indepth analysis**","metadata":{"papermill":{"duration":0.020874,"end_time":"2023-03-17T15:23:55.366316","exception":false,"start_time":"2023-03-17T15:23:55.345442","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"### **Finally, Most of the bird crowds going to  AF and EU**","metadata":{"papermill":{"duration":0.258589,"end_time":"2023-03-17T15:24:09.004299","exception":false,"start_time":"2023-03-17T15:24:08.745710","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"# ***Audio terms analysis***","metadata":{"papermill":{"duration":0.249422,"end_time":"2023-03-17T15:24:09.471839","exception":false,"start_time":"2023-03-17T15:24:09.222417","status":"completed"},"tags":[]}},{"cell_type":"code","source":"import math\nimport numpy as np\nimport pandas as pd\nimport librosa\nimport librosa.display\nimport matplotlib.pyplot as plt\nimport IPython.display as ipd\nimport scipy as sp\nimport soundfile as sf\nimport random","metadata":{"papermill":{"duration":0.289581,"end_time":"2023-03-17T15:24:09.977475","exception":false,"start_time":"2023-03-17T15:24:09.687894","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:23:51.612335Z","iopub.execute_input":"2024-04-09T16:23:51.612658Z","iopub.status.idle":"2024-04-09T16:23:51.668845Z","shell.execute_reply.started":"2024-04-09T16:23:51.612635Z","shell.execute_reply":"2024-04-09T16:23:51.668106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bird1_asbfly1 = '/kaggle/input/birdclef-2024/train_audio/asbfly/XC134896.ogg'\nbird2_ashdro1 = '/kaggle/input/birdclef-2024/train_audio/ashdro1/XC114598.ogg'\nbird3_barswa1 = '/kaggle/input/birdclef-2024/train_audio/barswa/XC133802.ogg'","metadata":{"papermill":{"duration":0.234315,"end_time":"2023-03-17T15:24:10.429492","exception":false,"start_time":"2023-03-17T15:24:10.195177","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:39:13.626554Z","iopub.execute_input":"2024-04-09T16:39:13.627404Z","iopub.status.idle":"2024-04-09T16:39:13.631682Z","shell.execute_reply.started":"2024-04-09T16:39:13.627370Z","shell.execute_reply":"2024-04-09T16:39:13.630806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ipd.Audio(bird1_asbfly1)","metadata":{"papermill":{"duration":0.262975,"end_time":"2023-03-17T15:24:10.915187","exception":false,"start_time":"2023-03-17T15:24:10.652212","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:39:31.107180Z","iopub.execute_input":"2024-04-09T16:39:31.107539Z","iopub.status.idle":"2024-04-09T16:39:31.161606Z","shell.execute_reply.started":"2024-04-09T16:39:31.107513Z","shell.execute_reply":"2024-04-09T16:39:31.160716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ipd.Audio(bird2_ashdro1)","metadata":{"papermill":{"duration":0.27411,"end_time":"2023-03-17T15:24:11.414944","exception":false,"start_time":"2023-03-17T15:24:11.140834","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:39:44.460043Z","iopub.execute_input":"2024-04-09T16:39:44.460410Z","iopub.status.idle":"2024-04-09T16:39:44.497126Z","shell.execute_reply.started":"2024-04-09T16:39:44.460383Z","shell.execute_reply":"2024-04-09T16:39:44.496249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ipd.Audio(bird3_barswa1)","metadata":{"papermill":{"duration":0.248656,"end_time":"2023-03-17T15:24:11.895041","exception":false,"start_time":"2023-03-17T15:24:11.646385","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:39:52.697432Z","iopub.execute_input":"2024-04-09T16:39:52.698378Z","iopub.status.idle":"2024-04-09T16:39:52.724150Z","shell.execute_reply.started":"2024-04-09T16:39:52.698344Z","shell.execute_reply":"2024-04-09T16:39:52.723222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Load the data**","metadata":{"papermill":{"duration":0.23215,"end_time":"2023-03-17T15:24:12.363609","exception":false,"start_time":"2023-03-17T15:24:12.131459","status":"completed"},"tags":[]}},{"cell_type":"code","source":"f1,sr= librosa.load(bird1_asbfly1)\nf2,_ = librosa.load(bird2_ashdro1)\nf3,_ = librosa.load(bird3_barswa1)\n\n#sample duration\nsample_duration = 1/sr\nprint(f\"Duration of 1 sample is: {sample_duration: .6f} seconds\")\n\n# duration of audio signal\nduration = sample_duration * len(f1)\nprint(f\"Duration of 1 sample is:{duration: .6f} seconds\")\n","metadata":{"papermill":{"duration":9.072626,"end_time":"2023-03-17T15:24:21.666458","exception":false,"start_time":"2023-03-17T15:24:12.593832","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:40:45.911942Z","iopub.execute_input":"2024-04-09T16:40:45.912706Z","iopub.status.idle":"2024-04-09T16:40:52.364340Z","shell.execute_reply.started":"2024-04-09T16:40:45.912672Z","shell.execute_reply":"2024-04-09T16:40:52.363279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Visualize the loaded data**","metadata":{"papermill":{"duration":0.233181,"end_time":"2023-03-17T15:24:22.133600","exception":false,"start_time":"2023-03-17T15:24:21.900419","status":"completed"},"tags":[]}},{"cell_type":"code","source":"#Visualize\nplt.figure(figsize=(15,17))\n\nplt.subplot(3,1,1)\nlibrosa.display.waveshow(f1,alpha=0.5)\nplt.ylim((-1,1))\nplt.title('bird1_asbfly1')\n\nplt.subplot(3,1,2)\nlibrosa.display.waveshow(f2,alpha=0.5)\nplt.title('bird2_ashdro1')\nplt.ylim((-1,1))\n\nplt.subplot(3,1,3)\nlibrosa.display.waveshow(f3,alpha=0.5)\nplt.title('bird3_barswa1')\nplt.ylim((-1,1))\n\nplt.tight_layout()\n\nplt.show()","metadata":{"papermill":{"duration":1.761242,"end_time":"2023-03-17T15:24:24.128879","exception":false,"start_time":"2023-03-17T15:24:22.367637","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-09T16:41:21.887468Z","iopub.execute_input":"2024-04-09T16:41:21.887853Z","iopub.status.idle":"2024-04-09T16:41:23.855972Z","shell.execute_reply.started":"2024-04-09T16:41:21.887824Z","shell.execute_reply":"2024-04-09T16:41:23.855066Z"},"trusted":true},"execution_count":null,"outputs":[]}]}