Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Get and set BRF parameters using the user config system #320

Merged
merged 7 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions gwhat/brf_mod/kgs_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
# Licensed under the terms of the GNU General Public License.


# ---- Imports: Standard Libraries

# ---- Standard library imports
import os
import os.path as osp
import requests
import zipfile
import io


# ---- Imports: Third Parties

# ---- Third party imports
from PyQt5.QtCore import Qt, QPoint
from PyQt5.QtCore import pyqtSignal as QSignal
from PyQt5.QtGui import QImage
Expand Down Expand Up @@ -142,23 +140,29 @@ def __initGUI__(self):
self.setContentsMargins(10, 10, 10, 10)

# Detrend and Correct Options
self.baro_spinbox = myqt.QDoubleSpinBox(100, 0, show_buttons=True)
self.baro_spinbox = QSpinBox()
self.baro_spinbox.setRange(0, 9999)
self.baro_spinbox.setValue(CONF.get('brf', 'nbr_of_baro_lags'))
self.baro_spinbox.setKeyboardTracking(True)

self.earthtides_spinbox = myqt.QDoubleSpinBox(
100, 0, show_buttons=True)
self.earthtides_spinbox = QSpinBox()
self.earthtides_spinbox.setRange(0, 9999)
self.earthtides_spinbox.setValue(
CONF.get('brf', 'nbr_of_earthtides_lags'))
self.earthtides_spinbox.setKeyboardTracking(True)
self.earthtides_spinbox.setEnabled(
CONF.get('brf', 'compute_with_earthtides'))

self.earthtides_cbox = QCheckBox('Nbr of ET lags :')
self.earthtides_cbox.setChecked(True)
self.earthtides_cbox.stateChanged.connect(
self.earthtides_cbox.setChecked(
CONF.get('brf', 'compute_with_earthtides'))
self.earthtides_cbox.toggled.connect(
lambda: self.earthtides_spinbox.setEnabled(
self.earthtides_cbox.isChecked()))

self.detrend_waterlevels_cbox = QCheckBox('Detrend water levels')
self.detrend_waterlevels_cbox.setChecked(True)
self.detrend_waterlevels_cbox.setChecked(
CONF.get('brf', 'detrend_waterlevels'))

# Setup options layout.
options_layout = QGridLayout()
Expand Down Expand Up @@ -233,6 +237,14 @@ def close(self):
""""Clos this brf manager"""
CONF.set('brf', 'graphs_labels_language',
self.viewer.btn_language.language)
CONF.set('brf', 'compute_with_earthtides',
self.earthtides_cbox.isChecked())
CONF.set('brf', 'nbr_of_earthtides_lags',
self.earthtides_spinbox.value())
CONF.set('brf', 'nbr_of_baro_lags',
self.baro_spinbox.value())
CONF.set('brf', 'detrend_waterlevels',
self.detrend_waterlevels_cbox.isChecked())
super().close()

@property
Expand Down Expand Up @@ -322,9 +334,9 @@ def __install_kgs_brf_installer(self):
"""
self.kgs_brf_installer = KGSBRFInstaller()
self.kgs_brf_installer.sig_kgs_brf_installed.connect(
self.__uninstall_kgs_brf_installer)
self.addWidget(self.kgs_brf_installer, 0, 0,
self.rowCount(), self.columnCount())
self.__uninstall_kgs_brf_installer)
self.addWidget(
self.kgs_brf_installer, 0, 0, self.rowCount(), self.columnCount())

def __uninstall_kgs_brf_installer(self):
"""
Expand Down Expand Up @@ -442,7 +454,7 @@ def __initGUI__(self):
self.current_brf.setAlignment(Qt.AlignCenter)
self.current_brf.setButtonSymbols(QAbstractSpinBox.NoButtons)
self.current_brf.setCorrectionMode(
QAbstractSpinBox.CorrectToNearestValue)
QAbstractSpinBox.CorrectToNearestValue)
self.current_brf.valueChanged.connect(self.navigate_brf)
self.current_brf.setValue(0)

Expand Down Expand Up @@ -625,7 +637,7 @@ def select_savefig_path(self):

dialog = QFileDialog()
fname, ftype = dialog.getSaveFileName(
self, "Save Figure", ddir, '*.pdf;;*.svg')
self, "Save Figure", ddir, '*.pdf;;*.svg')
ftype = ftype.replace('*', '')
if fname:
if not osp.samefile(osp.dirname(ddir), osp.dirname(fname)):
Expand Down Expand Up @@ -656,7 +668,7 @@ def select_export_brfdata_filepath(self):

dialog = QFileDialog()
fname, ftype = dialog.getSaveFileName(
self, "Export Data", ddir, "*.xlsx;;*.xls;;*.csv")
self, "Export Data", ddir, "*.xlsx;;*.xls;;*.csv")
ftype = ftype.replace('*', '')
if fname:
if not osp.samefile(osp.dirname(ddir), osp.dirname(fname)):
Expand Down Expand Up @@ -755,7 +767,7 @@ def __initGUI__(self):
self._markersize['widget'].setValue(5)
self._markersize['widget'].setRange(0, 25)
self._markersize['widget'].valueChanged.connect(
self._graphconf_changed)
self._graphconf_changed)

# ---- Y-Axis Options Widgets

Expand Down Expand Up @@ -792,7 +804,7 @@ def __initGUI__(self):
self._xlim['units'].addItems(['Hours', 'Days'])
self._xlim['units'].setCurrentIndex(1)
self._xlim['units'].currentIndexChanged.connect(
self.time_units_changed)
self.time_units_changed)
self._xlim['min'] = QSpinBox()
self._xlim['min'].setValue(0)
self._xlim['min'].setSingleStep(1)
Expand Down
29 changes: 19 additions & 10 deletions gwhat/brf_mod/tests/test_brf_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,26 @@
# This file is part of GWHAT (Ground-Water Hydrograph Analysis Toolbox).
# Licensed under the terms of the GNU General Public License.

# Standard library imports
# ---- Standard library imports
import os
import os.path as osp
os.environ['GWHAT_PYTEST'] = 'True'

# Third party imports
# ---- Third party imports
import pytest
from PyQt5.QtCore import Qt

# Local imports
from gwhat.brf_mod.kgs_gui import (BRFManager, KGSBRFInstaller, QMessageBox,
QFileDialog)
# ---- Local imports
from gwhat.brf_mod.kgs_gui import (
BRFManager, KGSBRFInstaller, QMessageBox, QFileDialog)
from gwhat.projet.reader_projet import ProjetReader
from gwhat.projet.reader_waterlvl import WLDataFrame
from gwhat.config.main import CONF


# =============================================================================
# ---- Pytest Fixtures

# =============================================================================
@pytest.fixture(scope="module")
def project(tmp_path_factory):
# Create a project and add add the wldset to it.
Expand All @@ -46,13 +49,19 @@ def wldataset(project):

@pytest.fixture
def brfmanager(qtbot):
# We need to reset the configs to defaults after each test to make sure
# they can be run independently one from another.
CONF.reset_to_defaults()

brfmanager = BRFManager(None)
qtbot.addWidget(brfmanager)
qtbot.addWidget(brfmanager.viewer)
return brfmanager


# =============================================================================
# ---- Tests BRFManager
# =============================================================================
@pytest.mark.skipif(os.environ.get('CI', None) is None,
reason="We do not want to run this locally")
def test_install_kgs_brf(brfmanager, mocker, qtbot):
Expand Down Expand Up @@ -125,8 +134,9 @@ def test_calcul_brf(brfmanager, wldataset, qtbot):
assert brfmanager.viewer.tbar.isEnabled()


# =============================================================================
# ---- Tests BRFViewer

# =============================================================================
@pytest.mark.skipif(os.name == 'posix',
reason="This feature is not supported on Linux")
def test_save_brf_figure(brfmanager, wldataset, mocker, qtbot,
Expand Down Expand Up @@ -177,7 +187,7 @@ def test_graph_panel(brfmanager, wldataset, mocker, qtbot):
assert(graph_opt_panel.xmin is None)
assert(graph_opt_panel.xmax is None)
assert(graph_opt_panel.xscale is None)
assert(graph_opt_panel.time_units is 'auto')
assert(graph_opt_panel.time_units == 'auto')

graph_opt_panel._xlim['auto'].setChecked(False)
assert(graph_opt_panel.xmin == 0)
Expand Down Expand Up @@ -248,5 +258,4 @@ def test_del_all_brf_result(brfmanager, wldataset, mocker, qtbot):


if __name__ == "__main__":
pytest.main(['-x', os.path.basename(__file__), '-v', '-rw'])
# pytest.main()
pytest.main(['-x', __file__, '-v', '-rw'])
4 changes: 3 additions & 1 deletion gwhat/brf_mod/tests/test_kgs_brf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
__install_dir__, 'tests', 'data', 'sample_BRFOutput.txt')


# =============================================================================
# ---- Tests BRFManager
# =============================================================================
def test_read_brf_output():
"""Test reading output data textfile from the KGS_BRF software."""
dataf = read_brf_output(BRFOUT_FNAME)
Expand Down Expand Up @@ -63,4 +65,4 @@ def test_read_brf_output():


if __name__ == "__main__":
pytest.main(['-x', os.path.basename(__file__), '-v', '-rw'])
pytest.main(['-x', __file__, '-v', '-rw'])
7 changes: 6 additions & 1 deletion gwhat/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
}
),
('brf',
{'graphs_labels_language': 'english'}
{'graphs_labels_language': 'english',
'compute_with_earthtides': True,
'nbr_of_earthtides_lags': 100,
'nbr_of_baro_lags': 100,
'detrend_waterlevels': True,
}
),
]

Expand Down