-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmake_obc.py
More file actions
101 lines (75 loc) · 2.93 KB
/
Copy pathmake_obc.py
File metadata and controls
101 lines (75 loc) · 2.93 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from __future__ import division,print_function
import matplotlib as mpl
import scipy as sp
from datatools import *
from gridtools import *
from plottools import *
import matplotlib.tri as mplt
import matplotlib.pyplot as plt
#from mpl_toolkits.basemap import Basemap
import os as os
import sys
np.set_printoptions(precision=8,suppress=True,threshold=sys.maxsize)
import netCDF4 as n4
import scipy.interpolate as interp
from gridtools import _load_nc
import copy
# Define names and types of data
name='kit4_kelp_20m_0.018'
grid='kit4'
### load the .nc file #####
data = loadnc('runs/'+grid+'/'+name+'/output/',singlename=grid + '_0001.nc')
print('done load')
data = ncdatasort(data)
print('done sort')
indata=load_fvcom_files('runs/'+grid+'/'+name+'/input','kit4','kit4_non_julian_obc.nc')
elobc_old=_load_nc('runs/'+grid+'/'+name+'/input/kit4_non_julian_obc.nc')
# Define names and types of data
filename='kit4_wave_nnh.nei'
neifile=loadnei('data/grid_stuff/'+filename)
neifile=get_nv(neifile)
nn=sort_boundary(neifile)
startidx=np.argwhere(nn==30659)
obc=nn[startidx:(startidx+48)]
startidx=np.argwhere(nn==13218)
obc=np.append(obc,nn[startidx:(startidx+81)])
#plot to check obc nodes
#f=plt.figure()
#ax=f.add_axes([.125,.1,.775,.8])
#ax.triplot(neifile['trigrid'],lw=.15,color='b')
#plotcoast(ax,filename='world_GSHHS_f_L1.nc',color='k',fill=True)
#ax.scatter(neifile['lon'][obc-1],neifile['lat'][obc-1],s=20,edgecolor='None',c='r')
#ax.axis([-132.5,-127,50.5,56])
#f.show()
dataout={}
dataout['spgf_num']=len(obc)
dataout['spgf_nodes']=(obc).astype(int)
dataout['spgf_distance']=np.zeros((len(obc),))+15000
dataout['spgf_value']=np.zeros((len(obc),))+0.000100
dataout['obcf_num']=len(obc)
dataout['obcf_numbers']=(np.arange(len(obc))+1).astype(int)
dataout['obcf_nodes']=(obc).astype(int)
dataout['obcf_value']=(np.zeros((len(obc),))+1).astype(int)
save_obcfile(dataout,'data/grid_stuff/','kit4_wave')
save_spgfile(dataout,'data/grid_stuff/','kit4_wave')
obcold=elobc_old['obc_nodes']-1
elobc=copy.deepcopy(elobc_old)
elobc['obc_nodes']=obc
var='tide_Ephase'
tmp=np.empty((len(elobc[var]),len(obc)))
for level in range(len(elobc_old[var])):
nn_tmp=interp.NearestNDInterpolator((data['nodell'][obcold,0],data['nodell'][obcold,1]), elobc_old[var][level,:])
tmp[level,:]=nn_tmp.__call__(neifile['nodell'][obc-1,0],neifile['nodell'][obc-1,1])
elobc[var]=tmp
var='tide_Eamp'
tmp=np.empty((len(elobc[var]),len(obc)))
for level in range(len(elobc_old[var])):
nn_tmp=interp.NearestNDInterpolator((data['nodell'][obcold,0],data['nodell'][obcold,1]), elobc_old[var][level,:])
tmp[level,:]=nn_tmp.__call__(neifile['nodell'][obc-1,0],neifile['nodell'][obc-1,1])
elobc[var]=tmp
var='tide_Eref'
tmp=np.empty((len(obc),))
nn_tmp=interp.NearestNDInterpolator((data['nodell'][obcold,0],data['nodell'][obcold,1]), elobc_old[var])
tmp=nn_tmp.__call__(neifile['nodell'][obc-1,0],neifile['nodell'][obc-1,1])
elobc[var]=tmp
save_elobc(elobc,'data/grid_stuff/kit4_wave_el_obc.nc')