From 3161f14b88d3213b1a2428e25c29ae35074644af Mon Sep 17 00:00:00 2001 From: Gama Anderson Date: Sat, 21 May 2016 15:14:37 +0200 Subject: [PATCH 1/2] lock nyquist --- artview/plugins/manual_unfold.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/artview/plugins/manual_unfold.py b/artview/plugins/manual_unfold.py index 04cb14c..cae3033 100644 --- a/artview/plugins/manual_unfold.py +++ b/artview/plugins/manual_unfold.py @@ -57,6 +57,7 @@ def __init__(self, Vradar=None, Vpoints=None, name=" ManualUnfold", instance. ''' super(ManualUnfold, self).__init__(name=name, parent=parent) + self.lockNyquist = False if Vradar is None: self.Vradar = Variable(None) @@ -179,6 +180,7 @@ def unfold(self, side): radar.fields[corrVel]['valid_min'] = - 1.5 * nyquist if 'valid_max' not in radar.fields[corrVel]: radar.fields[corrVel]['valid_max'] = 1.5 * nyquist + self.lockNyquist = True self.Vradar.update(strong_update) # save for undoing @@ -202,6 +204,7 @@ def foldBack(self): data = radar.fields[corrVel]['data'] data = data - 2 * unfold * nyquist radar.fields[corrVel]['data'] = data + self.lockNyquist = True self.Vradar.update() def _displayHelp(self): @@ -235,9 +238,10 @@ def NewRadar(self, variable, strong): if self.Vradar.value is None: return - if strong: + if strong and not self.lockNyquist: nyquist_vel = self.Vradar.value.get_nyquist_vel(0, True) self.nyquistVelocity.setValue(nyquist_vel) - + elif self.lockNyquist: + self.lockNyquist = False _plugins = [ManualUnfold] From c9f9d26bb49245db19b6ee53f0c14b5d639424f2 Mon Sep 17 00:00:00 2001 From: Gama Anderson Date: Sat, 21 May 2016 16:12:27 +0200 Subject: [PATCH 2/2] save before moving files --- artview/components/menu.py | 24 ++++++++++++++++++++++++ artview/core/common.py | 17 +++++++++++++++++ artview/plugins/dealias_region_based.py | 1 + artview/plugins/dealias_unwrap_phase.py | 1 + artview/plugins/manual_filter.py | 2 ++ artview/plugins/manual_unfold.py | 5 ++++- artview/plugins/phase_proc_lp.py | 1 + 7 files changed, 50 insertions(+), 1 deletion(-) diff --git a/artview/components/menu.py b/artview/components/menu.py index 7588ddd..1bad6c7 100644 --- a/artview/components/menu.py +++ b/artview/components/menu.py @@ -65,6 +65,7 @@ def __init__(self, pathDir=None, filename=None, Vradar=None, Vgrid=None, for m in mode: self.mode.append(m.lower()) self.Vradar = Vradar + self.current_container = self.Vradar self.Vgrid = Vgrid self.Vfilelist = Vfilelist self.sharedVariables = {"Vradar": None, @@ -99,9 +100,22 @@ def keyPressEvent(self, event): '''Change data file with left and right arrow keys.''' if event.key() == QtCore.Qt.Key_Right: # Menu control the file and open the radar + resp = True + if hasattr(self.current_container.value, 'changed') and self.current_container.value.changed: + resp = common.ShowQuestionYesNo("Save changes before moving to next File?") + if resp == QtGui.QMessageBox.Yes: + self.saveCurrent() + elif resp != QtGui.QMessageBox.No: + return self.AdvanceFileSelect(self.fileindex + 1) elif event.key() == QtCore.Qt.Key_Left: # Menu control the file and open the radar + if hasattr(self.current_container.value, 'changed') and self.current_container.value.changed: + resp = common.ShowQuestionYesNo("Save changes before moving to next File?") + if resp == QtGui.QMessageBox.Yes: + self.saveCurrent() + elif resp != QtGui.QMessageBox.No: + return self.AdvanceFileSelect(self.fileindex - 1) else: QtGui.QWidget.keyPressEvent(self, event) @@ -150,6 +164,12 @@ def showFileDialog(self): self.filename = filename self._openfile() + def saveCurrent(self): + if self.current_container == self.Vradar: + self.saveRadar() + elif self.current_container == self.Vgrid: + self.saveGrid() + def saveRadar(self): ''' Open a dialog box to save radar file. @@ -612,6 +632,7 @@ def _openfile(self, filename=None): # Add the filename for Display radar.filename = self.filename self.Vradar.change(radar) + self.current_container = self.Vradar return except: try: @@ -619,6 +640,7 @@ def _openfile(self, filename=None): # Add the filename for Display radar.filename = self.filename self.Vradar.change(radar) + self.current_container = self.Vradar return except: import traceback @@ -629,11 +651,13 @@ def _openfile(self, filename=None): grid = pyart.io.read_grid( self.filename, delay_field_loading=True) self.Vgrid.change(grid) + self.current_container = self.Vgrid return except: try: grid = pyart.io.read_grid(self.filename) self.Vgrid.change(grid) + self.current_container = self.Vgrid return except: import traceback diff --git a/artview/core/common.py b/artview/core/common.py index 9dd90c0..3dd0bf1 100644 --- a/artview/core/common.py +++ b/artview/core/common.py @@ -54,6 +54,23 @@ def ShowQuestion(msg): return response +def ShowQuestionYesNo(msg): + ''' + Show a Question message with yes no. + + Parameters:: + ---------- + msg - string + Message to display in MessageBox. + ''' + Dialog = QtGui.QDialog() + response = QtGui.QMessageBox.question( + Dialog, "Question", msg, + QtGui.QMessageBox.Yes, QtGui.QMessageBox.No, + QtGui.QMessageBox.Cancel) + + return response + def ShowLongText(msg, modal=True, set_html=False): ''' diff --git a/artview/plugins/dealias_region_based.py b/artview/plugins/dealias_region_based.py index 086035a..2575d7f 100644 --- a/artview/plugins/dealias_region_based.py +++ b/artview/plugins/dealias_region_based.py @@ -233,6 +233,7 @@ def dealias_region_based(self): # add fields and update self.Vradar.value.add_field(name, field, True) + self.Vradar.value.changed = True self.Vradar.update(strong_update) print("Correction took %fs" % (t1-t0)) diff --git a/artview/plugins/dealias_unwrap_phase.py b/artview/plugins/dealias_unwrap_phase.py index 1de6701..0730937 100644 --- a/artview/plugins/dealias_unwrap_phase.py +++ b/artview/plugins/dealias_unwrap_phase.py @@ -220,6 +220,7 @@ def dealias_unwrap_phase(self): # add fields and update self.Vradar.value.add_field(name, field, True) + self.Vradar.value.changed = True self.Vradar.update(strong_update) print("Correction took %fs" % (t1-t0)) diff --git a/artview/plugins/manual_filter.py b/artview/plugins/manual_filter.py index 1dc17ad..625b628 100644 --- a/artview/plugins/manual_filter.py +++ b/artview/plugins/manual_filter.py @@ -164,6 +164,7 @@ def removeFromField(self): data.mask[mask_ray, mask_range] = True self.Vradar.value.fields[self.Vfield.value]['data'] = data + self.Vradar.value.changed = True self.Vradar.update() def removeFromRadar(self): @@ -180,6 +181,7 @@ def removeFromRadar(self): data.mask[mask_ray, mask_range] = True self.Vradar.value.fields[field]['data'] = data + self.Vradar.value.changed = True self.Vradar.update() def reset(self): diff --git a/artview/plugins/manual_unfold.py b/artview/plugins/manual_unfold.py index cae3033..36c89a4 100644 --- a/artview/plugins/manual_unfold.py +++ b/artview/plugins/manual_unfold.py @@ -181,6 +181,7 @@ def unfold(self, side): if 'valid_max' not in radar.fields[corrVel]: radar.fields[corrVel]['valid_max'] = 1.5 * nyquist self.lockNyquist = True + self.Vradar.value.changed = True self.Vradar.update(strong_update) # save for undoing @@ -205,6 +206,7 @@ def foldBack(self): data = data - 2 * unfold * nyquist radar.fields[corrVel]['data'] = data self.lockNyquist = True + self.Vradar.value.changed = True self.Vradar.update() def _displayHelp(self): @@ -240,7 +242,8 @@ def NewRadar(self, variable, strong): if strong and not self.lockNyquist: nyquist_vel = self.Vradar.value.get_nyquist_vel(0, True) - self.nyquistVelocity.setValue(nyquist_vel) + if nyquist_vel > 0: + self.nyquistVelocity.setValue(nyquist_vel) elif self.lockNyquist: self.lockNyquist = False diff --git a/artview/plugins/phase_proc_lp.py b/artview/plugins/phase_proc_lp.py index 82c5558..f13463a 100644 --- a/artview/plugins/phase_proc_lp.py +++ b/artview/plugins/phase_proc_lp.py @@ -296,6 +296,7 @@ def phase_proc_lp(self): # add fields and update self.Vradar.value.add_field(reproc_phase_name, reproc_phase, True) self.Vradar.value.add_field(sob_kdp_name, sob_kdp, True) + self.Vradar.value.changed = True self.Vradar.update(strong_update) print("Correction took %fs" % (t1-t0))