maped_RG_dummy.py
1.92 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
title = "SetDummyBox"
tip = "set dummy-box using pixel coordinates"
onein = True
import numpy as np
from guidata.qt.QtGui import QMessageBox
from guidata.dataset.datatypes import DataSet
from guidata.dataset.dataitems import (IntItem, StringItem, ChoiceItem, FloatItem, BoolItem)
from guiqwt.config import _
class NOD3_App:
def __init__(self, parent):
self.parent = parent
self.parent.activateWindow()
def Error(self, msg):
QMessageBox.critical(self.parent.parent(), title,
_(u"Error:")+"\n%s" % str(msg))
def compute_app(self, **args):
class FuncParam(DataSet):
blcx = IntItem('blc(x)', default=0, max=10000, min=0)
blcy = IntItem('blc(y)', default=0, max=10000, min=0)
trcx = IntItem('trc(x)', default=0, max=10000, min=0)
trcy = IntItem('trc(y)', default=0, max=10000, min=0)
name = title.replace(" ", "")
if args == {}:
#param = FuncParam(_(title), "(!) USE VIEW -> AXES:PIXEL TO DETERMINE YOUR INPUTS (!)\nSet Pixel for bottom-left and top-right corner.\nCounting starts at 0.")
param = FuncParam(_(title), "Set Pixel for bottom-left and top-right corner.\nCounting starts at 0.")
else:
param = self.parent.ScriptParameter(name, args)
# if no parameter needed set param to None. activate next line
#param = None
self.Pixel = self.parent.Pixel
self.parent.view_axes_pixel()
self.parent.compute_11(name, lambda m, p: self.function(m, p), param, onein)
def function(self, m, p):
if (p.blcx>p.trcx) or (p.blcy>p.trcy):
self.Error("Box is not properly defined, make sure that blc(x)<=trc(x) and blc(y)<=trc(y)")
return [], None
m.data[p.blcy:p.trcy+1,p.blcx:p.trcx+1]=np.nan
if not self.Pixel:
self.parent.view_axes_coordinate()
return m, p