Bird tracking - GPS tracking of Lesser Black-backed Gulls and Herring Gulls breeding at the southern North Sea coast https://www.gbif.org/dataset/83e20573-f7dd-4852-9159-21566e1e691e
In [1]:
import pandas as pd
import matplotlib.pyplot as plt
In [2]:
df = pd.read_csv("/data/bird_tracking.csv")
df.head()
Out[2]:
In [3]:
pd.to_datetime(df.date_time).head()
Out[3]:
In [4]:
df["date_time"] = pd.to_datetime(df.date_time)
df.info()
In [5]:
df.head()
Out[5]:
In [6]:
df.bird_name.value_counts()
Out[6]:
In [7]:
df.bird_name.unique()
Out[7]:
In [8]:
start_time = df.groupby("bird_name").date_time.min()
start_time
Out[8]:
In [9]:
df["days"] = pd.to_timedelta(0)
for name in df.bird_name.unique():
df.loc[df.bird_name == name, "days"] = df.loc[df.bird_name == name, "date_time"] - start_time[name]
df["days"] = df["days"].dt.days
df.head()
Out[9]:
Let's observe whether we have continuous data data
In [10]:
days = df[df.bird_name == "Eric"].days
plt.plot(range(len(days)), days)
plt.xlabel("Observations")
plt.ylabel("days")
Out[10]:
In [11]:
cmap = {"Eric": "red", "Nico": "blue", "Sanne": "green"}
fig, ax = plt.subplots(figsize = (10,10))
for name in df.bird_name.unique():
df[df.bird_name == name].plot( "longitude", "latitude", color = cmap[name], ax = ax, label = name)
plt.legend()
Out[11]:
In [12]:
sanne = df[df.bird_name == "Sanne"]
sanne.date_time.describe()
Out[12]:
In [13]:
df["date_time"] = pd.to_datetime(df.date_time)
df.head()
Out[13]:
In [14]:
df1 = df.dropna()
In [15]:
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure(figsize = (10, 6))
ax = fig.add_subplot(111, projection='3d')
for name in df.bird_name.unique():
df1 = df[df.bird_name == name]
ax.plot(df1.longitude, df1.latitude, df1.altitude, color = cmap[name], label = name, alpha = 0.5)
ax.set_xlabel("longitude")
ax.set_ylabel("latitude")
ax.set_zlabel("altitude")
ax.legend()
Out[15]:
In [16]:
df.groupby("bird_name").agg({"altitude": "mean", "speed_2d": "mean"})
Out[16]:
In [17]:
import cartopy.crs as ccrs
import cartopy.feature as cfeature
proj = ccrs.Mercator()
plt.figure(figsize = (10, 10))
ax = plt.axes(projection = proj)
ax.set_extent((-25.0, 20.0, 52.0, 10.0))
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.BORDERS, linestyle = ":")
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.COASTLINE)
for name in df.bird_name.unique():
df1 = df[df.bird_name == name]
ax.plot(df1.longitude, df1.latitude, transform = ccrs.Geodetic(), label = name)
ax.legend(loc = "upper left")
Out[17]:
In [ ]: