Installation
- Install the tidepredictor package from the distributed wheel file. Available on https://github.com/DHI/tidepredictor/releases.
E.g. for version 0.1.0:
pip install https://github.com/DHI/tidepredictor/releases/download/v0.1.0/tidepredictor-0.1.0-py3-none-any.whl
- Copy constituent files (
.nc
files) to the ~/.local/share/tidepredictor
directory.
Usage
tidepredictor
can be used either as a command line tool or as a Python library.
Python library
import tidepredictor as tp
from datetime import datetime, timedelta
path = tp.get_default_constituent_path(tp.PredictionType.level)
repo = tp.NetCDFConstituentRepository(path)
predictor = tp.LevelPredictor(repo)
df = predictor.predict(
lon=-2.75,
lat=56.1,
start=datetime(2021, 1, 1),
end=datetime(2021, 1, 1, 12),
interval=timedelta(hours=1),
)
df
shape: (13, 2)
datetime[ns] |
f64 |
2021-01-01 00:00:00 |
-0.442367 |
2021-01-01 01:00:00 |
0.497577 |
2021-01-01 02:00:00 |
1.276745 |
2021-01-01 03:00:00 |
1.72732 |
2021-01-01 04:00:00 |
1.745138 |
… |
… |
2021-01-01 08:00:00 |
-1.28875 |
2021-01-01 09:00:00 |
-1.764365 |
2021-01-01 10:00:00 |
-1.7304 |
2021-01-01 11:00:00 |
-1.206373 |
2021-01-01 12:00:00 |
-0.351576 |
And similar for depth averaged currents.
path = tp.get_default_constituent_path(tp.PredictionType.current)
repo = tp.NetCDFConstituentRepository(path)
predictor = tp.CurrentPredictor(repo)
df = predictor.predict_depth_averaged(
lon=-2.75,
lat=56.1,
start=datetime(2021, 1, 1),
end=datetime(2021, 1, 1, 12),
interval=timedelta(hours=1)
)
df
shape: (13, 3)
datetime[ns] |
f64 |
f64 |
2021-01-01 00:00:00 |
-0.306778 |
-0.04915 |
2021-01-01 01:00:00 |
-0.266633 |
-0.056529 |
2021-01-01 02:00:00 |
-0.172855 |
-0.052108 |
2021-01-01 03:00:00 |
-0.043507 |
-0.037106 |
2021-01-01 04:00:00 |
0.09946 |
-0.013727 |
… |
… |
… |
2021-01-01 08:00:00 |
0.20092 |
0.054071 |
2021-01-01 09:00:00 |
0.051412 |
0.03789 |
2021-01-01 10:00:00 |
-0.106491 |
0.011537 |
2021-01-01 11:00:00 |
-0.224378 |
-0.016184 |
2021-01-01 12:00:00 |
-0.273847 |
-0.037307 |
And current profiles.
path = tp.get_default_constituent_path(tp.PredictionType.current)
repo = tp.NetCDFConstituentRepository(path)
predictor = tp.CurrentPredictor(repo, alpha=1.0/3)
df = predictor.predict_profile(
lon=-2.75,
lat=56.1,
start=datetime(2021, 1, 1),
end=datetime(2021, 1, 2, 1),
interval=timedelta(hours=1),
levels=[-1.0, -10.0, -27.0]
)
df
shape: (78, 7)
datetime[ns] |
f64 |
f64 |
f64 |
f64 |
f64 |
f64 |
2021-01-01 00:00:00 |
-1.0 |
-0.306778 |
-0.404441 |
-0.04915 |
-0.064797 |
30.0 |
2021-01-01 00:00:00 |
-10.0 |
-0.306778 |
-0.357327 |
-0.04915 |
-0.057249 |
30.0 |
2021-01-01 00:00:00 |
-27.0 |
-0.306778 |
-0.189858 |
-0.04915 |
-0.030418 |
30.0 |
2021-01-01 01:00:00 |
-1.0 |
-0.266633 |
-0.351516 |
-0.056529 |
-0.074525 |
30.0 |
2021-01-01 01:00:00 |
-10.0 |
-0.266633 |
-0.310567 |
-0.056529 |
-0.065843 |
30.0 |
… |
… |
… |
… |
… |
… |
… |
2021-01-02 00:00:00 |
-10.0 |
-0.31052 |
-0.361686 |
-0.039232 |
-0.045696 |
30.0 |
2021-01-02 00:00:00 |
-27.0 |
-0.31052 |
-0.192174 |
-0.039232 |
-0.02428 |
30.0 |
2021-01-02 01:00:00 |
-1.0 |
-0.313886 |
-0.413812 |
-0.055287 |
-0.072888 |
30.0 |
2021-01-02 01:00:00 |
-10.0 |
-0.313886 |
-0.365606 |
-0.055287 |
-0.064397 |
30.0 |
2021-01-02 01:00:00 |
-27.0 |
-0.313886 |
-0.194257 |
-0.055287 |
-0.034216 |
30.0 |
from plotnine import *
(
ggplot(df, aes("time","u", color="factor(depth)"))
+ geom_line() + geom_point()
+ labs(color="Depth")
)
Command line
!tidepredictor -x -2.75 -y 56.1 -s "2021-01-01" -e "2021-01-01 02:00:00" -i 30
time,level
2021-01-01T00:00:00Z,-0.442
2021-01-01T00:30:00Z,0.035
2021-01-01T01:00:00Z,0.498
2021-01-01T01:30:00Z,0.919
2021-01-01T02:00:00Z,1.277
All options are available as command line arguments.
Usage: tidepredictor [OPTIONS]
Predict the tides for a given location.
╭─ Options ────────────────────────────────────────────────────────────────────╮
│ * --lon -x FLOAT RANGE Longitude │
│ [-180<=x<=180] [default: None] │
│ [required] │
│ * --lat -y FLOAT RANGE Latitude │
│ [-90<=x<=90] [default: None] │
│ [required] │
│ --start -s [%Y-%m-%d|%Y-%m-%dT% Start date │
│ H:%M:%S|%Y-%m-%d [default: None] │
│ %H:%M:%S] │
│ --end -e [%Y-%m-%d|%Y-%m-%dT% End date │
│ H:%M:%S|%Y-%m-%d [default: None] │
│ %H:%M:%S] │
│ --interval -i INTEGER RANGE [x>=1] Interval in minutes │
│ [default: 30] │
│ --output -o PATH Output file, default │
│ is stdout │
│ [default: None] │
│ --format [csv|json] Output format │
│ [default: csv] │
│ --type [level|current] Type of prediction, │
│ level or u,v │
│ [default: level] │
│ --precision -p INTEGER RANGE [x>=0] Number of decimal │
│ places. (csv only) │
│ [default: 3] │
│ --alpha FLOAT Alpha factor for │
│ current profile │
│ [default: │
│ 0.14285714285714285] │
│ --install-completion Install completion │
│ for the current │
│ shell. │
│ --show-completion Show completion for │
│ the current shell, to │
│ copy it or customize │
│ the installation. │
│ --help Show this message and │
│ exit. │
╰──────────────────────────────────────────────────────────────────────────────╯