maped_pmedian.py
1.46 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 = "Median"
tip = "take the median of each pixel from n maps"
onein = False
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):
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 function(self, ms, p):
maps = []
scandir = []
for m in ms:
if 'SCANDIR' in m.header:
sd = m.header['SCANDIR']
if sd not in scandir:
scandir.append(sd)
maps.append(m.data.ravel())
maps = np.array(maps)
out = 0.0*maps[0]
l2 = len(ms)/2
for i in range(len(out)):
a = maps[:,i]
#a.sort()
#out[i] = a[np.where(a == a[l2])[0][0]]
out[i] = np.median(a)
m.data = out.reshape(m.data.shape)
if len(scandir) > 1:
m.header.__delitem__('SCANDIR')
return m, p