Skip to content

Commit

Permalink
Merge pull request #1 from jdha/PyNEMO3
Browse files Browse the repository at this point in the history
Py nemo3
  • Loading branch information
jdha authored Feb 14, 2020
2 parents b1ee0b2 + a666111 commit 6f50bc0
Show file tree
Hide file tree
Showing 37 changed files with 408 additions and 750 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PyNEMO Description
===================
14 changes: 7 additions & 7 deletions pynemo/gui/nemo_bdy_input_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
# pylint: disable=E1103
# pylint: disable=no-name-in-module
# pylint: disable=E1002
from PyQt4 import QtGui
from PyQt5 import QtGui, QtWidgets
from .nemo_bdy_namelist_edit import NameListEditor
from .nemo_bdy_mask_gui import MatplotlibWidget
from PyQt4.QtGui import QSizePolicy
from PyQt4.Qt import Qt
from PyQt5.QtWidgets import QSizePolicy
from PyQt5.Qt import Qt

class InputWindow(QtGui.QDialog):
class InputWindow(QtWidgets.QDialog):
'''
Input Window for editing pyNEMO settings
'''
Expand Down Expand Up @@ -43,15 +43,15 @@ def __init__(self, setup):

self.mpl_widget.set_mask_settings(float(setup.settings['mask_max_depth']), float(setup.settings['mask_shelfbreak_dist']))

splitter = QtGui.QSplitter(Qt.Horizontal)
splitter = QtWidgets.QSplitter(Qt.Horizontal)
splitter.addWidget(self.nl_editor)
splitter.addWidget(self.mpl_widget)

hbox = QtGui.QHBoxLayout()
hbox = QtWidgets.QHBoxLayout()
hbox.addWidget(splitter)
self.setLayout(hbox)
#set the Dialog title
self.setWindowTitle("PyNEMO Settings Editor")
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))
QtWidgets.QApplication.setStyle(QtWidgets.QStyleFactory.create('Cleanlooks'))
#show the window
self.show()
8 changes: 4 additions & 4 deletions pynemo/gui/nemo_bdy_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from scipy import ndimage
import matplotlib.pyplot as plt
from pynemo.utils import gcoms_break_depth
from PyQt4.QtGui import QMessageBox
from PyQt4 import QtCore
from PyQt5.QtWidgets import QMessageBox
from PyQt5 import QtCore

class Mask(object):
"""This is a Mask holder. which reads from a netCDF bathymetry file and
Expand Down Expand Up @@ -199,7 +199,7 @@ def remove_small_regions(self, index):
mask_data[index] = self.data[index]
#connected components
label_mask, num_labels = ndimage.label(mask_data)
mean_values = ndimage.sum(np.ones(self.data.shape),label_mask,range(1, num_labels+1))
mean_values = ndimage.sum(np.ones(self.data.shape),label_mask,list(range(1, num_labels+1)))
max_area_mask = None
if mean_values.size != 0:
max_area_index = np.argmax(mean_values)+1
Expand Down Expand Up @@ -228,7 +228,7 @@ def select_the_largest_region(self):
label_mask, num_labels = ndimage.label(mask_data)
if num_labels == 0: #if mask is empty/clear
return
mean_values = ndimage.sum(np.ones(self.data.shape),label_mask,range(1, num_labels+1))
mean_values = ndimage.sum(np.ones(self.data.shape),label_mask,list(range(1, num_labels+1)))
max_area_mask = None
if mean_values.size != 0:
max_area_index = np.argmax(mean_values)+1
Expand Down
18 changes: 9 additions & 9 deletions pynemo/gui/nemo_bdy_mask_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@
import numpy as np
from .selection_editor import PolygonEditor, BoxEditor
import os.path
from PyQt4.QtCore import pyqtSignal, pyqtSlot, Qt
from nemo_bdy_mask import Mask
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt
from .nemo_bdy_mask import Mask
import logging
from PyQt4.QtGui import QSizePolicy
from PyQt5.QtWidgets import QSizePolicy
from matplotlib.colors import Normalize

mask_alpha = 0.3

from PyQt4 import QtGui
from PyQt5 import QtGui, QtWidgets
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.path import Path
from matplotlib.transforms import Bbox
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
# pylint: disable=E1002
class MatplotlibWidget(QtGui.QWidget):
class MatplotlibWidget(QtWidgets.QWidget):
"""This class is a QWidget for pyNEMO mask plot"""
min_depth = 200.0
shelfbreak_dist = 200.0
mask_type = 0
def __init__(self, parent=None, mask=None, min_depth = 200.0, shelfbreak_dist = 200.0,*args, **kwargs):
""" Initialises the mask, matplot and the navigation toolbar """
super(MatplotlibWidget, self).__init__(parent)
#QtGui.QWidget.__init__(self, parent)
#QtWidgets.QWidget.__init__(self, parent)
self.figure = Figure(*args, **kwargs)
self.canvas = FigureCanvas(self.figure)
self.mask = mask
Expand All @@ -51,7 +51,7 @@ def __init__(self, parent=None, mask=None, min_depth = 200.0, shelfbreak_dist =
self.toolbar.drawing_tool.connect(self.drawing_tool_callback)
self.axes = self.figure.add_subplot(111)
self.cbar = None
layout = QtGui.QVBoxLayout()
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
self.setLayout(layout)
Expand Down Expand Up @@ -126,7 +126,7 @@ def add_mask(self):
x = np.arange(0, self.mask.lon.shape[0])
y = np.arange(0, self.mask.lon.shape[1])
x_vals, y_vals = np.meshgrid(y, x)
grid = zip(x_vals.ravel(), y_vals.ravel())
grid = list(zip(x_vals.ravel(), y_vals.ravel()))

self._drawing_tool.polygon.set_linewidth(1.0)
p_path = Path(self._drawing_tool.polygon.xy)
Expand All @@ -146,7 +146,7 @@ def remove_mask(self):
x = np.arange(0, self.mask.lon.shape[0])
y = np.arange(0, self.mask.lon.shape[1])
x_vals, y_vals = np.meshgrid(y, x)
grid = zip(x_vals.ravel(), y_vals.ravel()) #check for the index
grid = list(zip(x_vals.ravel(), y_vals.ravel())) #check for the index

self._drawing_tool.polygon.set_linewidth(1.0)
p_path = Path(self._drawing_tool.polygon.xy)
Expand Down
4 changes: 2 additions & 2 deletions pynemo/gui/nemo_bdy_mask_gui.py.interactive_cbar
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ from mpl_toolkits.basemap import Basemap, cm
import numpy as np
from .selection_editor import PolygonEditor, BoxEditor
import os.path
from PyQt4.QtCore import pyqtSignal, pyqtSlot, Qt
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt
from nemo_bdy_mask import Mask
import logging
from PyQt4.QtGui import QSizePolicy
from PyQt5.QtGui import QSizePolicy

mask_alpha = 0.3

Expand Down
43 changes: 22 additions & 21 deletions pynemo/gui/nemo_bdy_namelist_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
# pylint: disable=E1103
# pylint: disable=no-name-in-module
# pylint: disable=E1002
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import pyqtSignal, Qt, QRect, QPoint
from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtCore import pyqtSignal, Qt, QRect, QPoint

import ast
from PyQt4.QtGui import QMessageBox, QRegion, QIcon, QToolTip, QCursor
from PyQt5.QtGui import QRegion, QIcon, QCursor
from PyQt5.QtWidgets import QMessageBox, QToolTip

class NameListEditor(QtGui.QWidget):
class NameListEditor(QtWidgets.QWidget):
'''
This class creates a gui for the Namelist file options
'''
Expand All @@ -34,33 +35,33 @@ def init_ui(self):
'''
Initialises the UI components of the GUI
'''
client = QtGui.QWidget(self)
client = QtWidgets.QWidget(self)
# Create the Layout to Grid
grid = QtGui.QGridLayout()
grid = QtWidgets.QGridLayout()

# Loop through the settings and create widgets for each setting
index = 0
for setting in self.settings:
# initialises setting Widget
label = QtGui.QLabel(setting)
qlabel = QtGui.QPushButton("")
qlabel.setIcon(self.style().standardIcon(QtGui.QStyle.SP_MessageBoxQuestion))
label = QtWidgets.QLabel(setting)
qlabel = QtWidgets.QPushButton("")
qlabel.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MessageBoxQuestion))
if type(self.settings[setting]).__name__ in ['str', 'float', 'double',
'int', 'time', 'dict']:
text = QtGui.QLineEdit(self)
text = QtWidgets.QLineEdit(self)
text.setText(str(self.settings[setting]))
text.textChanged.connect(lambda value=setting,\
var_name=setting: self.label_changed(value, var_name))
if self.bool_settings.has_key(setting):
chkbox = QtGui.QCheckBox(self)
if setting in self.bool_settings:
chkbox = QtWidgets.QCheckBox(self)
chkbox.setChecked(self.bool_settings[setting])
chkbox.stateChanged.connect(lambda value=setting,\
var_name=setting:\
self.state_changed(value, var_name))
grid.addWidget(chkbox, index, 0)

elif type(self.settings[setting]).__name__ == 'bool':
text = QtGui.QComboBox(self)
text = QtWidgets.QComboBox(self)
text.insertItem(0, 'True')
text.insertItem(1, 'False')
if self.settings[setting]:
Expand All @@ -83,22 +84,22 @@ def init_ui(self):

client.setLayout(grid)
#scrollbars
scroll_area = QtGui.QScrollArea(self)
scroll_area = QtWidgets.QScrollArea(self)
#scroll_area.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
scroll_area.setWidget(client)

#save cancel buttons
btn_widget = QtGui.QWidget(self)
hbox_layout = QtGui.QHBoxLayout(self)
btn_save = QtGui.QPushButton('Save')
btn_widget = QtWidgets.QWidget(self)
hbox_layout = QtWidgets.QHBoxLayout(self)
btn_save = QtWidgets.QPushButton('Save')
btn_save.clicked.connect(self._btn_save_callback)
self.btn_cancel = QtGui.QPushButton('Close')
self.btn_cancel = QtWidgets.QPushButton('Close')
self.btn_cancel.clicked.connect(self._btn_cancel_callback)
hbox_layout.addWidget(btn_save)
hbox_layout.addWidget(self.btn_cancel)
btn_widget.setLayout(hbox_layout)

box_layout = QtGui.QVBoxLayout(self)
box_layout = QtWidgets.QVBoxLayout(self)
box_layout.addWidget(scroll_area)
box_layout.addWidget(btn_widget)
btn_widget.setMaximumWidth(400)
Expand All @@ -109,7 +110,7 @@ def init_ui(self):

def label_changed(self, value, name):
""" callback when the text is changed in the text box"""
self.new_settings[name] = unicode(value).encode('utf_8')
self.new_settings[name] = str(value).encode('utf_8')

def combo_index_changed(self, value, name):
""" callback when the True/False drop down for the settings which has boolean value
Expand Down Expand Up @@ -153,7 +154,7 @@ def _btn_save_callback(self):
try:
self.mask_settings_update.emit(float(self.settings['mask_max_depth']), float(self.settings['mask_shelfbreak_dist']))
except KeyError:
print 'Set the mask setting mask_max_depth and mask_shelfbreak_dist'
print('Set the mask setting mask_max_depth and mask_shelfbreak_dist')

if self.bool_settings['mask_file']:
self.bathymetry_update.emit(self.settings['bathy'],self.settings['mask_file'])
Expand Down
Loading

0 comments on commit 6f50bc0

Please sign in to comment.