Prediction example

Prediction example#

In this example, we will use the model to predict the tidal elevation on a specific location, like a tide gauge.

Warning

The model employed is an older FES tidal-atlas model due to its significantly smaller size compared to newer models. Do not use it for real applications. You can download the model from the AVISO website.

First, we import the required modules.

from __future__ import annotations

import os
import pathlib

import numpy
import pyfes

First we create an environment variable to store the path to the model file.

os.environ['DATASET_DIR'] = str(pathlib.Path().absolute().parent / 'tests' /
                                'python' / 'dataset')

Now we need to create the instances of the model used to calculate the ocean tide and the radial tide. To do this, we need to create a YAML file that describes the models and their parameters. The configuration file is fully documented in the documentation.

handlers = pyfes.load_config(pathlib.Path().absolute() / 'fes_slev.yml')

handlers is a dictionary that contains the handlers to the ocean and radial tide models.

print(handlers)
{'radial': <pyfes.core.tidal_model.CartesianComplex64 object at 0x7fefe16d2870>, 'tide': <pyfes.core.tidal_model.CartesianComplex64 object at 0x7fefe15a5630>}

Setup the longitude and latitude of the location where we want to calculate the tide.

lon = -7.688
lat = 59.195
date = numpy.datetime64('1983-01-01T00:00:00')

Generate the coordinates where we want to calculate the tide.

dates = numpy.arange(date, date + numpy.timedelta64(1, 'D'),
                     numpy.timedelta64(1, 'h'))
lons = numpy.full(dates.shape, lon)
lats = numpy.full(dates.shape, lat)

We can now calculate the ocean tide and the radial tide.

tide, lp, _ = pyfes.evaluate_tide(handlers['tide'],
                                  dates,
                                  lons,
                                  lats,
                                  num_threads=1)
load, load_lp, _ = pyfes.evaluate_tide(handlers['radial'],
                                       dates,
                                       lons,
                                       lats,
                                       num_threads=1)

Print the results

cnes_julian_days = (dates - numpy.datetime64('1950-01-01T00:00:00')
                    ).astype('M8[s]').astype(float) / 86400
hours = cnes_julian_days % 1 * 24
print(f"{'JulDay':>6s} {'Hour':>5s} {'Latitude':>10s} {'Longitude':>10s} "
      f"{'Short_tide':>10s} {'LP_tide':>10s} {'Pure_Tide':>10s} "
      f"{'Geo_Tide':>10s} {'Rad_Tide':>10s}")
print('=' * 89)
for ix, jd in enumerate(cnes_julian_days):
    print(f'{jd:>6.0f} {hours[ix]:>5.0f} {lats[ix]:>10.3f} {lons[ix]:>10.3f} '
          f'{tide[ix]:>10.3f} {lp[ix]:>10.3f} {tide[ix] + lp[ix]:>10.3f} '
          f'{tide[ix] + lp[ix] + load[ix]:>10.3f} {load[ix]:>10.3f}')
JulDay  Hour   Latitude  Longitude Short_tide    LP_tide  Pure_Tide   Geo_Tide   Rad_Tide
=========================================================================================
 12053     0     59.195     -7.688   -100.991      0.917   -100.075    -96.194      3.881
 12053     1     59.195     -7.688   -137.105      0.890   -136.215   -131.887      4.328
 12053     2     59.195     -7.688   -138.483      0.863   -137.620   -133.910      3.711
 12053     3     59.195     -7.688   -104.346      0.835   -103.511   -101.377      2.134
 12053     4     59.195     -7.688    -42.516      0.806    -41.710    -41.762     -0.052
 12053     5     59.195     -7.688     32.374      0.777     33.151     30.810     -2.341
 12053     6     59.195     -7.688    102.167      0.747    102.914     98.720     -4.194
 12053     7     59.195     -7.688    149.469      0.717    150.186    145.014     -5.172
 12053     8     59.195     -7.688    162.102      0.686    162.789    157.743     -5.046
 12053     9     59.195     -7.688    136.505      0.655    137.161    133.308     -3.852
 12053    10     59.195     -7.688     78.896      0.624     79.519     77.634     -1.885
 12053    11     59.195     -7.688      3.645      0.592      4.236      4.618      0.382
 12054    12     59.195     -7.688    -70.659      0.559    -70.100    -67.689      2.411
 12054    13     59.195     -7.688   -126.152      0.526   -125.626   -121.892      3.734
 12054    14     59.195     -7.688   -150.115      0.493   -149.622   -145.551      4.071
 12054    15     59.195     -7.688   -137.779      0.459   -137.320   -133.927      3.393
 12054    16     59.195     -7.688    -93.132      0.425    -92.707    -90.779      1.928
 12054    17     59.195     -7.688    -27.820      0.391    -27.429    -27.331      0.097
 12054    18     59.195     -7.688     41.541      0.356     41.898     40.305     -1.593
 12054    19     59.195     -7.688     97.250      0.322     97.571     94.888     -2.684
 12054    20     59.195     -7.688    124.939      0.286    125.226    122.344     -2.882
 12054    21     59.195     -7.688    117.465      0.251    117.716    115.584     -2.132
 12054    22     59.195     -7.688     77.026      0.215     77.242     76.607     -0.635
 12054    23     59.195     -7.688     14.661      0.180     14.841     16.051      1.210

Total running time of the script: (0 minutes 0.041 seconds)

Gallery generated by Sphinx-Gallery