In [1]:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from exploringShipLogbooks.basic_utils import extract_logbook_data
from mpl_toolkits.basemap import Basemap
%matplotlib inline
In [2]:
logbook_data = extract_logbook_data('CLIWOC15.csv')
In [3]:
logbook_data['LongitudeUnits'].value_counts()
Out[3]:
In [4]:
def convert_longitude_to_360(logbook_data):
degrees_180 = logbook_data['LongitudeUnits'] == '180 degrees'
grados_180 = logbook_data['LongitudeUnits'] == '180 GRADOS'
graden_180 = logbook_data['LongitudeUnits'] == '180 graden'
mask = [any(tup) for tup in zip(degrees_180, grados_180, graden_180)]
logbook_data.loc[mask, 'Lon3'] = logbook_data.loc[mask, 'Lon3'] + 180
logbook_data.loc[mask, 'LongitudeUnits'] = '360 degrees'
return logbook_data
In [5]:
def convert_longitude_to_180(logbook_data):
degrees_360 = logbook_data['LongitudeUnits'] == '360 degrees'
grados_360 = logbook_data['LongitudeUnits'] == '360 GRADOS'
mask = [any(tup) for tup in zip(degrees_360, grados_360)]
logbook_data.loc[mask, 'Lon3'] = logbook_data.loc[mask, 'Lon3'] - 180
logbook_data.loc[mask, 'LongitudeUnits'] = '180 degrees'
return logbook_data
In [8]:
logbook_data = convert_longitude_to_180(logbook_data)
#logbook_data = convert_longitude_to_360(logbook_data)
In [9]:
valid_locations = pd.notnull(logbook_data['Lat3']) & pd.notnull(logbook_data['Lon3'])
In [10]:
plt.figure(figsize=(20,10))
# setup Lambert Conformal basemap.
#m = Basemap(width=12000000,height=9000000,projection='lcc',
# resolution='c',lat_1=45.,lat_2=55,lat_0=50,lon_0=-107.)
m = Basemap(llcrnrlon=0,llcrnrlat=-80,urcrnrlon=360,urcrnrlat=80,projection='mill')
# draw a boundary around the map, fill the background.
# this background will end up being the ocean color, since
# the continents will be drawn on top.
m.drawmapboundary(fill_color='aqua')
# fill continents, set lake color same as ocean color.
m.fillcontinents(color='coral',lake_color='aqua')
# draw parallels and meridians.
# label parallels on right and top
# meridians on bottom and left
parallels = np.arange(-81,81,10.)
# labels = [left,right,top,bottom]
m.drawparallels(parallels,labels=[False,True,True,False])
meridians = np.arange(10.,351.,20.)
m.drawmeridians(meridians,labels=[True,False,False,True])
# plot blue dot on Boulder, colorado and label it as such.
#lon, lat = -104.237, 40.125 # Location of Boulder
#logbook_data['Lon3'][logbook_data['LongitudeUnits'] == '180 degrees'] = logbook_data['Lon3'][logbook_data['LongitudeUnits'] == '180 degrees'] + 180
lon = np.array(logbook_data['Lon3'][valid_locations])
lat = np.array(logbook_data['Lat3'][valid_locations])
# convert to map projection coords.
# Note that lon,lat can be scalars, lists or numpy arrays.
xpt,ypt = m(lon,lat)
m.plot(xpt,ypt,'bo') # plot a blue dot there
plt.show()
In [ ]: