forked from CNES/aviso-fes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tide_gauge.py
78 lines (66 loc) · 2.54 KB
/
tide_gauge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
# This file is part of FES library.
#
# FES is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FES is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# along with FES. If not, see <http://www.gnu.org/licenses/>.
"""
Example of using the FES Python interface
"""
import argparse
import datetime
import numpy as np
import pyfes
def usage():
"""
Command syntax
"""
parser = argparse.ArgumentParser(
description='Program example using the Python API for FES.')
parser.add_argument('ocean',
help='Path to the configuration file that contains '
'the definition of grids to use to compute the '
'ocean tide',
type=argparse.FileType('r'))
parser.add_argument('load',
help='Path to the configuration file that contains '
'the definition of grids to use to compute the '
'load tide',
type=argparse.FileType('r'))
parser.add_argument('--date',
help='Date of calculation of the oceanic tide.',
default=datetime.datetime(1983, 1, 1))
return parser.parse_args()
def main():
"""
Main program
"""
args = usage()
# Create handler
short_tide = pyfes.Handler('ocean', 'io', args.ocean.name)
radial_tide = pyfes.Handler('radial', 'io', args.load.name)
# Creating the time series
dates = np.array([
args.date + datetime.timedelta(seconds=item * 3600)
for item in range(24)
])
lats = np.full(dates.shape, 59.195)
lons = np.full(dates.shape, -7.688)
# Computes tides
tide, lp, _ = short_tide.calculate(lons, lats, dates)
load, load_lp, _ = radial_tide.calculate(lons, lats, dates)
for idx, date in enumerate(dates):
print('%s %9.3f %9.3f %9.3f %9.3f %9.3f %9.3f %9.3f' %
(date, lats[idx], lons[idx], tide[idx], lp[idx], tide[idx] +
lp[idx], tide[idx] + lp[idx] + load[idx], load[idx]))
if __name__ == '__main__':
main()