The goal of this project was to determine the postive and negative impacts of creating a speed reduction zone off the coast of Dominca through the use of sperm whale sigthing data and AIS vessel data.
import numpy as np
import pandas as pd
import geopandas as gpd
import os
import shapely
import matplotlib.pyplot as plt
from shapely.geometry import Polygon
= r"data/dma_admn_adm0_py_s1_dominode_v2.shp"
fp = pd.read_csv('data/sightings2005_2018.csv')
sightings = pd.read_csv('data/station1249.csv') ais
= 2002
projected_EPSG = 4326
geodetic_EPSG = 1852
meters_per_nm = 2000
cell_size = 2000
wide = 2000 length
= gpd.read_file(fp)
dr_shape
'geometry'] = dr_shape['geometry'].to_crs(epsg = projected_EPSG) dr_shape[
= gpd.points_from_xy(sightings['Long'], sightings['Lat'], crs = geodetic_EPSG)
geometry = gpd.GeoDataFrame(sightings, geometry = geometry, crs = geodetic_EPSG)
gdf
= pd.to_datetime(gdf['GPStime'])
gdf_time
'TIMESTAMP'] = gdf_time
gdf[
'geometry'] = gdf['geometry'].to_crs(epsg = projected_EPSG) gdf[
= plt.subplots(figsize=(5, 5))
fig, ax True)
ax.grid(= ax, color = "grey")
dr_shape.plot(ax = ax, color = "red", markersize = 1) gdf.plot(ax
<AxesSubplot:>
= gdf.total_bounds
xmin, ymin, xmax, ymax
= list(np.arange(xmin, xmax + cell_size, cell_size))
xs
= list(np.arange(ymin, ymax + cell_size, cell_size)) ys
def make_cell(x, y, cell_size):
= [
ring
(x, y),+ cell_size, y),
(x + cell_size, y + cell_size),
(x + cell_size)
(x, y
]= shapely.geometry.Polygon(ring)
cell return cell
= []
cells for x in xs:
for y in ys:
= make_cell(x, y, cell_size)
cell cells.append(cell)
= gpd.GeoDataFrame({'geometry': cells}, crs=2002)
grid
'geometry'] = grid['geometry'].to_crs(epsg = 2002)
grid[
= "none", figsize=(5, 5), linewidth = 1 ) grid.plot(facecolor
<AxesSubplot:>
'geometry'] = gdf['geometry'].to_crs(epsg = projected_EPSG)
gdf[= grid.sjoin(gdf, how = 'inner') joined
'count'] = joined.groupby(joined.index).count()['index_right']
grid[
= grid[grid["count"] >20.0]
grid_sub
= grid_sub.geometry.unary_union
unary
= unary.convex_hull
convex_hull
= gpd.GeoDataFrame(geometry = gpd.GeoSeries(convex_hull), crs = projected_EPSG)
zone
'geometry'] = zone['geometry'].to_crs(epsg = projected_EPSG)
zone[
= zone.difference(dr_shape)
whale_habitat_diff
= gpd.GeoDataFrame(geometry = whale_habitat_diff) whale_habitat
= plt.subplots(figsize=(10, 10))
fig, ax True)
ax.grid(= ax, color = "grey")
dr_shape.plot(ax = ax, facecolor = "none", edgecolor = "red") whale_habitat.plot(ax
<AxesSubplot:>
= gpd.points_from_xy(ais['LON'], ais['LAT'], crs = geodetic_EPSG)
ais_geog
= gpd.GeoDataFrame(ais, geometry = ais_geog)
ais_geo
'geometry'] = ais_geo['geometry'].to_crs(epsg = projected_EPSG) ais_geo[
= pd.to_datetime(ais_geo['TIMESTAMP'])
ais_time
'TIMESTAMP'] = ais_time ais_geo[
= ais_geo.sjoin(whale_habitat, how = "inner")
ais_whale
= ais_whale.sort_values(['MMSI', 'TIMESTAMP'], ascending = True)
ais_sorted
= ais_sorted.shift(periods = 1) ais_shifted
= ais_sorted['geometry'].distance(ais_shifted['geometry'])
distance
'distance(m)'] = distance
ais_sorted[
= ais_shifted['TIMESTAMP']
TIMESTAMP_2
'TIMESTAMP_2'] = TIMESTAMP_2
ais_sorted[
= ais_shifted['MMSI']
MMSI_2
'MMSI_2'] = MMSI_2 ais_sorted[
= ais_sorted[ais_sorted.MMSI == ais_sorted.MMSI_2] ais_sorted
'delta_time(s)'] = ais_sorted['TIMESTAMP'] - ais_sorted['TIMESTAMP_2']
ais_sorted[
= ais_sorted['delta_time(s)'] / np.timedelta64(1, 's')
seconds
'seconds'] = seconds ais_sorted[
= ais_sorted['distance(m)'] / ais_sorted['seconds']
average_speed
'average_speed(m/s)'] = average_speed ais_sorted[
'NM'] = ais_sorted['distance(m)']/meters_per_nm
ais_sorted[
'time@10knots'] = ais_sorted['NM'] / 10 * 60 * 60 ais_sorted[
'difference_seconds'] = ais_sorted['time@10knots'] - ais_sorted['seconds'] ais_sorted[
= ais_sorted.loc[ais_sorted['difference_seconds']>0] dif_sec_great_zero
sum(dif_sec_great_zero['difference_seconds']/ 60/60/24)
27.87604044821323
dif_sec_great_zero
Unnamed: 0 | MMSI | LON | LAT | TIMESTAMP | geometry | index_right | distance(m) | TIMESTAMP_2 | MMSI_2 | delta_time(s) | seconds | average_speed(m/s) | NM | time@10knots | difference_seconds | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
53218 | 53218 | 203106200 | -61.41927 | 15.34898 | 2015-04-26 16:08:16 | POINT (461363.603 1696280.393) | 0 | 1258.095562 | 2015-04-26 16:04:15 | 203106200.0 | 0 days 00:04:01 | 241.0 | 5.220314 | 0.679317 | 244.554213 | 3.554213 |
84957 | 84957 | 203518400 | -61.51546 | 15.41408 | 2015-04-14 17:35:26 | POINT (451023.962 1703455.061) | 0 | 2239.743578 | 2015-04-14 17:28:32 | 203518400.0 | 0 days 00:06:54 | 414.0 | 5.410009 | 1.209365 | 435.371322 | 21.371322 |
39279 | 39279 | 205531510 | -61.40981 | 15.35160 | 2015-05-02 18:26:15 | POINT (462378.106 1696572.914) | 0 | 675.968930 | 2015-05-02 18:24:17 | 205531510.0 | 0 days 00:01:58 | 118.0 | 5.728550 | 0.364994 | 131.397848 | 13.397848 |
139303 | 139303 | 205571000 | -61.50684 | 15.33412 | 2015-03-26 09:37:06 | POINT (451968.978 1694613.570) | 0 | 662.020878 | 2015-03-26 09:35:06 | 205571000.0 | 0 days 00:02:00 | 120.0 | 5.516841 | 0.357463 | 128.686564 | 8.686564 |
139301 | 139301 | 205571000 | -61.50115 | 15.33156 | 2015-03-26 09:39:06 | POINT (452580.343 1694331.833) | 0 | 673.159437 | 2015-03-26 09:37:06 | 205571000.0 | 0 days 00:02:00 | 120.0 | 5.609662 | 0.363477 | 130.851726 | 10.851726 |
… | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … | … |
450065 | 71530 | 775907000 | -61.41251 | 15.26938 | 2015-08-31 15:25:58 | POINT (462112.948 1687478.511) | 0 | 995.610920 | 2015-08-31 15:22:58 | 775907000.0 | 0 days 00:03:00 | 180.0 | 5.531172 | 0.537587 | 193.531280 | 13.531280 |
450061 | 71526 | 775907000 | -61.40833 | 15.27759 | 2015-08-31 15:28:58 | POINT (462559.266 1688387.759) | 0 | 1012.882607 | 2015-08-31 15:25:58 | 775907000.0 | 0 days 00:03:00 | 180.0 | 5.627126 | 0.546913 | 196.888628 | 16.888628 |
450059 | 71524 | 775907000 | -61.40408 | 15.28582 | 2015-08-31 15:31:59 | POINT (463013.057 1689299.250) | 0 | 1018.205189 | 2015-08-31 15:28:58 | 775907000.0 | 0 days 00:03:01 | 181.0 | 5.625443 | 0.549787 | 197.923255 | 16.923255 |
450056 | 71521 | 775907000 | -61.39967 | 15.29361 | 2015-08-31 15:34:59 | POINT (463484.122 1690162.135) | 0 | 983.093306 | 2015-08-31 15:31:59 | 775907000.0 | 0 days 00:03:00 | 180.0 | 5.461629 | 0.530828 | 191.098051 | 11.098051 |
172907 | 172907 | 982358863 | -61.40751 | 15.34122 | 2015-03-14 16:08:23 | POINT (462628.091 1695425.545) | 0 | 1086.815697 | 2015-03-14 16:04:52 | 982358863.0 | 0 days 00:03:31 | 211.0 | 5.150785 | 0.586834 | 211.260071 | 0.260071 |
21246 rows × 16 columns