-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_point.py
38 lines (31 loc) · 1.12 KB
/
export_point.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
import netCDF4 as nc
from scipy import interpolate
from pathlib import Path
import json
import yaml
fesdir = 'ocean_tide_extrapolated'
yamlfile = 'tidesite/_data/tidesites.yml'
with open(yamlfile) as f:
sites = yaml.safe_load(f)
print(sites)
#point = (63, 23)
# Reykjavík :
for site in sites:
print(site)
pathlist = Path(fesdir).glob('**/*.nc')
sitename = site['sitename']
point = (site['latitude'], site['longitude']+360)
data = []
for path in pathlist:
# print(path)
constname = path.stem
if constname == 'la2':
constname = 'lam2'
ds = nc.Dataset(path)
phase = interpolate.interpn((ds.variables['lat'], ds.variables['lon']), ds.variables['phase'], point ) [0]
ampl = interpolate.interpn((ds.variables['lat'], ds.variables['lon']), ds.variables['amplitude'], point )[0]
print(f' {sitename} {constname} {ampl}, {phase}')
data.append({'name':constname.upper(), 'amplitude':ampl, 'phase':phase})# use cm, not mm
dfile = site['datafile']
with open(f'tidesite/assets/{dfile}.json', 'w') as f:
json.dump(data, f)