Commit 2bc9dd65 authored by Domanski, Marian M.'s avatar Domanski, Marian M.
Browse files

Merge branch 'master' into 56-v4-1-0-code-review

parents ecf4538d dee5a12e
......@@ -117,3 +117,5 @@ MATLAB/
# FluEgg results
results/
error_log.txt
import os
import sys
from PyQt5.QtWidgets import QApplication
import traceback
import logging
from PyQt5.QtWidgets import QApplication, QMessageBox
from PyQt5.QtCore import Qt
import fluegg
import fluegggui
from fluegggui.gui import AppWindow
if __name__ == '__main__':
# Initialize the UI
fluegg.set_logging_level('critical')
fluegggui.set_logging_level('critical')
app = QApplication(sys.argv)
w = AppWindow()
w.show()
sys.exit(app.exec_())
class FluEggApp:
def __init__(self):
log_filename = os.path.join(os.getcwd(), 'error_log.txt')
formatter = logging.Formatter(
'%(asctime)s - %(message)s')
fh = logging.FileHandler(log_filename, delay=True)
fh.setLevel(logging.ERROR)
fh.setFormatter(formatter)
fluegggui.logger.addHandler(fh)
fluegg.set_logging_level('error')
fluegggui.set_logging_level('error')
sys.excepthook = self.excepthook
self._app = None
self._w = None
self._log_file = log_filename
def excepthook(self, etype, evalue, tb):
fluegggui.logger.error('Unhandled error occurred')
for line in traceback.format_exception(etype, evalue, tb):
fluegggui.logger.error(line.strip())
QMessageBox.warning(
self._w, 'Unhandled Exception',
'An unhandled exception occurred.\n\n' +
'See the file\n{}\n'.format(self._log_file) +
'for more information.')
def run_app(self):
self._app = QApplication(sys.argv)
self._w = AppWindow()
self._w.show()
return self._app.exec_()
fluegg_app = FluEggApp()
app_exit_code = fluegg_app.run_app()
sys.exit(app_exit_code)
......@@ -155,10 +155,11 @@ class RASProject:
"""Fetch RAS file plan name
"""
plan_file_extension = current_plan_line.split('=')[-1]
path, _ = os.path.split(current_project_file_path)
plan_file_list = glob.glob(path + '/*.' + plan_file_extension)
path, proj_file = os.path.split(current_project_file_path)
root, _ = os.path.splitext(proj_file)
plan_file_path = os.path.join(path, root + '.' + plan_file_extension)
with open(plan_file_list[0], 'r') as f:
with open(plan_file_path, 'r') as f:
plan_name_line = f.readline().strip()
return plan_name_line.split('=')[-1]
......@@ -208,11 +209,15 @@ class RASProject:
# convert from RAS distances to FluEgg distances
number_of_cells = profile_data.shape[0]
profile_data.loc[1:number_of_cells - 1, 'CumlDistance_km'] = \
0.5 * (profile_data.loc[1:number_of_cells - 1, 'CumlDistance_km'].values
+ profile_data.loc[2:number_of_cells, 'CumlDistance_km'].values)
profile_data['CumlDistance_km'] = profile_data['CumlDistance_km']/1000
dist_upstream = profile_data['CumlDistance_km'].values
dist_downstream = dist_upstream.max() - dist_upstream
cell_centers = 0.5 * \
(dist_downstream[1:number_of_cells-1] +
dist_downstream[2:number_of_cells])
dist_downstream[1:number_of_cells-1] = cell_centers
profile_data['CumlDistance_km'] = dist_downstream/1000
shear_velocity = self._calc_shear_velocity(ras_data)
profile_data['Ustar_mps'] = shear_velocity
......@@ -220,6 +225,9 @@ class RASProject:
profile_data['Vlat_mps'] = 0
profile_data['Temp_C'] = temperature
profile_data = profile_data.sort_values('CumlDistance_km')
profile_data = profile_data.reset_index(drop=True)
feet_to_meters = (2.54 * 12) / 100
if self._ras_units == 'English':
......
......@@ -125,44 +125,6 @@ class TestRASProject(unittest.TestCase):
project.close()
def test_ras_units_conversion(self):
# Tets RAS unit conversions
project = self._create_ras_project_unsteady()
self.assertEqual(project._n_conversion, 1.4859)
ras_data = project._get_data_from_ras(1)
shear_velocity = project._calc_shear_velocity(ras_data)
profile_data = project._get_profile_data(1, 22)
feet_to_meters = (2.54 * 12) / 100
self.assertEqual(
shear_velocity[1] * feet_to_meters,
profile_data['Ustar_mps'][1])
self.assertEqual(
ras_data['Hydr Depth C'][1] * feet_to_meters,
profile_data['Depth_m'][1])
self.assertEqual(
ras_data['Vel Chnl'][1] * feet_to_meters,
profile_data['Vmag_mps'][1])
self.assertAlmostEqual(
ras_data['ChannelDist'][2] * feet_to_meters / 1000 / 2,
profile_data['CumlDistance_km'][1])
self.assertEqual(
ras_data['Q Channel'][1] * feet_to_meters ** 3,
profile_data['Q_cms'][1])
manning_values = ras_data['Mann Wtd Chnl'].values
hydraulic_radius = ras_data['Hydr Radius C'].values
channel_velocity = ras_data['Vel Chnl']
ks = (8.1 * (manning_values / project._n_conversion)
* np.sqrt(project._gravity))**6
shear_velocity = np.abs(
channel_velocity /
(8.1 * ((hydraulic_radius / ks) ** (1 / 6))))
shear_velocity *= feet_to_meters
self.assertEqual(shear_velocity.all(),
profile_data['Ustar_mps'].all())
project.close()
if __name__ == '__main__':
unittest.main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment