Skip to content

Commit 038957a

Browse files
format black
1 parent 989431c commit 038957a

1 file changed

Lines changed: 90 additions & 72 deletions

File tree

schimpy/schism_structure.py

Lines changed: 90 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,24 @@
1616
OP_UP = 4
1717
HEIGHT = 5
1818

19+
1920
class SchismStructure(object):
20-
""" A class to hold structure information
21-
"""
21+
"""A class to hold structure information"""
22+
2223
def __init__(self):
2324
self._name = None
2425
self._reference = None
2526
self._ref_pair = (None, None)
2627
self._pairs = []
27-
self._type = None # Just lower case name
28+
self._type = None # Just lower case name
2829
self._n_duplicate = 0
2930
self._properties = None
3031
self._timeseries = None
31-
self._coords = None # Pair of physical coords
32+
self._coords = None # Pair of physical coords
3233

33-
# def __str__(self):
34-
# return "%s %s %s" % (self._name, self._type,
35-
# " ".join(map(str,self._properties)))
34+
# def __str__(self):
35+
# return "%s %s %s" % (self._name, self._type,
36+
# " ".join(map(str,self._properties)))
3637

3738
@property
3839
def name(self):
@@ -111,20 +112,19 @@ def coords(self, value):
111112

112113

113114
class SchismStructureIO(BaseIO):
114-
""" A class to manage hydraulic structure I/O files
115-
"""
115+
"""A class to manage hydraulic structure I/O files"""
116+
116117
def __init__(self, input):
117118
"""
118-
input = a SCHISM input instance
119+
input = a SCHISM input instance
119120
"""
120121
super(SchismStructureIO, self).__init__()
121122
self._input = input
122123

123124
def read(self, fname):
124-
""" Read in 'hydraulics.in' file.
125-
"""
125+
"""Read in 'hydraulics.in' file."""
126126
print("Reading in" + fname + "...")
127-
f = open(fname, 'r')
127+
f = open(fname, "r")
128128
# # of blocks
129129
tokens, ok = self._read_and_parse_line(f, 1)
130130
n_structures = int(tokens[0])
@@ -142,7 +142,7 @@ def read(self, fname):
142142
# # of pairs and reference pairs
143143
tokens, ok = self._read_and_parse_line(f, 3)
144144
n_pairs = int(tokens[0])
145-
ref_pair = (int(tokens[1]) - 1 , int(tokens[2]) - 1)
145+
ref_pair = (int(tokens[1]) - 1, int(tokens[2]) - 1)
146146
struct.reference_pair = ref_pair
147147
pairs = []
148148
# Pairs
@@ -177,8 +177,7 @@ def read(self, fname):
177177
coeff = float(tokens[0])
178178
op_down = float(tokens[1])
179179
op_up = float(tokens[2])
180-
struct.properties = [elevation, width, height,
181-
coeff, op_down, op_up]
180+
struct.properties = [elevation, width, height, coeff, op_down, op_up]
182181
elif struct_type == "transfer":
183182
tokens, ok = self._read_and_parse_line(f, 1)
184183
flow = float(tokens[0])
@@ -196,10 +195,9 @@ def read(self, fname):
196195
f.close()
197196
print("Done reading a structure file.")
198197

199-
def write(self, fname='hydraulics.in'):
200-
""" Write out 'hydraulics.in' file.
201-
"""
202-
f = open(fname, 'w')
198+
def write(self, fname="hydraulics.in"):
199+
"""Write out 'hydraulics.in' file."""
200+
f = open(fname, "w")
203201
buf = "%d !# of structures\n" % self._input.n_structures()
204202
f.write(buf)
205203
buf = "%f !Nudging factor\n" % self._input.nudging
@@ -211,11 +209,15 @@ def write(self, fname='hydraulics.in'):
211209
buf = "%d %s\n" % (i, struct.name)
212210
f.write(buf)
213211
# # of node pairs and reference nodes
214-
buf = "%d %d %d ! # of node-pairs, 2 ref." \
215-
"nodes (global indices) for 2 faces\n" \
216-
% (struct.n_node_pairs(),
217-
struct.reference_pair[0] + 1,
218-
struct.reference_pair[1] + 1)
212+
buf = (
213+
"%d %d %d ! # of node-pairs, 2 ref."
214+
"nodes (global indices) for 2 faces\n"
215+
% (
216+
struct.n_node_pairs(),
217+
struct.reference_pair[0] + 1,
218+
struct.reference_pair[1] + 1,
219+
)
220+
)
219221
f.write(buf)
220222
# node pairs
221223
for pair in struct.node_pairs:
@@ -225,89 +227,105 @@ def write(self, fname='hydraulics.in'):
225227
buf = "%s ! struct type\n" % struct.type
226228
f.write(buf)
227229
# nduplicate
228-
k = 'n_duplicates'
229-
n_duplicates = struct.properties[k] if k in struct.properties else 0.
230+
k = "n_duplicates"
231+
n_duplicates = struct.properties[k] if k in struct.properties else 0.0
230232
buf = "%d ! n_duplicates\n" % n_duplicates
231233
f.write(buf)
232234
# parameters
233235
if struct.type == "weir" or struct.type == "culvert":
234-
val = struct.properties['width'] if struct.type == "weir" else struct.properties['radius']
235-
buf = "%f %f ! elevation, width or radius\n" % \
236-
(struct.properties['elevation'],
237-
val)
236+
val = (
237+
struct.properties["width"]
238+
if struct.type == "weir"
239+
else struct.properties["radius"]
240+
)
241+
buf = "%f %f ! elevation, width or radius\n" % (
242+
struct.properties["elevation"],
243+
val,
244+
)
238245
f.write(buf)
239-
buf = "%f %f %f ! coef, op_downstream, op_upstream\n" % \
240-
(struct.properties['coefficient'],
241-
struct.properties['op_downstream'],
242-
struct.properties['op_upstream'])
246+
buf = "%f %f %f ! coef, op_downstream, op_upstream\n" % (
247+
struct.properties["coefficient"],
248+
struct.properties["op_downstream"],
249+
struct.properties["op_upstream"],
250+
)
243251
f.write(buf)
244252
elif struct.type == "radial" or struct.type == "orifice":
245-
buf = "%f %f %f ! elevation, width, height or radius\n" % \
246-
(struct.properties['elevation'],
247-
struct.properties['width'],
248-
struct.properties['height'])
253+
buf = "%f %f %f ! elevation, width, height or radius\n" % (
254+
struct.properties["elevation"],
255+
struct.properties["width"],
256+
struct.properties["height"],
257+
)
249258
f.write(buf)
250-
buf = "%f %f %f ! coef, op_downstream, op_upstream\n" % \
251-
(struct.properties['coefficient'],
252-
struct.properties['op_downstream'],
253-
struct.properties['op_upstream'])
259+
buf = "%f %f %f ! coef, op_downstream, op_upstream\n" % (
260+
struct.properties["coefficient"],
261+
struct.properties["op_downstream"],
262+
struct.properties["op_upstream"],
263+
)
254264
f.write(buf)
255265
elif struct.type == "radial_relheight":
256-
buf = "%f %f %f ! elevation, width, height\n" % \
257-
(struct.properties['elevation'],
258-
struct.properties['width'],
259-
struct.properties['height'])
266+
buf = "%f %f %f ! elevation, width, height\n" % (
267+
struct.properties["elevation"],
268+
struct.properties["width"],
269+
struct.properties["height"],
270+
)
260271
f.write(buf)
261-
buf = "%f %f ! coef, coef_height\n" % \
262-
(struct.properties['coefficient'],
263-
struct.properties['coefficient_height'])
272+
buf = "%f %f ! coef, coef_height\n" % (
273+
struct.properties["coefficient"],
274+
struct.properties["coefficient_height"],
275+
)
264276
f.write(buf)
265-
buf = "%f %f ! op_downstream, op_upstream\n" % \
266-
(struct.properties['op_downstream'],
267-
struct.properties['op_upstream'])
277+
buf = "%f %f ! op_downstream, op_upstream\n" % (
278+
struct.properties["op_downstream"],
279+
struct.properties["op_upstream"],
280+
)
268281
f.write(buf)
269282
elif struct.type == "weir_culvert":
270-
buf = "%f %f ! elevation and width for weir\n" % \
271-
(struct.properties['elevation'],
272-
struct.properties['width'])
283+
buf = "%f %f ! elevation and width for weir\n" % (
284+
struct.properties["elevation"],
285+
struct.properties["width"],
286+
)
273287
f.write(buf)
274-
buf = "%f %f %f ! coef, op_downstream, op_upstream for weirs\n" % \
275-
(struct.properties['coefficient'],
276-
struct.properties['op_downstream'],
277-
struct.properties['op_upstream'])
288+
buf = "%f %f %f ! coef, op_downstream, op_upstream for weirs\n" % (
289+
struct.properties["coefficient"],
290+
struct.properties["op_downstream"],
291+
struct.properties["op_upstream"],
292+
)
278293
f.write(buf)
279294
buf = "%d ! n_duplicates for culverts\n" % (
280-
struct.properties['culvert_n_duplicates'])
295+
struct.properties["culvert_n_duplicates"]
296+
)
281297
f.write(buf)
282-
buf = "%f %f\n" % (struct.properties['culvert_elevation'],
283-
struct.properties['culvert_radius'])
298+
buf = "%f %f\n" % (
299+
struct.properties["culvert_elevation"],
300+
struct.properties["culvert_radius"],
301+
)
284302
f.write(buf)
285-
buf = "%f %f %f ! coef, op_downstream, op_upstream for culverts\n" % \
286-
(struct.properties['culvert_coefficient'],
287-
struct.properties['culvert_op_downstream'],
288-
struct.properties['culvert_op_upstream'])
303+
buf = "%f %f %f ! coef, op_downstream, op_upstream for culverts\n" % (
304+
struct.properties["culvert_coefficient"],
305+
struct.properties["culvert_op_downstream"],
306+
struct.properties["culvert_op_upstream"],
307+
)
289308
f.write(buf)
290309
elif struct.type == "transfer":
291-
buf = "%f ! flow\n" % struct.properties['flow']
310+
buf = "%f ! flow\n" % struct.properties["flow"]
292311
f.write(buf)
293312
else:
294313
raise Exception("Not supported structure type")
295314

296-
buf = "%d ! time series enabled\n" % struct.properties['use_time_series']
315+
buf = "%d ! time series enabled\n" % struct.properties["use_time_series"]
297316
f.write(buf)
298317

299318
f.flush()
300319
f.close()
301320

302321
def _read_line_and_split(self, f, lc, expected_count=0):
303322
"""
304-
returns: (tokens, lc), tokens are parsed items and lc is
305-
the line counter after reading a line.
323+
returns: (tokens, lc), tokens are parsed items and lc is
324+
the line counter after reading a line.
306325
"""
307326
tokens = f.readline().split()
308327
lc += 1
309328
if expected_count > 0 and len(tokens) < expected_count:
310329
print("Line #: {}".format(lc))
311330
raise Exception("Line is corrupted.")
312331
return tokens, lc
313-

0 commit comments

Comments
 (0)