## (1) Overview

### Introduction

Analysis of global wind fields is common in meteorology and climate science. Often we want to examine not just the vector wind field, but more complex derived quantities that allow deeper insight into the properties of the flow such as rotation and convergence/divergence. These properties of the flow are often expressed as derivatives or integrals of the vector wind. For example vorticity, a measure of rotation in a fluid, is computed as the curl of the wind field, and the corresponding streamfunction is the inverse Laplacian of vorticity. The derivative quantities could be computed via finite difference approximations, although care needs to be taken to correctly account for spherical geometry. However, the integral quantities can be much more difficult to compute.

One way to approach the problem of computing complex derivatives and integrals over the sphere is to use a spectral representation, where a field over the surface of a sphere is represented as the summation of a finite series of basis functions. The appropriate basis functions on the sphere are the spherical harmonics [1]. Spherical harmonics have some nice properties that make derivatives and integrals of fields expressed in terms of them straightforward to compute. For example, the inverse Laplacian operator required to compute streamfunction from vorticity is simply a scalar multiplication in the spectral representation, since the Laplacian of a spherical harmonic is proportional to the spherical harmonic itself [2]. A particular caveat of using the spectral approach is that the field to be analysed must have global coverage, it cannot work on data that cover only a limited area of the globe as the expansion in terms of basis spherical harmonics would not be defined. However, there are still many use cases in meteorology and climate science where this restriction does not present a problem.

Computations using the spectral method require a spherical harmonic transform, a procedure that takes a field defined on a regular global grid and transforms it into its spectral representation in terms of spherical harmonic coefficients. An inverse spherical harmonic transform procedure is also required in order to return a field represented in terms of spherical harmonic coefficients back to a regular grid. Finally, procedures to compute derivatives and integrals of the fields in spectral form are required. These are not trivial to implement, and doing so is out of scope for most researchers simply wishing to analyse global atmospheric circulation. However, these transforms and calculus operations are commonly used in atmospheric modelling, and well tested and optimized implementations of the required algorithms already exist. The windspharm library is designed to bridge the gap between the data analyst and the numerical computation, by providing a simple high-level interface to an existing numerical code that performs the complex calculations for the spectral method.

Of the existing software packages for computing with spherical harmonics, many are intended as low-level building blocks for implementing computational models [3, 4, 5, 6]. These packages expose the spectral transform algorithms at a low-level, and are not easy to use or appropriate for most data analyst users. Some packages offer a higher-level interface to spherical harmonic computations aimed at data analysis, for example NCL [7] has a good suite of spherical harmonic operators that are tailored to atmospheric science use cases, although the capability to retain metadata through the computations is only partial due to language-level restrictions. windspharm was designed to allow users to take advantage of the powerful spectral computations without having to handle spherical harmonic coefficients themselves. The windspharm library brings a high-level interface, designed to be easy to use for atmospheric science use cases, along with good metadata support to atmospheric scientists working with Python.

### Implementation and architecture

The windspharm library is implemented in a hierarchical structure. The core of the library consists of a solver object, which is constructed by passing input vector wind components on a regular grid represented as NumPy arrays [8]. Method calls to the solver object are made to construct the required output, again in the form of gridded arrays. Given vector wind components the solver can compute vorticity (relative and absolute), divergence, streamfunction, velocity potential, and rotational and divergent components of the wind field. Figure 1 shows example outputs from computing vorticity and streamfunction from a wind field. The solver can also apply spectral truncation to scalar fields, and compute the gradient of an arbitrary scalar field. These supplementary operations are useful for processing quantities output from other methods of the solver.

Figure 1

Examples of quantities computed with windspharm. a) Wind speed (colours) and direction (arrows) on the 500 hPa pressure surface from the ECMWF analysis valid at 00:00 UTC on the 27th January 2016. b) Relative vorticity, and c) streamfunction, both computed from the wind field using windspharm.

The solver is built on top of the pyspharm library, which is a Python interface to the SPHEREPACK software [3, 9]. All of the numerical computation is handled by SPHEREPACK, a well-tested and highly optimized computational core, via the pyspharm Python interface. The primary role of windspharm is to provide an interface to these computations that does not expose the details of the methods. The user inputs data on a regular grid and always gets back results on the same regular grid, with windspharm managing calls to pyspharm to perform the operations required to compute the result.

### Quality control

The windspharm library features a suite of unit and integration tests that test the core functionality of the software. The end user can run these tests against their installed version of windspharm to verify it is functioning correctly. The test suite is updated as development on the library progresses. A continuous integration service Travis CI [13] is used to automatically run the full test suite on a variety of Python versions each time a pull request to the windspharm repository is made, which helps to ensure that changes and new features do not break the existing functionality.

The windspharm library also comes with some example programs and data, to demonstrate examples of how the library may be used. These example programs may require additional dependencies for plotting output, which are noted within the documentation for each program.

## (2) Availability

Linux, OSX

### Programming language

Python 2.7 or Python > = 3.3

### Dependencies

windspharm has a set of core dependencies that must be installed to use the software:

• setuptools > = 0.7.2
• numpy > = 1.6
• pyspharm > = 1.8

The metadata interfaces are optional, and must be supported by additional optional dependencies. It is not expected that any one user would require all the available metadata interfaces, only needing the dependency for their interface(s) of choice from the list below:

• iris > = 1.2 (for the iris metadata interface)
• cdms2 (for the cdms2 metadata interface)
• xarray (for the xarray metadata interface)

Running the provided test suite also requires additional optional dependencies that are not required for normal use of windspharm:

• nose
• pep8

### Software location

#### Archive

Name: Zenodo

Persistent identifier: http://dx.doi.org/10.5281/zenodo.50571

Publisher: Andrew Dawson

Version published: 1.5.0

Date published: 27/04/2016

### Code repository

Name: Github

Identifier: https://github.com/ajdawson/windspharm