filter_wiener.py
1.28 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
title = "Wiener Filter"
tip = "applies Wiener filter to data"
onein = True
import numpy as np
import scipy.signal as sps
from guidata.dataset.datatypes import DataSet
from guidata.dataset.dataitems import (IntItem, FloatArrayItem, StringItem,
ChoiceItem, FloatItem, DictItem,
BoolItem)
from guiqwt.config import _
class NOD3_App:
def __init__(self, parent):
self.parent = parent
self.parent.activateWindow()
def compute_app(self, **args):
class FuncParam(DataSet):
size = IntItem('Size:')
noise = FloatItem('Noise:')
name = title.replace(" ", "")
if args == {}:
param = FuncParam(_(title), "description")
else:
param = self.parent.ScriptParameter(name, args)
# if no parameter needed set param to None. activate next line
#param = None
self.name = name
self.parent.compute_11(name, lambda m, p: self.function(m, p), param, onein)
def function(self, m, p):
mask = np.isnan(m.data)
data = np.where(mask, np.nanmin(m.data), m.data)
data = sps.wiener(data, mysize=(p.size, p.size), noise=p.noise**2)
m.data = np.where(mask, np.nan, data)
return m, p