Skip to content

Commit 993b98d

Browse files
Add files via upload
1 parent db5b00a commit 993b98d

20 files changed

+62109
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Track the movement of three gulls(birds) namely - Eric, Nico & Sanne : dataset : https://inbo.carto.com/u/lifewatch/datasets
2+
3+
One fascinating area of research uses GPS to track movements of animals.
4+
It is now possible to manufacturer a small GPS device that is solar charged,
5+
so you don't need to change batteries, and use
6+
it to track flight patterns of birds.
7+
The data for this case study comes from the LifeWatch INBO project.
8+
Several data sets have been released as part of this project.
9+
We will use a small data set that consists of migration data for three
10+
gulls named Eric, Nico, and Sanne.
11+
The csv file contains eight columns, and includes variables
12+
like latitude, longitude, altitude, and time stamps.
13+
In this case study, we will first load the data,
14+
visualize some simple flight trajectories,
15+
track flight speed, learn about daytime and much, much more.
16+
17+
18+
19+
Order of Project subparts :
20+
1.bird_migration_trajectories_lat.long.py
21+
2.bird_migration_speed.py
22+
3.bird_migration_date.time.py
23+
4.bird_migration_daily_mean_speed.py
24+
5.bird_migration_cartographic.py
25+
26+
27+
I did this project to accompany my learnings from HarvardX course - PH526x Using Python for Research.
28+
29+
- Amartya Ranjan Saikia ([email protected]/[email protected])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import cartopy.crs as ccrs
2+
import cartopy.feature as cfeature
3+
import matplotlib.pyplot as plt
4+
5+
proj = ccrs.Mercator() #To move forward, we need to specify a specific projection that we're interested in using.
6+
7+
plt.figure(figsize=(10,10))
8+
ax = plt.axes(projections=proj)
9+
ax.set_extent((-25.0, 20.0, 52.0, 10.0))
10+
ax.add_feature(cfeature.LAND)
11+
ax.add_feature(cfeature.OCEAN)
12+
ax.add_feature(cfeature.COASTLINE)
13+
ax.add_feature(cfeature.BORDERS, linestyle=':')
14+
for name in bird_names:
15+
ix = birddata['bird_name'] == name
16+
x,y = birddata.longitude[ix], birddata.latitude[ix]
17+
ax.plot(x,y,'.', transform=ccrs.Geodetic(), label=name)
18+
plt.legend(loc="upper left")
19+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pandas as pd
2+
import matplotlib.pyplot as plt
3+
import datetime
4+
import numpy as np
5+
6+
#code from bird_migration_date.time *************************************
7+
timestamps = []
8+
for k in range(len(birddata)):
9+
timestamps.append(datetime.datetime.strptime(birddata.date_time.iloc[k][:-3], "%Y-%m-%d %H:%M:%S"))
10+
birddata["timestamp"] = pd.Series(timestamps, index = birddata.index)
11+
12+
#code from bird_migration_date.time *************************************
13+
data = birddata[birddata.bird_name == "Eric"]
14+
times = data.timestamp
15+
elapsed_time = [time-times[0] for time in times]
16+
elapsed_days = np.array(elapsed_time)/datetime.timedelta(days=1)
17+
18+
next_day = 1
19+
inds = []
20+
daily_mean_speed = []
21+
for (i,t) in enumerate(elapsed_days):
22+
if t < next_day:
23+
inds.append(i)
24+
else:
25+
daily_mean_speed.append(np.mean(data.speed_2d[inds]))
26+
next_day += 1
27+
inds = []
28+
29+
plt.figure(figsize = (8,6))
30+
plt.plot(daily_mean_speed, "rs-")
31+
plt.xlabel(" Day ")
32+
plt.ylabel(" Mean Speed (m/s) ");
33+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import pandas as pd
2+
import matplotlib.pyplot as plt
3+
import datetime
4+
5+
# >>>birddata.column #check the columns of dataset
6+
# >>>birddata.date_time[0:3] #check first few entries of date_time
7+
# >>>datetime.datetime.today() #returns the current Date (yy-mm-dd) & time (h:m:s)
8+
9+
# >>>time_1 = datetime.datetime.today()
10+
# >>>time_2 = datetime.datetime.today() #enter this code waiting few seconds
11+
# >>>time_2-time_1 #you will get the measure of elapsed seconds as output,the resulting object is called date time time delta object
12+
13+
# >>>date_str = birddata.date_time[0]
14+
# >>>date_str
15+
# >>>date_str[:-3] # slices/removes the UTC +00 coordinated time stamps
16+
# >>>datetime.datetime.strptime(date_str[:-3], "%Y-%m-%d %H:%M:%S") #the time stamp strings from date_str are converted to datetime object to be worked upon.
17+
18+
timestamps = []
19+
for k in range(len(birddata)):
20+
timestamps.append(datetime.datetime.strptime(birddata.date_time.iloc[k][:-3], "%Y-%m-%d %H:%M:%S"))
21+
'''
22+
The next step for me is to construct a panda series object
23+
and insert the timestamp from my Python list into that object.
24+
I can then append the panda series as a new column in my bird data data frame.
25+
'''
26+
birddata["timestamp"] = pd.Series(timestamps, index = birddata.index)
27+
# >>>birddata.timestamp[4] - birddata.timestamp[3] #measure time difference between row 4 & 3
28+
29+
'''
30+
What I'd like to do next is to create a list that captures the amount of time
31+
that has elapsed since the beginning of data collection.
32+
'''
33+
times = birddata.timestamp[birddata.bird_name == "Eric"]
34+
elapsed_time = [time-times[0] for time in times]
35+
36+
#But how can we measure time in certain units, like hours or days?
37+
# >>>elapsed_time[1000]/datetime.timedelta(days=1) #output is the no of days have passed between these two points
38+
# >>>len(elapsed_time) # check the length of entries
39+
# >>>elapsed_time[19000]/datetime.timedelta(hours=1) #output is the no of hours have passed between these two points
40+
41+
plt.plot(np.array(elapsed_time)/datetime.timedelta(days=1))
42+
plt.xlabel(" Observation ")
43+
plt.ylabel(" Elapsed time (days) ")
44+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import pandas as pd
2+
import matplotlib.pyplot as plt
3+
import numpy as np
4+
5+
ix = birddata.bird_name == "Eric" #storing the indices of the bird Eric
6+
speed = birddata.speed_2d[ix]
7+
# >>>plt.hist(speed) #[F.A.I.L.S] ,since we have non numeric numbers in the speed array
8+
# >>>plt.hist(speed[:10]) #plot a histogram using the first 10 observations of speed [works]
9+
# >>>np.isnan(speed) #>>>np.isnan(speed).any() #I am looking for any non number objects in the speed column using numpy's isnan function.
10+
# >>>np.sum(np.isnan(speed)) # I find out the count of non numeric entries, False=0 & True =1 from isnan()
11+
12+
# >>>ind = np.isnan(speed)
13+
# >>>plt.hist(speed[~ind]) #we will include only those entries for which ind != True
14+
15+
plt.figure(figsize = (8,4))
16+
# >>>speed = birddata.speed_2d[birddata.bird_name == "Eric"] #step 5 & 6 combined
17+
ind = np.isnan(speed)
18+
plt.hist(speed[~ind], bins=np.linspace(0,30,20), normed=True)
19+
plt.xlabel(" 2D speed (m/s) ")
20+
plt.ylabel(" Frequency ")
21+
plt.show()
22+
23+
24+
'''
25+
We can also plot a similar histogram using the pandas module instead of pyplot.
26+
The benefit of using pandas is that we do not have to deal with NaNs explicitly.
27+
Instead, all of that happens under the hood.
28+
29+
NaNs - Not-a-Number
30+
31+
>>>birddata.speed_2d.plot(kind='hist', range=[0,30])
32+
>>>plt.xlabel("2D speed")
33+
>>>plt.savefig("hist_birdmig_speed.pdf")
34+
'''
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pandas as pd
2+
import matplotlib.pyplot as plt
3+
import numpy as np
4+
5+
birddata = pd.read_csv("bird_tracking.csv") #make sure,you are in the right directory , check (>>>pwd)
6+
7+
# >>>birddata.info() #look at basic info abot the data frame
8+
# >>>birddata.head() #look for first 5 rows in the data set
9+
# >>>birddata.tail() #look for last 5 rows in the data set
10+
11+
bird_names = pd.unique(birddata.bird_name) #look at the unique names of the birds in the csv_file
12+
# >>>print(bird_name)
13+
14+
ix = birddata.bird_name == "Eric" #storing the indices of the bird Eric
15+
x,y = birddata.longitude[ix], birddata.latitude[ix]
16+
plt.figure(figsize = (7,7))
17+
plt.plot(x,y,"b.")
18+
# >>>plt.show() #if you want to check trajectory of "Eric" only
19+
20+
''' To look at all the birds trajectories, we plot each bird in the same plot '''
21+
plt.figure(figsize = (7,7))
22+
for bird_name in bird_names:
23+
ix = birddata.bird_name == bird_name #storing the indices of the bird Eric
24+
x,y = birddata.longitude[ix], birddata.latitude[ix]
25+
plt.plot(x,y,".", label=bird_name)
26+
plt.xlabel("Longitude")
27+
plt.ylabel("Latitude")
28+
plt.legend(loc="lower right")
29+
plt.show()

0 commit comments

Comments
 (0)