Time-filter for Great Whale’s migration routes
By: Bryan R. Vallejo
Tags: Keplergl, Geospatial, Wildlife, Whales

Great Whales are fascinating animals when talking about their migration behavior. Silva et al (2013) explain that whales devote a substantial amount of time and energy each year moving between widely separated geographic areas. As we can see in the maps of this story the Great Whales move from the Azores Islands through the North Atlantic Ocean in a quite long trip. The longest one registered in this dataset is 7194 km and corresponds to 2009.

The main findings by visualizing migration routes with a time filter are related to the influence of seasonality in the movement of whales. As we can see in the demo, the Great Whales that started their journey in early summer (purple and yellow) keep moving in middle latitudes, the assumption is that they forage during their migration habitat. On the other hand, the other whales (green, orange, blue, and pink) started later foraging activity near the Azores Islands.

Referring to the migration behavior of Great Whales one important factor is food availability. During the foraging season, whales require to be aware of timing and physical at the departure because it influences the arrival time and physical condition at the breeding ground, ultimately affecting reproductive success [1]. I explained in one of my demos how migration behavior can be analyzed to find the nesting spots in Bird’s tracking records. Find the article here: Stop detection in Bird’s migration GPS tracks — Movingpandas & KeplerGl.

“The aim of this practice is to filter the migration routes of Great Whales by year and transform the GPS tracks to Linestring. For the second part, to find the foraging spot based on animal behavior parameters”

This demo is the first part of animal behavior analytics in Great Whale’s migration routes. For the second part, the algorithms to identify the foraging spots will be included. Take a look at the foraging behavior analytics in the demos: Foraging spots in Blue Whales GPS tracking, and Foraging spots in penguin tracking in Antarctica.

The main focused in Great Whale’s behavior analysis is to understand the relevance of feeding at migratory habitats and whether if this strategy may cascade through later stages in their life cycle. The questions that need to be answered by analyzing migration routes are: how long does the individual whale stay at this migratory habitat? what are the daily movements and activities in the region? Do the feed at other sites along their path? [1]

“The questions nowadays can be answered with movement analytics and the software dedicated to this analysis is Wildlife Tracker”

DATA

The dataset used in this Demo corresponds to Azores Great Whales Satellite Telemetry Program. It can be found in Movebank and it is under license Creative Commons Attribution Non-commercial.

PRACTICE

In this practice, I will show how to transform GPS tracking records to Linestring, and how to perform a simple time filter to review in this case 2009 Great Whale’s migration routes. I selected 2009 because it is the year that contains the longest migration route with 7194 km.

To begin we are going to import all needed libraries:

import pandas as pd

import geopandas as gpd

import movingpandas as mpd

from shapely.geometry import Point

from datetime import datetime, timedelta

from keplergl import KeplerGl

Then, we read the data file:

fp = r’data/azores_great_whales.geojson’

geodata = gpd.read_file(fp, driver=’GeoJSON’)

Next, we prepare the data including timestamp as an index. We create a new id for whales in columns id_whale , and we include the year and month .

# preparing data

geodata[‘t’] = pd.to_datetime(geodata[‘timestamp’])

geodata = geodata.set_index(‘t’) # setting individuals

geodata[‘id_whale’] = [‘w’+str(idwhale) for idwhale in geodata[‘ind_ident’].to_list()] # time attributes

geodata[‘year’] = geodata.index.year

geodata[‘month’] = geodata.index.month

Here, we create a trajectory_collection object, and create a function that gives back the GPS records transformed into LineString.

traj_collection = mpd.TrajectoryCollection(geodata, ‘id_whale’) def line_tracement(trajectory_collection):



tracement = gpd.GeoDataFrame(columns = [‘geometry’], geometry = ‘geometry’)

tracement[‘whale_id’] = [route.id for route in trajectory_collection]



tracement[‘i’] = tracement[‘whale_id’]

tracement = tracement.set_index(‘i’)



for line in trajectory_collection:



tracement.at[line.id, ‘geometry’] = line.to_linestring()

tracement.at[line.id, ‘length_km’] = line.get_length()/1000



return tracement

We apply the function:

whales_lines = line_tracement(traj_collection)

And we will see a table formated as next:

Image by the Author. Structure of table that contains routes as LineString

At the moment we can already visualize the routes that we have and they look like this:

Image by the Author. Great Whale’s migration routes in all study period

Then, we can start applying the time filter:

# prepare tables for visualizationgeovis = geodata[[‘timestamp’, ‘long’, ‘lat’,’id_whale’, ‘year’, ‘geometry’]] geovis = geovis.reset_index(drop=True) subset = [2009] geovis = geovis.loc[geovis[‘year’].isin(subset)] geovis[‘year_id’] = [‘Year ‘+str(year) for year in geovis[‘year’].to_list() ]

You may notice that we have 6 Great Whales for our 2009 visualization and that we apply the filter in the GPS records, not in the line table. The table looks like this:

Image by the Author. Great Whale’s GPS records with time filter applied in 2009

To add a nice visualization, we include the time filter also in the LineString table with the ids of the 6 whales of 2009. Like this:

whales_subset=[‘w80711’, ‘w80712’, ‘w80717’, ‘w80716’, ‘w80700’, ‘w80709’]

year_whalelines = whales_lines.loc[whales_lines[‘whale_id’].isin(whales_subset)]

You can already see the 6 Great Whale’s migration routes on a map like this:

Image by the Author. Great Whale’s migration routes in 2009

Now, we are going to work with visualization. We create a KeplerGl instance, add the datasets, and configure the map as already showed before. Here you can add a time filter that can be used for animation of the GPS records (points):