In [39]:
%matplotlib inline
import warnings
warnings.filterwarnings("ignore")
In [36]:
import pandas as pd
whales = pd.read_csv('whale_sightings.csv')
whales
Out[36]:
In [40]:
whales.plot(x='Longitude',y='Latitude',kind='scatter')
Out[40]:
In [41]:
from mpl_toolkits.basemap import Basemap
# Create map
m = Basemap(projection='mill',
llcrnrlat=39.9,
urcrnrlat=48.3,
llcrnrlon=-69,
urcrnrlon=-54.7,
resolution='l')
x, y = m(whales['Longitude'].values,whales['Latitude'].values)
cs = m.scatter(x,y,s=30,marker='o',color='#66ff66', edgecolor='k')
m.fillcontinents()
Out[41]:
In [42]:
def make_basemap():
from mpl_toolkits.basemap import Basemap
# Create map
m = Basemap(projection='mill',
llcrnrlat=39.9,
urcrnrlat=48.3,
llcrnrlon=-69,
urcrnrlon=-54.7,
resolution='l')
m.fillcontinents()
return m
def plot_whales(whales, m):
x, y = m(whales['Longitude'].values,whales['Latitude'].values)
cs = m.scatter(x,y,s=60,marker='o',color='#66ff66', edgecolor='k',zorder=50)
return
In [43]:
make_basemap()
Out[43]:
In [7]:
make_basemap()
plot_whales(whales, m)
In [44]:
def make_basemap():
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
fig1 = plt.figure(figsize=(13,10))
# Create map
m = Basemap(projection='mill',
llcrnrlat=39.9,
urcrnrlat=48.3,
llcrnrlon=-69,
urcrnrlon=-54.7,
resolution='i')
m.drawcoastlines(color='#a6a6a6',linewidth=0.5,zorder=42)
m.fillcontinents(color='#e6e6e6',zorder=42)
m.drawmapboundary()
plt.tight_layout()
return m
In [45]:
m = make_basemap()
plot_whales(whales, m)
In [46]:
%matplotlib notebook
m = make_basemap()
plot_whales(whales, m)
In [48]:
import my_functions as mf
m = make_basemap()
plot_whales(whales, m)
mf.add_maritimes_region(m)
mf.plot_CriticalHabitats()
In [55]:
import my_functions as mf
m = make_basemap()
plot_whales(whales, m)
mf.add_maritimes_region(m)
mf.plot_CriticalHabitats(m)
In [56]:
m = make_basemap()
plot_whales(whales,m)
mf.add_maritimes_region(m)
mf.add_NAFO_areas(m)
mf.plot_CriticalHabitats(m)
In [26]:
def add_bathymetry(m):
import matplotlib.pyplot as plt
import netCDF4
import urllib.request
import numpy as np
bathymetry_file = 'usgsCeSrtm30v6.nc'
minlat=39.9
maxlat=48.3
minlon=-69
maxlon=-54.7
isub = 1
base_url='http://coastwatch.pfeg.noaa.gov/erddap/griddap/usgsCeSrtm30v6.nc?'
query='topo[(%f):%d:(%f)][(%f):%d:(%f)]' % (maxlat,isub,minlat,minlon,isub,maxlon)
url = base_url+query
# store data in NetCDF file
urllib.request.urlretrieve(url, bathymetry_file)
# open NetCDF data in
nc = netCDF4.Dataset(bathymetry_file)
ncv = nc.variables
lon = ncv['longitude'][:]
lat = ncv['latitude'][:]
lons, lats = np.meshgrid(lon, lat)
topo = ncv['topo'][:, :]
TOPOmasked = np.ma.masked_where(topo>0,topo)
# For topo
x, y = m(lons, lats)
plt.pcolormesh(x,y,TOPOmasked,cmap=plt.get_cmap('Blues_r'),zorder=5,vmax=2000)
depth_levels_1 = np.linspace(topo.min(), -700, num=5)
depth_levels = np.append(depth_levels_1,np.linspace(-650, -50, num=15))
depth_levels = depth_levels.tolist()
cs = plt.contour(
x,
y,
topo,
depth_levels,
cmap=plt.get_cmap('Blues_r'),
linewidths=0.3,
linestyles='solid',
zorder=19)
return
In [27]:
m = make_basemap()
add_bathymetry(m)
In [57]:
import _pickle as pickle
m = make_basemap()
mf.add_maritimes_region(m)
mf.add_NAFO_areas(m)
mf.plot_CriticalHabitats(m)
add_bathymetry(m)
pickle.dump(m, open('basemap.p', 'wb'), -1)
In [58]:
m = pickle.load(open('basemap.p','rb'))
plot_whales(whales,m)
In [59]:
vms_csv = 'vms_autoDownloaded.csv'
fishing_ships = pd.read_csv(vms_csv)
fishing_ships
Out[59]:
In [60]:
import matplotlib.pyplot as plt
m = pickle.load(open('basemap.p','rb'))
# Change Lat/Lons into proyected x/y coordinates
x, y = m(fishing_ships['LONGITUDE'].values,fishing_ships['LATITUDE'].values)
plt.scatter(x,y,s=1,marker='o',color='r', zorder=10)
plot_whales(whales,m)
In [61]:
def make_heatmap(info, m, data):
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
x = np.arange(info['minlon'], info['maxlon'], info['bin_size'], dtype=np.float64)
y = np.arange(info['minlat'], info['maxlat'], info['bin_size'], dtype=np.float64)
info['bin_number'] = (np.ceil((info['maxlon'] - info['minlon'])/info['bin_size']),
np.ceil((info['maxlat'] - info['minlat'])/info['bin_size']))
x,y = m(data['LONGITUDE'].values, data['LATITUDE'].values)
H, xedges, yedges = np.histogram2d(x,y,bins=300)
# Rotate and flip H...
H = np.rot90(H)
H = np.flipud(H)
# Mask zeros
Hmasked = np.ma.masked_where(H==0,H)
# Log H for better display
Hmasked = np.log10(Hmasked)
# Make map
cs = m.pcolor(xedges,yedges,Hmasked,cmap=plt.get_cmap('inferno_r'), zorder=49)
return
In [62]:
#from gridder import make_heatmap
info = {}
info['minlat'] = 39.9
info['maxlat'] = 48.3
info['minlon'] = -69
info['maxlon'] = -54.7
info['bin_size'] = 0.01 # Degrees
m = pickle.load(open('basemap.p','rb'))
plot_whales(whales,m)
make_heatmap(info, m, fishing_ships)
In [63]:
from datetime import datetime
import numpy as np
import my_functions as mf
VR_NUMBER, LATITUDE, LONGITUDE, POSITION_UTC_DATE, SPEED_KNOTS = [],[],[],[],[]
unis = pd.unique(fishing_ships['VR_NUMBER'])
for ship in unis:
singleship = fishing_ships[fishing_ships['VR_NUMBER'] == ship].reset_index()
if len(singleship) > 1:
for i in range(1,len(singleship)):
startdate = datetime.strptime(singleship['POSITION_UTC_DATE'][i-1], '%Y-%m-%d %H:%M:%S')
enddate = datetime.strptime(singleship['POSITION_UTC_DATE'][i], '%Y-%m-%d %H:%M:%S')
elapsed_time = enddate-startdate
elapsed_distance = mf.distance(singleship['LATITUDE'][i-1],
singleship['LONGITUDE'][i-1],
singleship['LATITUDE'][i],
singleship['LONGITUDE'][i]) / 1852
if elapsed_time.seconds > 0:
speed = elapsed_distance / (elapsed_time.seconds / 3600)
else:
speed = np.nan
VR_NUMBER.append(singleship['VR_NUMBER'][i])
LATITUDE.append(singleship['LATITUDE'][i])
LONGITUDE.append(singleship['LONGITUDE'][i])
POSITION_UTC_DATE.append(singleship['POSITION_UTC_DATE'][i])
SPEED_KNOTS.append(speed)
new_fishing_ships = pd.DataFrame({'VR_NUMBER':VR_NUMBER,
'LATITUDE':LATITUDE,
'LONGITUDE':LONGITUDE,
'POSITION_UTC_DATE':POSITION_UTC_DATE,
'SPEED_KNOTS':SPEED_KNOTS})
Note that new_fishing_ships
has an extra column named SPEED_KNOTS
In [64]:
new_fishing_ships
Out[64]:
In [65]:
myFilter = (new_fishing_ships['SPEED_KNOTS']>0.5) & (new_fishing_ships['SPEED_KNOTS']<4.5)
fishing3 = new_fishing_ships[myFilter]
m = pickle.load(open('basemap.p','rb'))
plot_whales(whales,m)
make_heatmap(info, m, fishing3)
whales get entangled
Whales get sotted by planes, ships, and gliders.
https://whalesandmarinefauna.files.wordpress.com/2013/01/628x471_004.jpg
https://media.mnn.com/assets/images/2017/12/TangledNorthAtlanticRightWhale.jpg
spoter planes https://pbs.twimg.com/media/DdVa8ltX0AEo10V.jpg
https://assets.skiesmag.com/images/online/MaritimeProtector/1.jpg
https://assets.skiesmag.com/images/online/MaritimeProtector/4.jpg
http://www.releases.gov.nl.ca/releases/2013/fishaq/1216n04_pic.jpg
https://ssl.c.photoshelter.com/img-get2/I0000jNrkh7emj4Q/fit=1000x750/GSBCAN0401005.jpg
http://imgproc.airliners.net/photos/airliners/5/7/1/2711175.jpg?v=v40
https://twitter.com/FishOceansCAN/status/991054848538923008
Spoter vessels CCGS Corporal McLaren M.M.V. https://navaltoday.com/wp-content/uploads/2015/05/Canadian-Coast-Guard-Expands-Fleet.jpg
http://www.ccg-gcc.gc.ca/Vessel-Procurement/Gallery
Present the data (I think it is better to do this bit by bit... present each data set just before it is used)
WHale possitions
PLane surveys
Glider surveys