{"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":"code","source":"from IPython.core.display import HTML; import urllib.request\n\ndef apply_styling_changes():\n    get_url= urllib.request.urlopen('https://raw.githubusercontent.com/heyrobin/heyrobin-personalization/main/theme.css').read().decode(\"utf-8\")\n    return HTML(\"<style>\"+get_url+\"</style>\")\napply_styling_changes()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-26T05:25:20.735723Z","iopub.execute_input":"2022-06-26T05:25:20.736695Z","iopub.status.idle":"2022-06-26T05:25:21.130606Z","shell.execute_reply.started":"2022-06-26T05:25:20.736592Z","shell.execute_reply":"2022-06-26T05:25:21.129673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div class=\"page-title\">The Songs of Indian Birds</div>\n<div class=\"page-summary \"> Statistical analysis of indian birds.</div>","metadata":{}},{"cell_type":"markdown","source":"<img src=\"https://github.com/heyrobin/Birds-identify-eda/blob/main/banner.jpg?raw=true\">","metadata":{}},{"cell_type":"markdown","source":"Some birds are little as finger and some are larger than a dog but each species has a unique distinctions and sounds. A morning with a chirp of little birb can make your morning delight but sad part of this reality is they are getting extinct every year we hear the news of them getting extinct.\n\nIn this notebook we are looking at the types of birds found in india and there sounds. I created the seprate dataset with the country name of the species found I created a function below which takes lattitude and logitude data to country name.\n\nThis notebook only contains the analysis of the birds. Do upvote and share if you enjoy the notebook.","metadata":{}},{"cell_type":"code","source":"#Data\nimport numpy as np\nimport pandas as pd\n\n#vizuals\nimport seaborn as sns\nimport plotly.express as px\nimport matplotlib.pyplot as plt\nimport plotly.graph_objects as go\n\nimport librosa\nimport librosa.display\nimport IPython.display as ipd\n\nplt.rcParams['figure.figsize'] = (14,4)\nplt.rcParams['axes.edgecolor'] = 'black'\nplt.rcParams['axes.linewidth'] = 1.5\nplt.rcParams['figure.frameon'] = True\nplt.rcParams['axes.spines.top'] = False\nplt.rcParams['axes.spines.right'] = False\nplt.rcParams[\"font.family\"] = \"monospace\";\n\n# Color Palettes\ncolors = [\"#D8C7AD\"]\n\n#data\n\n'''Location of the data'''\n#!ls -GFlash --color ../input/birdclef-2022/\n\nlink = \"../input/birdclef-2022\"\ntrain = pd.read_csv(link + '/train_metadata.csv')\n\nbirb = pd.read_csv(\"../input/bird-location/newdat.csv\")\n\nindia_df = birb[birb[\"country\"]==\"India\"]\nindia_df = india_df[['primary_label','type','latitude','longitude','scientific_name','common_name','rating','time','filename','geom','geoms','city','country','country_code']]\nindia_df.head()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-26T05:25:21.13278Z","iopub.execute_input":"2022-06-26T05:25:21.133367Z","iopub.status.idle":"2022-06-26T05:25:25.217366Z","shell.execute_reply.started":"2022-06-26T05:25:21.133322Z","shell.execute_reply":"2022-06-26T05:25:25.216412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# I have created dataset for new location below is the following code\n\n'''from tqdm import tqdm\nfrom geopy.geocoders import Nominatim\n\n# joining latitude and longitude to a new column\ntrain[\"geom\"] = train[\"latitude\"].map(str) + ',' + train[\"longitude\"].map(str)\n\n#looping and appending the 3 new location column from lat and long\ncity = []\ncountry_code = []\ncountry = []\n\nfor i in tqdm(train[\"geom\"]):\n    try:\n        geolocator = Nominatim(user_agent=\"http\")\n        location = geolocator.reverse(i)\n        Country = location.raw.get('address').get('country')\n        City = location.raw.get('address').get('city')\n        Country_code = location.raw.get('address').get('country_code')\n    except:\n        print(\"none\")\n    print(Country,City,Country_code)\n    city.append(City)\n    country_code.append(Country_code)\n    country.append(Country)\n\n\n#creating new columns\ntrain[\"country\"] = pd.Series(country)\ntrain[\"city\"] = pd.Series(city)\ntrain[\"country_code\"] = pd.Series(country_code)\n\ntrain.to_csv('newdat.csv')'''\n\n\n# Function\n# Add Image\ndef imager(link,X,Y,Zoom):\n    fig.add_layout_image(\n        dict(\n            source=link,\n            xref=\"paper\", yref=\"paper\",\n            x=X,y=Y,\n            sizex=Zoom, sizey=Zoom,\n            xanchor=\"right\", yanchor=\"bottom\"\n        )\n    )\n    \n\n# Add Text    \ndef texter(Text,X,Y,sizer,font):\n    fig.add_annotation(text=Text,\n                  xref=\"paper\", yref=\"paper\",\n                  x=X,y=Y, showarrow=False,\n                    font=dict(\n                        family=font,\n                        size=sizer,\n                        color=\"#4c4e4d\"\n                        ))","metadata":{"scrolled":true,"_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-06-26T05:25:25.218693Z","iopub.execute_input":"2022-06-26T05:25:25.218912Z","iopub.status.idle":"2022-06-26T05:25:25.226142Z","shell.execute_reply.started":"2022-06-26T05:25:25.218885Z","shell.execute_reply":"2022-06-26T05:25:25.224759Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div class=\"page-title2 \"> Species</div>","metadata":{}},{"cell_type":"markdown","source":"These are the lists of all the indian species found in the dataset. We have <b>30</b> species and from diffrent locations.","metadata":{}},{"cell_type":"code","source":"Datas = india_df[\"common_name\"].value_counts().reset_index().sort_values(by='common_name')\n\n# Creating the bar chart\ntrace = go.Bar(\n    y = Datas[\"index\"],\n    x = Datas[\"common_name\"],\n    orientation = \"h\",\n    marker_color= \"#4F7177\",\n    text = Datas[\"common_name\"],\n)\n\nlayout = dict(\n    width = 600,\n    height= 1000,\n    plot_bgcolor = \"#FFFFFF\",\n    font=dict(family='Arial',\n              size=12, \n              color='black'),\n    margin = dict(\n        l=0,\n        r=0,\n        b=100,\n        t=100,\n        pad=0\n    ),\n    xaxis = dict(showline=True, linewidth=1.45, linecolor=\"#4F7177\",gridcolor='#D5D7D8',\n                 #griddash='dot',\n                 title_text='Counts'),\n    yaxis = dict(showline=True, linewidth=1.45, linecolor=\"#4F7177\",ticksuffix = \"  \",title_text='Name'),\n    bargap = 0.15,hoverlabel_bgcolor=\"#4F7177\",hovermode=\"x\"\n)\n\nfig = go.Figure(data = trace, layout = layout)\n\nfig.layout.xaxis.fixedrange = True\nfig.layout.yaxis.fixedrange = True\n\n\n#text\ntexter(\"Indian Birds Species\",0.000,1.10,28,\"Work Sans\")\ntexter(\"Birds found in the dataset\",0.000,1.06,18,\"Source Sans Pro\")\ntexter(\"heyRobin!\",1.00,-0.06,16,\"Playfair Display\")\n\n\nfig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-26T05:25:25.228459Z","iopub.execute_input":"2022-06-26T05:25:25.228758Z","iopub.status.idle":"2022-06-26T05:25:25.43939Z","shell.execute_reply.started":"2022-06-26T05:25:25.228719Z","shell.execute_reply":"2022-06-26T05:25:25.438471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div class=\"page-title2 \"> Location</div>","metadata":{}},{"cell_type":"code","source":"fig = px.scatter_geo(\n    india_df,\n    lat=\"latitude\",\n    lon=\"longitude\",\n    color=\"common_name\",\n    width=1000,\n    height=800,\n    title=\"Birds Species\",\n    #projection=\"natural earth\",\n    projection=\"mercator\",\n    scope='asia'\n)\nfig.update_layout(title = 'Species in India',\n                  dragmode=False,\n                 geo=dict(bgcolor= '#E1E3D8'))\nfig.update_geos(fitbounds='locations')\nfig.show()\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-06-26T05:25:25.440863Z","iopub.execute_input":"2022-06-26T05:25:25.441066Z","iopub.status.idle":"2022-06-26T05:25:26.392621Z","shell.execute_reply.started":"2022-06-26T05:25:25.441042Z","shell.execute_reply":"2022-06-26T05:25:26.391826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<hr>","metadata":{}},{"cell_type":"markdown","source":"<div class=\"page-title2 \"> Bird Recordings</div>\n\nThe following data includes all the audio files in the data. We will display the recordings and audio spectrum<br> of all the indian birds present in the data.","metadata":{}},{"cell_type":"markdown","source":"<h2 style=\"font-weight: bold;\">1. Indian Peafowl</h2>\n\n\n\n<div class =\"image\"> <img style=\"float: left;margin:5px 20px 5px 1px\" src=\"https://cdn.download.ams.birds.cornell.edu/api/v1/asset/97326721/1800\" width=\"400\" height=\"500\"></div>\n<p>Peafowl is a common name for three bird species in the genera Pavo and<br> Afropavo within the tribe Pavonini of the family Phasianidae,<br>the pheasants and their allies.</p>","metadata":{}},{"cell_type":"code","source":"# function\n# name represents the selected bird\n#num represents number of audio in the selected bird\n\ndef bird(num,name):\n    loca = india_df[india_df['common_name'] == name][\"filename\"].values[num]\n    all = link+'/train_audio/'+loca\n    #diplay wave\n    ar, sr = librosa.load(link+'/train_audio/'+loca, duration=10)\n    arr = librosa.stft(ar)\n    arr_db = librosa.amplitude_to_db(abs(arr))\n    librosa.display.specshow(arr_db, sr=sr, x_axis='s', y_axis='hz')\n    plt.colorbar()\n    return ipd.Audio(all)\n\nbird(10,\"Indian Peafowl\")","metadata":{"execution":{"iopub.status.busy":"2022-06-26T05:25:26.393885Z","iopub.execute_input":"2022-06-26T05:25:26.39412Z","iopub.status.idle":"2022-06-26T05:25:28.277644Z","shell.execute_reply.started":"2022-06-26T05:25:26.394091Z","shell.execute_reply":"2022-06-26T05:25:28.276733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h2 style=\"font-weight: bold;\">2. Black-crowned Night-Heron</h2>\n\n\n<div class =\"image\"> <img style=\"float: left;margin:5px 20px 5px 1px\" src=\"https://cdn.download.ams.birds.cornell.edu/api/v1/asset/304988121/1800\" width=\"400\" height=\"500\"></div>\n<p>The black-crowned night heron, or black-capped night heron, commonly shortened to just night heron<br> in Eurasia,is a medium-sized heron found throughout a large part of the world, including parts<br> of Europe, Asia, and North and South America.","metadata":{}},{"cell_type":"code","source":"bird(2,\"Black-crowned Night-Heron\")","metadata":{"execution":{"iopub.status.busy":"2022-06-26T05:25:28.278958Z","iopub.execute_input":"2022-06-26T05:25:28.279174Z","iopub.status.idle":"2022-06-26T05:25:29.367541Z","shell.execute_reply.started":"2022-06-26T05:25:28.279143Z","shell.execute_reply":"2022-06-26T05:25:29.366716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h2 style=\"font-weight: bold;\">3. Black-bellied Plover</h2>\n\n<div class =\"image\"> <img style=\"float: left;margin:5px 20px 5px 1px\" src=\"https://cdn.download.ams.birds.cornell.edu/api/v1/asset/297925101/1800\" width=\"400\" height=\"500\"></div>\n\n<p>Black-bellied Plovers are a dazzling mix of snow white and jet black, accented by checkerboard wings. <br>They are supreme aerialists, both agile and swift, and are readily identified at great distance by <br>black axillaries (“armpit” feathers) in all plumages—and by their distinctive, mournful-sounding call. <br>The largest and heaviest of North American plovers, Black-bellied is also the hardiest, breeding farther <br>north than other species, at the very top of the world. It is also a very widespread shorebird,<br> occurring on six continents.</p>","metadata":{}},{"cell_type":"code","source":"bird(3,\"Black-bellied Plover\")","metadata":{"execution":{"iopub.status.busy":"2022-06-26T05:25:29.368611Z","iopub.execute_input":"2022-06-26T05:25:29.368819Z","iopub.status.idle":"2022-06-26T05:25:29.89921Z","shell.execute_reply.started":"2022-06-26T05:25:29.368794Z","shell.execute_reply":"2022-06-26T05:25:29.898661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h2 style=\"font-weight: bold;\">4. Black Francolin</h2>\n\n<left><p><img style=\"float: left;margin:5px 20px 5px 1px\" src=\"https://cdn.download.ams.birds.cornell.edu/api/v1/asset/97329251/1800\" width=\"400\" height=\"500\"></p></left>\n\n<p>Strikingly patterned male is unmistakable with his jet-black face and breast, white cheek patch, dark rust-brown collar,<br>\n    and bright white spots. Brownish female has a small orange nape patch, pale throat, and dense black-and-white markings all<br>\n    over the body; compare with larger Gray Francolin. Occurs in dry grasslands, agricultural land, and weedy fields. </p>","metadata":{}},{"cell_type":"code","source":"bird(1,\"Black Francolin\")","metadata":{"execution":{"iopub.status.busy":"2022-06-26T05:25:29.900267Z","iopub.execute_input":"2022-06-26T05:25:29.900644Z","iopub.status.idle":"2022-06-26T05:25:30.47502Z","shell.execute_reply.started":"2022-06-26T05:25:29.90061Z","shell.execute_reply":"2022-06-26T05:25:30.47412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"\n\n<h2 style=\"font-weight: bold;\">5. Barn Owl</h2>\n\n<left><p><img style=\"float: left;margin:5px 20px 5px 1px\" src=\"https://cdn.download.ams.birds.cornell.edu/api/v1/asset/297342281/1800\" width=\"400\" height=\"500\"></p></left>\n\n<p>Strikingly patterned male is unmistakable with his jet-black face and breast, white cheek patch, dark rust-brown collar,<br>\n    and bright white spots. Brownish female has a small orange nape patch, pale throat, and dense black-and-white markings all<br>\n    over the body; compare with larger Gray Francolin. Occurs in dry grasslands, agricultural land, and weedy fields. </p>","metadata":{}},{"cell_type":"code","source":"bird(4,\"Barn Owl\")","metadata":{"execution":{"iopub.status.busy":"2022-06-26T05:25:30.47679Z","iopub.execute_input":"2022-06-26T05:25:30.477001Z","iopub.status.idle":"2022-06-26T05:25:31.578901Z","shell.execute_reply.started":"2022-06-26T05:25:30.476976Z","shell.execute_reply":"2022-06-26T05:25:31.578027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h2 style=\"font-weight: bold;\">6. Ruff</h2>\n\n<left><p><img style=\"float: left;margin:5px 20px 5px 1px\" src=\"https://cdn.download.ams.birds.cornell.edu/api/v1/asset/301258541/1800\" width=\"400\" height=\"500\"></p></left>\n\n<p>A bizarre and unique shorebird. Medium-sized with fairly short, slightly drooped bill. Leg color varies from dull greenish<br>\n    to bright orange; bill can be entirely dark or mostly orange. Plumage highly variable, especially breeding males, which have<br>\n    fancy neck ruffs that can be black, white, buffy, reddish-brown, or any combination thereof. Females and nonbreeding birds can <br>\n    be confusing, usually plain grayish-brown overall, sometimes with blotchy markings on the neck and belly. Juveniles are bright<br> \n    buffy with neat scaly patterning on the upperparts.<br></p>\n","metadata":{}},{"cell_type":"code","source":"bird(0,\"Ruff\")","metadata":{"execution":{"iopub.status.busy":"2022-06-26T05:26:54.810826Z","iopub.execute_input":"2022-06-26T05:26:54.811344Z","iopub.status.idle":"2022-06-26T05:26:55.599677Z","shell.execute_reply.started":"2022-06-26T05:26:54.811307Z","shell.execute_reply":"2022-06-26T05:26:55.598791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h2 style=\"font-weight: bold;\">7. Mallard</h2>\n\n<left><p><img style=\"float: left;margin:5px 20px 5px 1px\" src=\"https://www.allaboutbirds.org/guide/assets/photo/308743051-1280px.jpg\" width=\"400\" height=\"500\"></p></left>\n\n<p>If someone at a park is feeding bread to ducks, chances are there are Mallards in the fray. Perhaps the most familiar of<br>\n    all ducks, Mallards occur throughout North America and Eurasia in ponds and parks as well as wilder wetlands and estuaries.<br>\n    The male’s gleaming green head, gray flanks, and black tail-curl arguably make it the most easily identified duck. Mallards<br>\n    have long been hunted for the table, and almost all domestic ducks come from this species.<br></p>\n","metadata":{}},{"cell_type":"code","source":"bird(0,\"Mallard\")","metadata":{"execution":{"iopub.status.busy":"2022-06-26T05:27:15.369461Z","iopub.execute_input":"2022-06-26T05:27:15.369724Z","iopub.status.idle":"2022-06-26T05:27:16.102649Z","shell.execute_reply.started":"2022-06-26T05:27:15.369697Z","shell.execute_reply":"2022-06-26T05:27:16.101717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h2 style=\"font-weight: bold;\">8. Sanderling</h2>\n\n<left><p><img style=\"float: left;margin:5px 20px 5px 1px\" src=\"https://www.allaboutbirds.org/guide/assets/photo/64814541-1280px.jpg\" width=\"400\" height=\"500\"></p></left>\n\n<p>The Sanderling’s black legs blur as it runs back and forth on the beach, picking or probing for tiny<br>\n    prey in the wet sand left by receding waves. Sanderlings are medium-sized “peep” sandpipers recognizable<br>\n    by their pale nonbreeding plumage, black legs and bill, and obsessive wave-chasing habits. Learn this<br>\n    species, and you’ll have an aid in sorting out less common shorebirds. These extreme long-distance<br>\n    migrants breed only on High Arctic tundra, but during the winter they live on most of the sandy beaches<br>\n    of the world.<br></p>\n","metadata":{}},{"cell_type":"code","source":"bird(0,\"Sanderling\")","metadata":{"execution":{"iopub.status.busy":"2022-06-26T05:29:12.157094Z","iopub.execute_input":"2022-06-26T05:29:12.157366Z","iopub.status.idle":"2022-06-26T05:29:12.924765Z","shell.execute_reply.started":"2022-06-26T05:29:12.157339Z","shell.execute_reply":"2022-06-26T05:29:12.923923Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We have seen some of the birds with there sounds, The audio is very noisy but we were able to see them on Spectrogram.","metadata":{}},{"cell_type":"code","source":"india_df[\"common_name\"].unique()","metadata":{"execution":{"iopub.status.busy":"2022-06-26T05:28:43.220091Z","iopub.execute_input":"2022-06-26T05:28:43.221Z","iopub.status.idle":"2022-06-26T05:28:43.226631Z","shell.execute_reply.started":"2022-06-26T05:28:43.22096Z","shell.execute_reply":"2022-06-26T05:28:43.225767Z"},"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<hr>\n<div class=\"mini-bio\" style=\"font-size:18px;\">Thanks for reading share your feedback and leave an upvote if you liked the notebook.</div>\n<br>\n\n<div class=\"mini-bio-cred\">Image Source : <a href=\"https://ebird.org/\">@ebird.org</a></div>\n<div class=\"mini-bio-cred\">Analysis and Vizuals <a href=\"https://kaggle.com/heyrobin/\">@heyRobin</a></div>\n","metadata":{}}]}