maped_dummy_repair.py
2.12 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
title = "Repair Dummies"
tip = "repair single dummies if possible"
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 Info(self, msg):
QMessageBox.information(self.parent.parent(), title,
str(msg))
def compute_app(self, **args):
name = title.replace(" ", "")
# if no parameter needed set param to None. activate next line
param = None
self.parent.compute_11(name, lambda m, p: self.function(m, p), param, onein)
def yintpn(self, a, b, c, d, y):
if y == 0.0:
return b
e = b-a
f = b-c
g = e+f+f+d-c
g = g*y-e-f-g
g = g*y-a+c
return 0.5*g*y+b
def repair(self, data):
rows, cols = data.shape
#piy, pix = np.where(np.isnan(data[2:-2,2:-2]))
piy, pix = np.where(np.isnan(data))
notrepaired = 0
for i in range(len(pix)):
try:
#y, x = piy[i]+2, pix[i]+2
y, x = piy[i], pix[i]
if y+1 < rows and not np.isnan(data[y-1, x]) and not np.isnan(data[y+1, x]):
data[y,x] = self.yintpn(data[y-2, x], data[y-1, x], data[y+1, x], data[y+2, x], 0.5)
elif x+1 < cols and not np.isnan(data[y, x-1]) and not np.isnan(data[y, x+1]):
data[y,x] = self.yintpn(data[y, x-2], data[y, x-1], data[y, x+1], data[y, x+2], 0.5)
else:
notrepaired += 1
except:
notrepaired += 1
return notrepaired
def function(self, m, p):
n = self.repair(m.data)
n = self.repair(m.data)
if n > 0:
self.Info(str("%d Dummies can't be repaired!" % n))
return m, p