pol_mapclip.py
2.84 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
title = "PerPol"
tip = "clips maps and devide them"
onein = 2
import numpy as np
import scipy.stats as ss
from scipy import optimize, signal
from guiqwt import pyplot
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):
#s = StringItem('s', default="string")
#i = IntItem('i', default=0, max=100, min=0)
clip = FloatItem('Clip', default=1.)
#b = BoolItem("bool", default=True)
#clipval = ChoiceItem("Clip value", (("Minimum", "Minimum"), ("Dummy", "Dummy"),
clipval = ChoiceItem("Clip value", (("Dummy", "Dummy"), ("RMS", "RMS")), default="Dummy")
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.parent.compute_11(name, lambda m, p: self.function(m, p), param, onein)
def plot(self, xy, p, lh, x0):
x = xy[1][:lh]
y = xy[0][:lh]
self.parent.fig = pyplot.figure("Rice distribution")
sig = str("sigma = %f" % x0)
pyplot.plot(x, y, "b-", label=sig)
pyplot.legend()
pyplot.plot(x, p(x), "r-", label="fit")
pyplot.xlabel("sqrt(U^2 + Q^2)")
pyplot.ylabel("#bins")
pyplot.zlabel("Rice distribution")
#self.parent.fig.win.setWindowIcon(get_icon(sys.path[0]+'/MPIfR.svg'))
pyplot.show(mainloop=False)
def function(self, ms, p):
data = None
for m in ms:
if m.header["MAPTYPE"] == "PI":
PI = m.data
rms = m.header['PSIG']
elif m.header["MAPTYPE"][0] == "I":
m.header["MAPTYPE"] = "I"
I = m.data
else:
self.Error("sorry, please check map type")
return [], p
if p.clipval == "Minimum":
cval = np.nanmin(PI)
elif p.clipval == "RMS":
cval = p.clip*rms
else:
cval = np.nan
Iclip = np.where(I < p.clip*rms, cval, I)
m.data = PI / Iclip
m.header["MAPTYPE"] = 'PP'
if 'EXTNAME' in m.header:
extname = m.header['EXTNAME'].replace("PI", 'PP').replace("I", 'PP')
else:
extname = "MAP-PP"
m.header["EXTNAME"] = extname
return m, p