{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":91844,"databundleVersionId":11361821,"sourceType":"competition"}],"dockerImageVersionId":30918,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"Published on March 10, 2025. By Prata, Marília (mpwolke)","metadata":{}},{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport plotly.graph_objs as go\nimport plotly.offline as py\nimport plotly.express as px\n\n#Ignore warnings\nimport warnings\nwarnings.filterwarnings('ignore')\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-03-10T22:43:30.020505Z","iopub.execute_input":"2025-03-10T22:43:30.020783Z","iopub.status.idle":"2025-03-10T22:44:50.982135Z","shell.execute_reply.started":"2025-03-10T22:43:30.020738Z","shell.execute_reply":"2025-03-10T22:44:50.981044Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"_kg_hide-input":true,"_kg_hide-output":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Dataset Description\n\n\"Your challenge in this competition is to identify which species (birds, amphibians, mammals, insects) are calling in recordings made in **El Silencio Natural Reserve, Colombia**. This is an important task for scientists who monitor animal populations for conservation purposes. More accurate solutions could enable more comprehensive monitoring.\"\n\nhttps://www.kaggle.com/competitions/birdclef-2025/data","metadata":{}},{"cell_type":"markdown","source":"![](https://image2.slideserve.com/5206482/colombia-middle-magdalena-valley-properties-l.jpg)SlideServe","metadata":{}},{"cell_type":"markdown","source":"## Competition Citation:\n\n@misc{birdclef-2025,\n\n    author = {Holger Klinck and Juan Sebastián Cañas and Maggie Demkin and Sohier Dane and Stefan Kahl and Tom Denton},\n    \n    title = {BirdCLEF+ 2025},\n    \n    year = {2025},\n    howpublished = {\\url{https://kaggle.com/competitions/birdclef-2025}},","metadata":{}},{"cell_type":"code","source":"#By Paulo Junqueira https://www.kaggle.com/code/paulojunqueira/pew-pew-overview-birdclef-2023/notebook\n\nimport re\nimport librosa\nimport librosa.display\n\nimport IPython.display as ipd\nfrom urllib.request import urlopen\nfrom datetime import datetime, timedelta\n\nimport plotly.graph_objects as go\nfrom scipy.interpolate import interp1d \nfrom bs4 import BeautifulSoup as bs\nimport librosa\nimport librosa.display\nimport IPython.display as ipd\n# import noisereduce as nr\n\nfrom tqdm.notebook import tqdm\n# Pytorch\nimport torch\nimport torchaudio\nimport requests\nfrom PIL import Image","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-10T23:10:04.747903Z","iopub.execute_input":"2025-03-10T23:10:04.748282Z","iopub.status.idle":"2025-03-10T23:10:04.763828Z","shell.execute_reply.started":"2025-03-10T23:10:04.748254Z","shell.execute_reply":"2025-03-10T23:10:04.762623Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## metadata csv file","metadata":{}},{"cell_type":"code","source":"meta = pd.read_csv('../input/birdclef-2025/train.csv')\nmeta['secondary_labels'] = meta['secondary_labels'].apply(lambda x: re.findall(r\"'(\\w+)'\", x))\nmeta['len_sec_labels'] = meta['secondary_labels'].map(len)\nmeta.head(2)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-10T22:54:42.320285Z","iopub.execute_input":"2025-03-10T22:54:42.320629Z","iopub.status.idle":"2025-03-10T22:54:42.594548Z","shell.execute_reply.started":"2025-03-10T22:54:42.320603Z","shell.execute_reply":"2025-03-10T22:54:42.593579Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## The Middle Magdalena Valley\n\n\n**The silence, natural reserve, and research station.**\n\n\n\"Let’s save the forests and wetlands of the Middle Magdalena Valley.\"\n\n\"Biodiverse Colombia Foundation has been working in the Middle Magdalena Valley since 2006 on conservation projects for three threatened species: the gray tamarin (Saguinus leucopus), the river turtle (Podocnemis lewyana), both endemic to this area, and the brown spider monkey (Ateles fusciceps).\"\n\nhttps://www.fundacionbiodiversa.org/fundacion2024/information/","metadata":{}},{"cell_type":"code","source":"#By Paulo Junqueira https://www.kaggle.com/code/paulojunqueira/pew-pew-overview-birdclef-2023/notebook\n\n#Two lines Required to Plot Plotly\nimport plotly.io as pio\npio.renderers.default = 'iframe'\n\n\ndf_plot = meta.groupby(['primary_label','latitude', 'longitude']).count().reset_index()[['primary_label','scientific_name','latitude', 'longitude']].rename(columns = {'scientific_name':'count'})\nmeta_2 = meta.merge(df_plot, on = ['primary_label','latitude', 'longitude'], how = 'left').dropna(subset = ['count'])\nmeta_2['count'] = meta_2['count'].astype('int')\n\nvalues_list = meta_2['count'].values.tolist()\n\ninterpolation = interp1d([1, max(values_list)], [3,20])\nradius = interpolation(values_list)\nfig = go.Figure(go.Densitymapbox(lat =meta_2['latitude'],lon = meta_2['longitude'], radius = radius,z = meta_2['count']))\n\nfig.update_layout(mapbox_style=\"open-street-map\",height = 800,\n                  mapbox = {\n                          'center': {'lat': 0, \n                          'lon': 0},\n                      'zoom':0\n                  })\nfig.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-10T23:29:20.366073Z","iopub.execute_input":"2025-03-10T23:29:20.366478Z","iopub.status.idle":"2025-03-10T23:29:20.512130Z","shell.execute_reply.started":"2025-03-10T23:29:20.366449Z","shell.execute_reply":"2025-03-10T23:29:20.510787Z"},"_kg_hide-input":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Protection of the last forest remnants and wetlands: an urgent need.\n\n\"Humid tropical rainforests, Earth's most biodiverse and ancient ecosystems, are vital for climate regulation and water resource protection. However, rainforests face severe threats. In **Colombia**, a megadiverse country, **the lowlands of the Magdalena Valley** are a biodiversity hotspot and home to many endangered species. Over 70% of the Magdalena Valley lowland rainforests are replaced by vast pastures for cattle ranching, and **illegal logging is common in forest fragment remnants.** The protection of the last forest remnants and wetlands is an urgent need.\"\n\nhttps://www.kaggle.com/competitions/birdclef-2025/overview","metadata":{}},{"cell_type":"code","source":"#By Ben Jenkins https://www.kaggle.com/code/benjenkins96/identify-eastern-african-bird-species-by-sound\n\n# Set up a figure with subplots\nfig, axs = plt.subplots(2, 2, figsize=(12, 8))\n\n# Plot a histogram of the latitude values\nmeta['latitude'].hist(bins=50, ax=axs[0, 0])\naxs[0, 0].set_title('Distribution of Latitude', color='red')\naxs[0, 0].set_xlabel('Latitude', color='red')\naxs[0, 0].set_ylabel('Count', color='red')\n# Plot a histogram of the longitude values\nmeta['longitude'].hist(bins=50, ax=axs[0, 1])\naxs[0, 1].set_title('Distribution of Longitude', color='red')\naxs[0, 1].set_xlabel('Longitude', color='red')\naxs[0, 1].set_ylabel('Count', color='red')\n\n# Plot a scatterplot of the latitude and longitude values\nmeta.plot.scatter(x='longitude', y='latitude', alpha=0.1, ax=axs[1, 0])\naxs[1, 0].set_title('Geographic Distribution of Recordings', color='red')\naxs[1, 0].set_xlabel('Longitude', color='red')\naxs[1, 0].set_ylabel('Latitude', color='red')\n\n# Print the top 10 authors with the most recordings\nmeta['author'].value_counts().nlargest(10).plot.barh(ax=axs[1, 1])\naxs[1, 1].set_title('Top 10 Authors with the Most Recordings', color='red')\naxs[1, 1].set_xlabel('Count', color='red')\naxs[1, 1].set_ylabel('Author', color='red')\n\n# Adjust the layout of the subplots\nplt.tight_layout()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-10T23:26:28.909778Z","iopub.execute_input":"2025-03-10T23:26:28.912992Z","iopub.status.idle":"2025-03-10T23:26:30.932831Z","shell.execute_reply.started":"2025-03-10T23:26:28.912829Z","shell.execute_reply":"2025-03-10T23:26:30.931370Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Most Recordings contributor: Jayrson Araujo de Oliveira  \n\n\"Professor passionate for Biology, especially Birds. He said, he is just beginning to learn about ornithology and intend to advance in my knowledge to the limit, especially recognition of songs' bird. The vast majority of the songs I put on this site are also on wikiaves.com.br.\"\n\nhttps://xeno-canto.org/contributor/LXKLWEDKEM","metadata":{}},{"cell_type":"markdown","source":"## Taxonomy csv file","metadata":{}},{"cell_type":"code","source":"taxonomy = pd.read_csv(\"/kaggle/input/birdclef-2025/taxonomy.csv\")\npd.set_option('display.max_columns', None)\ntaxonomy.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-10T23:32:25.996590Z","iopub.execute_input":"2025-03-10T23:32:25.997037Z","iopub.status.idle":"2025-03-10T23:32:26.019018Z","shell.execute_reply.started":"2025-03-10T23:32:25.997006Z","shell.execute_reply":"2025-03-10T23:32:26.017796Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Magdalena Valley animals Class Names","metadata":{}},{"cell_type":"code","source":"ax = taxonomy['class_name'].value_counts()[:20].plot.barh(figsize=(16, 8), color='green')\nax.set_title('Colombian Animals Class names', size=18, color='orange')\nax.set_ylabel('class_name', size=10)\nax.set_xlabel('Count', size=10);","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-11T00:04:56.722963Z","iopub.execute_input":"2025-03-11T00:04:56.723388Z","iopub.status.idle":"2025-03-11T00:04:57.123601Z","shell.execute_reply.started":"2025-03-11T00:04:56.723355Z","shell.execute_reply":"2025-03-11T00:04:57.122366Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Groupby forest animals by Scientific name and Class names","metadata":{}},{"cell_type":"code","source":"taxonomy.groupby(['scientific_name','class_name']).size().reset_index(name='count')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-11T00:07:58.225034Z","iopub.execute_input":"2025-03-11T00:07:58.225471Z","iopub.status.idle":"2025-03-11T00:07:58.241731Z","shell.execute_reply.started":"2025-03-11T00:07:58.225441Z","shell.execute_reply":"2025-03-11T00:07:58.240592Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Colombian Forest Animals by Class names","metadata":{}},{"cell_type":"code","source":"#Eunji Goo https://www.kaggle.com/code/quantum09/is-it-going-to-rain\n\nclass_proportion = taxonomy['class_name'].value_counts()/taxonomy['class_name'].value_counts().sum()\ncolormap = plt.cm.tab10(range(0, len(class_proportion)))\nlabels = class_proportion.index\nvalues = class_proportion.values\n\nbars = plt.barh(labels, values)\n\n#plt.xlabel(\"Frequency\") #Não alterou nada\n\n#plt.legend(title='Forest Animals Class names' , bbox_to_anchor=(1.0, 1), loc='lower right')#HORRÌVEL!\n\nbar_plot = class_proportion.plot.barh(color=colormap)\n\n# Add titles, labels, invert y-axis\n\nbar_plot.set_title(\"Colombian Forest Animals by Class names\")\nbar_plot.set_ylabel(\"Class Names\")\n\ntotal = values.sum()\nfor bar, count in zip(bars, values):\n    width = bar.get_width()\n    pct = count / total * 100\n    plt.text(width, bar.get_y() + bar.get_height()/2,\n             f\"{count}\\n({pct:.1f}%)\",\n             ha='left', va='center')\n\n#Invert the axis to have the descending order\nbar_plot.invert_yaxis()\nplt.show(bar_plot)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-11T00:17:59.963219Z","iopub.execute_input":"2025-03-11T00:17:59.963604Z","iopub.status.idle":"2025-03-11T00:18:00.260317Z","shell.execute_reply.started":"2025-03-11T00:17:59.963568Z","shell.execute_reply":"2025-03-11T00:18:00.259273Z"},"_kg_hide-input":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Let's try to hear a sample of EL Silencio Natural Reserve.","metadata":{}},{"cell_type":"code","source":"#Code by Sayantan Mazumdar https://www.kaggle.com/swaralipibose/converting-audio-to-spectogram-noise-image-data/notebook\n\n!pip install soundfile -q","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-11T00:31:41.013781Z","iopub.execute_input":"2025-03-11T00:31:41.014335Z","iopub.status.idle":"2025-03-11T00:31:46.341196Z","shell.execute_reply.started":"2025-03-11T00:31:41.014300Z","shell.execute_reply":"2025-03-11T00:31:46.339799Z"},"_kg_hide-output":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#Code by Sayantan Mazumdar https://www.kaggle.com/swaralipibose/converting-audio-to-spectogram-noise-image-data/notebook\n\n!pip install noisereduce","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-11T00:32:02.422346Z","iopub.execute_input":"2025-03-11T00:32:02.422722Z","iopub.status.idle":"2025-03-11T00:32:06.916320Z","shell.execute_reply.started":"2025-03-11T00:32:02.422689Z","shell.execute_reply":"2025-03-11T00:32:06.915078Z"},"_kg_hide-output":true,"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Convert Audio to Frequency\n\nIt's freezing the page, therefore I commented the snippet.","metadata":{}},{"cell_type":"code","source":"#Code by Sayantan Mazumdar https://www.kaggle.com/swaralipibose/converting-audio-to-spectogram-noise-image-data/notebook\n\n#Convert Audio to Frequency\n\n#import soundfile as sf\n#freq,rate=sf.read('../input/birdclef-2025/train_audio/1139490/CSA36389.ogg')\n#import plotly.express as px\n#import numpy as np\n#px.line(x=np.array(list(range(len(freq)))),y=freq)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-11T00:40:53.827602Z","iopub.execute_input":"2025-03-11T00:40:53.828107Z","iopub.status.idle":"2025-03-11T00:40:57.511546Z","shell.execute_reply.started":"2025-03-11T00:40:53.828070Z","shell.execute_reply":"2025-03-11T00:40:57.510636Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Display ogg Audio\n\nThat's a description of the recordings, not an expected animal.  ","metadata":{}},{"cell_type":"code","source":"#Code by Sayantan Mazumdar https://www.kaggle.com/swaralipibose/converting-audio-to-spectogram-noise-image-data/notebook\n\nimport IPython\nIPython.display.Audio(\"../input/birdclef-2025/train_audio/1139490/CSA36389.ogg\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-11T00:42:18.339233Z","iopub.execute_input":"2025-03-11T00:42:18.339618Z","iopub.status.idle":"2025-03-11T00:42:18.372381Z","shell.execute_reply.started":"2025-03-11T00:42:18.339589Z","shell.execute_reply":"2025-03-11T00:42:18.371182Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"##  El Silencio Natural Reserve\n\n\"Established in 2012, El Silencio Natural Reserve protects 5,407 acres of tropical lowland forests and wetlands. Home to diverse wildlife, including 295 birds, 34 amphibians, 69 mammals, 50 reptiles, and nearly 500 plant species, El Silencio is a **model for regional conservation and sustainability**.\"\n\nhttps://www.kaggle.com/competitions/birdclef-2025/overview","metadata":{}},{"cell_type":"markdown","source":"![](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSc_4VFSnT2fXRYvJkvJ_ksANI5b8eMT9ma3w&s)","metadata":{}},{"cell_type":"markdown","source":"#Acknowledgements:\n\nPaulo Junqueira https://www.kaggle.com/code/paulojunqueira/pew-pew-overview-birdclef-2023/notebook\n\nBen Jenkins https://www.kaggle.com/code/benjenkins96/identify-eastern-african-bird-species-by-sound\n\nSayantan Mazumdar https://www.kaggle.com/swaralipibose/converting-audio-to-spectogram-noise-image-data/notebook\n\nEunji Goo https://www.kaggle.com/code/quantum09/is-it-going-to-rain\n\nMarília Prata https://www.kaggle.com/code/mpwolke/birdclef-2024-western-ghats-species/notebook","metadata":{}}]}