# Copyright (c) 2021 The Ensaio Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
#
# This code is part of the Fatiando a Terra project (https://www.fatiando.org)
#
"""
Topography and bathymetry of Southern Africa
--------------------------------------------

This dataset consists in a regular grid with topography and bathymetry over
Southern Africa. It was generated by cropping the ETOPO1 global topography
grid to the desired area.
The topography and bathymetry heights are referenced to sea level (what can be
considered as the geoid).

**Original source:** `ETOPO1
<https://doi.org/10.7289/V5C8276M>`__

**Pre-processing:** `Source code for preparation of the original dataset for
redistribution in Ensaio
<https://github.com/fatiando-data/southern-africa-topography>`__
"""

import pygmt
import xarray as xr

import ensaio

###############################################################################
# Download and cache the data and return the path to it on disk
fname = ensaio.fetch_southern_africa_topography(version=1)
print(fname)

###############################################################################
# Load the netCDF file with xarray (netcdf4 is required)
data = xr.load_dataarray(fname)
data

###############################################################################
# Make a PyGMT map of the topography and bathymetry data
fig = pygmt.Figure()
fig.grdimage(data, cmap="etopo1", projection="M15c")
fig.colorbar(frame='af+l"topography [m]"', position="JCR")
fig.basemap(frame=True)
fig.coast(shorelines="0.1p", area_thresh=1e4)
fig.show()
