{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib\n", "import matplotlib.pyplot as plt\n", "import shapely.geometry as sgeom\n", "from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER\n", "import cartopy.feature \n", "import cartopy.crs as ccrs\n", "\n", "import matplotlib.lines as mlines" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Matplot lib default settings\n", "plt.rcParams[\"figure.figsize\"] = (10, 6)\n", "plt.rcParams['axes.grid'] = True\n", "plt.rcParams['grid.alpha'] = 0.3\n", "plt.rcParams['grid.color'] = \"grey\"\n", "plt.rcParams['grid.linestyle'] = \"--\"\n", "plt.rcParams['grid.linewidth'] = 0.5\n", "plt.rcParams['axes.grid'] = True\n", "\n", "# # https://stackoverflow.com/a/20709149\n", "matplotlib.rcParams['text.usetex'] = True\n", "matplotlib.rcParams['font.family'] = 'sans-serif'\n", "\n", "matplotlib.rcParams['text.latex.preamble'] = [\n", " r'\\usepackage{siunitx}', # i need upright \\micro symbols, but you need...\n", " r'\\sisetup{detect-all}', # ...this to force siunitx to actually use your fonts\n", " r'\\usepackage[default]{sourcesanspro}',\n", " r'\\usepackage{amsmath}',\n", " r'\\usepackage{sansmath}', # load up the sansmath so that math -> helvet\n", " r'\\sansmath', # <- tricky! -- gotta actually tell tex to use!\n", "]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def blank_axes(ax):\n", " \"\"\"\n", " blank_axes: blank the extraneous spines and tick marks for an axes\n", "\n", " Input:\n", " ax: a matplotlib Axes object\n", "\n", " Output: None\n", " \"\"\"\n", "\n", "\n", " ax.spines['right'].set_visible(False)\n", " ax.spines['top'].set_visible(False)\n", " ax.spines['bottom'].set_visible(False)\n", " ax.spines['left'].set_visible(False)\n", " ax.yaxis.set_ticks_position('none')\n", " ax.xaxis.set_ticks_position('none')\n", " ax.tick_params(labelbottom='off', labeltop='off', labelleft='off', labelright='off' ,\\\n", " bottom='off', top='off', left='off', right='off' )\n", "#end blank_axes" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [ 66, 268, 296 ] }, "outputs": [], "source": [ "# Define figure and axes\n", "fig, ax1 = plt.subplots(figsize=(5, 5),\n", " subplot_kw=dict(projection=ccrs.PlateCarree()))\n", "\n", "# Inset axes showing overall Australia plot\n", "ax2 = fig.add_axes([0.14, 0.58, 0.20, 0.15], projection=ccrs.PlateCarree())\n", "\n", "# Define extents to our axes\n", "ax1_extent = [146, 154, -35, -30]\n", "ax2_extent = [110, 157, -42, -7]\n", "ax1.set_extent(ax1_extent)\n", "ax2.set_extent(ax2_extent)\n", "\n", "# Add gridlines to ax1\n", "gl = ax1.gridlines(draw_labels=True, linestyle='--', zorder=2, alpha=0.5)\n", "gl.xlabels_top = gl.ylabels_right = False\n", "gl.xformatter = LONGITUDE_FORMATTER\n", "gl.yformatter = LATITUDE_FORMATTER\n", "\n", "# Define features we want to plot\n", "feat_rivers = cartopy.feature.NaturalEarthFeature(\n", " 'physical',\n", " 'rivers_lake_centerlines',\n", " '10m',\n", " edgecolor=cartopy.feature.COLORS['water'],\n", " facecolor='none')\n", "\n", "feat_oceans = cartopy.feature.NaturalEarthFeature(\n", " 'physical', 'ocean', '10m', facecolor=cartopy.feature.COLORS['water'])\n", "\n", "feat_borders = cartopy.feature.NaturalEarthFeature(\n", " 'cultural',\n", " 'admin_1_states_provinces',\n", " '10m',\n", " edgecolor='black',\n", " facecolor=cartopy.feature.COLORS['land'],\n", " linewidth=0.5)\n", "\n", "# Add features to our plots\n", "ax1.add_feature(feat_rivers)\n", "ax1.add_feature(feat_oceans)\n", "ax1.add_feature(feat_borders)\n", "ax2.add_feature(feat_oceans)\n", "ax2.add_feature(feat_borders)\n", "\n", "# Plot location box on ax2\n", "ax1_extent_box = sgeom.box(ax1_extent[0], ax1_extent[2], ax1_extent[1],\n", " ax1_extent[3])\n", "ax2.add_geometries([ax1_extent_box],\n", " ccrs.PlateCarree(),\n", " color='none',\n", " edgecolor='r',\n", " linewidth=2)\n", "\n", "# Define marker properties\n", "marker_edge_width = 1.3\n", "marker_edge_color = '#ffffff'\n", "wave_buoy_color = 'red'\n", "wave_buoy_marker = 'o'\n", "tide_gauge_color = 'blue'\n", "tide_gauge_marker = 's'\n", "beach_color = 'green'\n", "beach_marker = '^'\n", "\n", "# Plot beaches\n", "# df_sites.groupby('beach').mean()[['lat','lon']].to_dict('index')\n", "beaches = {\n", " 'AVOCAn': {\n", " 'lat': -33.460695367777774,\n", " 'lon': 151.43853769000003\n", " },\n", " 'AVOCAs': {\n", " 'lat': -33.467647595,\n", " 'lon': 151.43574445875\n", " },\n", " 'BILG': {\n", " 'lat': -33.645234478,\n", " 'lon': 151.328779182\n", " },\n", " 'BLUEYS': {\n", " 'lat': -32.35377103,\n", " 'lon': 152.53584677666666\n", " },\n", " 'BOAT': {\n", " 'lat': -32.43502469599999,\n", " 'lon': 152.530818656\n", " },\n", " 'BOOM': {\n", " 'lat': -32.34039573142857,\n", " 'lon': 152.54337415\n", " },\n", " 'CATHIE': {\n", " 'lat': -31.57630510275862,\n", " 'lon': 152.8433463127586\n", " },\n", " 'CRESn': {\n", " 'lat': -31.12568202392001,\n", " 'lon': 153.00734157120007\n", " },\n", " 'CRESs': {\n", " 'lat': -31.180938470000008,\n", " 'lon': 152.97574073\n", " },\n", " 'DEEWHYn': {\n", " 'lat': -33.745759471666666,\n", " 'lon': 151.3055993875\n", " },\n", " 'DEEWHYs': {\n", " 'lat': -33.751954194999996,\n", " 'lon': 151.29818175499997\n", " },\n", " 'DIAMONDn': {\n", " 'lat': -32.026216662195125,\n", " 'lon': 152.55036803634147\n", " },\n", " 'DIAMONDs': {\n", " 'lat': -32.046040624285716,\n", " 'lon': 152.54134085\n", " },\n", " 'DUNBn': {\n", " 'lat': -31.674815349864858,\n", " 'lon': 152.81198585391894\n", " },\n", " 'DUNBs': {\n", " 'lat': -31.710181410909083,\n", " 'lon': 152.79323301090912\n", " },\n", " 'ELIZA': {\n", " 'lat': -32.3298006057143,\n", " 'lon': 152.53714101142856\n", " },\n", " 'ENTRA': {\n", " 'lat': -33.31609181329114,\n", " 'lon': 151.5278903848101\n", " },\n", " 'FOST': {\n", " 'lat': -32.17670982666667,\n", " 'lon': 152.51195243333333\n", " },\n", " 'GRANTSn': {\n", " 'lat': -31.613473751666664,\n", " 'lon': 152.8381070795833\n", " },\n", " 'GRANTSs': {\n", " 'lat': -31.63005646785714,\n", " 'lon': 152.83392283714286\n", " },\n", " 'HARGn': {\n", " 'lat': -33.25858048428571,\n", " 'lon': 151.56334493285718\n", " },\n", " 'HARGs': {\n", " 'lat': -33.26487224142857,\n", " 'lon': 151.5624840085714\n", " },\n", " 'HARR': {\n", " 'lat': -31.859077996607144,\n", " 'lon': 152.72314068214285\n", " },\n", " 'LHOUSE': {\n", " 'lat': -32.443838815384616,\n", " 'lon': 152.52969125769232\n", " },\n", " 'LHOUSEn': {\n", " 'lat': -31.506830332043016,\n", " 'lon': 152.900197138172\n", " },\n", " 'LHOUSEs': {\n", " 'lat': -31.55095255875001,\n", " 'lon': 152.85847451375002\n", " },\n", " 'MACM': {\n", " 'lat': -33.494884234375,\n", " 'lon': 151.42840894187498\n", " },\n", " 'MANNING': {\n", " 'lat': -31.922794031338576,\n", " 'lon': 152.63626414188988\n", " },\n", " 'MONA': {\n", " 'lat': -33.68342594,\n", " 'lon': 151.31180166238096\n", " },\n", " 'NAMB': {\n", " 'lat': -30.702570222054792,\n", " 'lon': 152.99174024657532\n", " },\n", " 'NARRA': {\n", " 'lat': -33.71824857833333,\n", " 'lon': 151.30161430805555\n", " },\n", " 'NINEMn': {\n", " 'lat': -32.098527227407416,\n", " 'lon': 152.5245430024074\n", " },\n", " 'NINEMs': {\n", " 'lat': -32.146616644,\n", " 'lon': 152.50721414266667\n", " },\n", " 'NSHORE_n': {\n", " 'lat': -31.35297012609755,\n", " 'lon': 152.94414099536587\n", " },\n", " 'NSHORE_s': {\n", " 'lat': -31.4042148925,\n", " 'lon': 152.91674769522717\n", " },\n", " 'OLDBAR': {\n", " 'lat': -31.981825014722215,\n", " 'lon': 152.58157028555553\n", " },\n", " 'ONEMILE': {\n", " 'lat': -32.19014868,\n", " 'lon': 152.53698099153846\n", " },\n", " 'PEARLn': {\n", " 'lat': -33.5394179,\n", " 'lon': 151.310494964\n", " },\n", " 'PEARLs': {\n", " 'lat': -33.543258066,\n", " 'lon': 151.30794061\n", " },\n", " 'SCOT': {\n", " 'lat': -30.740275808333333,\n", " 'lon': 152.99018976333335\n", " },\n", " 'STOCNn': {\n", " 'lat': -32.78820750815384,\n", " 'lon': 152.0395944421538\n", " },\n", " 'STOCNs': {\n", " 'lat': -32.833099094162684,\n", " 'lon': 151.9039352245933\n", " },\n", " 'STOCS': {\n", " 'lat': -32.8965449047826,\n", " 'lon': 151.79411199869566\n", " },\n", " 'STUART': {\n", " 'lat': -30.835545341910105,\n", " 'lon': 153.00643798999994\n", " },\n", " 'SWRO': {\n", " 'lat': -30.885526112307694,\n", " 'lon': 153.05837861230768\n", " },\n", " 'TREACH': {\n", " 'lat': -32.454167825000006,\n", " 'lon': 152.508508009375\n", " },\n", " 'WAMBE': {\n", " 'lat': -33.43660858444444,\n", " 'lon': 151.445516972963\n", " }\n", "}\n", "\n", "for beach in beaches:\n", " ax1.plot(beaches[beach]['lon'],\n", " beaches[beach]['lat'],\n", " color=beach_color,\n", " marker=beach_marker,\n", " markeredgewidth=marker_edge_width-0.5,\n", " markeredgecolor='#000000',\n", " transform=ccrs.Geodetic())\n", "\n", "\n", "# Add wave buoys\n", "wave_buoys = [\n", " {\n", " 'name': 'Sydney',\n", " 'lat': -33.77166667,\n", " 'lon': 151.40861111\n", " },\n", " {\n", " 'name': 'Crowdy Head',\n", " 'lat': -31.81388889,\n", " 'lon': 152.85611111\n", " },\n", " {\n", " 'name': 'Coffs Harbour',\n", " 'lat': -30.36250000,\n", " 'lon': 153.26916667\n", " },\n", "]\n", "\n", "for wave_buoy in wave_buoys:\n", " ax1.plot(wave_buoy['lon'],\n", " wave_buoy['lat'],\n", " color=wave_buoy_color,\n", " marker=wave_buoy_marker,\n", " markeredgewidth=marker_edge_width,\n", " markeredgecolor=marker_edge_color,\n", " transform=ccrs.Geodetic())\n", "\n", "# Add tide gauges\n", "tide_gauges = [\n", " {\n", " 'name': 'HMAS Penguin',\n", " 'lat': -33.82546,\n", " 'lon': 151.25853\n", " },\n", " {\n", " 'name': 'Patonga',\n", " 'lat': -33.55098,\n", " 'lon': 151.27461\n", " },\n", " {\n", " 'name': 'Shoal Bay',\n", " 'lat': -32.71967,\n", " 'lon': 152.17565\n", " },\n", " {\n", " 'name': 'Forster',\n", " 'lat': -32.17398,\n", " 'lon': 152.50820\n", " },\n", " {\n", " 'name': 'Crowdy Head',\n", " 'lat': -31.83870,\n", " 'lon': 152.75001\n", " },\n", " {\n", " 'name': 'Port Macquarie',\n", " 'lat': -31.42682,\n", " 'lon': 152.91112\n", " },\n", " {\n", " 'name': 'Coffs Harbour',\n", " 'lat': -30.30286,\n", " 'lon': 153.14614\n", " },\n", "]\n", "\n", "for tide_gauge in tide_gauges:\n", " ax1.plot(tide_gauge['lon'],\n", " tide_gauge['lat'],\n", " color=tide_gauge_color,\n", " marker=tide_gauge_marker,\n", " markeredgewidth=marker_edge_width,\n", " markeredgecolor=marker_edge_color,\n", " transform=ccrs.Geodetic())\n", "\n", "\n", "\n", "# Prepare legend\n", "legend_buoy = mlines.Line2D([], [],\n", " color=wave_buoy_color,\n", " marker=wave_buoy_marker,\n", " markersize=5,\n", " linestyle=\"None\",\n", " markeredgewidth=marker_edge_width,\n", " markeredgecolor=marker_edge_color,\n", " label='Wave buoys')\n", "\n", "legend_gauge = mlines.Line2D([], [],\n", " color=tide_gauge_color,\n", " marker=tide_gauge_marker,\n", " markersize=5,\n", " linestyle=\"None\",\n", " markeredgewidth=marker_edge_width,\n", " markeredgecolor=marker_edge_color,\n", " label='Tide gauges')\n", "\n", "legend_beaches = mlines.Line2D([], [],\n", " color=beach_color,\n", " marker=beach_marker,\n", " markersize=5,\n", " linestyle=\"None\",\n", " markeredgewidth=marker_edge_width-0.5,\n", " markeredgecolor='#000000',\n", " label='Beaches included')\n", "\n", "handles = [legend_buoy, legend_gauge, legend_beaches]\n", "names = ['Wave buoys', 'Tide gauges', 'Surveyed\\nbeaches']\n", "\n", "# create legend\n", "ax1.legend(handles, names, title=r'\\underline{Legend}', loc='lower left')\n", "\n", "# Add landmarks\n", "ax1.text(151.204325-0.1, -33.869810, r'\\textsc{Sydney}', transform=ccrs.Geodetic(),ha='right',zorder=4)\n", "ax1.text(151.784937-0.1, -32.928103, r'\\textsc{Newcastle}', transform=ccrs.Geodetic(),ha='right',zorder=4)\n", "ax1.text(152.909329-0.1, -31.440207, r'\\textsc{Port Macquarie}', transform=ccrs.Geodetic(),ha='right',zorder=4)\n", "ax1.text(153.111704-0.1, -30.300466, r'\\textsc{Coffs Harbour}', transform=ccrs.Geodetic(),ha='right',zorder=4)\n", "ax1.text(150.891708-0.1, -34.433129, r'\\textsc{Wollongong}', transform=ccrs.Geodetic(),ha='right',zorder=4)\n", "\n", "ax1.plot(151.204325, -33.869810, transform=ccrs.Geodetic(),zorder=3,color='k',marker='.')\n", "ax1.plot(151.784937, -32.928103, transform=ccrs.Geodetic(),zorder=3,color='k',marker='.')\n", "ax1.plot(152.909329, -31.440207, transform=ccrs.Geodetic(),zorder=3,color='k',marker='.')\n", "ax1.plot(153.111704, -30.300466, transform=ccrs.Geodetic(),zorder=3,color='k',marker='.')\n", "ax1.plot(150.891708, -34.433129,transform=ccrs.Geodetic(),zorder=3,color='k',marker='.')\n", "\n", "\n", "ax2.text(133.729975, -25.173095, r'\\textsc{Australia}', transform=ccrs.Geodetic(),ha='center',zorder=4,va='bottom', fontsize=6, bbox=dict(facecolor=cartopy.feature.COLORS['land'],pad=0.1,linewidth=0, alpha=0.9))\n", "\n", "# # Add inset for Narrabeen\n", "# ax3 = fig.add_axes([0.7, 0.28, 0.2, 0.3], projection=ccrs.PlateCarree())\n", "# ax3_extent = [151.296915, 151.316252, -33.739274, -33.702466]\n", "# # ax3_extent = [151.296915, 151.32, -33.739274, -33.68]\n", "# ax3.set_extent(ax3_extent)\n", "# # ax3.add_feature(feat_oceans)\n", "# # ax3.add_feature(feat_borders)\n", "\n", "\n", "fig.savefig('07_c&p_locality.png',dpi=600,bbox_inches = \"tight\", pad_inches=0.01)\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# # Try using overpass api\n", "# # Hard because coastline is given as line string, not shapefile.\n", "\n", "# import overpass\n", "# api = overpass.API()\n", "# response = api.get('way[\"natural\"=\"coastline\"](-34, 151.0, -33, 152);out geom;')\n", "# coords = [x['geometry']['coordinates'] for x in response['features']]\n", "\n", "\n", "# for line in coords:\n", "# lats = [x[1] for x in line]\n", "# lons = [x[0] for x in line]\n", "# ax3.plot(lons,lats, transform=ccrs.Geodetic())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###" ] } ], "metadata": { "hide_input": false, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.7" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }