In [ ]:
from IPython.display import Image

Image('itaguare.jpg', format='jpg', retina=True)

In [ ]:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap


def make_map(llcrnrlon=None, urcrnrlon=None, llcrnrlat=None, urcrnrlat=None, img='itaguare_cropped.jpg'):
    m = Basemap(projection='merc', llcrnrlon=llcrnrlon, urcrnrlon=urcrnrlon,
                llcrnrlat=llcrnrlat, urcrnrlat=urcrnrlat, resolution='c',
                lat_ts=(llcrnrlat + urcrnrlat) / 2.)

    fig, ax = plt.subplots(figsize=(10, 10), facecolor='none')
    m.ax = ax

    image = plt.imread(img)
    m.imshow(image, origin='upper', alpha=0.75)
  
    meridians = np.linspace(llcrnrlon, urcrnrlon, 4)
    parallels = np.linspace(llcrnrlat, urcrnrlat, 4)
    kw = dict(linewidth=0)
    m.drawparallels(parallels, labels=[1, 0, 0, 0], **kw)
    m.drawmeridians(meridians, labels=[0, 0, 0, 1], **kw)
    return fig, m

In [ ]:
from pandas import DataFrame

df1 = DataFrame.from_csv('drifter_01.txt')
df2 = DataFrame.from_csv('drifter_02.txt')

In [ ]:
from pyproj import Proj

myProj = Proj("+proj=utm +zone=23K, +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs")

UTMx, UTMy = myProj(df1['lon'].values, df1['lat'].values)
df1['UTMx'], df1['UTMy'] = UTMx, UTMy

UTMx, UTMy = myProj(df2['lon'].values, df2['lat'].values)
df2['UTMx'], df2['UTMy'] = UTMx, UTMy
\begin{align*} \dfrac{dx}{dt} &= u \\ \dfrac{dy}{dt} &= v \end{align*}

In [ ]:
def vel(x, t):
    dx = np.diff(x)
    dt = np.diff(t) / np.timedelta64(1, 's')
    return np.r_[0, dx / dt]

df1['u'] = vel(df1['UTMx'], df1.index.values)
df1['v'] = vel(df1['UTMy'], df1.index.values)

df2['u'] = vel(df2['UTMx'], df2.index.values)
df2['v'] = vel(df2['UTMy'], df2.index.values)

In [ ]:
df1.head(5)

In [ ]:
df2.head(5)

In [ ]:
df2.columns

In [ ]:
llcrnrlon = -(45 + (58 + 32.27/60) / 60)  # 45°58'32.27"W
urcrnrlon = -(45 + (57 + 54.54/60) / 60)  # 45°57'54.54"W
llcrnrlat = -(23 + (47 +  7.65/60) / 60)  # 23°47' 7.65"S
urcrnrlat = -(23 + (46 + 42.25/60) / 60)  # 23°46'42.25"S

fig, m = make_map(llcrnrlon=llcrnrlon, urcrnrlon=urcrnrlon, llcrnrlat=llcrnrlat, urcrnrlat=urcrnrlat)

kw = dict(marker='o', markeredgecolor='w', markersize=6, linestyle='none', latlon=True)

m.plot(df1['lon'].values, df1['lat'].values, markerfacecolor='b', **kw)
m.plot(df2['lon'].values, df2['lat'].values, markerfacecolor='r', **kw)

In [ ]:
x = df2['UTMx'] - df2['UTMx'][0]
y = df2['UTMy'] - df2['UTMy'][0]

fig, ax = plt.subplots()
kw = dict(cmap=plt.cm.rainbow, zorder=1)
speed = np.sqrt(df2['u']**2 + df2['v']**2)
ax.scatter(x, y, c=speed, **kw)

kw = dict(scale=20, alpha=0.6, color='black', zorder=3)
Q = ax.quiver(x, y, df2['u'], df2['v'], **kw)
fig.tight_layout()
ax.grid(True)

In [ ]:
fig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(nrows=2, ncols=2, figsize=(12, 6))

ax0.plot(df1.index, df1['UTMx'] - df1['UTMx'].iloc[0])
ax0.set_ylabel("Drifter 1 (X) [m]")

ax1.plot(df2.index, df2['UTMx'] - df2['UTMx'].iloc[0])
ax1.set_ylabel("Drifter 2 (X) [m]")

ax2.plot(df1.index, df1['UTMy'] - df1['UTMy'].iloc[0])
ax2.set_ylabel("Drifter 1 (Y) [m]")

ax3.plot(df2.index, df2['UTMy'] - df2['UTMy'].iloc[0])
ax3.set_ylabel("Drifter 2 (Y) [m]")

In [ ]:
fig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(nrows=2, ncols=2, figsize=(12, 6))

ax0.plot(df1.index, df1['u'])
ax0.set_ylabel("Drifter 1 (u) [$m s^{-1}$]")

ax1.plot(df2.index, df2['u'])
ax1.set_ylabel("Drifter 2 (u) [$m s^{-1}$]")

ax2.plot(df1.index, df1['v'])
ax2.set_ylabel("Drifter 1 (v) [$m s^{-1}$]")

ax3.plot(df2.index, df2['v'])
ax3.set_ylabel("Drifter 2 (v) [$m s^{-1}$]")

In [ ]: