import pandas as pd
bird_data = pd.read_csv('./bird_tracking.csv')
bird_data.head()
bird_data.info()
import matplotlib.pyplot as plt
import numpy as np
idx = bird_data.bird_name == 'Eric'
eric_x, eric_y = bird_data.longitude[idx], bird_data.latitude[idx]
plt.figure(figsize=(7,7))
%matplotlib inline
plt.plot(eric_x,eric_y,'.')
all_bird_names
plt.figure(figsize=(7,7))
for name in all_bird_names:
idx = bird_data.bird_name == name
x, y = bird_data.longitude[idx], bird_data.latitude[idx]
plt.plot(x,y,'.',label=name)
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.legend(loc='lower right')
idx = bird_data.bird_name == 'Eric'
speed = bird_data.speed_2d[idx]
any(np.isnan(speed)) # or np.isnan(speed).any()
There must be some value is not a numerical value.We need to pay attention.
np.sum(np.isnan(speed))
There are 85 values that are not numerical values.
ind = np.isnan(speed)
plt.figure(figsize=(8,4))
plt.hist(speed[~ind], bins=np.linspace(0,30,20),normed=True)
plt.xlabel('2d speed m/s')
plt.ylabel('frequency')
bird_data.speed_2d.plot(kind='hist',range=[0,30])
plt.xlabel('2d speed m/s')
plt.ylabel('frequency')
import datetime
datetime.datetime.today()
time1 = datetime.datetime.today()
time2 = datetime.datetime.today()
time2 - time1
date_str = bird_data.date_time[0]
date_str
date_str = date_str[:-3]
date_str
datetime.datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S")
def date_str2_date(date_str):
return datetime.datetime.strptime(date_str[:-3], "%Y-%m-%d %H:%M:%S")
timestamp = bird_data.date_time.apply(date_str2_date)
timestamp[:10]
bird_data['timestamp'] = timestamp
bird_data.columns
time = bird_data.timestamp[idx] # Eric
elasped_time = time - time[0]
elasped_time[:10]
elasped_time[1000] / datetime.timedelta(days=1)
elasped_time[1000] / datetime.timedelta(hours=1)
elasped_days = elasped_time / datetime.timedelta(days=1)
next_day = 1
ins = []
daily_mean_speed = []
for i,t in enumerate(elasped_days):
if t < next_day:
ins.append(next_day)
else:
daily_mean_speed.append(np.mean(bird_data.speed_2d[ins]))
next_day += 1
ins = []
plt.figure(figsize=(8,6))
plt.plot(daily_mean_speed)
plt.xlabel('Day')
plt.ylabel('Speed 2d m/s')
bird_data.columns
bird_data.date_time[idx]
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.OCEAN)
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.BORDERS, linestyle=':')
for name in all_bird_names:
idx = bird_data.bird_name == name
x, y = bird_data.longitude[idx], bird_data.latitude[idx]
ax.plot(x,y, '.',transform=ccrs.Geodetic(), label=name)
plt.legend(loc='best')
bird_data.date_time = pd.to_datetime(bird_data.date_time)
bird_data["date"] = bird_data.date_time.dt.date
grouped_bydates = bird_data.groupby(['bird_name','date'])
grouped_birdday = bird_data.groupby(['bird_name','date'])
eric_daily_speed = grouped_bydates.speed_2d.mean()["Eric"]
sanne_daily_speed = grouped_bydates.speed_2d.mean()["Sanne"]
nico_daily_speed = grouped_bydates.speed_2d.mean()["Nico"]
eric_daily_speed.plot(label="Eric")
sanne_daily_speed.plot(label="Sanne")
nico_daily_speed.plot(label="Nico")
plt.legend(loc="best")