Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ ttide_py Public
forked from moflaher/ttide_py

A direct conversion of T_Tide to Python

guziy/ttide_py

 
 

Repository files navigation

ttide_py

A direct conversion of T_Tide to Python.

This is a work in progress. It is not done.

It is now mostly functional. Any help with finishing the conversion is welcome.

Credit for T_Tide goes to Rich Pawlowicz, the original creator of T_Tide. It is available at https://www.eoas.ubc.ca/~rich/.

A description of the theoretical basis of the analysis and some implementation details of the Matlab version can be found in:

Pawlowicz, R., B. Beardsley, and S. Lentz, "Classical Tidal "Harmonic Analysis Including Error Estimates in MATLAB using T_TIDE", Computers and Geosciences, 28, 929-937 (2002).

Citation of this article would be appreciated if you find the toolbox useful (either the Matlab version, or this Python one).

Installation

This has little to no testing. Use at your own risk. There are several ways to install:

Using pip:

pip install ttide

Using conda:

conda install -c fortiers -c conda-forge fortiers::ttide

From source:

git clone https://github.com:guziy/ttide_py.git
cd ttide_py
pip install .

Development Setup

To set up a development environment:

  1. Install pixi (package manager):
curl -fsSL https://pixi.sh/install.sh | bash
  1. Clone the repository and install dependencies:
git clone https://github.com:guziy/ttide_py.git
cd ttide_py
pixi install
  1. Available make commands:
# Testing
make test              # Run tests
make test-py38        # Test with Python 3.8
make test-py39        # Test with Python 3.9
make test-py310       # Test with Python 3.10
make test-py311       # Test with Python 3.11
make test-py312       # Test with Python 3.12
make test-py313       # Test with Python 3.13
make test-all         # Run tests with all Python versions

# Code quality
make lint             # Run linting
make lint-fix         # Run linting with auto-fix
make format           # Format code

# Package management
make conda-build      # Build conda package
make conda-upload     # Upload conda package

# Cleanup
make clean            # Clean build artifacts

The project uses:

  • pytest for testing
  • ruff for linting and formatting
  • hatchling for building

Example Usage

Imports and define some variables:

import ttide as tt
import numpy as np

t = np.arange(1001)
m2_freq = 2 * np.pi / 12.42

Here is an example 'real' (scalar) dataset:

elev = 5 * np.cos(m2_freq * t)

Compute the tidal fit:

tfit_e = tt.t_tide(elev)

All other input is optional. Currently dt, stime, lat, constitnames, output, errcalc, synth, out_style, and secular can be specified. Take a look at the t_tide docstring for more info on these variables.

tfit_e is an instance of the TTideCon ("TTide Constituents") class. It includes a t_predic method that is also availabe as the special __call__ method. This makes it possible to construct the fitted time-series by simply doing:

elev_fit = tfit_e(t)

Or extrapolate the fit to other times:

extrap_fit = tfit_e(np.arange(2000,2500))

And here is an example 'complex' (vector) dataset:

vel = 0.8 * elev + 1j * 2 * np.sin(m2_freq * t)

tfit_v = tt.t_tide(vel)

And so on...

Notes

  1. The code to handle timeseries longer then 18.6 years has not been converted yet.

  2. The code is a little messy and they are a few hacky bits that probably will need to be fixed. The most notable is in noise_realizations. It swaps eig vectors around to match Matlab's output. Also, the returned diagonal array would sometimes be a negative on the order of 10^-10. Values between (-0.00000000001,0) are forced to 0.

  3. ttide_py was initially converted to python with SMOP. Available at, https://github.com/victorlei/smop.git.

About

A direct conversion of T_Tide to Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 72.9%
  • Cython 25.4%
  • Makefile 1.7%