#!/usr/bin/env python # coding: utf-8 # In[8]: import numpy as np import matplotlib import matplotlib.pyplot as plt import cartopy as cart import cartopy.crs as ccrs import cmocean.cm as cmo import seaborn as sns from glob import glob # import pickle as pkl # import pandas as pd # In[5]: get_ipython().run_line_magic('load_ext', 'autoreload') get_ipython().run_line_magic('autoreload', '2') get_ipython().run_line_magic('load_ext', 'version_information') get_ipython().run_line_magic('version_information', 'numpy, matplotlib, cartopy, cmocean, seaborn, glob') # ## Bathymetry data # # https://www.naturalearthdata.com/downloads/10m-physical-vectors/10m-bathymetry/ # # Just Download All the data. # In[6]: shp_dict = {} files = glob('../data/ne_10m_bathymetry_all/*.shp') assert len(files) > 0 files.sort() for f in files: depth = f.split('_')[-1].split('.')[0] # depth = '-' + f.split('_')[-1].split('.')[0] # depths.append(depth) nei = cart.io.shapereader.Reader(f) shp_dict[depth] = nei # In[9]: depths = [d for d in shp_dict.keys()][::-1] colors = sns.mpl_palette('cmo.ice_r',n_colors=8) cmap = sns.mpl_palette('cmo.ice',n_colors=8,as_cmap=True) # In[10]: fig = plt.figure(figsize=(13,13)) ax = plt.axes(projection=ccrs.PlateCarree()) ax.set_extent((-20, 45, -52, -16), crs=ccrs.PlateCarree()) i = 0 for depth in depths[:8]: ax.add_geometries(shp_dict[depth].geometries(),crs=ccrs.PlateCarree(),color=colors[i]) i+=1 # ax.set_facecolor('grey') # ax.add_feature(cart.feature.LAND,color='grey') ax.add_feature(cart.feature.NaturalEarthFeature(category='physical',name='LAND',scale='110m'),color='grey', zorder=0) # ax.coastlines(lw=1,resolution='110m') gl = ax.gridlines(draw_labels=True) gl.right_labels = False # Add custom colorbar axi = fig.add_axes([0.92,0.35,0.025,0.3]) # axi = fig.add_axes([0.8,0.2,0.025,0.6]) norm = matplotlib.colors.Normalize(vmin=-6000,vmax=0) cbar = matplotlib.colorbar.ColorbarBase(ax=axi,cmap=cmap,norm=norm, boundaries=(-np.array(depths[:8]).astype(int)).tolist()[::-1], ticks=-np.array(depths).astype(int), spacing='proportional', extend='neither', label='Depth (m)' ) # ax.plot(sampling_locs['longitude'], # sampling_locs['latitude'], # zorder=5, color='yellow' ) # ax.scatter(sampling_locs['longitude'], # sampling_locs['latitude'], # zorder=5, color='yellow', label='Sampling locs.') # ax.legend(loc='upper left', shadow=True, fontsize=12)