-
Notifications
You must be signed in to change notification settings - Fork 2
/
bnd.py
68 lines (61 loc) · 2.1 KB
/
bnd.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
import numpy as np
from pydelft.grd import grd
from pydelft.dep import dep
from tkinter import filedialog
import sys
import os
import pandas as pd
class bnd():
'''Delft3d boundary definition file'''
def __init__(self, fname=None):
self.read_bnd(fname)
def read_bnd(self, fname=None):
'''Read a Delft3d boundary definition file'''
if not fname:
fname = filedialog.askopenfilename()
else:
fname = fname
column_names = ['name','type','forcing','m1','n1','m2','n2',
'reflection coefficient','vertical profile',
'label1','label2']
data = pd.read_csv(fname, delim_whitespace=True,header=None,
names = column_names)
for n in data.columns:
setattr(self, n, np.array(data[n]))
self.num_bnds = np.size(self.name)
def read_grd(self, fname=None):
self.grid = grd(fname)
print('loaded %s' %self.grid.filename)
def get_xy(self):
'''Get x,y coordinates of each boundary section from associated
grid.'''
x1 = []
for i in self.m1:
# m,n indices in .bnd start from 1 and are 1 greater than
# the array size...
if i-1 == self.grid.x[0].size:
x1.append(self.grid.x[0][i-2])
else:
x1.append(self.grid.x[0][i-1])
x2 = []
for i in self.m2:
if i-1 == self.grid.x[0].size:
x2.append(self.grid.x[0][i-2])
else:
x2.append(self.grid.x[0][i-1])
y1 = []
for i in self.n1:
if i-1 == self.grid.y[:,0].size:
y1.append(self.grid.y[:,0][i-2])
else:
y1.append(self.grid.y[:,0][i-1])
y2 = []
for i in self.n2:
if i-1 == self.grid.y[:,0].size:
y2.append(self.grid.y[:,0][i-2])
else:
y2.append(self.grid.y[:,0][i-1])
self.x1 = np.array(x1)
self.x2 = np.array(x2)
self.y1 = np.array(y1)
self.y2 = np.array(y2)