pol_zerorms.py
2.11 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
title = "PI-Offset"
tip = "reset baseline offset to zero"
onein = True
import numpy as np
from scipy.interpolate import InterpolatedUnivariateSpline
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):
units = ('Pixel', 'Degree', 'Arcmin', 'Arcsec')
class FuncParam(DataSet):
s = StringItem('s', default="string")
i = IntItem('i', default=0, max=100, min=0)
a = FloatItem('a', default=1.)
b = BoolItem("bool", default=True)
c = ChoiceItem(_(u"Mode"), zip(units, units), default=units[0])
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 histo(self, data):
ny, nx = data.shape
mask = ~np.isnan(data)
hdata = data[mask]
med = max(5*np.median(hdata), 5*abs(hdata.min()))
#bins = min(int(2*np.log(nx*ny)+0.5), 64)
#bins = min(int((nx*ny)/250.0+0.5), 64)
bins = min(int(np.sqrt(nx*ny)/3.0 + 0.5), 64)
hdata = np.where(abs(hdata) < med, hdata, np.nan)
mask = ~np.isnan(hdata)
hist, xb = np.histogram(hdata[mask], bins=bins)
spline = InterpolatedUnivariateSpline(xb[:-1], hist)
x = np.linspace(-abs(xb[0]), +abs(xb[0]), 64)
y = spline(x)
ymax = np.argmax(hist)
rms = xb[ymax]
return rms
def function(self, m, p):
m.data -= self.histo(m.data)
return m, p