-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis_bin.py
More file actions
50 lines (37 loc) · 1.79 KB
/
analysis_bin.py
File metadata and controls
50 lines (37 loc) · 1.79 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
'''
Analysis bins represent different discharges that are used to calculate the
sandbar analysis. These discharges correspond to different elevations.
'''
from typing import Dict
from logger import Logger
class AnalysisBin:
'''
Analysis bins represent different discharges that are used to calculate the
sandbar analysis. These discharges correspond to different elevations.
'''
def __init__(self, bin_id, title, lower_discharge, upper_discharge):
self.bin_id = bin_id
self.title = title
self.lower_discharge = lower_discharge
self.upper_discharge = upper_discharge
def __repr__(self):
return f'Analysis Bin: {self.bin_id} - {self.title} lower: {self.lower_discharge} upper: {self.upper_discharge}'
def load_analysis_bins(analysis_bin_element) -> Dict[int, AnalysisBin]:
'''
Load analysis bins from input XML file
'''
analysis_bins = {}
log = Logger('Load Bins')
# Note that lower or upper Discharge may be NULL
for bin_tag in analysis_bin_element.iterfind('Bin'):
lower_discharge = float(bin_tag.attrib['lower']) if len(bin_tag.attrib['lower']) > 0 else None
upper_discharge = float(bin_tag.attrib['upper']) if len(bin_tag.attrib['upper']) > 0 else None
analysis_bins[int(bin_tag.attrib['id'])] = AnalysisBin(
int(bin_tag.attrib['id']),
bin_tag.attrib['title'],
lower_discharge,
upper_discharge)
assert len(analysis_bins) > 0, f'{len(analysis_bins)} analysis bins loaded from the input XML file.'
log.info(f'{len(analysis_bins)} analysis bins loaded from the input XML file.')
log.debug('Analysis Bins:', analysis_bins, 'original Element:', analysis_bin_element)
return analysis_bins