Multitaper spectral analysis class interface

The SHWindow class provides an interface to compute window functions that concentrate energy spatially in a given region and within a given spherical harmonic bandwidth. This allows to calculate spectral estimates localized to specific regions with the best possible spectral resolution.

To demonstrate, in this example, we will determine the spectrum of the bathymetry of Earth and compare it with that of the surface topography. To this end, we will need to generate window functions that are separately concentrated over the land and the oceans. To start, we read the topography of Earth from the example files, create masks for the oceans and land, and plot the masks:

In [1]:
from __future__ import print_function # only necessary if using Python 2.x
%matplotlib inline

import matplotlib.pyplot as plt
import numpy as np
import pyshtools
In [2]:
%config InlineBackend.figure_format = 'retina'  # if you are not using a retina display, comment this line
In [3]:
infile = '../ExampleDataFiles/srtmp300.msl'
clm = pyshtools.SHCoeffs.from_file(infile)
topo = clm.expand(grid='DH2')

land_mask = pyshtools.SHGrid.from_array( > 0)
ocean_mask = pyshtools.SHGrid.from_array( <= 0)

fig, (col1, col2) = plt.subplots(1, 2)
land_mask.plot(ax=col1, tick_interval=(45, 45), minor_tick_interval=None)
col1.set(title='Land mask')
ocean_mask.plot(ax=col2, tick_interval=(45, 45), minor_tick_interval=None)
col2.set(title='Ocean mask');

Next, let's plot the masked topography over the oceans and land:

In [4]:
fig, ax = (topo * ocean_mask *(-1)).plot(colorbar=True, cb_label='Bathymetry', show=False)    # show=False is used to avoid a warning when plotting in inline mode
fig2, ax2 = (topo * land_mask).plot(colorbar=True, cb_label='Elevation', show=False)