Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.3.0
hooks:
- id: check-ast
- id: debug-statements
- id: check-added-large-files

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
rev: v2.2.1
hooks:
- id: codespell
exclude: >
Expand Down
94 changes: 53 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,69 @@
# gsw Python package
# GSW-Python

![https://travis-ci.org/TEOS-10/GSW-Python](https://travis-ci.org/TEOS-10/GSW-Python.svg?branch=master) ![https://conda.anaconda.org/conda-forge](https://anaconda.org/conda-forge/gsw/badges/installer/conda.svg) [![DOI](https://zenodo.org/badge/86503067.svg)](https://zenodo.org/badge/latestdoi/86503067)
[![Tests](https://github.com/TEOS-10/GSW-Python/actions/workflows/tests.yml/badge.svg)](https://github.com/TEOS-10/GSW-Python/actions/workflows/tests.yml)
[![Wheels](https://github.com/TEOS-10/GSW-Python/actions/workflows/cibuildwheel.yml/badge.svg)](https://github.com/TEOS-10/GSW-Python/actions/workflows/cibuildwheel.yml)
[![DOI](https://zenodo.org/badge/86503067.svg)](https://zenodo.org/badge/latestdoi/86503067)


This Python implementation of the Thermodynamic Equation of
Seawater 2010 (TEOS-10) is based primarily on numpy ufunc wrappers of
the GSW-C implementation. We expect it to replace the original
[python-gsw](https://github.com/TEOS-10/python-gsw)
pure-python implementation after a brief overlap period.
The primary reasons for this change are that by building on the
C implementation we reduce code duplication and we gain an immediate
update to the 75-term equation. Additional benefits include a
major increase in speed, a reduction in memory usage, and the
inclusion of more functions. The penalty is that a C (or MSVC C++ for
Windows) compiler is required to build the package from source.
This Python implementation of the Thermodynamic Equation of Seawater 2010 (TEOS-10) is based primarily on numpy ufunc wrappers of the GSW-C implementation.
This library replaces the original [python-gsw](https://github.com/TEOS-10/python-gsw) pure-python implementation..
The primary reasons for this change are that by building on the C implementation we reduce code duplication and we gain an immediate update to the 75-term equation.
Additional benefits include a major increase in speed,
a reduction in memory usage,
and the inclusion of more functions.
The penalty is that a C (or MSVC C++ for Windows) compiler is required to build the package from source.

**Warning: this is for Python >=3.5 only.**
**Warning: this is for Python >=3.8 only.**

Documentation is provided at https://teos-10.github.io/GSW-Python/.

For the core functionality, we use an auto-generated C extension
module to wrap the C functions as numpy
[ufuncs](https://docs.scipy.org/doc/numpy/reference/ufuncs.html),
and then use an
autogenerated Python module to add docstrings and handle masked
arrays. 165 scalar C functions with only double-precision
arguments and return values are wrapped as ufuncs, and 158 of
these are exposed in the ``gsw`` namespace with an additional
wrapper in Python.

A hand-written wrapper is used for one C function, and others
are re-implemented directly in Python instead of being wrapped.
Additional functions present in GSW-Matlab but not in GSW-C may
be re-implemented in Python, but there is no expectation that
all such functions will be provided.

The package can be installed from a clone of the repo using
``pip install .``. It is neither necessary nor recommended
to run the code generators, and no instructions are provided
for them; their output is
included in the repo. You will need a suitable compiler: gcc or
clang for unix-like systems, or the MSVC compiler set used for Python
itself on Windows. For Windows, some of the source code has been
modified to C++ because the MSVC C compiler does not support the
module to wrap the C functions as numpy [ufuncs](https://docs.scipy.org/doc/numpy/reference/ufuncs.html),
and then use an autogenerated Python module to add docstrings and handle masked arrays.
165 scalar C functions with only double-precision arguments and return values are wrapped as ufuncs,
and 158 of these are exposed in the ``gsw`` namespace with an additional wrapper in Python.

A hand-written wrapper is used for one C function, and others are re-implemented directly in Python instead of being wrapped.
Additional functions present in GSW-Matlab but not in GSW-C may be re-implemented in Python,
but there is no expectation that all such functions will be provided.

## Installation

Pip users can install the pre-built wheels with:

```shell
pip install gsw
```

conda users will find binaries on conda-forge,

```shell
conda install gsw --channel conda-forge
```

The development version of the package can be installed from a clone of the repo using

```shell
pip install .
```

It is neither necessary nor recommended to run the code generators,
and no instructions are provided for them;
their output is included in the repo.
You will need a suitable compiler:
gcc or clang for unix-like systems,
or the MSVC compiler set used for Python itself on Windows.
For Windows, some of the source code has been modified to C++ because the MSVC C compiler does not support the
C99 complex data type used in original GSW-C.

To test, after installation, run "pytest" from the source directory.

## Note for xarray users

A wrapper around gsw called [gsw-xarray](https://github.com/DocOtak/gsw-xarray)
exists for xarray. It adds CF compliant attributes when possible, units, and name.
A wrapper around gsw called [gsw-xarray](https://github.com/DocOtak/gsw-xarray) exists for xarray.
It adds CF compliant attributes when possible, units, and name.

## Note on generating the docstrings

## Note for on generating the docstrings
The autogenerated docstrings are checked with codespell in the CIs.
when autogenerating them the we need to run `pre-commit run --all-files` and fix the documentation issues found.
when autogenerating them we need to run ``pre-commit run --all-files`` and fix the documentation issues found.
10 changes: 2 additions & 8 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
.. gsw documentation master file, created by
sphinx-quickstart on Mon Mar 13 15:27:45 2017.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

GSW-Python
==========
This Python implementation of the Thermodynamic Equation of
Seawater 2010 (`TEOS-10 <https://teos-10.org/>`__) is based
primarily on numpy ufunc wrappers of
the `GSW-C <https://github.com/TEOS-10/python-gsw/>`__ implementation.
We expect it to replace the original
`python-gsw <https://github.com/TEOS-10/python-gsw/>`__
pure-python implementation after a brief overlap period.
This library replaces the original
`python-gsw <https://github.com/TEOS-10/python-gsw/>`__ pure-python implementation.
The primary reasons for this change are that by building on the
C implementation we reduce code duplication and we gain an immediate
update to the 75-term equation. Additional benefits include a
Expand Down
2 changes: 1 addition & 1 deletion gsw/_wrapped_ufuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def C_from_SP(SP, t, p):
"""
Calculates conductivity, C, from (SP,t,p) using PSS-78 in the range
2 < SP < 42. If the input Practical Salinity is less than 2 then a
modified form of the Hill et al. (1986) fomula is used for Practical
modified form of the Hill et al. (1986) formula is used for Practical
Salinity. The modification of the Hill et al. (1986) expression is to
ensure that it is exactly consistent with PSS-78 at SP = 2.

Expand Down
6 changes: 4 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ classifiers =
License :: OSI Approved :: BSD License
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Topic :: Scientific/Engineering


[options]
zip_safe = False
install_requires =
numpy
python_requires = >=3.6
python_requires = >=3.8
packages = find:
include_package_data = True

Expand Down